introduce roundToIconSize(int size)

return a size rounded tothe nearest inferior standard icon size.
sizes larger than iconSizes.huge, it will be returned unmodified
Reviewed by: Kai Uwe Broulik <kde@privat.broulik.de>

Change-Id: I85c575ea1cc7965ae9bede9e5a8b7b4cb342580e
This commit is contained in:
Marco Martin 2014-09-19 16:38:22 +02:00
parent cd8c134578
commit b98fdd7753
2 changed files with 25 additions and 0 deletions

View File

@ -104,6 +104,23 @@ QQmlPropertyMap *Units::iconSizes() const
return m_iconSizes;
}
int Units::roundToIconSize(int size) const
{
if (size < devicePixelIconSize(KIconLoader::SizeSmall)) {
return devicePixelIconSize(KIconLoader::SizeSmall/2);
} else if (size < devicePixelIconSize(KIconLoader::SizeSmallMedium)) {
return devicePixelIconSize(KIconLoader::SizeSmall);
} else if (size < devicePixelIconSize(KIconLoader::SizeMedium)) {
return devicePixelIconSize(KIconLoader::SizeSmallMedium);
} else if (size < devicePixelIconSize(KIconLoader::SizeLarge)) {
return devicePixelIconSize(KIconLoader::SizeMedium);
} else if (size < devicePixelIconSize(KIconLoader::SizeEnormous)) {
return devicePixelIconSize(KIconLoader::SizeHuge);
} else {
return size;
}
}
int Units::devicePixelIconSize(const int size) const
{
/* in kiconloader.h

View File

@ -122,6 +122,14 @@ public:
*/
QQmlPropertyMap *iconSizes() const;
/**
* @return a size rounded tothe nearest inferior standard icon size.
* sizes larger than iconSizes.huge, it will be returned unmodified
* @param int size the size we want to be rounded down
* @see iconSizes
*/
Q_INVOKABLE int roundToIconSize(int size) const;
/**
* @return Pixel value for large spacing between elements.
* @since 5.0