IconItem: Add usesPlasmaTheme property

Add usesPlasmaTheme (enabled by default) property to make it possible
to disable using icons from Plasma theme.

REVIEW: 126814
This commit is contained in:
David Rosca 2016-01-20 11:28:56 +01:00
parent fd9b5bd006
commit 83cec13edb
2 changed files with 35 additions and 3 deletions

View File

@ -43,6 +43,7 @@ IconItem::IconItem(QQuickItem *parent)
m_smooth(false), m_smooth(false),
m_active(false), m_active(false),
m_animated(true), m_animated(true),
m_usesPlasmaTheme(true),
m_textureChanged(false), m_textureChanged(false),
m_sizeChanged(false), m_sizeChanged(false),
m_svgFromIconLoader(false), m_svgFromIconLoader(false),
@ -115,10 +116,12 @@ void IconItem::setSource(const QVariant &source)
m_svgIcon->setColorGroup(m_colorGroup); m_svgIcon->setColorGroup(m_colorGroup);
m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()));
} }
//try as a svg icon
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first());
m_svgIcon->setContainsMultipleImages(true); if (m_usesPlasmaTheme) {
//try as a svg icon from plasma theme
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first());
m_svgIcon->setContainsMultipleImages(true);
}
//success? //success?
if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) { if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) {
@ -263,6 +266,29 @@ void IconItem::setAnimated(bool animated)
emit animatedChanged(); emit animatedChanged();
} }
bool IconItem::usesPlasmaTheme() const
{
return m_usesPlasmaTheme;
}
void IconItem::setUsesPlasmaTheme(bool usesPlasmaTheme)
{
if (m_usesPlasmaTheme == usesPlasmaTheme) {
return;
}
m_usesPlasmaTheme = usesPlasmaTheme;
// Reload icon with new settings
if (m_svgIcon && m_svgIcon->hasElement(m_source.toString())) {
const QVariant src = m_source;
m_source.clear();
setSource(src);
}
emit usesPlasmaThemeChanged();
}
bool IconItem::isValid() const bool IconItem::isValid() const
{ {
return !m_icon.isNull() || m_svgIcon || !m_pixmapIcon.isNull() || !m_imageIcon.isNull(); return !m_icon.isNull() || m_svgIcon || !m_pixmapIcon.isNull() || !m_imageIcon.isNull();

View File

@ -44,6 +44,7 @@ class IconItem : public QQuickItem
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged) Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged)
Q_PROPERTY(bool usesPlasmaTheme READ usesPlasmaTheme WRITE setUsesPlasmaTheme NOTIFY usesPlasmaThemeChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedSizeChanged) Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedSizeChanged) Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
@ -68,6 +69,9 @@ public:
bool isAnimated() const; bool isAnimated() const;
void setAnimated(bool animated); void setAnimated(bool animated);
bool usesPlasmaTheme() const;
void setUsesPlasmaTheme(bool usesPlasmaTheme);
bool isValid() const; bool isValid() const;
int paintedWidth() const; int paintedWidth() const;
@ -86,6 +90,7 @@ Q_SIGNALS:
void sourceChanged(); void sourceChanged();
void smoothChanged(); void smoothChanged();
void animatedChanged(); void animatedChanged();
void usesPlasmaThemeChanged();
void validChanged(); void validChanged();
void colorGroupChanged(); void colorGroupChanged();
void paintedSizeChanged(); void paintedSizeChanged();
@ -111,6 +116,7 @@ private:
bool m_smooth; bool m_smooth;
bool m_active; bool m_active;
bool m_animated; bool m_animated;
bool m_usesPlasmaTheme;
bool m_textureChanged; bool m_textureChanged;
bool m_sizeChanged; bool m_sizeChanged;