Blob Blame History Raw
diff -ur kdebase-workspace-4.0.83/libs/plasma/containment.cpp kdebase-workspace-4.0.83-kde#154119/libs/plasma/containment.cpp
--- kdebase-workspace-4.0.83/libs/plasma/containment.cpp	2008-06-18 14:41:38.000000000 +0200
+++ kdebase-workspace-4.0.83-kde#154119/libs/plasma/containment.cpp	2008-06-27 09:08:24.000000000 +0200
@@ -395,6 +395,11 @@
                 desktopMenu.addSeparator();
             }
 
+            QList<QAction*> containmentAppletActions = contextAppletActions(applet);
+            foreach(QAction* action, containmentAppletActions) {
+                desktopMenu.addAction(action);
+            }
+
             QAction* closeApplet = applet->d->actions.action("remove");
             if (!closeApplet) { //unlikely but not impossible
                 kDebug() << "no remove action!!!!!!!!";
@@ -938,6 +943,12 @@
     }
 }
 
+QList<QAction*> Containment::contextAppletActions(Applet *)
+{
+    //kDebug() << "empty context actions";
+    return QList<QAction*>();
+}
+
 KActionCollection& Containment::Private::actions()
 {
     return static_cast<Applet*>(q)->d->actions;
diff -ur kdebase-workspace-4.0.83/libs/plasma/containment.h kdebase-workspace-4.0.83-kde#154119/libs/plasma/containment.h
--- kdebase-workspace-4.0.83/libs/plasma/containment.h	2008-06-18 14:41:38.000000000 +0200
+++ kdebase-workspace-4.0.83-kde#154119/libs/plasma/containment.h	2008-06-27 08:56:14.000000000 +0200
@@ -266,6 +266,14 @@
          */
         void removeAssociatedWidget(QWidget *widget);
 
+        /**
+         * Returns a list of applet-related QAction instances.
+         *
+         * @return A list of actions. The default implementation returns an
+         *         empty list.
+         **/
+        virtual QList<QAction*> contextAppletActions(Applet *applet);
+
     Q_SIGNALS:
         /**
          * This signal is emitted when a new applet is created by the containment
diff -ur kdebase-workspace-4.0.83/plasma/containments/panel/panel.cpp kdebase-workspace-4.0.83-kde#154119/plasma/containments/panel/panel.cpp
--- kdebase-workspace-4.0.83/plasma/containments/panel/panel.cpp	2008-06-18 14:41:39.000000000 +0200
+++ kdebase-workspace-4.0.83-kde#154119/plasma/containments/panel/panel.cpp	2008-06-27 09:47:59.000000000 +0200
@@ -23,6 +23,7 @@
 
 #include <QApplication>
 #include <QGraphicsLinearLayout>
+#include <QGraphicsSceneHoverEvent>
 #include <QPainter>
 #include <QBitmap>
 #include <QDesktopWidget>
@@ -51,7 +52,9 @@
       m_configureAction(0),
       m_addPanelAction(0),
       m_currentSize(QSize(QApplication::desktop()->screenGeometry(screen()).width(), 38)),
-      m_lastViewGeom()
+      m_lastViewGeom(),
+      m_moveAppletAction(0),
+      m_movedApplet(0)
 {
     m_background = new Plasma::PanelSvg(this);
     m_background->setImagePath("widgets/panel-background");
@@ -102,6 +105,37 @@
     return actions;
 }
 
+QList<QAction*> Panel::contextAppletActions(Applet *applet)
+{
+    if (!m_moveAppletAction) {
+        m_moveAppletAction = new QAction( KIcon("transform-move"), i18n("transform-move"), this);
+    }
+
+    QVariant appletV;
+    appletV.setValue((QObject*)applet);
+    m_moveAppletAction->setData(appletV);
+
+    if (!m_movedApplet || (m_movedApplet && m_movedApplet!=applet)) {
+        m_moveAppletAction->setText(i18n("Start Move of %1", applet->name()));
+        if (!m_movedApplet) {
+            m_moveAppletAction->setEnabled(true);
+            connect(m_moveAppletAction, SIGNAL(triggered(bool)), SLOT(startAppletMove()));
+        }
+        else {
+            m_moveAppletAction->setEnabled(false);
+        }
+    }
+    else {
+        m_moveAppletAction->setEnabled(true);
+        m_moveAppletAction->setText(i18n("Stop Move of %1", applet->name()));
+        connect(m_moveAppletAction, SIGNAL(triggered(bool)), SLOT(stopAppletMove()));
+    }
+
+    QList<QAction*> actions;
+    actions << m_moveAppletAction;
+    return actions;
+}
+
 void Panel::backgroundChanged()
 {
     constraintsEvent(Plasma::LocationConstraint);
@@ -443,6 +477,83 @@
     }
 }
 
+void Panel::startAppletMove()
+{
+    QAction *action = qobject_cast<QAction*>(sender());
+    if (!action) {
+        return;
+    }
+
+    m_movedApplet = qobject_cast<Applet*>(action->data().value<QObject*>());
+    setAcceptsHoverEvents(true);
+    setCursor(Qt::SizeAllCursor);
+}
+
+void Panel::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+{
+    if (!m_movedApplet) {
+        Applet::hoverMoveEvent(event);
+        return;
+    }
+
+    QPointF pos = event->pos();
+    m_movedApplet->setPos(pos);
+
+    // reposition the applet in our layout
+    QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout*>(layout());
+
+    if (!lay) {
+        return;
+    }
+
+    Plasma::FormFactor f = formFactor();
+    int currentIndex = -1, insertIndex = -1;
+
+    for (int i = 0; i < lay->count(); ++i) {
+        QGraphicsLayoutItem *sibling = lay->itemAt(i);
+        if (sibling == m_movedApplet) {
+            currentIndex = i;
+        }
+        QRectF siblingGeometry = sibling->geometry();
+        if (f == Plasma::Horizontal) {
+            qreal middle = (siblingGeometry.left() + siblingGeometry.right()) / 2.0;
+            if (pos.x() < middle) {
+                insertIndex = i;
+                break;
+            } else if (pos.x() <= siblingGeometry.right()) {
+                insertIndex = i + 1;
+                break;
+            }
+        } else { // Plasma::Vertical
+            qreal middle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0;
+            if (pos.y() < middle) {
+                insertIndex = i;
+                break;
+            } else if (pos.y() <= siblingGeometry.bottom()) {
+                insertIndex = i + 1;
+                break;
+            }
+        }
+    }
+
+    if (currentIndex != -1 && insertIndex != -1) {
+        if (insertIndex > currentIndex) {
+            --insertIndex;
+        }
+        if (insertIndex != currentIndex) {
+            lay->removeAt(currentIndex);
+            lay->insertItem(insertIndex, m_movedApplet);
+        }
+    }
+}
+
+void Panel::stopAppletMove()
+{
+    setCursor(Qt::ArrowCursor);
+    setAcceptsHoverEvents(false);
+    m_movedApplet = 0;
+}
+
 K_EXPORT_PLASMA_APPLET(panel, Panel)
 
 #include "panel.moc"
diff -ur kdebase-workspace-4.0.83/plasma/containments/panel/panel.h kdebase-workspace-4.0.83-kde#154119/plasma/containments/panel/panel.h
--- kdebase-workspace-4.0.83/plasma/containments/panel/panel.h	2008-06-18 14:41:39.000000000 +0200
+++ kdebase-workspace-4.0.83-kde#154119/plasma/containments/panel/panel.h	2008-06-27 09:21:24.000000000 +0200
@@ -49,6 +49,9 @@
                         const QRect &contentsRect);
     void paintBackground(QPainter *painter, const QRect &contentsRect);
 
+    QList<QAction*> contextAppletActions(Applet *applet);
+    void hoverMoveEvent(QGraphicsSceneHoverEvent *event); 
+
 protected:
     void saveState(KConfigGroup &config) const;
 
@@ -59,6 +62,9 @@
     void appletRemoved(Plasma::Applet* applet);
     void addPanel();
 
+    void startAppletMove();
+    void stopAppletMove();
+
 private:
     /**
      * update the formfactor based on the location
@@ -73,6 +79,8 @@
     Plasma::PanelSvg *m_background;
     QAction* m_configureAction;
     QAction* m_addPanelAction;
+    QAction* m_moveAppletAction;
+    Applet *m_movedApplet;
 
     //cached values
     QSize m_currentSize;