allow plasmoids to change icon

changing icon will change the icon of the default compact representation
This commit is contained in:
Marco Martin 2013-09-23 16:44:31 +02:00
parent 135d4039aa
commit fab4818c92
6 changed files with 32 additions and 12 deletions

View File

@ -332,11 +332,12 @@ void Applet::setTitle(const QString &title) const
QString Applet::icon() const
{
if (!d->appletDescription.isValid()) {
return QString();
}
return d->icon;
}
return d->appletDescription.icon();
void Applet::setIcon(const QString &icon)
{
d->icon = icon;
}
KPluginInfo Applet::pluginInfo() const

View File

@ -282,10 +282,16 @@ class PLASMA_EXPORT Applet : public QObject
static Applet *loadPlasmoid(const QString &path, uint appletId = 0);
/**
* Returns the icon related to this applet
* @returns The icon name related to this applet
* By default is the one in the plasmoid desktop file
**/
QString icon() const;
/**
* Sets an icon name for this applet
* @param icon Freedesktop compatible icon name
*/
void setIcon(const QString &icon);
//ACTIONS

View File

@ -52,6 +52,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
q(applet),
immutability(Types::Mutable),
appletDescription(info ? *info : KPluginInfo(service)),
icon(appletDescription.isValid() ? appletDescription.icon() : QString()),
mainConfig(0),
pendingConstraints(Types::NoConstraint),
script(0),

View File

@ -87,6 +87,7 @@ public:
// applet info we keep around in case its needed
KPluginInfo appletDescription;
QString customTitle;
QString icon;
// bookkeeping
KConfigGroup *mainConfig;

View File

@ -221,21 +221,31 @@ QObject* AppletInterface::configuration() const
return m_configuration;
}
uint AppletInterface::id() const
{
return applet()->id();
}
QString AppletInterface::icon() const
{
return applet()->icon();
}
void AppletInterface::setIcon(const QString &icon)
{
if (applet()->icon() == icon) {
return;
}
applet()->setIcon(icon);
emit iconChanged();
}
QString AppletInterface::title() const
{
return applet()->title();
}
uint AppletInterface::id() const
{
return applet()->id();
}
void AppletInterface::setTitle(const QString &title)
{
if (applet()->title() == title) {

View File

@ -64,11 +64,10 @@ class AppletInterface : public QQuickItem
*/
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
//TODO: writable icon
/**
* Icon to represent the plasmoid
*/
Q_PROPERTY(QString icon READ icon CONSTANT)
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
/**
* Applet id: is unique in the whole Plasma session and will never change across restarts
@ -235,6 +234,7 @@ public:
//PROPERTY ACCESSORS-------------------------------------------------------------------
QString icon() const;
void setIcon(const QString &icon);
QString title() const;
void setTitle(const QString &title);
@ -294,6 +294,7 @@ Q_SIGNALS:
void configNeedsSaving();
//PROPERTY change notifiers--------------
void iconChanged();
void titleChanged();
void formFactorChanged();
void locationChanged();