From 6973dac801ebc40321d539c41c68743e2da5557b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 9 Mar 2016 11:32:46 +0100 Subject: [PATCH] add icon/titleChanged make it possible to set icon and title from the Applet subclass, making appletInterface (so plasmoid obj) notice about the change and relay the notify signal --- src/plasma/applet.cpp | 12 +++++++++++- src/plasma/applet.h | 18 +++++++++++++++--- .../qml/plasmoid/appletinterface.cpp | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index 8ddb4baa2..2da99243a 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -335,9 +335,14 @@ QString Applet::title() const return i18n("Unknown"); } -void Applet::setTitle(const QString &title) const +void Applet::setTitle(const QString &title) { + if (title == d->customTitle) { + return; + } + d->customTitle = title; + emit titleChanged(title); } QString Applet::icon() const @@ -347,7 +352,12 @@ QString Applet::icon() const void Applet::setIcon(const QString &icon) { + if (icon == d->icon) { + return; + } + d->icon = icon; + emit iconChanged(icon); } KPluginInfo Applet::pluginInfo() const diff --git a/src/plasma/applet.h b/src/plasma/applet.h index 95662c75f..c3ab03049 100644 --- a/src/plasma/applet.h +++ b/src/plasma/applet.h @@ -71,8 +71,8 @@ class PLASMA_EXPORT Applet : public QObject Q_PROPERTY(Plasma::Types::ImmutabilityType immutability READ immutability WRITE setImmutability NOTIFY immutabilityChanged) Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged) Q_PROPERTY(Plasma::Types::Location location READ location NOTIFY locationChanged) - Q_PROPERTY(QString title READ title WRITE setTitle FINAL) - Q_PROPERTY(QString icon READ icon WRITE setIcon FINAL) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged FINAL) public: //CONSTRUCTORS @@ -290,7 +290,7 @@ public: * @since 5.0 * @param title the user-visible title for the applet. */ - void setTitle(const QString &title) const; + void setTitle(const QString &title); /** * Attempts to load an applet from a package @@ -419,6 +419,18 @@ Q_SIGNALS: */ void destroyedChanged(bool destroyed); + /** + * Emitted when the title has changed + * @since 5.20 + */ + void titleChanged(const QString &title); + + /** + * Emitted when the icon name for the applet has changed + * @since 5.20 + */ + void iconChanged(const QString &icon); + //CONFIGURATION /** * Emitted when an applet has changed values in its configuration diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 3ce97b8a0..2337652ea 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -80,6 +80,12 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant connect(applet(), &Plasma::Applet::destroyedChanged, this, &AppletInterface::destroyedChanged); + connect(applet(), &Plasma::Applet::titleChanged, + this, &AppletInterface::titleChanged); + + connect(applet(), &Plasma::Applet::iconChanged, + this, &AppletInterface::iconChanged); + connect(applet(), &Plasma::Applet::activated, this, &AppletInterface::activated);