*Applet::destroy() now handles everything needed for removing an applet prettily and safely.
*removed Containment::Private::destroyApplet in favour of just calling Applet::destroy() directly. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=805666
This commit is contained in:
parent
57ce2ba858
commit
61ae3df3fc
31
applet.cpp
31
applet.cpp
@ -255,26 +255,41 @@ KConfigGroup Applet::globalConfig() const
|
||||
|
||||
void Applet::destroy()
|
||||
{
|
||||
if (d->transient) {
|
||||
return; //don't double delete
|
||||
}
|
||||
d->transient = true;
|
||||
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
||||
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
||||
Animator::self()->animateItem(this, Animator::DisappearAnimation);
|
||||
}
|
||||
|
||||
void Applet::Private::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
||||
{
|
||||
if (anim != Animator::DisappearAnimation || item != q) {
|
||||
return; //it's not our time yet
|
||||
}
|
||||
//kDebug() << "???????????????? DESTROYING APPLET" << name() << " ???????????????????????????";
|
||||
QGraphicsWidget * item = dynamic_cast<QGraphicsWidget *>(parentItem());
|
||||
QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>(q->parentItem());
|
||||
//it probably won't matter, but right now if there are applethandles, *they* are the parent.
|
||||
//not the containment.
|
||||
|
||||
//is the applet in a containment and is the containment have a layout? if yes, we remove the applet in the layout
|
||||
if (item && item->layout()) {
|
||||
QGraphicsLayout *l = item->layout();
|
||||
if (parent && parent->layout()) {
|
||||
QGraphicsLayout *l = parent->layout();
|
||||
for (int i = 0; i < l->count(); ++i) {
|
||||
if (this == l->itemAt(i)) {
|
||||
if (q == l->itemAt(i)) {
|
||||
l->removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d->configXml) {
|
||||
d->configXml->setDefaults();
|
||||
if (configXml) {
|
||||
configXml->setDefaults();
|
||||
}
|
||||
|
||||
d->transient = true;
|
||||
deleteLater();
|
||||
q->deleteLater();
|
||||
}
|
||||
|
||||
ConfigXml* Applet::configScheme() const
|
||||
|
5
applet.h
5
applet.h
@ -32,6 +32,7 @@
|
||||
#include <plasma/configxml.h>
|
||||
#include <plasma/packagestructure.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/animator.h>
|
||||
|
||||
class KConfigDialog;
|
||||
class QGraphicsView;
|
||||
@ -462,7 +463,8 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
void setImmutability(const ImmutabilityType immutable);
|
||||
|
||||
/**
|
||||
* Destroys the applet; it will be deleted and configurations reset.
|
||||
* Destroys the applet; it will be removed nicely and deleted.
|
||||
* Its configuration will also be deleted.
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
@ -670,6 +672,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
Q_DISABLE_COPY(Applet)
|
||||
Q_PRIVATE_SLOT(d, void checkImmutability())
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim))
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
void checkImmutability();
|
||||
void themeChanged();
|
||||
void resetConfigurationObject();
|
||||
void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
||||
|
||||
static uint s_maxAppletId;
|
||||
static uint s_maxZValue;
|
||||
|
@ -329,7 +329,7 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
case RemoveButton:
|
||||
if (m_pressedButton == releasedAtButton) {
|
||||
forceDisappear();
|
||||
Animator::self()->animateItem(m_applet, Animator::DisappearAnimation);
|
||||
m_applet->destroy();
|
||||
}
|
||||
break;
|
||||
case MoveButton: {
|
||||
|
@ -308,11 +308,8 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
||||
}
|
||||
|
||||
QAction* closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
|
||||
QVariant appletV;
|
||||
appletV.setValue((QObject*)applet);
|
||||
closeApplet->setData(appletV);
|
||||
closeApplet->setIcon(KIcon("edit-delete"));
|
||||
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(destroyApplet()));
|
||||
connect(closeApplet, SIGNAL(triggered(bool)), applet, SLOT(destroy()));
|
||||
desktopMenu.addAction(closeApplet);
|
||||
hasEntries = true;
|
||||
}
|
||||
@ -951,18 +948,6 @@ void Containment::Private::containmentConstraintsEvent(Plasma::Constraints const
|
||||
}
|
||||
}
|
||||
|
||||
void Containment::Private::destroyApplet()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction*>(q->sender());
|
||||
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
|
||||
Animator::self()->animateItem(applet, Animator::DisappearAnimation);
|
||||
}
|
||||
|
||||
Applet* Containment::Private::addApplet(const QString& name, const QVariantList& args,
|
||||
const QRectF& appletGeometry, uint id, bool delayInit)
|
||||
{
|
||||
@ -1018,19 +1003,7 @@ void Containment::Private::appletDestroyed(QObject* object)
|
||||
|
||||
void Containment::Private::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
||||
{
|
||||
if (anim == Animator::DisappearAnimation) {
|
||||
QGraphicsItem *parent = item->parentItem();
|
||||
|
||||
while (parent) {
|
||||
if (parent == q) {
|
||||
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
||||
applet->destroy();
|
||||
break;
|
||||
}
|
||||
|
||||
parent = parent->parentItem();
|
||||
}
|
||||
} else if (anim == Animator::AppearAnimation) {
|
||||
if (anim == Animator::AppearAnimation) {
|
||||
if (q->containmentType() == DesktopContainment &&
|
||||
item->parentItem() == q &&
|
||||
qgraphicsitem_cast<Applet*>(item)) {
|
||||
|
@ -352,7 +352,6 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim))
|
||||
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
|
||||
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
|
||||
Q_PRIVATE_SLOT(d, void destroyApplet())
|
||||
Q_PRIVATE_SLOT(d, void positionToolBox())
|
||||
Q_PRIVATE_SLOT(d, void zoomIn())
|
||||
Q_PRIVATE_SLOT(d, void zoomOut())
|
||||
|
@ -66,7 +66,6 @@ public:
|
||||
void positionContainment();
|
||||
void setLockToolText();
|
||||
void handleDisappeared(AppletHandle *handle);
|
||||
void destroyApplet();
|
||||
void appletDestroyed(QObject*);
|
||||
void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
||||
void zoomIn();
|
||||
|
Loading…
Reference in New Issue
Block a user