support usesPlasmaTheme in our iconitem

pull/1/head
Michail Vourlakos 8 years ago
parent 162d84e31d
commit 12a200916a

@ -43,7 +43,8 @@ IconItem::IconItem(QQuickItem *parent)
m_smooth(false),
m_active(false),
m_textureChanged(false),
m_sizeChanged(false)
m_sizeChanged(false),
m_usesPlasmaTheme(false)
{
setFlag(ItemHasContents, true);
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
@ -100,6 +101,15 @@ void IconItem::setSource(const QVariant &source)
connect(m_svgIcon.get(), &Plasma::Svg::repaintNeeded, this, &IconItem::schedulePixmapUpdate);
}
if (m_usesPlasmaTheme) {
//try as a svg icon from plasma theme
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first());
m_svgIcon->setContainsMultipleImages(true);
//invalidate the image path to recalculate it later
} else {
m_svgIcon->setImagePath(QString());
}
//success?
if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) {
m_icon = QIcon();
@ -254,6 +264,28 @@ int IconItem::paintedHeight() const
return boundingRect().size().toSize().height();
}
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
const QVariant src = m_source;
m_source.clear();
setSource(src);
update();
emit usesPlasmaThemeChanged();
}
void IconItem::updatePolish()
{
QQuickItem::updatePolish();

@ -83,6 +83,11 @@ class IconItem : public QQuickItem {
*/
Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
/**
* If set, icon will try and use icons from the Plasma theme if possible
*/
Q_PROPERTY(bool usesPlasmaTheme READ usesPlasmaTheme WRITE setUsesPlasmaTheme NOTIFY usesPlasmaThemeChanged)
/**
* Contains the last valid icon name
*/
@ -109,6 +114,9 @@ public:
int paintedWidth() const;
int paintedHeight() const;
bool usesPlasmaTheme() const;
void setUsesPlasmaTheme(bool usesPlasmaTheme);
QString lastValidSourceName();
void updatePolish() Q_DECL_OVERRIDE;
@ -127,6 +135,7 @@ signals:
void smoothChanged();
void validChanged();
void paintedSizeChanged();
void usesPlasmaThemeChanged();
private slots:
void schedulePixmapUpdate();
@ -153,6 +162,8 @@ private:
bool m_textureChanged;
bool m_sizeChanged;
bool m_usesPlasmaTheme;
};
}

Loading…
Cancel
Save