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

List:       kde-panel-devel
Subject:    [Panel-devel] Applets reordering
From:       cedric <cedric.borgese () gmail ! com>
Date:       2007-10-27 16:09:33
Message-ID: 200710272016.36859.cedric.borgese () gmail ! com
[Download RAW message or body]

Ok, I wrote a new patch, but I'm not happy with it as it has some drawbacks.

1) to catch when an applet got focus, I reimplemented focusInEvent, but in 
practice, this method is never called, so I tried with mousePressEvent, it 
works better, but only when you click on the QGraphicsItem that is the 
applet, so in all applets I tested, it works only if you click on the 
border :/
I don't find a reliable way to catch when an applet got focus.

2) using mousePressEvent works only if the applet derivate doesn't 
reimplements it, for example, it not work for the Frame applet.
Of course we can fix all applets, but this is really a bad design as it 
implies all writers of applet know these trics and don't forget to call the 
parent method.

3) this is not directly related to this patch, but it is a bug to fix :
as applets are children of containment, if a containment B is above another 
one A, all applets on A can never be shown above B. This bug is annoying on 
dual screen setups, there are 2 desktop containment lets say A and B, if A is 
the below container, when you drag your applet from A to B, it "magically" 
disappear on the egde of the screen.
I don't know if this could be solved changing the z value of a container once 
one of its applet is selected as I don't know a reliable way to know that 
(same problem for the applets) and I don't know if the QGraphics system will 
take the changes on the fly while we are dragging the applet (I guess it is 
ok for this, but haven't tested)
But with this method we get trouble for panel containments if desktop 
containments are draw above them.

just a comment on my patch, I made this change :

-            r.moveLeft(INTER_CONTAINMENT_MARGIN * screen);
+            //r.moveLeft(r.x() + INTER_CONTAINMENT_MARGIN * screen);

to fix the problem seen by andras (and me) explained here 
http://lists.kde.org/?t=119344065800002&r=1&w=2
I discuss about it on IRC and got no feedback until here, but it is not 
intended to be commited, so you can ignore it.

["focus.diff" (text/x-diff)]

Index: containment.h
===================================================================
--- containment.h	(révision 729916)
+++ containment.h	(copie de travail)
@@ -206,6 +206,15 @@
          */
         QSizeF contentSizeHint() const;
 
+        /**
+         * Move an applet above of all other applets
+         *
+         * @param applet the applet that get focus and
+         * should be moved on top of all oter applets.
+         */
+        void focusApplet(Applet& applet);
+
+
     public Q_SLOTS:
         /**
          * Informs the Corona as to what position it is in. This is informational
Index: applet.h
===================================================================
--- applet.h	(révision 729916)
+++ applet.h	(copie de travail)
@@ -587,6 +587,16 @@
          **/
         Containment* containment() const;
 
+        /**
+         * Triggered when the applet receive focus.
+         **/
+        virtual void focusInEvent(QFocusEvent* event);
+
+        /**
+         * The event handler, for mouse press events.
+         **/
+        virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
+
     protected Q_SLOTS:
         /**
          * @internal used to show the configuration of an applet on first show
Index: containment.cpp
===================================================================
--- containment.cpp	(révision 729926)
+++ containment.cpp	(copie de travail)
@@ -56,7 +56,8 @@
           location(Floating),
           layout(0),
           screen(0),
-          immutable(false)
+          immutable(false),
+          focusedApplet(0)
     {
     }
 
@@ -74,6 +75,7 @@
     QSize size;
     int screen;
     bool immutable;
+    Applet* focusedApplet;
 };
 
 Containment::Containment(QGraphicsItem* parent,
@@ -132,6 +134,7 @@
                                  const QStyleOptionGraphicsItem *option,
                                  const QRect& contentsRect)
 {
+    Q_UNUSED(option);
     // If the derived class can't be bothered - just draw a plane old rectangle
     painter->drawRect(contentsRect.adjusted(1, 1, -1, -1));
 }
@@ -310,6 +313,7 @@
     }
 
     applet->setParentItem(this);
+    focusApplet(*applet);
     //panels don't want backgrounds, which is important when setting geometry
     if (type() == PanelContainment) {
         applet->setDrawStandardBackground(false);
@@ -365,6 +369,10 @@
     Applet* applet = static_cast<Plasma::Applet*>(object);
     int index = d->applets.indexOf(applet);
 
+    if (d->focusedApplet == applet) {
+        d->focusedApplet = 0;
+    }
+
     if (index > -1) {
         d->applets.removeAt(index);
     }
@@ -416,7 +424,7 @@
         QRect r = desktop.screenGeometry(screen);
 
         if (type() == DesktopContainment) {
-            r.moveLeft(INTER_CONTAINMENT_MARGIN * screen);
+            //r.moveLeft(r.x() + INTER_CONTAINMENT_MARGIN * screen);
             setGeometry(r);
             //kDebug() << "setting geometry to" << desktop.screenGeometry(screen) << geometry();
         } else if (type() == PanelContainment) {
@@ -478,7 +486,10 @@
 {
     //kDebug() << "drop event:" << event->mimeData()->text();
 
-    QString mimetype(static_cast<Corona*>(scene())->appletMimeType());
+    QString mimetype;
+    if (scene()) {
+        mimetype = static_cast<Corona*>(scene())->appletMimeType();
+    }
 
     if (event->mimeData()->hasFormat(mimetype) && scene()) {
         QString plasmoidName;
@@ -510,6 +521,22 @@
     }
 }
 
+void Containment::focusApplet(Applet& applet)
+{
+    kDebug() << "Applet " << reinterpret_cast<int>(&applet) << " got focus.";
+    if (&applet == d->focusedApplet) {
+        return;
+    }
+
+    Applet* oldFocused = d->focusedApplet;
+    if (oldFocused) {
+        oldFocused->setZValue(0);
+    }
+
+    applet.setZValue(1000);
+    d->focusedApplet = &applet;
 }
 
+}
+
 #include "containment.moc"
Index: applet.cpp
===================================================================
--- applet.cpp	(révision 729916)
+++ applet.cpp	(copie de travail)
@@ -1122,6 +1122,24 @@
     return QGraphicsItem::itemChange(change, value);
 }
 
+void Applet::focusInEvent(QFocusEvent* event)
+{
+    Containment* c = containment();
+    if (c)
+    {
+        c->focusApplet(*this);
+    }
+}
+
+void Applet::mousePressEvent(QGraphicsSceneMouseEvent* event)
+{
+    Containment* c = containment();
+    if (c)
+    {
+        c->focusApplet(*this);
+    }
+}
+
 void Applet::setGeometry(const QRectF& geometry)
 {
     if (geometry.size().width() > 0 && geometry.size().height() > 0 && size() != geometry.size()) {


_______________________________________________
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