improve how iconitem tracks source changes

--this is used mostly to identify when the colors
should be updated
pull/5/head
Michail Vourlakos 6 years ago
parent ddb941d465
commit 7a6dfa352c

@ -90,6 +90,7 @@ void IconItem::setSource(const QVariant &source)
if (!sourceString.isEmpty()) {
setLastValidSourceName(sourceString);
setLastLoadedSourceId(sourceString);
//If a url in the form file:// is passed, take the image pointed by that from disk
QUrl url(sourceString);
@ -162,12 +163,18 @@ void IconItem::setSource(const QVariant &source)
}
} else if (source.canConvert<QIcon>()) {
m_icon = source.value<QIcon>();
m_iconCounter++;
setLastLoadedSourceId("_icon_"+QString::number(m_iconCounter));
m_imageIcon = QImage();
m_svgIconName.clear();
m_svgIcon.reset();
} else if (source.canConvert<QImage>()) {
m_icon = QIcon();
m_imageIcon = source.value<QImage>();
m_iconCounter++;
setLastLoadedSourceId("_image_"+QString::number(m_iconCounter));
m_icon = QIcon();
m_svgIconName.clear();
m_svgIcon.reset();
} else {
@ -190,6 +197,15 @@ QVariant IconItem::source() const
return m_source;
}
void IconItem::setLastLoadedSourceId(QString id)
{
if (m_lastLoadedSourceId == id) {
return;
}
m_lastLoadedSourceId = id;
}
QString IconItem::lastValidSourceName()
{
return m_lastValidSourceName;
@ -512,8 +528,8 @@ void IconItem::loadPixmap()
m_iconPixmap = result;
if (m_providesColors && m_lastValidSourceName != m_lastColorsSourceName) {
m_lastColorsSourceName = m_lastValidSourceName;
if (m_providesColors && m_lastLoadedSourceId != m_lastColorsSourceId) {
m_lastColorsSourceId = m_lastLoadedSourceId;
updateColors();
}

@ -165,6 +165,7 @@ private slots:
private:
void loadPixmap();
void updateColors();
void setLastLoadedSourceId(QString id);
void setLastValidSourceName(QString name);
void setBackgroundColor(QColor background);
void setGlowColor(QColor glow);
@ -188,8 +189,20 @@ private:
std::unique_ptr<Plasma::Svg> m_svgIcon;
QString m_svgIconName;
//! can be used to track changes during source "changes" independent
//! of the source type
int m_iconCounter{0};
//! last source name that was valid
QString m_lastValidSourceName;
QString m_lastColorsSourceName;
//! the last icon that was loaded independent of its type svg/pixmap/image
//! this is set and used only internally. One of its uses is to check
//! when the colors must be updated
QString m_lastLoadedSourceId;
//! last source name that was used in order to produce colors
QString m_lastColorsSourceId;
QStringList m_overlays;
//this contains the raw variant it was passed

Loading…
Cancel
Save