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
This commit is contained in:
Marco Martin 2016-03-09 11:32:46 +01:00
parent d405378219
commit 6973dac801
3 changed files with 32 additions and 4 deletions

View File

@ -335,9 +335,14 @@ QString Applet::title() const
return i18n("Unknown"); return i18n("Unknown");
} }
void Applet::setTitle(const QString &title) const void Applet::setTitle(const QString &title)
{ {
if (title == d->customTitle) {
return;
}
d->customTitle = title; d->customTitle = title;
emit titleChanged(title);
} }
QString Applet::icon() const QString Applet::icon() const
@ -347,7 +352,12 @@ QString Applet::icon() const
void Applet::setIcon(const QString &icon) void Applet::setIcon(const QString &icon)
{ {
if (icon == d->icon) {
return;
}
d->icon = icon; d->icon = icon;
emit iconChanged(icon);
} }
KPluginInfo Applet::pluginInfo() const KPluginInfo Applet::pluginInfo() const

View File

@ -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::ImmutabilityType immutability READ immutability WRITE setImmutability NOTIFY immutabilityChanged)
Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged) Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
Q_PROPERTY(Plasma::Types::Location location READ location NOTIFY locationChanged) Q_PROPERTY(Plasma::Types::Location location READ location NOTIFY locationChanged)
Q_PROPERTY(QString title READ title WRITE setTitle FINAL) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
Q_PROPERTY(QString icon READ icon WRITE setIcon FINAL) Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged FINAL)
public: public:
//CONSTRUCTORS //CONSTRUCTORS
@ -290,7 +290,7 @@ public:
* @since 5.0 * @since 5.0
* @param title the user-visible title for the applet. * @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 * Attempts to load an applet from a package
@ -419,6 +419,18 @@ Q_SIGNALS:
*/ */
void destroyedChanged(bool destroyed); 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 //CONFIGURATION
/** /**
* Emitted when an applet has changed values in its configuration * Emitted when an applet has changed values in its configuration

View File

@ -80,6 +80,12 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant
connect(applet(), &Plasma::Applet::destroyedChanged, connect(applet(), &Plasma::Applet::destroyedChanged,
this, &AppletInterface::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, connect(applet(), &Plasma::Applet::activated,
this, &AppletInterface::activated); this, &AppletInterface::activated);