[plasma/union] src: Add a "DefaultStyleChangedEvent" to PlatformPlugin

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 11:20:05 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a0dd225076fc1a07ebd1589876212444434dc5a5 by Arjen Hiemstra.
Committed on 05/08/2026 at 11:15.
Pushed by ahiemstra into branch 'master'.

Add a "DefaultStyleChangedEvent" to PlatformPlugin

It can be sent when the platform determines that the default style
changed for some reason.

M  +16   -0    src/PlatformPlugin.cpp
M  +10   -0    src/PlatformPlugin.h
M  +8    -0    src/output/qtquick/plugin/QuickElement.cpp

https://invent.kde.org/plasma/union/-/commit/a0dd225076fc1a07ebd1589876212444434dc5a5

diff --git a/src/PlatformPlugin.cpp b/src/PlatformPlugin.cpp
index d8343244..3f528c8d 100644
--- a/src/PlatformPlugin.cpp
+++ b/src/PlatformPlugin.cpp
@@ -6,9 +6,14 @@
 #include <QIcon>
 #include <QStandardPaths>
 
+#include "EventHelper.h"
+
 using namespace Union;
 using namespace Qt::StringLiterals;
 
+UNION_EXPORT QEvent::Type DefaultStyleChangedEvent::s_type = QEvent::None;
+static EventTypeRegistration<DefaultStyleChangedEvent> defaultStyleChangedEventRegistration;
+
 PlatformPlugin::PlatformPlugin(QObject *parent)
     : Plugin(parent)
 {
@@ -43,3 +48,14 @@ qreal PlatformPlugin::animationSpeedMultiplier()
 {
     return 1.0;
 }
+
+void PlatformPlugin::sendDefaultStyleChangedEvent()
+{
+    DefaultStyleChangedEvent event;
+    QCoreApplication::sendEvent(this, &event);
+}
+
+DefaultStyleChangedEvent::DefaultStyleChangedEvent()
+    : QEvent(DefaultStyleChangedEvent::s_type)
+{
+}
diff --git a/src/PlatformPlugin.h b/src/PlatformPlugin.h
index d5a2d082..a5fe3979 100644
--- a/src/PlatformPlugin.h
+++ b/src/PlatformPlugin.h
@@ -78,8 +78,18 @@ public:
      * Emitted whenever animationSpeedMultiplier changes.
      */
     Q_SIGNAL void animationSpeedMultiplierChanged();
+
+protected:
+    void sendDefaultStyleChangedEvent();
 };
 
+class DefaultStyleChangedEvent : public QEvent
+{
+public:
+    DefaultStyleChangedEvent();
+
+    static QEvent::Type s_type;
+};
 }
 
 Q_DECLARE_INTERFACE(Union::PlatformPlugin, "org.kde.union.PlatformPlugin")
diff --git a/src/output/qtquick/plugin/QuickElement.cpp b/src/output/qtquick/plugin/QuickElement.cpp
index 1470e7f8..4cab9da0 100644
--- a/src/output/qtquick/plugin/QuickElement.cpp
+++ b/src/output/qtquick/plugin/QuickElement.cpp
@@ -445,6 +445,14 @@ bool QuickElement::eventFilter(QObject *watched, QEvent *event)
         return false;
     }
 
+    if (event->type() == DefaultStyleChangedEvent::s_type) {
+        if (m_styleId.isEmpty() && !attachedParent()) {
+            setStyle(StyleRegistry::instance()->defaultStyle());
+            update();
+        }
+        return false;
+    }
+
     return QObject::eventFilter(watched, event);
 }