diff --git a/applet.cpp b/applet.cpp index f6145f4a0..92a19d7a2 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1265,6 +1265,18 @@ void Applet::flushPendingConstraintsEvents() } } + if (!unlocked && d->handle) { + AppletHandle *h = d->handle.data(); + disconnect(this); + + QGraphicsScene *s = scene(); + if (s && h->scene() == s) { + s->removeItem(h); + } + + h->deleteLater(); + } + emit immutabilityChanged(immutability()); } @@ -1754,6 +1766,40 @@ bool Applet::eventFilter(QObject *o, QEvent *e) bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { + if (watched == this) { + switch (event->type()) { + case QEvent::GraphicsSceneHoverEnter: + //kDebug() << "got hoverenterEvent" << immutability() << " " << immutability(); + if (immutability() == Mutable) { + QGraphicsSceneHoverEvent *he = static_cast(event); + if (d->handle) { + d->handle.data()->setHoverPos(he->pos()); + } else { + //kDebug() << "generated applet handle"; + AppletHandle *handle = new AppletHandle(containment(), this, he->pos()); + connect(handle, SIGNAL(disappearDone(AppletHandle*)), + this, SLOT(handleDisappeared(AppletHandle*))); + connect(this, SIGNAL(geometryChanged()), + handle, SLOT(appletResized())); + d->handle = handle; + } + } + break; + + case QEvent::GraphicsSceneHoverMove: + if (d->handle && !d->handle.data()->shown() && immutability() == Mutable) { + QGraphicsSceneHoverEvent *he = static_cast(event); + d->handle.data()->setHoverPos(he->pos()); + } + break; + + default: + break; + } + + return false; + } + switch (event->type()) { case QEvent::GraphicsSceneMouseMove: case QEvent::GraphicsSceneMousePress: @@ -2359,6 +2405,16 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value) } } break; + case ItemParentHasChanged: + { + Containment *c = containment(); + if (c && c->containmentType() == Containment::DesktopContainment) { + installSceneEventFilter(this); + } else { + removeSceneEventFilter(this); + } + } + break; case ItemPositionHasChanged: emit geometryChanged(); // fall through! @@ -2868,6 +2924,24 @@ void AppletPrivate::resetConfigurationObject() } } +void AppletPrivate::handleDisappeared(AppletHandle *h) +{ + if (h == handle.data()) { + h->detachApplet(); + QGraphicsScene *scene = q->scene(); + if (scene && h->scene() == scene) { + scene->removeItem(h); + } + h->deleteLater(); + } +} + +void ContainmentPrivate::checkRemoveAction() +{ + q->enableAction("remove", q->immutability() == Mutable); +} + + uint AppletPrivate::s_maxAppletId = 0; int AppletPrivate::s_maxZValue = 0; int AppletPrivate::s_minZValue = 0; diff --git a/applet.h b/applet.h index 3d0ed18ab..a417dfddb 100644 --- a/applet.h +++ b/applet.h @@ -1124,6 +1124,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state)) Q_PRIVATE_SLOT(d, void globalShortcutChanged()) Q_PRIVATE_SLOT(d, void propagateConfigChanged()) + Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle)) /** * Reimplemented from QGraphicsItem diff --git a/containment.cpp b/containment.cpp index 87bb4f532..f0c0196ba 100644 --- a/containment.cpp +++ b/containment.cpp @@ -67,7 +67,6 @@ #include "remote/accessmanager.h" #include "private/applet_p.h" -#include "private/applethandle_p.h" #include "private/containmentactionspluginsconfig_p.h" #include "private/extenderitemmimedata_p.h" #include "private/extenderapplet_p.h" @@ -888,9 +887,6 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) applet->removeSceneEventFilter(currentContainment); KConfigGroup oldConfig = applet->config(); currentContainment->d->applets.removeAll(applet); - if (currentContainment->d->handles.contains(applet)) { - currentContainment->d->handles.remove(applet); - } applet->setParentItem(this); applet->setParent(this); @@ -918,12 +914,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) applet->setPos(pos); } - if (delayInit || currentContainment) { - if (d->type == DesktopContainment) { - applet->installSceneEventFilter(this); - //applet->setWindowFlags(Qt::Window); - } - } else { + if (!delayInit && !currentContainment) { applet->restore(*applet->d->mainConfigGroup()); applet->init(); Plasma::Animation *anim = Plasma::Animator::create(Plasma::Animator::AppearAnimation); @@ -1696,51 +1687,8 @@ void Containment::wheelEvent(QGraphicsSceneWheelEvent *event) bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { - Applet *applet = qgraphicsitem_cast(watched); - - // Otherwise we're watching something we shouldn't be... - Q_ASSERT(applet != 0); - if (!d->applets.contains(applet)) { - return false; - } - - //kDebug() << "got sceneEvent"; - switch (event->type()) { - case QEvent::GraphicsSceneHoverEnter: - //kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability(); - if (immutability() == Mutable && applet->immutability() == Mutable) { - QGraphicsSceneHoverEvent *he = static_cast(event); - if (d->handles.contains(applet)) { - AppletHandle *handle = d->handles.value(applet); - if (handle) { - handle->setHoverPos(he->pos()); - } - } else { - //kDebug() << "generated applet handle"; - AppletHandle *handle = new AppletHandle(this, applet, he->pos()); - d->handles[applet] = handle; - connect(handle, SIGNAL(disappearDone(AppletHandle*)), - this, SLOT(handleDisappeared(AppletHandle*))); - connect(applet, SIGNAL(geometryChanged()), - handle, SLOT(appletResized())); - } - } - break; - case QEvent::GraphicsSceneHoverMove: - if (immutability() == Mutable && applet->immutability() == Mutable) { - QGraphicsSceneHoverEvent *he = static_cast(event); - if (d->handles.contains(applet)) { - AppletHandle *handle = d->handles.value(applet); - if (handle) { - handle->setHoverPos(he->pos()); - } - } - } - break; - default: - break; - } - + Q_UNUSED(watched) + Q_UNUSED(event) return false; } @@ -2205,24 +2153,6 @@ void ContainmentPrivate::triggerShowAddWidgets() emit q->showAddWidgetsInterface(QPointF()); } -void ContainmentPrivate::handleDisappeared(AppletHandle *handle) -{ - if (handles.contains(handle->applet())) { - handles.remove(handle->applet()); - handle->detachApplet(); - QGraphicsScene *scene = q->scene(); - if (scene && handle->scene() == scene) { - scene->removeItem(handle); - } - handle->deleteLater(); - } -} - -void ContainmentPrivate::checkRemoveAction() -{ - q->enableAction("remove", q->immutability() == Mutable); -} - void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constraints) { if (!q->isContainment()) { @@ -2242,22 +2172,6 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra a->setImmutability(q->immutability()); a->updateConstraints(ImmutableConstraint); } - - //clear handles on lock - if (!unlocked) { - QMap h = handles; - handles.clear(); - - foreach (AppletHandle *handle, h) { - handle->disconnect(q); - - if (q->scene()) { - q->scene()->removeItem(handle); - } - - handle->deleteLater(); - } - } } // pass on the constraints that are relevant here @@ -2341,10 +2255,6 @@ void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet) focusedApplet = 0; } - if (handles.contains(applet)) { - handles.remove(applet); - } - emit q->appletRemoved(applet); emit q->configNeedsSaving(); } @@ -2362,11 +2272,7 @@ void ContainmentPrivate::appletAppearAnimationComplete() void ContainmentPrivate::appletAppeared(Applet *applet) { - kDebug() << type << Containment::DesktopContainment; - if (type == Containment::DesktopContainment) { - applet->installSceneEventFilter(q); - } - + //kDebug() << type << Containment::DesktopContainment; KConfigGroup *cg = applet->d->mainConfigGroup(); applet->save(*cg); emit q->configNeedsSaving(); diff --git a/containment.h b/containment.h index 8297b9e60..c60eda01c 100644 --- a/containment.h +++ b/containment.h @@ -644,7 +644,6 @@ Q_SIGNALS: Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete()) Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) - Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle)) Q_PRIVATE_SLOT(d, void positionToolBox()) Q_PRIVATE_SLOT(d, void requestConfiguration()) Q_PRIVATE_SLOT(d, void updateToolBoxVisibility()) diff --git a/private/applet_p.h b/private/applet_p.h index 7a951b72d..bd3c1e9e9 100644 --- a/private/applet_p.h +++ b/private/applet_p.h @@ -29,6 +29,7 @@ #include #include "plasma/animator.h" +#include "plasma/private/applethandle_p.h" #include "plasma/private/dataengineconsumer_p.h" #include "plasma/ui_publish.h" @@ -107,6 +108,7 @@ public: */ void setIsContainment(bool isContainment, bool forceUpdate = false); + void handleDisappeared(AppletHandle *handle); QString globalName() const; QString instanceName(); void scheduleConstraintsUpdate(Plasma::Constraints c); @@ -174,17 +176,18 @@ public: AppletOverlayWidget *messageOverlay; QGraphicsProxyWidget *messageOverlayProxy; Plasma::BusyWidget *busyWidget; - - // sripting and package stuff - AppletScript *script; - Package *package; - ConfigLoader *configLoader; QWeakPointer messageOkButton; QWeakPointer messageYesButton; QWeakPointer messageNoButton; QWeakPointer messageCancelButton; QWeakPointer messageCloseAction; + // sripting and package stuff + AppletScript *script; + Package *package; + ConfigLoader *configLoader; + QWeakPointer handle; + // actions stuff; put activationAction into actions? KActionCollection *actions; KAction *activationAction; diff --git a/private/applethandle.cpp b/private/applethandle.cpp index 96f4bf81d..59dfd38eb 100644 --- a/private/applethandle.cpp +++ b/private/applethandle.cpp @@ -58,10 +58,10 @@ qreal _k_pointAngle(QPointF point); QPointF _k_rotatePoint(QPointF point, qreal angle); QPointF _k_projectPoint(QPointF point, QPointF v); -AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos) +AppletHandle::AppletHandle(Containment *containment, Applet *applet, const QPointF &hoverPos) : QGraphicsObject(applet), m_pressedButton(NoButton), - m_containment(parent), + m_containment(containment), m_applet(applet), m_iconSize(KIconLoader::SizeSmall), m_opacity(0.0), @@ -116,6 +116,11 @@ AppletHandle::~AppletHandle() delete m_backgroundBuffer; } +bool AppletHandle::shown() const +{ + return !m_hoverTimer->isActive(); +} + Applet *AppletHandle::applet() const { return m_applet; diff --git a/private/applethandle_p.h b/private/applethandle_p.h index 3b770004d..4c1fd020d 100644 --- a/private/applethandle_p.h +++ b/private/applethandle_p.h @@ -61,8 +61,9 @@ class AppletHandle : public QGraphicsObject AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos); virtual ~AppletHandle(); - void detachApplet (); + bool shown() const; + void detachApplet(); Applet *applet() const; QRectF boundingRect() const; diff --git a/private/containment_p.h b/private/containment_p.h index 5fe1a102d..4025bf4d3 100644 --- a/private/containment_p.h +++ b/private/containment_p.h @@ -96,7 +96,6 @@ public: QPointF preferredPos(Corona *corona) const; QPointF preferredPanelPos(Corona *corona) const; void setLockToolText(); - void handleDisappeared(AppletHandle *handle); void appletDestroyed(Applet*); void appletAppearAnimationComplete(); void appletAppeared(Applet*); @@ -172,7 +171,6 @@ public: Applet::List applets; Applet *focusedApplet; Plasma::Wallpaper *wallpaper; - QMap handles; QHash localActionPlugins; int screen; int lastScreen;