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
This commit is contained in:
Marco Martin 2014-10-10 17:36:44 +02:00
parent 68eadae6c8
commit 66a1a497ef
5 changed files with 42 additions and 0 deletions

View File

@ -257,6 +257,7 @@ FrameSvgItem::FrameSvgItem(QQuickItem *parent)
setFlag(ItemHasContents, true); setFlag(ItemHasContents, true);
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate())); connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate()));
connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio); connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio);
connect(m_frameSvg, &Svg::fromCurrentThemeChanged, this, &FrameSvgItem::fromCurrentThemeChanged);
} }
FrameSvgItem::~FrameSvgItem() FrameSvgItem::~FrameSvgItem()
@ -338,6 +339,11 @@ FrameSvgItemMargins *FrameSvgItem::fixedMargins() const
return m_fixedMargins; return m_fixedMargins;
} }
bool FrameSvgItem::fromCurrentTheme() const
{
return m_frameSvg->fromCurrentTheme();
}
void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders) void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
{ {
if (m_frameSvg->enabledBorders() == borders) { if (m_frameSvg->enabledBorders() == borders) {

View File

@ -132,6 +132,11 @@ class FrameSvgItem : public QQuickItem
*/ */
Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged) 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: public:
/** /**
* @return true if the svg has the necessary elements with the given prefix * @return true if the svg has the necessary elements with the given prefix
@ -156,6 +161,8 @@ public:
FrameSvgItemMargins *margins() const; FrameSvgItemMargins *margins() const;
FrameSvgItemMargins *fixedMargins() const; FrameSvgItemMargins *fixedMargins() const;
bool fromCurrentTheme() const;
void geometryChanged(const QRectF &newGeometry, void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry); const QRectF &oldGeometry);
@ -177,6 +184,7 @@ Q_SIGNALS:
void imagePathChanged(); void imagePathChanged();
void prefixChanged(); void prefixChanged();
void enabledBordersChanged(); void enabledBordersChanged();
void fromCurrentThemeChanged();
private Q_SLOTS: private Q_SLOTS:
void doUpdate(); void doUpdate();

View File

@ -111,6 +111,7 @@ public:
qreal devicePixelRatio; qreal devicePixelRatio;
bool multipleImages : 1; bool multipleImages : 1;
bool themed : 1; bool themed : 1;
bool fromCurrentTheme : 1;
bool applyColors : 1; bool applyColors : 1;
bool usesColors : 1; bool usesColors : 1;
bool cacheRendering : 1; bool cacheRendering : 1;

View File

@ -140,6 +140,7 @@ SvgPrivate::SvgPrivate(Svg *svg)
devicePixelRatio(1.0), devicePixelRatio(1.0),
multipleImages(false), multipleImages(false),
themed(false), themed(false),
fromCurrentTheme(false),
applyColors(false), applyColors(false),
usesColors(false), usesColors(false),
cacheRendering(true), cacheRendering(true),
@ -202,6 +203,12 @@ bool SvgPrivate::setImagePath(const QString &imagePath)
themePath.clear(); themePath.clear();
localRectCache.clear(); localRectCache.clear();
elementsWithSizeHints.clear(); elementsWithSizeHints.clear();
bool oldFromCurrentTheme = fromCurrentTheme;
fromCurrentTheme = actualTheme()->currentThemeHasImage(imagePath);
if (fromCurrentTheme != oldFromCurrentTheme) {
emit q->fromCurrentThemeChanged(fromCurrentTheme);
}
if (themed) { if (themed) {
themePath = actualPath; themePath = actualPath;
@ -857,6 +864,11 @@ bool Svg::isUsingRenderingCache() const
return d->cacheRendering; return d->cacheRendering;
} }
bool Svg::fromCurrentTheme() const
{
return d->fromCurrentTheme;
}
void Svg::setTheme(Plasma::Theme *theme) void Svg::setTheme(Plasma::Theme *theme)
{ {
if (!theme || theme == d->theme.data()) { if (!theme || theme == d->theme.data()) {

View File

@ -61,6 +61,7 @@ class PLASMA_EXPORT Svg : public QObject
Q_PROPERTY(bool multipleImages READ containsMultipleImages WRITE setContainsMultipleImages) Q_PROPERTY(bool multipleImages READ containsMultipleImages WRITE setContainsMultipleImages)
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged) Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged)
Q_PROPERTY(bool usingRenderingCache READ isUsingRenderingCache WRITE setUsingRenderingCache) 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); Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged);
public: public:
@ -368,6 +369,15 @@ public:
*/ */
bool isUsingRenderingCache() const; 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. * Sets the Plasma::Theme to use with this Svg object.
* *
@ -423,6 +433,11 @@ Q_SIGNALS:
*/ */
void colorGroupChanged(); void colorGroupChanged();
/**
* Emitted when fromCurrentTheme() value has changed
*/
void fromCurrentThemeChanged(bool fromCurrentTheme);
private: private:
SvgPrivate *const d; SvgPrivate *const d;
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);