Introduce units.iconSizeHints.* to provide user-configurable icon size hints

Summary:
In effect this is meant to resurrect the "Panel" icon size setting from
the Icons -> Advanced KCM in System Settings, for use as a ceiling on
panel icons to avoid them taking up too much space, especially in wide
vertical panels.

Previously, the actually-unused "Desktop" size hint was added to the
iconSizes map. I believe this was in error, as the size hints are
semantically different from the size classes. This patch marks the
"desktop" iconSizes map entry as deprecated and makes it available
under iconSizeHints instead.

The soon-to-be-updated D5592 will demonstrate this API in use.

CCBUG:378443

Reviewers: #plasma, mart

Subscribers: plasma-devel, #frameworks

Tags: #plasma, #frameworks

Differential Revision: https://phabricator.kde.org/D5593
This commit is contained in:
Eike Hein 2017-04-26 20:37:32 +09:00
parent 884f89b9b0
commit 4f48901b05
2 changed files with 35 additions and 4 deletions

View File

@ -72,6 +72,7 @@ Units::Units(QObject *parent)
}
m_iconSizes = new QQmlPropertyMap(this);
m_iconSizeHints = new QQmlPropertyMap(this);
updateDevicePixelRatio(); // also updates icon sizes
updateSpacing(); // updates gridUnit and *Spacing properties
@ -135,7 +136,11 @@ void Units::iconLoaderSettingsChanged()
m_iconSizes->insert(QStringLiteral("huge"), devicePixelIconSize(KIconLoader::SizeHuge));
m_iconSizes->insert(QStringLiteral("enormous"), devicePixelIconSize(KIconLoader::SizeEnormous));
m_iconSizeHints->insert(QStringLiteral("panel"), devicePixelIconSize(KIconLoader::global()->currentSize(KIconLoader::Panel)));
m_iconSizeHints->insert(QStringLiteral("desktop"), devicePixelIconSize(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
emit iconSizesChanged();
emit iconSizeHintsChanged();
}
QQmlPropertyMap *Units::iconSizes() const
@ -143,6 +148,11 @@ QQmlPropertyMap *Units::iconSizes() const
return m_iconSizes;
}
QQmlPropertyMap *Units::iconSizeHints() const
{
return m_iconSizeHints;
}
int Units::roundToIconSize(int size)
{
/*Do *not* use devicePixelIconSize here, we want to use the sizes of the pixmaps of the smallest icons on the disk. And those are unaffected by dpi*/

View File

@ -70,15 +70,28 @@ class Units : public QObject
* * large
* * huge
* * enormous
*
* Not devicePixelRation-adjusted::
* * desktop
* * desktop (DEPRECATED: use iconSizeHints instead)
*
*/
//note the iconSizeChanges signal indicates that one (or more) of these icons have changed
//note the iconSizeChanged signal indicates that one (or more) of these icons have changed
//but the property map itself remains constant
Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes CONSTANT)
/**
* units.iconSizeHints provides access to user-configurable icon size hints,
* to be used where appropriate in the user interface.
*
* Conceptually, an icon size hint is a key that has one of the sizes from
* @iconSizes property as value.
*
* Currently available hints:
* * panel
* * desktop
*/
//note the iconSizeHintsChanged signal indicates that one (or more) of these icons have changed
//but the property map itself remains constant
Q_PROPERTY(QQmlPropertyMap *iconSizeHints READ iconSizeHints CONSTANT)
// layout hints
/**
@ -143,6 +156,12 @@ public:
*/
QQmlPropertyMap *iconSizes() const;
/**
* @return map with user-configurable icon size hints, indexed by name
* @since 5.33
*/
QQmlPropertyMap *iconSizeHints() const;
/**
* @return Pixel value for large spacing between elements.
* @since 5.0
@ -180,6 +199,7 @@ Q_SIGNALS:
void devicePixelRatioChanged();
void gridUnitChanged();
void iconSizesChanged();
void iconSizeHintsChanged();
void spacingChanged();
void durationChanged();
@ -206,6 +226,7 @@ private:
qreal m_devicePixelRatio;
QQmlPropertyMap *m_iconSizes;
QQmlPropertyMap *m_iconSizeHints;
static SharedAppFilter *s_sharedAppFilter;
int m_smallSpacing;