fix up swapContainment a bit; it doesn't need to take the old containment, as we already know what that is, document with some comments, and make better use of save/restore and addApplet

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=849912
This commit is contained in:
Aaron J. Seigo 2008-08-20 13:13:03 +00:00
parent 3687d22770
commit 3f7d35a61b
2 changed files with 20 additions and 10 deletions

View File

@ -236,27 +236,38 @@ Containment* View::containment() const
return d->containment;
}
Containment* View::swapContainment(Containment* old, const QString& name, const QVariantList& args)
Containment* View::swapContainment(const QString& name, const QVariantList& args)
{
Containment *old = d->containment;
Plasma::Corona* corona = old->corona();
KConfigGroup containmentConfig = old->config();
Plasma::Containment *c = corona->addContainment(name, args);
if (c) {
KConfigGroup cfg = c->config();
if (old->wallpaper()) {
old->wallpaper()->save(KConfigGroup(&cfg, "Wallpaper"));
}
// ensure that the old containments configuration is up to date
old->save(containmentConfig);
// load the configuration of the old containment into the new one
c->restore(containmentConfig);
// move the applets from the old to the new containment
foreach (QGraphicsItem* item, old->childItems()) {
Plasma::Applet* applet = dynamic_cast<Plasma::Applet*>(item);
if (applet) {
QRectF geom = applet->geometry();
item->setParentItem(c);
applet->setGeometry(geom);
c->addApplet(applet, applet->pos(), true);
}
}
// set our containment
setContainment(c);
// destroy the old one
old->destroy();
// and now save the config
containmentConfig = c->config();
c->save(containmentConfig);
corona->requestConfigSync();
return c;
}
return old;

3
view.h
View File

@ -122,11 +122,10 @@ public:
* Swap the containment for this view, which will also cause the view
* to track the geometry of the containment.
*
* @param old Pointer to old containment
* @param name the plugin name for the new containment.
* @param args argument list to pass to the containment
*/
Containment* swapContainment(Containment* old, const QString& name,
Containment* swapContainment(const QString& name,
const QVariantList& args = QVariantList());
/**