diff --git a/applethandle.cpp b/applethandle.cpp index 1b6e072d8..8cd2dd765 100644 --- a/applethandle.cpp +++ b/applethandle.cpp @@ -30,6 +30,8 @@ #include "applet.h" #include "containment.h" +#include "corona.h" +#include "applet.h" #include "theme.h" namespace Plasma @@ -259,6 +261,32 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) else if (m_pressedButton == MoveButton) { QPointF delta = event->pos()-event->lastPos(); setPos(pos()+delta); + // test for containment change + if (!m_containment->sceneBoundingRect().contains(event->scenePos())) { + // see which containment it belongs to + Corona * corona = qobject_cast(scene()); + if (corona) { + QList containments = corona->containments(); + for (int i = 0; i < containments.size(); ++i) { + if (containments[i]->sceneBoundingRect().contains(event->scenePos())) { + // add the applet to the new containment + // and take it from the old one + QPointF scenePosition = scenePos(); + kDebug() << "moving to other containment with position" << event->pos() << event->scenePos(); + kDebug() << "position before reparenting" << pos() << scenePos(); + m_applet->removeSceneEventFilter(m_containment); + m_containment = containments[i]; + //m_containment->addChild(m_applet); + //setParentItem(containments[i]); + setPos(m_containment->mapFromScene(scenePosition)); + m_applet->installSceneEventFilter(m_containment); + m_containment->addApplet(m_applet); + update(); + break; + } + } + } + } } else if (m_pressedButton == RotateButton) { if (_k_distanceForPoint(event->pos()-event->lastPos()) <= 1.0) { return; diff --git a/containment.cpp b/containment.cpp index 726a8973e..6657d2b4c 100644 --- a/containment.cpp +++ b/containment.cpp @@ -352,12 +352,13 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui applet = new Applet; } - addChild(applet); //panels don't want backgrounds, which is important when setting geometry if (containmentType() == PanelContainment) { applet->setDrawStandardBackground(false); } + addApplet(applet); + //the applet needs to be given constraints before it can set its geometry applet->updateConstraints(Plasma::AllConstraints); @@ -387,15 +388,20 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui applet->init(); } - d->applets << applet; - connect(applet, SIGNAL(destroyed(QObject*)), - this, SLOT(appletDestroyed(QObject*))); Phase::self()->animateItem(applet, Phase::Appear); emit appletAdded(applet); return applet; } +void Containment::addApplet(Applet * applet) +{ + d->applets << applet; + addChild(applet); + connect(applet, SIGNAL(destroyed(QObject*)), + this, SLOT(appletDestroyed(QObject*))); +} + void Containment::appletDestroyed(QObject* object) { // we do a static_cast here since it really isn't an Applet by this @@ -602,6 +608,7 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event) //QEvent::GraphicsSceneHoverEnter // Otherwise we're watching something we shouldn't be... + kDebug() << "got sceneEvent"; Q_ASSERT(applet!=0); if (!d->applets.contains(applet)) { return false; @@ -609,7 +616,9 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event) switch (event->type()) { case QEvent::GraphicsSceneHoverEnter: + kDebug() << "got hoverenterEvent" << d->immutable << " " << applet->isImmutable(); if (!d->immutable && !applet->isImmutable() && !d->handles.contains(applet)) { + kDebug() << "generated applet handle"; AppletHandle *handle = new AppletHandle(this, applet); d->handles[applet] = handle; connect(handle, SIGNAL(disappearDone(AppletHandle*)), diff --git a/containment.h b/containment.h index cadf565b0..c81a801e2 100644 --- a/containment.h +++ b/containment.h @@ -173,6 +173,11 @@ class PLASMA_EXPORT Containment : public Applet */ void clearApplets(); + /** + * add existing applet to this containment + */ + void addApplet(Applet * applet); + /** * Sets the physical screen this Containment is associated with. *