animate items being removed. whee. the only problem would be if the item is being removed but plasma is quit before the anim finishes... or if some top-level applet calls disappear on itself (though why they'd do that i don't?)

let's see if that ever really matters. if it does, then we can simply keep a list of applets being removed around. but let's play fast 'n loose for now.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=728722
This commit is contained in:
Aaron J. Seigo 2007-10-24 02:10:10 +00:00
parent 603130699a
commit db095df33e
2 changed files with 36 additions and 1 deletions

View File

@ -128,6 +128,10 @@ void Containment::init()
// irc meeting // irc meeting
translate(0, -r.height() - INTER_CONTAINMENT_MARGIN); translate(0, -r.height() - INTER_CONTAINMENT_MARGIN);
} }
//TODO: would be nice to not do this on init, as it causes Phase to init
connect(Phase::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)),
this, SLOT(appletDisappearComplete(QGraphicsItem*,Plasma::Phase::Animation)));
} }
void Containment::initConstraints(KConfigGroup* group) void Containment::initConstraints(KConfigGroup* group)
@ -266,8 +270,11 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
if (scene() && !static_cast<Corona*>(scene())->isImmutable()) { if (scene() && !static_cast<Corona*>(scene())->isImmutable()) {
QAction* closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu); QAction* closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
QVariant appletV;
appletV.setValue((QObject*)applet);
closeApplet->setData(appletV);
connect(closeApplet, SIGNAL(triggered(bool)), connect(closeApplet, SIGNAL(triggered(bool)),
applet, SLOT(destroy())); this, SLOT(destroyApplet()));
desktopMenu.addAction(closeApplet); desktopMenu.addAction(closeApplet);
hasEntries = true; hasEntries = true;
} }
@ -432,6 +439,31 @@ void Containment::appletDestroyed(QObject* object)
} }
} }
void Containment::destroyApplet()
{
QAction *action = qobject_cast<QAction*>(sender());
if (!action) {
return;
}
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
Phase::self()->animateItem(applet, Phase::Disappear);
}
void Containment::appletDisappearComplete(QGraphicsItem *item, Plasma::Phase::Animation anim)
{
if (anim == Phase::Disappear) {
if (item->parentItem() == this) {
Applet *applet = qgraphicsitem_cast<Applet*>(item);
if (applet) {
applet->destroy();
}
}
}
}
Applet::List Containment::applets() const Applet::List Containment::applets() const
{ {
return d->applets; return d->applets;

View File

@ -28,6 +28,7 @@
#include <kgenericfactory.h> #include <kgenericfactory.h>
#include <plasma/applet.h> #include <plasma/applet.h>
#include <plasma/phase.h>
namespace Plasma namespace Plasma
{ {
@ -230,6 +231,8 @@ class PLASMA_EXPORT Containment : public Applet
* @internal * @internal
*/ */
void appletDestroyed(QObject*); void appletDestroyed(QObject*);
void destroyApplet();
void appletDisappearComplete(QGraphicsItem *item, Plasma::Phase::Animation anim);
void dropEvent(QGraphicsSceneDragDropEvent* event); void dropEvent(QGraphicsSceneDragDropEvent* event);
private: private: