support simple QObjects too

support ColorScope in Svg as well (that's not a QQuickItem)
This commit is contained in:
Marco Martin 2016-01-08 16:11:19 +01:00
parent 5911ad2920
commit 5b79da30f0
3 changed files with 23 additions and 7 deletions

View File

@ -26,11 +26,11 @@
QHash<QObject *, ColorScope *> ColorScope::s_attachedScopes = QHash<QObject *, ColorScope *>();
ColorScope::ColorScope(QQuickItem *parent)
ColorScope::ColorScope(QQuickItem *parent, QObject *parentObject)
: QQuickItem(parent),
m_inherit(false),
m_group(Plasma::Theme::NormalColorGroup),
m_parent(parent)
m_parent(parentObject)
{
connect(&m_theme, &Plasma::Theme::themeChanged, this, &ColorScope::colorsChanged);
@ -53,7 +53,7 @@ ColorScope *ColorScope::qmlAttachedProperties(QObject *object)
return s_attachedScopes.value(object);
}
ColorScope *s = new ColorScope(qp);
ColorScope *s = new ColorScope(qp, object);
s_attachedScopes[object] = s;
if (!qp) {
@ -65,9 +65,14 @@ ColorScope *ColorScope::qmlAttachedProperties(QObject *object)
ColorScope *ColorScope::findParentScope() const
{
QQuickItem *p = 0;
QObject *p = 0;
if (m_parent) {
p = m_parent->parentItem();
QQuickItem *gp = qobject_cast<QQuickItem *>(m_parent);
if (gp) {
p = gp->parentItem();
} else {
p = m_parent->parent();
}
}
if (!p || !m_parent) {

View File

@ -61,7 +61,7 @@ class ColorScope : public QQuickItem
public:
/// @cond INTERNAL_DOCS
ColorScope(QQuickItem *parent = 0);
ColorScope(QQuickItem *parent = 0, QObject *parentObject = 0);
~ColorScope();
void setColorGroup(Plasma::Theme::ColorGroup group);
@ -91,7 +91,7 @@ private:
Plasma::Theme m_theme;
Plasma::Theme::ColorGroup m_group;
QPointer<ColorScope> m_parentScope;
QQuickItem *m_parent;
QObject *m_parent;
static QHash<QObject *, ColorScope *> s_attachedScopes;
};

View File

@ -39,6 +39,17 @@ ColumnLayout {
Column {
id: widgetsParent
anchors.centerIn: parent
PlasmaCore.Svg {
id: audioSvg
imagePath: "icons/audio"
colorGroup: PlasmaCore.ColorScope.colorGroup
}
PlasmaCore.SvgItem {
width: 32
height: 32
elementId: "audio-volume-medium"
svg: audioSvg
}
Row {
PlasmaCore.IconItem {
colorGroup: PlasmaCore.ColorScope.colorGroup