Revert "Make the attached property a simple QObject"
This reverts commit 68a273aef6c1dea1ea74794240121b136db0eb58. introduced regressions in several places
This commit is contained in:
parent
2961144640
commit
1b1dc79dc4
@ -28,15 +28,15 @@
|
||||
|
||||
#include <PlasmaQuick/AppletQuickItem>
|
||||
|
||||
QHash<QObject *, ColorScopeAttached *> ColorScopeAttached::s_attachedScopes = QHash<QObject *, ColorScopeAttached *>();
|
||||
QHash<QObject *, ColorScope *> ColorScope::s_attachedScopes = QHash<QObject *, ColorScope *>();
|
||||
|
||||
QWeakPointer<Plasma::Theme> ColorScopeAttached::s_theme;
|
||||
QWeakPointer<Plasma::Theme> ColorScope::s_theme;
|
||||
|
||||
ColorScopeAttached::ColorScopeAttached(QObject *parent)
|
||||
: QObject(parent),
|
||||
ColorScope::ColorScope(QQuickItem *parent, QObject *parentObject)
|
||||
: QQuickItem(parent),
|
||||
m_inherit(false),
|
||||
m_group(Plasma::Theme::NormalColorGroup),
|
||||
m_parent(parent),
|
||||
m_parent(parentObject),
|
||||
m_actualGroup(Plasma::Theme::NormalColorGroup)
|
||||
{
|
||||
m_theme = s_theme.toStrongRef();
|
||||
@ -46,52 +46,98 @@ ColorScopeAttached::ColorScopeAttached(QObject *parent)
|
||||
m_theme = s_theme.toStrongRef();
|
||||
}
|
||||
|
||||
connect(m_theme.data(), &Plasma::Theme::themeChanged, this, &ColorScopeAttached::colorsChanged);
|
||||
connect(m_theme.data(), &Plasma::Theme::themeChanged, this, &ColorScope::colorsChanged);
|
||||
|
||||
connect(this, &ColorScopeAttached::colorGroupChanged, this, &ColorScopeAttached::colorsChanged);
|
||||
connect(this, &ColorScope::colorGroupChanged, this, &ColorScope::colorsChanged);
|
||||
|
||||
QQuickItem *parentItem = qobject_cast<QQuickItem *>(m_parent);
|
||||
if (parentObject && qobject_cast<QQuickItem *>(parentObject)) {
|
||||
connect(static_cast<QQuickItem *>(parentObject), &QQuickItem::windowChanged,
|
||||
this, [this]() {
|
||||
findParentScope();
|
||||
checkColorGroupChanged();
|
||||
});
|
||||
|
||||
auto scopeChange = [this] () {
|
||||
findParentScope();
|
||||
checkColorGroupChanged();
|
||||
};
|
||||
|
||||
if (parentItem) {
|
||||
connect(parentItem, &QQuickItem::windowChanged,
|
||||
this, scopeChange);
|
||||
|
||||
connect(parentItem, &QQuickItem::parentChanged,
|
||||
this, scopeChange);
|
||||
connect(static_cast<QQuickItem *>(parentObject), &QQuickItem::parentChanged,
|
||||
this, [this]() {
|
||||
findParentScope();
|
||||
checkColorGroupChanged();
|
||||
});
|
||||
} else if (parent) {
|
||||
connect(parent, &QQuickItem::parentChanged,
|
||||
this, &ColorScope::checkColorGroupChanged);
|
||||
}
|
||||
findParentScope();
|
||||
}
|
||||
|
||||
ColorScopeAttached::~ColorScopeAttached()
|
||||
ColorScope::~ColorScope()
|
||||
{
|
||||
m_deleting = true;
|
||||
s_attachedScopes.remove(m_parent);
|
||||
}
|
||||
|
||||
void ColorScopeAttached::setParentScope(ColorScopeAttached* parentScope)
|
||||
ColorScope *ColorScope::qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
const auto cs = s_attachedScopes.value(object);
|
||||
if (cs) {
|
||||
return cs;
|
||||
}
|
||||
|
||||
ColorScope *s = new ColorScope(nullptr, object);
|
||||
s_attachedScopes[object] = s;
|
||||
s->m_inherit = true;
|
||||
s->setParent(object);
|
||||
s->checkColorGroupChanged();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void ColorScope::setParentScope(ColorScope* parentScope)
|
||||
{
|
||||
if (parentScope == m_parentScope)
|
||||
return;
|
||||
|
||||
if (m_parentScope) {
|
||||
disconnect(m_parentScope.data(), &ColorScopeAttached::colorGroupChanged,
|
||||
this, &ColorScopeAttached::checkColorGroupChanged);
|
||||
disconnect(m_parentScope.data(), &ColorScope::colorGroupChanged,
|
||||
this, &ColorScope::checkColorGroupChanged);
|
||||
}
|
||||
|
||||
m_parentScope = parentScope;
|
||||
|
||||
if (parentScope) {
|
||||
connect(parentScope, &ColorScopeAttached::colorGroupChanged,
|
||||
this, &ColorScopeAttached::checkColorGroupChanged);
|
||||
connect(parentScope, &ColorScope::colorGroupChanged,
|
||||
this, &ColorScope::checkColorGroupChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorScopeAttached::setColorGroup(Plasma::Theme::ColorGroup group)
|
||||
ColorScope *ColorScope::findParentScope()
|
||||
{
|
||||
QObject *candidate = parentItem();
|
||||
if (!candidate) {
|
||||
candidate = parent();
|
||||
}
|
||||
|
||||
while (candidate) {
|
||||
auto *quickCandidate = qobject_cast<QQuickItem *>(candidate);
|
||||
if (quickCandidate && quickCandidate->parentItem()) {
|
||||
candidate = quickCandidate->parentItem();
|
||||
} else {
|
||||
candidate = candidate->parent();
|
||||
}
|
||||
|
||||
ColorScope *s = qobject_cast<ColorScope *>(candidate);
|
||||
if (!s) {
|
||||
// Make sure AppletInterface always has a ColorScope
|
||||
s = static_cast<ColorScope *>(qmlAttachedPropertiesObject<ColorScope>(candidate, qobject_cast<PlasmaQuick::AppletQuickItem *>(candidate)));
|
||||
}
|
||||
if (s && !s->m_deleting) {
|
||||
setParentScope(s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ColorScope::setColorGroup(Plasma::Theme::ColorGroup group)
|
||||
{
|
||||
if (m_group == group) {
|
||||
return;
|
||||
@ -102,57 +148,57 @@ void ColorScopeAttached::setColorGroup(Plasma::Theme::ColorGroup group)
|
||||
checkColorGroupChanged();
|
||||
}
|
||||
|
||||
Plasma::Theme::ColorGroup ColorScopeAttached::colorGroup() const
|
||||
Plasma::Theme::ColorGroup ColorScope::colorGroup() const
|
||||
{
|
||||
return m_actualGroup;
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::textColor() const
|
||||
QColor ColorScope::textColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::TextColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::highlightColor() const
|
||||
QColor ColorScope::highlightColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::HighlightColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::highlightedTextColor() const
|
||||
QColor ColorScope::highlightedTextColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::HighlightedTextColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::backgroundColor() const
|
||||
QColor ColorScope::backgroundColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::BackgroundColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::positiveTextColor() const
|
||||
QColor ColorScope::positiveTextColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::PositiveTextColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::neutralTextColor() const
|
||||
QColor ColorScope::neutralTextColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::NeutralTextColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::negativeTextColor() const
|
||||
QColor ColorScope::negativeTextColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::NegativeTextColor, colorGroup());
|
||||
}
|
||||
|
||||
QColor ColorScopeAttached::disabledTextColor() const
|
||||
QColor ColorScope::disabledTextColor() const
|
||||
{
|
||||
return m_theme->color(Plasma::Theme::DisabledTextColor, colorGroup());
|
||||
}
|
||||
|
||||
bool ColorScopeAttached::inherit() const
|
||||
bool ColorScope::inherit() const
|
||||
{
|
||||
return m_inherit;
|
||||
}
|
||||
|
||||
void ColorScopeAttached::setInherit(bool inherit)
|
||||
void ColorScope::setInherit(bool inherit)
|
||||
{
|
||||
if (m_inherit == inherit) {
|
||||
return;
|
||||
@ -162,7 +208,20 @@ void ColorScopeAttached::setInherit(bool inherit)
|
||||
checkColorGroupChanged();
|
||||
}
|
||||
|
||||
void ColorScopeAttached::checkColorGroupChanged()
|
||||
void ColorScope::itemChange(ItemChange change, const ItemChangeData &value)
|
||||
{
|
||||
if (change == QQuickItem::ItemSceneChange) {
|
||||
//we have a window: create the representations if needed
|
||||
if (value.window) {
|
||||
findParentScope();
|
||||
checkColorGroupChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void ColorScope::checkColorGroupChanged()
|
||||
{
|
||||
const auto last = m_actualGroup;
|
||||
if (m_inherit) {
|
||||
@ -177,137 +236,4 @@ void ColorScopeAttached::checkColorGroupChanged()
|
||||
}
|
||||
}
|
||||
|
||||
ColorScopeAttached *ColorScopeAttached::findParentScope()
|
||||
{
|
||||
QObject *candidate = parent();
|
||||
|
||||
while (candidate) {
|
||||
auto *quickCandidate = qobject_cast<QQuickItem *>(candidate);
|
||||
if (quickCandidate && quickCandidate->parentItem()) {
|
||||
candidate = quickCandidate->parentItem();
|
||||
} else {
|
||||
candidate = candidate->parent();
|
||||
}
|
||||
|
||||
// Make sure AppletInterface always has a ColorScopeAttached
|
||||
ColorScopeAttached *s = static_cast<ColorScopeAttached *>(qmlAttachedPropertiesObject<ColorScope>(candidate, qobject_cast<PlasmaQuick::AppletQuickItem *>(candidate)));
|
||||
|
||||
if (s && !s->m_deleting) {
|
||||
setParentScope(s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ColorScope::ColorScope(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
{
|
||||
m_ownAttached = qobject_cast<ColorScopeAttached *>(qmlAttachedPropertiesObject<ColorScope>(this, true));
|
||||
|
||||
connect(m_ownAttached, &ColorScopeAttached::colorGroupChanged,
|
||||
this, &ColorScope::colorGroupChanged);
|
||||
connect(m_ownAttached, &ColorScopeAttached::colorsChanged,
|
||||
this, &ColorScope::colorsChanged);
|
||||
connect(m_ownAttached, &ColorScopeAttached::inheritChanged,
|
||||
this, &ColorScope::inheritChanged);
|
||||
}
|
||||
|
||||
ColorScope::~ColorScope()
|
||||
{}
|
||||
|
||||
void ColorScope::setColorGroup(Plasma::Theme::ColorGroup group)
|
||||
{
|
||||
m_ownAttached->setColorGroup(group);
|
||||
}
|
||||
|
||||
Plasma::Theme::ColorGroup ColorScope::colorGroup() const
|
||||
{
|
||||
return m_ownAttached->colorGroup();
|
||||
}
|
||||
|
||||
QColor ColorScope::textColor() const
|
||||
{
|
||||
return m_ownAttached->textColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::highlightColor() const
|
||||
{
|
||||
return m_ownAttached->highlightColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::highlightedTextColor() const
|
||||
{
|
||||
return m_ownAttached->highlightedTextColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::backgroundColor() const
|
||||
{
|
||||
return m_ownAttached->backgroundColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::positiveTextColor() const
|
||||
{
|
||||
return m_ownAttached->positiveTextColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::neutralTextColor() const
|
||||
{
|
||||
return m_ownAttached->neutralTextColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::negativeTextColor() const
|
||||
{
|
||||
return m_ownAttached->negativeTextColor();
|
||||
}
|
||||
|
||||
QColor ColorScope::disabledTextColor() const
|
||||
{
|
||||
return m_ownAttached->disabledTextColor();
|
||||
}
|
||||
|
||||
bool ColorScope::inherit() const
|
||||
{
|
||||
return m_ownAttached->inherit();
|
||||
}
|
||||
|
||||
void ColorScope::setInherit(bool inherit)
|
||||
{
|
||||
m_ownAttached->setInherit(inherit);
|
||||
}
|
||||
|
||||
void ColorScope::itemChange(ItemChange change, const ItemChangeData &value)
|
||||
{
|
||||
if (change == QQuickItem::ItemSceneChange) {
|
||||
//we have a window: create the representations if needed
|
||||
if (value.window) {
|
||||
m_ownAttached->findParentScope();
|
||||
m_ownAttached->checkColorGroupChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
ColorScopeAttached *ColorScope::qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
const auto cs = ColorScopeAttached::s_attachedScopes.value(object);
|
||||
if (cs) {
|
||||
return cs;
|
||||
}
|
||||
|
||||
ColorScopeAttached *s = new ColorScopeAttached(object);
|
||||
ColorScopeAttached::s_attachedScopes[object] = s;
|
||||
s->m_inherit = true;
|
||||
s->setParent(object);
|
||||
s->checkColorGroupChanged();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#include "moc_colorscope.cpp"
|
||||
|
@ -28,110 +28,6 @@
|
||||
#include <Plasma/Theme>
|
||||
|
||||
class QQuickItem;
|
||||
class ColorScope;
|
||||
|
||||
class ColorScopeAttached : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* Specifies the color group to use for this ColorScope
|
||||
*/
|
||||
Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged)
|
||||
|
||||
/**
|
||||
* The main foreground color within this colorscope
|
||||
*/
|
||||
Q_PROPERTY(QColor textColor READ textColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* The highlight color within this colorscope
|
||||
*/
|
||||
Q_PROPERTY(QColor highlightColor READ highlightColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* The highlighted text color within this colorscope
|
||||
*/
|
||||
Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* The background color that should be used within this colorscope
|
||||
*/
|
||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* Color of foreground objects with a "positive message" connotation (usually green)
|
||||
*/
|
||||
Q_PROPERTY(QColor positiveTextColor READ positiveTextColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* Color of foreground objects with a "neutral message" connotation (usually yellow)
|
||||
*/
|
||||
Q_PROPERTY(QColor neutralTextColor READ neutralTextColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* Color of foreground objects with a "negative message" connotation (usually red)
|
||||
*/
|
||||
Q_PROPERTY(QColor negativeTextColor READ negativeTextColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* Color of disabled text @since 5.64
|
||||
*/
|
||||
Q_PROPERTY(QColor disabledTextColor READ disabledTextColor NOTIFY colorsChanged)
|
||||
|
||||
/**
|
||||
* true if the scope inherits from its parent scope
|
||||
* @since 5.39
|
||||
*/
|
||||
Q_PROPERTY(bool inherit READ inherit WRITE setInherit NOTIFY inheritChanged)
|
||||
|
||||
public:
|
||||
ColorScopeAttached(QObject *parent);
|
||||
~ColorScopeAttached();
|
||||
|
||||
void setColorGroup(Plasma::Theme::ColorGroup group);
|
||||
Plasma::Theme::ColorGroup colorGroup() const;
|
||||
|
||||
QColor textColor() const;
|
||||
QColor highlightColor() const;
|
||||
QColor highlightedTextColor() const;
|
||||
QColor backgroundColor() const;
|
||||
QColor positiveTextColor() const;
|
||||
QColor neutralTextColor() const;
|
||||
QColor negativeTextColor() const;
|
||||
QColor disabledTextColor() const;
|
||||
|
||||
bool inherit() const;
|
||||
void setInherit(bool inherit);
|
||||
|
||||
/// @endcond
|
||||
|
||||
ColorScopeAttached *findParentScope();
|
||||
|
||||
void checkColorGroupChanged();
|
||||
|
||||
Q_SIGNALS:
|
||||
void colorGroupChanged();
|
||||
void colorsChanged();
|
||||
void inheritChanged();
|
||||
|
||||
private:
|
||||
|
||||
void setParentScope(ColorScopeAttached * parentScope);
|
||||
|
||||
bool m_inherit;
|
||||
Plasma::Theme::ColorGroup m_group;
|
||||
QPointer<ColorScopeAttached> m_parentScope;
|
||||
QObject *const m_parent;
|
||||
Plasma::Theme::ColorGroup m_actualGroup;
|
||||
bool m_deleting = false;
|
||||
|
||||
static QHash<QObject *, ColorScopeAttached *> s_attachedScopes;
|
||||
|
||||
static QWeakPointer<Plasma::Theme> s_theme;
|
||||
QSharedPointer<Plasma::Theme> m_theme;
|
||||
friend class ColorScope;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ColorScope
|
||||
@ -197,7 +93,7 @@ class ColorScope : public QQuickItem
|
||||
|
||||
public:
|
||||
/// @cond INTERNAL_DOCS
|
||||
explicit ColorScope(QQuickItem *parent = nullptr);
|
||||
explicit ColorScope(QQuickItem *parent = nullptr, QObject *parentObject = nullptr);
|
||||
~ColorScope() override;
|
||||
|
||||
void setColorGroup(Plasma::Theme::ColorGroup group);
|
||||
@ -216,7 +112,7 @@ public:
|
||||
void setInherit(bool inherit);
|
||||
|
||||
////NEEDED BY QML TO CREATE ATTACHED PROPERTIES
|
||||
static ColorScopeAttached *qmlAttachedProperties(QObject *object);
|
||||
static ColorScope *qmlAttachedProperties(QObject *object);
|
||||
|
||||
/// @endcond
|
||||
|
||||
@ -229,7 +125,20 @@ Q_SIGNALS:
|
||||
void inheritChanged();
|
||||
|
||||
private:
|
||||
ColorScopeAttached *m_ownAttached;
|
||||
void checkColorGroupChanged();
|
||||
void setParentScope(ColorScope * parentScope);
|
||||
|
||||
bool m_inherit;
|
||||
Plasma::Theme::ColorGroup m_group;
|
||||
QPointer<ColorScope> m_parentScope;
|
||||
QObject *const m_parent;
|
||||
Plasma::Theme::ColorGroup m_actualGroup;
|
||||
bool m_deleting = false;
|
||||
|
||||
static QHash<QObject *, ColorScope *> s_attachedScopes;
|
||||
|
||||
static QWeakPointer<Plasma::Theme> s_theme;
|
||||
QSharedPointer<Plasma::Theme> m_theme;
|
||||
|
||||
};
|
||||
|
||||
|
@ -42,8 +42,7 @@ T.Button {
|
||||
Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl
|
||||
Kirigami.MnemonicData.label: control.text
|
||||
|
||||
contentItem: GridLayout {
|
||||
columns: control.display == T.AbstractButton.TextBesideIcon ? 2 : 1
|
||||
contentItem: RowLayout {
|
||||
PlasmaCore.IconItem {
|
||||
id: icon
|
||||
Layout.fillWidth: true
|
||||
|
@ -63,7 +63,6 @@ T.TabButton {
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
background: Item {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user