support setting a custom name from applets (e.g. a timezone for a clock ;)

This commit is contained in:
Aaron Seigo 2012-11-07 02:14:18 +01:00
parent e174c6d998
commit 4f3a52cec2
3 changed files with 18 additions and 2 deletions

View File

@ -487,6 +487,10 @@ bool Applet::isBusy() const
QString Applet::name() const QString Applet::name() const
{ {
if (!d->customName.isEmpty()) {
return d->customName;
}
if (d->isContainment) { if (d->isContainment) {
const Containment *c = qobject_cast<const Containment*>(this); const Containment *c = qobject_cast<const Containment*>(this);
if (c && c->d->isPanelContainment()) { if (c && c->d->isPanelContainment()) {
@ -503,6 +507,11 @@ QString Applet::name() const
return d->appletDescription.name(); return d->appletDescription.name();
} }
void Applet::setName(const QString &name) const
{
d->customName = name;
}
QFont Applet::font() const QFont Applet::font() const
{ {
return QApplication::font(); return QApplication::font();

View File

@ -74,7 +74,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface) Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
Q_PROPERTY(QString name READ name) Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString pluginName READ pluginName) Q_PROPERTY(QString pluginName READ pluginName)
Q_PROPERTY(QString category READ category) Q_PROPERTY(QString category READ category)
Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability) Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
@ -354,12 +354,18 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/** /**
* Returns the user-visible name for the applet, as specified in the * Returns the user-visible name for the applet, as specified in the
* .desktop file. * .desktop file. Can be changed with @see setName
* *
* @return the user-visible name for the applet. * @return the user-visible name for the applet.
**/ **/
QString name() const; QString name() const;
/**
* Sets a custom name for this instance of the applet. E.g. a clock might
* use the timezone as its name rather than the .desktop file
*/
void setName(const QString &name) const;
/** /**
* @return the font currently set for this widget * @return the font currently set for this widget
**/ **/

View File

@ -148,6 +148,7 @@ public:
// applet info we keep around in case its needed // applet info we keep around in case its needed
KPluginInfo appletDescription; KPluginInfo appletDescription;
QVariantList args; QVariantList args;
QString name;
// bookkeeping // bookkeeping
QSet<QGraphicsItem*> registeredAsDragHandle; QSet<QGraphicsItem*> registeredAsDragHandle;