actually make plasmoid removal work and harden the applet handle against the applet being removed from under it

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=739867
This commit is contained in:
Aaron J. Seigo 2007-11-22 05:11:06 +00:00
parent e9d29e93b5
commit 9c52d8f067
4 changed files with 77 additions and 43 deletions

View File

@ -77,12 +77,17 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
} }
m_applet->setParentItem(this); m_applet->setParentItem(this);
connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
startFading(FadeIn); startFading(FadeIn);
} }
AppletHandle::~AppletHandle() AppletHandle::~AppletHandle()
{ {
if (!m_applet) {
return;
}
QRectF rect(m_applet->boundingRect()); QRectF rect(m_applet->boundingRect());
QPointF center = rect.center(); QPointF center = rect.center();
@ -162,7 +167,7 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
break; break;
} }
if (m_applet->hasConfigurationInterface()) { if (m_applet && m_applet->hasConfigurationInterface()) {
painter->drawPixmap(point + shiftC, KIcon("configure").pixmap(ICON_SIZE, ICON_SIZE)); painter->drawPixmap(point + shiftC, KIcon("configure").pixmap(ICON_SIZE, ICON_SIZE));
point += QPointF(0.0, ICON_SIZE + ICON_MARGIN); point += QPointF(0.0, ICON_SIZE + ICON_MARGIN);
} }
@ -187,7 +192,7 @@ AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const
QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(ICON_SIZE, ICON_SIZE))); QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(ICON_SIZE, ICON_SIZE)));
if (m_applet->hasConfigurationInterface()) { if (m_applet && m_applet->hasConfigurationInterface()) {
if (activeArea.containsPoint(point, Qt::OddEvenFill)) { if (activeArea.containsPoint(point, Qt::OddEvenFill)) {
return ConfigureButton; return ConfigureButton;
} }
@ -223,12 +228,12 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
ButtonType releasedAtButton = mapToButton(event->pos()); ButtonType releasedAtButton = mapToButton(event->pos());
if (event->button()==Qt::LeftButton && m_pressedButton==releasedAtButton) { if (m_applet && event->button() == Qt::LeftButton && m_pressedButton==releasedAtButton) {
if (m_pressedButton==ConfigureButton) { if (m_pressedButton == ConfigureButton) {
//FIXME: Remove this call once the configuration management change was done //FIXME: Remove this call once the configuration management change was done
m_containment->emitLaunchActivated(); m_containment->emitLaunchActivated();
m_applet->showConfigurationInterface(); m_applet->showConfigurationInterface();
} else if (m_pressedButton==RemoveButton) { } else if (m_pressedButton == RemoveButton) {
Phase::self()->animateItem(m_applet, Phase::Disappear); Phase::self()->animateItem(m_applet, Phase::Disappear);
forceDisappear(); forceDisappear();
} }
@ -258,7 +263,10 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
static const qreal snapAngle = 3.14159 / 2.0; static const qreal snapAngle = 3.14159 / 2.0;
if (m_pressedButton == MoveButton) { if (!m_applet) {
QGraphicsItem::mouseMoveEvent(event);
}
else if (m_pressedButton == MoveButton) {
QPointF delta = event->pos()-event->lastPos(); QPointF delta = event->pos()-event->lastPos();
setPos(pos()+delta); setPos(pos()+delta);
} else if (m_pressedButton == RotateButton) { } else if (m_pressedButton == RotateButton) {
@ -318,6 +326,12 @@ void AppletHandle::fadeAnimation(qreal progress)
update(); update();
} }
void AppletHandle::appletDestroyed()
{
m_applet = 0;
deleteLater();
}
void AppletHandle::startFading(FadeType anim) void AppletHandle::startFading(FadeType anim)
{ {
if (m_animId!=0) { if (m_animId!=0) {

View File

@ -58,6 +58,7 @@ class AppletHandle : public QObject, public QGraphicsItem
private Q_SLOTS: private Q_SLOTS:
void fadeAnimation(qreal progress); void fadeAnimation(qreal progress);
void appletDestroyed();
private: private:
static const int HANDLE_WIDTH = 5; static const int HANDLE_WIDTH = 5;

View File

@ -213,39 +213,39 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
desktopMenu.addAction(action); desktopMenu.addAction(action);
} }
} else { } else {
bool hasEntries = false; bool hasEntries = false;
if (applet->hasConfigurationInterface()) { if (applet->hasConfigurationInterface()) {
QAction* configureApplet = new QAction(i18n("%1 Settings...", applet->name()), &desktopMenu); QAction* configureApplet = new QAction(i18n("%1 Settings...", applet->name()), &desktopMenu);
connect(configureApplet, SIGNAL(triggered(bool)), connect(configureApplet, SIGNAL(triggered(bool)),
applet, SLOT(showConfigurationInterface())); applet, SLOT(showConfigurationInterface()));
desktopMenu.addAction(configureApplet); desktopMenu.addAction(configureApplet);
hasEntries = true; hasEntries = true;
} }
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; QVariant appletV;
appletV.setValue((QObject*)applet); appletV.setValue((QObject*)applet);
closeApplet->setData(appletV); closeApplet->setData(appletV);
connect(closeApplet, SIGNAL(triggered(bool)), connect(closeApplet, SIGNAL(triggered(bool)),
this, SLOT(destroyApplet())); this, SLOT(destroyApplet()));
desktopMenu.addAction(closeApplet); desktopMenu.addAction(closeApplet);
hasEntries = true; hasEntries = true;
} }
QList<QAction*> actions = applet->contextActions(); QList<QAction*> actions = applet->contextActions();
if (!actions.isEmpty()) { if (!actions.isEmpty()) {
desktopMenu.addSeparator(); desktopMenu.addSeparator();
foreach(QAction* action, actions) { foreach(QAction* action, actions) {
desktopMenu.addAction(action); desktopMenu.addAction(action);
} }
hasEntries = true; hasEntries = true;
} }
if (!hasEntries) { if (!hasEntries) {
QGraphicsItem::contextMenuEvent(event); QGraphicsItem::contextMenuEvent(event);
kDebug() << "no entries"; kDebug() << "no entries";
return; return;
} }
} }
@ -254,6 +254,18 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
desktopMenu.exec(event->screenPos()); desktopMenu.exec(event->screenPos());
} }
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::setFormFactor(FormFactor formFactor) void Containment::setFormFactor(FormFactor formFactor)
{ {
if (d->formFactor == formFactor && layout()) { if (d->formFactor == formFactor && layout()) {
@ -400,12 +412,18 @@ void Containment::appletDestroyed(QObject* object)
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim) void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim)
{ {
if (anim == Phase::Disappear) { if (anim == Phase::Disappear) {
if (item->parentItem() == this) { QGraphicsItem *parent = item->parentItem();
Applet *applet = qgraphicsitem_cast<Applet*>(item);
if (applet) { while (parent) {
applet->destroy(); if (parent == this) {
Applet *applet = qgraphicsitem_cast<Applet*>(item);
if (applet) {
applet->destroy();
}
} }
parent = parent->parentItem();
} }
} else if (anim == Phase::Appear) { } else if (anim == Phase::Appear) {
if (containmentType() == DesktopContainment) { if (containmentType() == DesktopContainment) {

View File

@ -283,6 +283,7 @@ class PLASMA_EXPORT Containment : public Applet
private Q_SLOTS: private Q_SLOTS:
void handleDisappeared(AppletHandle *handle); void handleDisappeared(AppletHandle *handle);
void destroyApplet();
private: private:
Q_DISABLE_COPY(Containment) Q_DISABLE_COPY(Containment)