KDE/kdebase/workspace

Davide Bettio davbet at aliceposta.it
Wed Apr 30 17:04:50 CEST 2008


SVN commit 802774 by bettio:

API REVIEW:
* watchForMouseMove() -> registerAsDragHandle() / unregisterDragHandle()
* Added isRegisteredAsDragHandle() (I'm not really sure If it's a good idea to add this method).

ping me if you find better names for registerAsDragHandle() / unregisterDragHandle().

CCMAIL: panel-devel at kde.org


 M  +26 -13    libs/plasma/applet.cpp  
 M  +17 -5     libs/plasma/applet.h  
 M  +1 -1      plasma/applets/icon/icon.cpp  
 M  +1 -1      plasma/applets/trash/trash.cpp  


--- trunk/KDE/kdebase/workspace/libs/plasma/applet.cpp #802773:802774
@@ -351,7 +351,7 @@
     KPluginInfo appletDescription;
     Package* package;
     OverlayWidget *needsConfigOverlay;
-    QList<QGraphicsItem*> watchedForMouseMove;
+    QList<QGraphicsItem*> registeredAsDragHandle;
     QStringList loadedEngines;
     Plasma::PanelSvg *background;
     AppletScript *script;
@@ -1069,24 +1069,37 @@
     d->aspectRatioMode = mode;
 }
 
-void Applet::watchForMouseMove( QGraphicsItem * watched, bool watch )
+void Applet::registerAsDragHandle( QGraphicsItem * item )
 {
-    if (!watched) {
+    if (!item) {
         return;
     }
 
-    int index = d->watchedForMouseMove.indexOf(watched);
-    if (watch) {
-        if (index == -1) {
-            d->watchedForMouseMove.append(watched);
-            watched->installSceneEventFilter(this);
-        }
-    } else if (index != -1) {
-        d->watchedForMouseMove.removeAt(index);
-        watched->removeSceneEventFilter(this);
+    int index = d->registeredAsDragHandle.indexOf(item);
+    if (index == -1) {
+        d->registeredAsDragHandle.append(item);
+        item->installSceneEventFilter(this);
     }
 }
 
+void Applet::unregisterDragHandle( QGraphicsItem * item )
+{
+    if (!item) {
+        return;
+    }
+
+    int index = d->registeredAsDragHandle.indexOf(item);
+    if (index != -1) {
+        d->registeredAsDragHandle.removeAt(index);
+        item->removeSceneEventFilter(this);
+    }
+}
+
+bool Applet::isRegisteredAsDragHandle( QGraphicsItem * item )
+{
+    return (d->registeredAsDragHandle.indexOf(item) != -1);
+}
+
 bool Applet::hasConfigurationInterface() const
 {
     return d->hasConfigurationInterface;
@@ -1106,7 +1119,7 @@
 {
     switch (event->type()) {
         case QEvent::GraphicsSceneMouseMove: {
-            if (d->watchedForMouseMove.contains( watched )) {
+            if (d->registeredAsDragHandle.contains( watched )) {
                 mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
                 return true;
             }
--- trunk/KDE/kdebase/workspace/libs/plasma/applet.h #802773:802774
@@ -608,18 +608,30 @@
         void setBackgroundHints(const BackgroundHints hints);
 
         /**
-         * Register the widgets that manages mouse clicks but you still want
+         * Register the widgets that manage mouse clicks but you still want
          * to be able to drag the applet around when holding the mouse pointer
-         * on that widgets.
+         * on that widget.
          *
          * Calling this results in an eventFilter being places on the widget.
          *
-         * @param widget the widget to watch for mouse move
-         * @param watch whether to start watching the widget, or to stop doing so
+         * @param item the item to watch for mouse move
          */
-        void watchForMouseMove(QGraphicsItem *widget, bool watch);
+        void registerAsDragHandle( QGraphicsItem * item );
 
         /**
+         * Unregister a widget registered with registerAsDragHandle.
+         *
+         * @param item the item to unregister
+         */
+        void unregisterDragHandle( QGraphicsItem * item );
+
+        /**
+         * @param item the item to look for if it is registered or not
+         * @return true if it is registered, false otherwise
+         */
+        bool isRegisteredAsDragHandle( QGraphicsItem * item );
+
+        /**
          * @internal event filter; used for focus watching
          **/
         bool eventFilter( QObject *o, QEvent *e );
--- trunk/KDE/kdebase/workspace/plasma/applets/icon/icon.cpp #802773:802774
@@ -68,7 +68,7 @@
     }
     setDisplayLines(2);
 
-    watchForMouseMove(m_icon, true);
+    registerAsDragHandle(m_icon);
 
     // we do this right away since we may have our config
     // read shortly by the containment. usually applets don't need
--- trunk/KDE/kdebase/workspace/plasma/applets/trash/trash.cpp #802773:802774
@@ -94,7 +94,7 @@
 
     m_dirLister->openUrl(m_trashUrl);
     m_icon->setDrawBackground(true);
-    watchForMouseMove(m_icon, true);
+    registerAsDragHandle(m_icon);
     //setMinimumSize(m_icon->sizeFromIconSize(IconSize(KIconLoader::Small)));
     resize(m_icon->sizeFromIconSize(IconSize(KIconLoader::Desktop)));
     //FIXME PORT TO TOOLTIP MANAGER


More information about the Panel-devel mailing list