]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Dolphin Places: Make it easier to drag and drop items
authorVishesh Handa <me@vhanda.in>
Tue, 7 May 2013 09:42:56 +0000 (15:12 +0530)
committerVishesh Handa <me@vhanda.in>
Mon, 13 May 2013 09:09:23 +0000 (14:39 +0530)
When doing a drop, a check is performed to see if it is within x pixels
from the top or x pixel from the bottom of the rect. If it is, then the
drop is considered a drop between items.

This x was fixed to qMax( 4, myStyleOption.padding ) which would
generally be 4. This is fine for some cases, but when the rectangle size
increases then this 4 pixels is not enough. Hence this 'x' is now being
set to 30% of the rectangle height.

By default the rectangle height is 20 pixels, so x is now 6 instead of 4
in the default case, which does make it slightly easier.

Also, this in-between-items check is only performed when moving from one
item to another. This is not good since if you enter the item and the
bottom, the indicator is shown, and then as to start moving it up it
stops showing, and then it should start showing again as you approach
the top edge.

Modified the code to run the check on every mouse drag event even if the
hovered item has not changed.

Both these changes combined make it much easier to drag and drop items.

REVIEW: 110342

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistview.cpp

index c6239df94150560a5e24fe6e85d3e85155c88d17..c8c0fc5f1ba3ddd4fec2982ae82a2013aad0cca3 100644 (file)
@@ -838,26 +838,36 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
             oldHoveredWidget->setHovered(false);
             emit itemUnhovered(oldHoveredWidget->index());
         }
+    }
 
-        if (newHoveredWidget) {
-            bool droppingBetweenItems = false;
-            if (m_model->sortRole().isEmpty()) {
-                // The model supports inserting items between other items.
-                droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
-            }
+    if (newHoveredWidget) {
+        bool droppingBetweenItems = false;
+        if (m_model->sortRole().isEmpty()) {
+            // The model supports inserting items between other items.
+            droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
+        }
 
-            const int index = newHoveredWidget->index();
-            if (!droppingBetweenItems && m_model->supportsDropping(index)) {
+        const int index = newHoveredWidget->index();
+        if (!droppingBetweenItems) {
+            if (m_model->supportsDropping(index)) {
                 // Something has been dragged on an item.
                 m_view->hideDropIndicator();
-                newHoveredWidget->setHovered(true);
-                emit itemHovered(index);
+                if (!newHoveredWidget->isHovered()) {
+                    newHoveredWidget->setHovered(true);
+                    emit itemHovered(index);
+                }
 
-                if (m_autoActivationTimer->interval() >= 0) {
+                if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
                     m_autoActivationTimer->setProperty("index", index);
                     m_autoActivationTimer->start();
                 }
             }
+        } else {
+            m_autoActivationTimer->stop();
+            if (newHoveredWidget && newHoveredWidget->isHovered()) {
+                newHoveredWidget->setHovered(false);
+                emit itemUnhovered(index);
+            }
         }
     }
 
index a2629c5654dc0511a9c860ee241a42cc1f82132a..d0096550a62b9f0ff221fdeb49a9eff1e30822cb 100644 (file)
@@ -2365,7 +2365,8 @@ int KItemListView::showDropIndicator(const QPointF& pos)
         const QRectF rect = itemRect(widget->index());
         if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
             if (m_model->supportsDropping(widget->index())) {
-                const int gap = qMax(4, m_styleOption.padding);
+                // Keep 30% of the rectangle as the gap instead of always having a fixed gap
+                const int gap = qMax(4.0, 0.3 * rect.height());
                 if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
                     return -1;
                 }