[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    [Panel-devel] containment switching patch
From:       Jeremy <jeremy () scitools ! com>
Date:       2007-11-25 20:20:02
Message-ID: 200711251320.02914.jeremy () scitools ! com
[Download RAW message or body]

Hi all,

I have a patch here that works mostly.  Any input is appreciated.  The idea is 
to reparent an applet when it is moved into another containment (just desktop 
to desktop containment so far, no tricky panel stuff yet).  Anyway, if you 
have two screens it's trivial to test the patch, if you don't you just have 
to hack your plasma-appletsrc to add another desktop containment, then you 
can test while zoomed out.  The only thing missing is when you drop the 
applet on the new containment, the handle jumps to a differentt location.

thanks,

Jeremy Whiting

["containment.patch" (text/x-diff)]

Index: containment.h
===================================================================
--- containment.h	(revision 741450)
+++ containment.h	(working copy)
@@ -174,6 +174,11 @@
         void clearApplets();
 
         /**
+         * add existing applet to this containment
+         */
+        void addApplet(Applet * applet);
+
+        /**
          * Sets the physical screen this Containment is associated with.
          *
          * @param screen the screen number this containment is the desktop for, or \
                -1
Index: applethandle.cpp
===================================================================
--- applethandle.cpp	(revision 741450)
+++ applethandle.cpp	(working copy)
@@ -30,6 +30,8 @@
 
 #include "applet.h"
 #include "containment.h"
+#include "corona.h"
+#include "applet.h"
 #include "theme.h"
 
 namespace Plasma
@@ -246,6 +248,32 @@
     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<Corona*>(scene());
+            if (corona) {
+                QList<Containment*> 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;
Index: containment.cpp
===================================================================
--- containment.cpp	(revision 741450)
+++ containment.cpp	(working copy)
@@ -351,12 +351,14 @@
         applet = new Applet;
     }
 
-    addChild(applet);
     //panels don't want backgrounds, which is important when setting geometry
     if (containmentType() == PanelContainment) {
         applet->setDrawStandardBackground(false);
     }
 
+    addChild(applet);
+    addApplet(applet);
+
     //the applet needs to be given constraints before it can set its geometry
     applet->updateConstraints(Plasma::AllConstraints);
 
@@ -386,15 +388,19 @@
         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;
+    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
@@ -601,6 +607,7 @@
     //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;
@@ -608,7 +615,9 @@
 
     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*)),



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic