diff --git a/src/declarativeimports/core/colorscope.h b/src/declarativeimports/core/colorscope.h --- a/src/declarativeimports/core/colorscope.h +++ b/src/declarativeimports/core/colorscope.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -124,13 +125,16 @@ void setParentScope(ColorScope * parentScope); bool m_inherit; - Plasma::Theme m_theme; Plasma::Theme::ColorGroup m_group; QPointer m_parentScope; QObject *const m_parent; Plasma::Theme::ColorGroup m_actualGroup; static QHash s_attachedScopes; + + static QWeakPointer s_theme; + QSharedPointer m_theme; + }; QML_DECLARE_TYPEINFO(ColorScope, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/declarativeimports/core/colorscope.cpp b/src/declarativeimports/core/colorscope.cpp --- a/src/declarativeimports/core/colorscope.cpp +++ b/src/declarativeimports/core/colorscope.cpp @@ -27,14 +27,24 @@ QHash ColorScope::s_attachedScopes = QHash(); +QWeakPointer ColorScope::s_theme; + ColorScope::ColorScope(QQuickItem *parent, QObject *parentObject) : QQuickItem(parent), m_inherit(false), m_group(Plasma::Theme::NormalColorGroup), m_parent(parentObject), m_actualGroup(Plasma::Theme::NormalColorGroup) { - connect(&m_theme, &Plasma::Theme::themeChanged, this, &ColorScope::colorsChanged); + m_theme = s_theme.toStrongRef(); + if (!m_theme) { + QSharedPointer themePtr(new Plasma::Theme); + s_theme = themePtr; + m_theme = s_theme.toStrongRef(); + } + + connect(s_theme.data(), &Plasma::Theme::themeChanged, this, &ColorScope::colorsChanged); + connect(this, &ColorScope::colorGroupChanged, this, &ColorScope::colorsChanged); QQuickItem *parentItem = qobject_cast(parentObject); @@ -138,37 +148,37 @@ QColor ColorScope::textColor() const { - return m_theme.color(Plasma::Theme::TextColor, colorGroup()); + return m_theme->color(Plasma::Theme::TextColor, colorGroup()); } QColor ColorScope::highlightColor() const { - return m_theme.color(Plasma::Theme::HighlightColor, colorGroup()); + return m_theme->color(Plasma::Theme::HighlightColor, colorGroup()); } QColor ColorScope::highlightedTextColor() const { - return m_theme.color(Plasma::Theme::HighlightedTextColor, colorGroup()); + return m_theme->color(Plasma::Theme::HighlightedTextColor, colorGroup()); } QColor ColorScope::backgroundColor() const { - return m_theme.color(Plasma::Theme::BackgroundColor, colorGroup()); + return m_theme->color(Plasma::Theme::BackgroundColor, colorGroup()); } QColor ColorScope::positiveTextColor() const { - return m_theme.color(Plasma::Theme::PositiveTextColor, colorGroup()); + return m_theme->color(Plasma::Theme::PositiveTextColor, colorGroup()); } QColor ColorScope::neutralTextColor() const { - return m_theme.color(Plasma::Theme::NeutralTextColor, colorGroup()); + return m_theme->color(Plasma::Theme::NeutralTextColor, colorGroup()); } QColor ColorScope::negativeTextColor() const { - return m_theme.color(Plasma::Theme::NegativeTextColor, colorGroup()); + return m_theme->color(Plasma::Theme::NegativeTextColor, colorGroup()); } bool ColorScope::inherit() const