From 66a1a497ef7e1d9b126a080c36d15ddd33b10b62 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 10 Oct 2014 17:36:44 +0200 Subject: [PATCH] add a property to tell if fallback happened add a property in Svg (and framesvgitem) to tell if the current theme has this image, or if some fallback did happen useful for items that are better not displayed than showing the potentially different default theme Change-Id: Ib914c0e196c5c941d35d9a600cc7d38818fc754f --- src/declarativeimports/core/framesvgitem.cpp | 6 ++++++ src/declarativeimports/core/framesvgitem.h | 8 ++++++++ src/plasma/private/svg_p.h | 1 + src/plasma/svg.cpp | 12 ++++++++++++ src/plasma/svg.h | 15 +++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/src/declarativeimports/core/framesvgitem.cpp b/src/declarativeimports/core/framesvgitem.cpp index 18b7fd281..d7b843c26 100644 --- a/src/declarativeimports/core/framesvgitem.cpp +++ b/src/declarativeimports/core/framesvgitem.cpp @@ -257,6 +257,7 @@ FrameSvgItem::FrameSvgItem(QQuickItem *parent) setFlag(ItemHasContents, true); connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate())); connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio); + connect(m_frameSvg, &Svg::fromCurrentThemeChanged, this, &FrameSvgItem::fromCurrentThemeChanged); } FrameSvgItem::~FrameSvgItem() @@ -338,6 +339,11 @@ FrameSvgItemMargins *FrameSvgItem::fixedMargins() const return m_fixedMargins; } +bool FrameSvgItem::fromCurrentTheme() const +{ + return m_frameSvg->fromCurrentTheme(); +} + void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders) { if (m_frameSvg->enabledBorders() == borders) { diff --git a/src/declarativeimports/core/framesvgitem.h b/src/declarativeimports/core/framesvgitem.h index d82540345..ac4342869 100644 --- a/src/declarativeimports/core/framesvgitem.h +++ b/src/declarativeimports/core/framesvgitem.h @@ -132,6 +132,11 @@ class FrameSvgItem : public QQuickItem */ Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged) + /** + * Holds whether the current svg is present in the current theme and NO fallback is involved + */ + Q_PROPERTY(bool fromCurrentTheme READ fromCurrentTheme NOTIFY fromCurrentThemeChanged) + public: /** * @return true if the svg has the necessary elements with the given prefix @@ -156,6 +161,8 @@ public: FrameSvgItemMargins *margins() const; FrameSvgItemMargins *fixedMargins() const; + bool fromCurrentTheme() const; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -177,6 +184,7 @@ Q_SIGNALS: void imagePathChanged(); void prefixChanged(); void enabledBordersChanged(); + void fromCurrentThemeChanged(); private Q_SLOTS: void doUpdate(); diff --git a/src/plasma/private/svg_p.h b/src/plasma/private/svg_p.h index 3ff0ec892..a31d0acd1 100644 --- a/src/plasma/private/svg_p.h +++ b/src/plasma/private/svg_p.h @@ -111,6 +111,7 @@ public: qreal devicePixelRatio; bool multipleImages : 1; bool themed : 1; + bool fromCurrentTheme : 1; bool applyColors : 1; bool usesColors : 1; bool cacheRendering : 1; diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp index bcb550f7c..2a0fe8d9d 100644 --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -140,6 +140,7 @@ SvgPrivate::SvgPrivate(Svg *svg) devicePixelRatio(1.0), multipleImages(false), themed(false), + fromCurrentTheme(false), applyColors(false), usesColors(false), cacheRendering(true), @@ -202,6 +203,12 @@ bool SvgPrivate::setImagePath(const QString &imagePath) themePath.clear(); localRectCache.clear(); elementsWithSizeHints.clear(); + bool oldFromCurrentTheme = fromCurrentTheme; + fromCurrentTheme = actualTheme()->currentThemeHasImage(imagePath); + + if (fromCurrentTheme != oldFromCurrentTheme) { + emit q->fromCurrentThemeChanged(fromCurrentTheme); + } if (themed) { themePath = actualPath; @@ -857,6 +864,11 @@ bool Svg::isUsingRenderingCache() const return d->cacheRendering; } +bool Svg::fromCurrentTheme() const +{ + return d->fromCurrentTheme; +} + void Svg::setTheme(Plasma::Theme *theme) { if (!theme || theme == d->theme.data()) { diff --git a/src/plasma/svg.h b/src/plasma/svg.h index 647dad640..4bd1f1171 100644 --- a/src/plasma/svg.h +++ b/src/plasma/svg.h @@ -61,6 +61,7 @@ class PLASMA_EXPORT Svg : public QObject Q_PROPERTY(bool multipleImages READ containsMultipleImages WRITE setContainsMultipleImages) Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged) Q_PROPERTY(bool usingRenderingCache READ isUsingRenderingCache WRITE setUsingRenderingCache) + Q_PROPERTY(bool fromCurrentTheme READ fromCurrentTheme NOTIFY fromCurrentThemeChanged) Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged); public: @@ -368,6 +369,15 @@ public: */ bool isUsingRenderingCache() const; + /** + * Wether the current theme has this Svg, without any fallback + * to the default theme involved + * + * @return true if the svg is loaded from the current theme + * @see Theme::currentThemeHasImage + */ + bool fromCurrentTheme() const; + /** * Sets the Plasma::Theme to use with this Svg object. * @@ -423,6 +433,11 @@ Q_SIGNALS: */ void colorGroupChanged(); + /** + * Emitted when fromCurrentTheme() value has changed + */ + void fromCurrentThemeChanged(bool fromCurrentTheme); + private: SvgPrivate *const d; bool eventFilter(QObject *watched, QEvent *event);