]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Modify code according to dolphin policy
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 645b2d34a0ecc6a30275baf20d1e28663c75d103..c8e0094b5a1b9b680bf812269f190eafccf21c9f 100644 (file)
@@ -40,6 +40,7 @@
 #include <QGraphicsView>
 #include <QMimeData>
 #include <QTimer>
+#include <QAccessible>
 
 KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) :
     QObject(parent),
@@ -251,7 +252,15 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
 
     case Qt::Key_Left:
         if (index > 0) {
-            --index;
+            const int expandedParentsCount = m_model->expandedParentsCount(index);
+            if (expandedParentsCount == 0) {
+                --index;
+            } else {
+                // Go to the parent of the current item.
+                do {
+                    --index;
+                } while (index > 0 && m_model->expandedParentsCount(index) == expandedParentsCount);
+            }
             m_keyboardAnchorIndex = index;
             m_keyboardAnchorPos = keyboardAnchorPos(index);
         }
@@ -545,7 +554,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
             break;
 
         case MultiSelection:
-            if (controlPressed) {
+            if (controlPressed && !shiftPressed) {
                 m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle);
                 m_selectionManager->beginAnchoredSelection(m_pressedIndex);
             } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
@@ -770,7 +779,6 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con
 
 bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
-    Q_UNUSED(transform);
     if (!m_model || !m_view) {
         return false;
     }
@@ -791,22 +799,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
         }
 
         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 (m_model->supportsDropping(index)) {
+            if (!droppingBetweenItems && m_model->supportsDropping(index)) {
+                // Something has been dragged on an item.
+                m_view->hideDropIndicator();
                 newHoveredWidget->setHovered(true);
-            } else if (m_model->sortRole().isEmpty()) {
-                // The model supports the inserting of items on
-                // the given index as no sort-role has been
-                // specified. Assure that a drag-indicator
-                // is shown by the view.
-                const int dropIndex = m_view->showDropIndicator(pos);
-                Q_UNUSED(dropIndex); // TODO
-            }
-            emit itemHovered(index);
+                emit itemHovered(index);
 
-            if (m_autoActivationTimer->interval() >= 0) {
-                m_autoActivationTimer->setProperty("index", index);
-                m_autoActivationTimer->start();
+                if (m_autoActivationTimer->interval() >= 0) {
+                    m_autoActivationTimer->setProperty("index", index);
+                    m_autoActivationTimer->start();
+                }
             }
         }
     }
@@ -816,7 +825,6 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
 
 bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
-    Q_UNUSED(transform)
     if (!m_view) {
         return false;
     }
@@ -825,8 +833,23 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT
     m_view->setAutoScroll(false);
 
     const QPointF pos = transform.map(event->pos());
-    const int index = m_view->itemAt(pos);
-    emit itemDropEvent(index, event);
+
+    int dropAboveIndex = -1;
+    if (m_model->sortRole().isEmpty()) {
+        // The model supports inserting of items between other items.
+        dropAboveIndex = m_view->showDropIndicator(pos);
+    }
+
+    if (dropAboveIndex >= 0) {
+        // Something has been dropped between two items.
+        m_view->hideDropIndicator();
+        emit aboveItemDropEvent(dropAboveIndex, event);
+    } else {
+        // Something has been dropped on an item or on an empty part of the view.
+        emit itemDropEvent(m_view->itemAt(pos), event);
+    }
+
+    QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropEnd);
 
     return true;
 }
@@ -1071,12 +1094,11 @@ void KItemListController::startDragging()
     const QPixmap pixmap = m_view->createDragPixmap(selectedItems);
     drag->setPixmap(pixmap);
 
-    // TODO: The vertical hotspot of -24 should be replaced by the
-    // height of the QCursor-pixmap.
-    const QPoint hotSpot(pixmap.width() / 2, -24);
+    const QPoint hotSpot(pixmap.width() / 2, 0);
     drag->setHotSpot(hotSpot);
 
     drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction);
+    QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropStart);
 }
 
 KItemListWidget* KItemListController::hoveredWidget() const