Store the title and icon in extenderitem's config so applets don't have to store/restore this info manually.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=877485
This commit is contained in:
Rob Scheepmaker 2008-10-29 17:01:11 +00:00
parent bd7e7b10c9
commit 871508e467
2 changed files with 15 additions and 7 deletions

View File

@ -72,15 +72,19 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
uint sourceAppletId = dg.readEntry("sourceAppletId", 0); uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
//TODO: automatically load title and icon. //check if we're creating a new item or reinstantiating an existing one.
if (!sourceAppletId) { if (!sourceAppletId) {
//The item is new //The item is new
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName()); dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName());
dg.writeEntry("sourceAppletId", hostExtender->d->applet->id()); dg.writeEntry("sourceAppletId", hostExtender->d->applet->id());
dg.writeEntry("sourceIconName", hostExtender->d->applet->icon());
d->sourceApplet = hostExtender->d->applet; d->sourceApplet = hostExtender->d->applet;
d->collapseIcon = new Icon(KIcon(hostExtender->d->applet->icon()), "", this);
} else { } else {
//The item already exists. //The item already exists.
d->name = dg.readEntry("extenderItemName", ""); d->name = dg.readEntry("extenderItemName", "");
d->title = dg.readEntry("extenderTitle", "");
d->collapseIcon = new Icon(KIcon(dg.readEntry("extenderIconName", "")), "", this);
//Find the sourceapplet. //Find the sourceapplet.
Corona *corona = hostExtender->d->applet->containment()->corona(); Corona *corona = hostExtender->d->applet->containment()->corona();
@ -97,15 +101,13 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
//make sure we keep monitoring if the source applet still exists, so the return to source icon //make sure we keep monitoring if the source applet still exists, so the return to source icon
//can be hidden if it is removed. //can be hidden if it is removed.
connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved())); connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved()));
connect(d->collapseIcon, SIGNAL(clicked()), this, SLOT(toggleCollapse()));
//create the toolbox. //create the toolbox.
d->toolbox = new QGraphicsWidget(this); d->toolbox = new QGraphicsWidget(this);
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox); d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
d->toolbox->setLayout(d->toolboxLayout); d->toolbox->setLayout(d->toolboxLayout);
//create the collapse/applet icon.
d->collapseIcon = new Icon(KIcon(hostExtender->d->applet->icon()), "", this);
connect(d->collapseIcon, SIGNAL(clicked()), this, SLOT(toggleCollapse()));
//set the extender we want to move to. //set the extender we want to move to.
setExtender(hostExtender); setExtender(hostExtender);
@ -135,6 +137,7 @@ KConfigGroup ExtenderItem::config() const
void ExtenderItem::setTitle(const QString &title) void ExtenderItem::setTitle(const QString &title)
{ {
d->title = title; d->title = title;
config().writeEntry("extenderTitle", title);
update(); update();
} }
@ -180,6 +183,7 @@ void ExtenderItem::setIcon(const QIcon &icon)
void ExtenderItem::setIcon(const QString &icon) void ExtenderItem::setIcon(const QString &icon)
{ {
d->collapseIcon->setIcon(icon); d->collapseIcon->setIcon(icon);
config().writeEntry("extenderIconName", icon);
} }
QIcon ExtenderItem::icon() const QIcon ExtenderItem::icon() const

View File

@ -112,7 +112,8 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
/** /**
* @param title the title that will be shown in the extender item's dragger. Default is * @param title the title that will be shown in the extender item's dragger. Default is
* no title. * no title. This title will also be stored in the item's configuration, so you don't have
* to manually store/restore this information for your extender items.
*/ */
void setTitle(const QString &title); void setTitle(const QString &title);
@ -123,7 +124,8 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
/** /**
* You can assign names to extender items to look them up through the item() function. * You can assign names to extender items to look them up through the item() function.
* Make sure you only use unique names. * Make sure you only use unique names. This name will be stored in the item's
* configuration.
* @param name the name of the item. Defaults to an empty string. * @param name the name of the item. Defaults to an empty string.
*/ */
void setName(const QString &name); void setName(const QString &name);
@ -135,7 +137,9 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
/** /**
* @param icon the icon name to display in the extender item's * @param icon the icon name to display in the extender item's
* drag handle. Defaults to the source applet's icon. * drag handle. Defaults to the source applet's icon. This icon name will also be stored
* in the item's configuration, so you don't have to manually store/restore this
* information.
*/ */
void setIcon(const QString &icon); void setIcon(const QString &icon);