[Panel-devel] KDE/kdebase/workspace/plasma/applets/kickoff/ui

Aaron J. Seigo aseigo at kde.org
Sat Nov 17 20:30:58 CET 2007


SVN commit 738047 by aseigo:

ensure that a parent menu is shown in the same position and with the same item selected when leaving a submenu. patch by Jason Stubbs (who needs to get an svn account ;)

not safe yet for multi-level jumps (or menu resets, it seems), but that isn't possible with the current UI anyways.
CCMAIL:panel-devel at kde.org.


 M  +31 -24    flipscrollview.cpp  


--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/flipscrollview.cpp #738046:738047
@@ -24,6 +24,7 @@
 #include <QMouseEvent>
 #include <QPainter>
 #include <QScrollBar>
+#include <QStack>
 #include <QTimeLine>
 #include <QtDebug>
 
@@ -42,7 +43,6 @@
           , backArrowHover(false)
           , flipAnimTimeLine(new QTimeLine())
           , animLeftToRight(true)
-          , previousVerticalOffset(0)
     {
     }
     ~Private() 
@@ -58,33 +58,40 @@
             return q->rootIndex(); 
         }
     }
-    QModelIndex previousRoot() const {
-        return previousRootIndex;
+    QModelIndex previousRoot() const
+    {
+        if (previousRootIndices.isEmpty()) {
+            return QModelIndex();
+        }
+        return previousRootIndices.top();
     }
     void setCurrentRoot(const QModelIndex& index)
     {
-        previousRootIndex = currentRootIndex;
-        previousVerticalOffset = q->verticalOffset();
-        currentRootIndex = index;
-       
-        updateScrollBarRange();
-        q->verticalScrollBar()->setValue(0);
-
-        // when going back up the tree, highlight the item which opens
-        // the branch we have just left
-        if (previousRootIndex.parent() == index)
-            hoveredIndex = previousRootIndex;
-        else
+        if (previousRootIndices.isEmpty() || previousRootIndices.top() != index) {
+            // we're entering into a submenu
+            animLeftToRight = true;
             hoveredIndex = QModelIndex();
+            previousRootIndices.push(currentRootIndex);
+            currentRootIndex = index;
+            previousVerticalOffsets.append(q->verticalOffset());
+            updateScrollBarRange();
+            q->verticalScrollBar()->setValue(0);
+        } else {
+            // we're exiting to the parent menu
+            animLeftToRight = false;
+            hoveredIndex = currentRootIndex;
+            previousRootIndices.pop();
+            currentRootIndex = index;
+            updateScrollBarRange();
+            q->verticalScrollBar()->setValue(previousVerticalOffsets.pop());
+        }
 
-        // set whether the flip animation should go in a left to right
-        // or right to left direction. 
-        // note: this check used gives the wrong value for animLeftToRight
-        // if we go down more than one level of the tree at once 
-        animLeftToRight = currentRootIndex.parent() == previousRootIndex;
-
         flipAnimTimeLine->start();
     }
+    int previousVerticalOffset()
+    {
+        return previousVerticalOffsets.isEmpty() ? 0 : previousVerticalOffsets.top();
+    }
     int treeDepth(const QModelIndex& headerIndex) const 
     {
         int depth = 0;
@@ -209,13 +216,13 @@
 
     QTimeLine *flipAnimTimeLine;
     bool animLeftToRight;
-    int previousVerticalOffset;
 
     static const int FLIP_ANIM_DURATION = 300;
 
 private:
      QPersistentModelIndex currentRootIndex;
-     QPersistentModelIndex previousRootIndex;
+     QStack<QPersistentModelIndex> previousRootIndices;
+     QStack<int> previousVerticalOffsets;
 };
 
 FlipScrollView::FlipScrollView(QWidget *parent)
@@ -285,7 +292,7 @@
     }
 
     if (parentIsPreviousRoot) {
-        topOffset -= d->previousVerticalOffset;
+        topOffset -= d->previousVerticalOffset();
     } else {
         topOffset -= verticalOffset();
     }


More information about the Panel-devel mailing list