commit d8339715e428ea3d5eb2cc12388d85996e44ac9c Author: David Edmundson Date: Thu Jun 13 13:27:17 2019 +0100 Allow QtQuick applets and wallpapers to defer UiReadyConstraint - V1 diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 41c8d423c..afb6f69bf 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -169,7 +169,9 @@ void AppletInterface::init() geometryChanged(QRectF(), QRectF(x(), y(), width(), height())); emit busyChanged(); - applet()->updateConstraints(Plasma::Types::UiReadyConstraint); + updateUiReadyConstraint(); + + connect(this, &AppletInterface::isLoadingChanged, this, &AppletInterface::updateUiReadyConstraint); connect(applet(), &Plasma::Applet::activated, this, [ = ]() { @@ -851,5 +853,16 @@ bool AppletInterface::eventFilter(QObject *watched, QEvent *event) return AppletQuickItem::eventFilter(watched, event); } +void AppletInterface::updateUiReadyConstraint() +{ + if (!isLoading()) { + applet()->updateConstraints(Plasma::Types::UiReadyConstraint); + } +} + +bool AppletInterface::isLoading() const +{ + return m_loading; +} #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index f09f99f48..9f75b5e47 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -238,6 +238,8 @@ class AppletInterface : public PlasmaQuick::AppletQuickItem */ Q_PROPERTY(QVariantList availableScreenRegion READ availableScreenRegion NOTIFY availableScreenRegionChanged) + Q_PROPERTY(bool loading MEMBER m_loading NOTIFY isLoadingChanged) + public: AppletInterface(DeclarativeAppletScript *script, const QVariantList &args = QVariantList(), QQuickItem *parent = nullptr); ~AppletInterface() override; @@ -448,6 +450,8 @@ Q_SIGNALS: void configurationRequiredChanged(); void configurationRequiredReasonChanged(); + void isLoadingChanged(); + protected Q_SLOTS: void init() override; @@ -455,6 +459,15 @@ protected: bool event(QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override; + /* + * Returns true if this plasmoid or a dependent feature (i.e wallpaper) is loading + */ + virtual bool isLoading() const; + /* + * Set UIReadyConstraint if we're not currently loading + */ + void updateUiReadyConstraint(); + private Q_SLOTS: void destroyedChanged(bool destroyed); @@ -474,6 +487,7 @@ private: QVariantList m_args; Plasma::Types::BackgroundHints m_backgroundHints; bool m_hideOnDeactivate : 1; + bool m_loading = false; //this is used to build an emacs style shortcut int m_oldKeyboardShortcut; QObject *m_dummyNativeInterface; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index db0d8b9d1..cd06ec92f 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -860,6 +860,8 @@ void ContainmentInterface::loadWallpaper() //Qml seems happier if the parent gets set in this way m_wallpaperInterface->setProperty("parent", QVariant::fromValue(this)); + connect(m_wallpaperInterface, &WallpaperInterface::isLoadingChanged, this, &AppletInterface::updateUiReadyConstraint); + //set anchors QQmlExpression expr(qmlObject()->engine()->rootContext(), m_wallpaperInterface, QStringLiteral("parent")); QQmlProperty prop(m_wallpaperInterface, QStringLiteral("anchors.fill")); @@ -1216,4 +1218,14 @@ void ContainmentInterface::addContainmentActions(QMenu *desktopMenu, QEvent *eve return; } +bool ContainmentInterface::isLoading() const +{ + bool loading = AppletInterface::isLoading(); + if (m_wallpaperInterface) { + loading &= m_wallpaperInterface->isLoading(); + } + return loading; +} + + #include "moc_containmentinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 34a3f2f8c..ef4e54c6e 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -168,6 +168,8 @@ protected: void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event); void addContainmentActions(QMenu *desktopMenu, QEvent *event); + virtual bool isLoading() const override; + Q_SIGNALS: /** * Emitted when an applet is added diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp index 2269fee3b..d1988b566 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -266,4 +266,10 @@ WallpaperInterface * WallpaperInterface::qmlAttachedProperties(QObject* object) return object->parent() ? nullptr : s_rootObjects.value(QtQml::qmlEngine(object)); } +bool WallpaperInterface::isLoading() const +{ + return m_loading; +} + + #include "moc_wallpaperinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.h b/src/scriptengines/qml/plasmoid/wallpaperinterface.h index b315f519d..daea6a80a 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.h +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.h @@ -49,6 +49,7 @@ class WallpaperInterface : public QQuickItem Q_PROPERTY(QString pluginName READ pluginName NOTIFY packageChanged) Q_PROPERTY(KDeclarative::ConfigPropertyMap *configuration READ configuration NOTIFY configurationChanged) + Q_PROPERTY(bool loading MEMBER m_loading NOTIFY isLoadingChanged) public: explicit WallpaperInterface(ContainmentInterface *parent = nullptr); @@ -86,9 +87,12 @@ public: static WallpaperInterface *qmlAttachedProperties(QObject *object); + bool isLoading() const; + Q_SIGNALS: void packageChanged(); void configurationChanged(); + void isLoadingChanged(); private Q_SLOTS: void syncWallpaperPackage(); @@ -103,6 +107,7 @@ private: KDeclarative::ConfigPropertyMap *m_configuration; KConfigLoader *m_configLoader; KActionCollection *m_actions; + bool m_loading = false; static QHash s_rootObjects; };