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

List:       kde-commits
Subject:    playground/base/kickoff-rewrite-kde4/src
From:       Robert Knight <robertknight () gmail ! com>
Date:       2007-10-05 9:49:03
Message-ID: 1191577743.658184.20368.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 721464 by knight:


* Re-order the drawing in the FlipScrollView to prevent
  the header being drawn on top of the back arrow
* Stop UrlItemView scrolling up when mousing over a header item.
* Fix keyboard navigation of UrlItemView with hidden items and simplify 
  the code.  Just record the visual order of items at layout time 
  and move around in that list in response to cursor actions.


 M  +4 -2      core/applicationmodel.cpp  
 M  +21 -21    ui/flipscrollview.cpp  
 M  +17 -92    ui/urlitemview.cpp  


--- trunk/playground/base/kickoff-rewrite-kde4/src/core/applicationmodel.cpp #721463:721464
@@ -363,9 +363,11 @@
 /**
  * FIXME This is a temporary workaround to map the icon names found
  * in the desktop directory files (from /usr/share/desktop-directories)
- * into the Oxygen icon names.
+ * into the Oxygen icon names.  (Only applies if the Gnome menu files
+ * are also installed)
  *
- * This list was compiled from Kubuntu 7.04
+ * This list was compiled from Kubuntu 7.04 with the gnome-menus
+ * package present.
  *
  * This needs to be discussed on kde-core-devel and fixed
  */
--- trunk/playground/base/kickoff-rewrite-kde4/src/ui/flipscrollview.cpp #721463:721464
@@ -490,6 +490,27 @@
 
     const qreal timerValue = d->flipAnimTimeLine->currentValue();
     
+    // draw header for current view
+    QRect headerRect = d->headerRect(d->currentRoot());
+    if (d->animLeftToRight) {
+        headerRect.translate((int)(headerRect.width()*(1-timerValue)),0);
+    } else {
+        headerRect.translate((int)(-headerRect.width()*(1-timerValue)),0);
+    }
+    if (event->rect().intersects(headerRect)) {
+        d->drawHeader(&painter,headerRect,d->currentRoot());
+    }
+    // draw header for previous view
+    QRect prevHeaderRect = d->headerRect(d->previousRoot());
+    if (d->animLeftToRight) {
+        prevHeaderRect.translate((int)(-prevHeaderRect.width()*timerValue),0);
+    } else {
+        prevHeaderRect.translate((int)(prevHeaderRect.width()*timerValue),0);
+    }
+    if (event->rect().intersects(prevHeaderRect) && timerValue < 1.0) {
+        d->drawHeader(&painter,prevHeaderRect,d->previousRoot());
+    }
+
     // draw navigation
     QStyle::State state = 0;
     if (d->currentRoot().isValid()) {
@@ -512,27 +533,6 @@
         
         painter.restore();
     }
-
-    // draw header for current view
-    QRect headerRect = d->headerRect(d->currentRoot());
-    if (d->animLeftToRight) {
-        headerRect.translate((int)(headerRect.width()*(1-timerValue)),0);
-    } else {
-        headerRect.translate((int)(-headerRect.width()*(1-timerValue)),0);
-    }
-    if (event->rect().intersects(headerRect)) {
-        d->drawHeader(&painter,headerRect,d->currentRoot());
-    }
-    // draw header for previous view
-    QRect prevHeaderRect = d->headerRect(d->previousRoot());
-    if (d->animLeftToRight) {
-        prevHeaderRect.translate((int)(-prevHeaderRect.width()*timerValue),0);
-    } else {
-        prevHeaderRect.translate((int)(prevHeaderRect.width()*timerValue),0);
-    }
-    if (event->rect().intersects(prevHeaderRect) && timerValue < 1.0) {
-        d->drawHeader(&painter,prevHeaderRect,d->previousRoot());
-    }
 }
 void FlipScrollView::updateFlipAnimation(qreal)
 {
--- trunk/playground/base/kickoff-rewrite-kde4/src/ui/urlitemview.cpp #721463:721464
@@ -50,6 +50,7 @@
     {
         // clear existing layout information
         itemRects.clear();
+        visualOrder.clear();
 
         if (!q->model())
             return;
@@ -101,6 +102,10 @@
                 itemRects.insert(child,QRect(QPoint(horizontalOffset,verticalOffset),
                                              childSize));
 
+                if (childSize.isValid()) {
+                    visualOrder << child;
+                }
+
                 //qDebug() << "Item rect" << child.data(Qt::DisplayRole) 
                 //        << "set to" << itemRects[child];
 
@@ -165,7 +170,7 @@
         if (itemStateProvider && !itemStateProvider->isVisible(index)) {
             return QSize();
         } else {
-            return QSize(q->width(),HEADER_HEIGHT);
+            return QSize(q->width()-HEADER_LEFT_MARGIN,HEADER_HEIGHT);
         }
     }
 
@@ -177,93 +182,14 @@
     {
         return point - QPoint(0,q->verticalOffset());
     }
-    QModelIndex findNextLeaf(const QModelIndex& index)
-    {
-        Q_ASSERT(index.isValid());
 
-        // if the current node has children then dig down to the first leaf node
-        const QAbstractItemModel *model = index.model();
-        QModelIndex node = index;
-        while (model->hasChildren(node)) {
-            node = model->index(0,0,node);
-        }
-        if (node == index) {
-            // if index is already a leaf node, then go to the node's next sibling
-            // if it is a leaf, return it otherwise recurse down into the sibling to 
-            // find its first leaf
-            if (node.row() < model->rowCount(node.parent())-1) {
-                QModelIndex sibling = node.sibling(node.row()+1,node.column());
-                if (!model->hasChildren(sibling)) {
-                    return sibling;
-                } else {
-                    return findNextLeaf(sibling);
-                }
-            } else {
-                // if index is the last row in the current branch then go up the tree until
-                // we reach an item which has a next sibling and then recurse into that sibling
-                // to find the next leaf.
-                while (node.parent().isValid() && node.row() == model->rowCount(node.parent())-1) {
-                    node = node.parent();
-                }
-                node = node.sibling(node.row()+1,node.column());
-                if (node.isValid()) {
-                    return findNextLeaf(node);
-                } else {
-                    // if this is the last leaf in the model, return it
-                    return index;
-                }
-            }
-        } else {
-            return node;
-        }
-    }
-    QModelIndex findPreviousLeaf(const QModelIndex& index)
-    {
-        Q_ASSERT(index.isValid());
-
-        const QAbstractItemModel *model = index.model();
-        // if the current index has a previous sibling then recurse into the sibling if it has
-        // children or return the sibling otherwise
-        if (index.row() > 0) {
-            QModelIndex sibling = index.sibling(index.row()-1,index.column());
-            if (!model->hasChildren(sibling)) {
-                return sibling;
-            } else {
-                return findPreviousLeaf(sibling);
-            }
-        } else {
-            // if the index has no previous sibling then move up the tree until a node is reached
-            // that does have a previous sibling or the root of the tree is reached
-            QModelIndex node = index.parent();
-            while (node.parent().isValid() && node.row() == 0) {
-                node = node.parent();
-            }
-            // if the node has a previous sibling then return it if it has no children, otherwise
-            // find the last leaf of the sibling
-            node = node.sibling(node.row()-1,node.column());
-            if (node.isValid()) {
-                if (!model->hasChildren(node)) {
-                    return node;
-                }
-
-                while (model->hasChildren(node)) {
-                    node = node.child(0,0);
-                }
-                node = model->index(model->rowCount(node.parent())-1,0,node.parent());
-                return node;
-            } else {
-                // this is the first leaf in the tree, return it 
-                return index;
-            }
-        } 
-    }
-
     UrlItemView * const q;
     QPersistentModelIndex currentRootIndex;
     QPersistentModelIndex hoveredIndex;
 
     QHash<QModelIndex,int> itemChildOffsets;
     QHash<QModelIndex,QRect> itemRects;
+    QList<QModelIndex> visualOrder;
 
     int contentsHeight;
     ItemStateProvider *itemStateProvider;
@@ -331,15 +257,12 @@
 void UrlItemView::updateLayout()
 {
     d->doLayout();
-    
-    if (model() && (model()->hasChildren(currentIndex()) || !currentIndex().isValid())) {
-        // find the first usable index and set it to be the current index
-        QModelIndex index = currentIndex().isValid() ? currentIndex() : model()->index(0,0);
-        if (index.isValid() && model()->hasChildren(index)) {
-            index = d->findNextLeaf(index);
-        }   
-        setCurrentIndex(index);
+   
+    if (!d->visualOrder.contains(currentIndex())) {
+        // select the first valid index
+        setCurrentIndex(moveCursor(MoveDown,0)); 
     }
+    
 
     if (viewport()->isVisible()) {
         viewport()->update();
@@ -405,12 +328,14 @@
 {
     QModelIndex index = currentIndex();
 
+    int visualIndex = d->visualOrder.indexOf(index);
+
     switch (cursorAction) {
         case MoveUp:
-               index = d->findPreviousLeaf(index); 
+                visualIndex = qMax(0,visualIndex-1); 
             break;
         case MoveDown:
-               index = d->findNextLeaf(index); 
+                visualIndex = qMin(d->visualOrder.count()-1,visualIndex+1);
             break;
         case MoveLeft:
         case MoveRight:
@@ -424,7 +349,7 @@
     // when changing the current item with the keyboard, clear the mouse-over item
     d->hoveredIndex = QModelIndex();
 
-    return index;
+    return d->visualOrder.value(visualIndex,QModelIndex());
 }
 
 void UrlItemView::setSelection(const QRect& rect,QItemSelectionModel::SelectionFlags flags)
[prev in list] [next in list] [prev in thread] [next in thread] 

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