]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Use KColorSchemeManager
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 60f23c1dbe6b6ee1e2a1d21cec7173700db47bc3..71c37a7aff00057a91d9db4815bee17b8399c451 100644 (file)
@@ -241,6 +241,8 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
     int key = event->key();
     const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
 
+    const bool horizontalScrolling = m_view->scrollOrientation() == Qt::Horizontal;
+
     // Handle the expanding/collapsing of items
     // expand / collapse all selected directories
     if (m_view->supportsItemExpanding() && m_model->isExpandable(index) && (key == Qt::Key_Right || key == Qt::Key_Left)) {
@@ -276,7 +278,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
 
     // For horizontal scroll orientation, transform
     // the arrow keys to simplify the event handling.
-    if (m_view->scrollOrientation() == Qt::Horizontal) {
+    if (horizontalScrolling) {
         switch (key) {
         case Qt::Key_Up:
             key = Qt::Key_Left;
@@ -295,6 +297,34 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
         }
     }
 
+    if (m_view->layoutDirection() == Qt::RightToLeft) {
+        if (horizontalScrolling) {
+            // swap up and down arrow keys
+            switch (key) {
+            case Qt::Key_Up:
+                key = Qt::Key_Down;
+                break;
+            case Qt::Key_Down:
+                key = Qt::Key_Up;
+                break;
+            default:
+                break;
+            }
+        } else if (!m_view->supportsItemExpanding()) {
+            // swap left and right arrow keys
+            switch (key) {
+            case Qt::Key_Left:
+                key = Qt::Key_Right;
+                break;
+            case Qt::Key_Right:
+                key = Qt::Key_Left;
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
     const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed;
 
     if (selectSingleItem) {
@@ -357,7 +387,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
         break;
 
     case Qt::Key_PageUp:
-        if (m_view->scrollOrientation() == Qt::Horizontal) {
+        if (horizontalScrolling) {
             // The new current index should correspond to the first item in the current column.
             int newIndex = qMax(index - 1, 0);
             while (newIndex != index && m_view->itemRect(newIndex).topLeft().y() < m_view->itemRect(index).topLeft().y()) {
@@ -385,7 +415,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
         break;
 
     case Qt::Key_PageDown:
-        if (m_view->scrollOrientation() == Qt::Horizontal) {
+        if (horizontalScrolling) {
             // The new current index should correspond to the last item in the current column.
             int newIndex = qMin(index + 1, m_model->count() - 1);
             while (newIndex != index && m_view->itemRect(newIndex).topLeft().y() > m_view->itemRect(index).topLeft().y()) {
@@ -575,7 +605,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent *event, const
 
     const Qt::MouseButtons buttons = event->buttons();
 
-    if (!onPress(event->screenPos(), event->pos(), event->modifiers(), buttons)) {
+    if (!onPress(event->pos(), event->modifiers(), buttons)) {
         startRubberBand();
         return false;
     }
@@ -727,7 +757,7 @@ bool KItemListController::contextMenuEvent(QContextMenuEvent *event)
     // That's because the same click might have de-selected the item or because the press was only in the row of the item but not on it.
     if (pressedItem && m_selectionManager->selectedItems().contains(pressedItem.value())) {
         // The selection rectangle for an item was clicked
-        Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), globalPos);
+        Q_EMIT itemContextMenuRequested(pressedItem.value(), globalPos);
         return true;
     }
 
@@ -813,10 +843,12 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
                 Q_EMIT itemHovered(index);
             }
 
-            if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
+            if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0 && m_model->canEnterOnHover(index)) {
                 m_autoActivationTimer->setProperty("index", index);
                 m_autoActivationTimer->start();
+                newHoveredWidget->startActivateSoonAnimation(m_autoActivationTimer->remainingTime());
             }
+
         } else {
             m_autoActivationTimer->stop();
             if (newHoveredWidget && newHoveredWidget->isHovered()) {
@@ -1087,7 +1119,7 @@ void KItemListController::tapTriggered(QTapGesture *tap, const QTransform &trans
         if (m_dragActionOrRightClick) {
             m_dragActionOrRightClick = false;
         } else {
-            onPress(m_pressedMouseGlobalPos.toPoint(), tap->position().toPoint(), Qt::NoModifier, Qt::LeftButton);
+            onPress(tap->position().toPoint(), Qt::NoModifier, Qt::LeftButton);
             onRelease(transform.map(tap->position()), Qt::NoModifier, Qt::LeftButton, true);
         }
         m_isTouchEvent = false;
@@ -1202,7 +1234,7 @@ void KItemListController::twoFingerTapTriggered(QGestureEvent *event, const QTra
         const QPointF pressedMousePos = transform.map(twoTap->pos());
         m_pressedIndex = m_view->itemAt(pressedMousePos);
         if (m_pressedIndex.has_value()) {
-            onPress(twoTap->screenPos().toPoint(), twoTap->pos().toPoint(), Qt::ControlModifier, Qt::LeftButton);
+            onPress(twoTap->pos().toPoint(), Qt::ControlModifier, Qt::LeftButton);
             onRelease(transform.map(twoTap->pos()), Qt::ControlModifier, Qt::LeftButton, false);
         }
     }
@@ -1470,9 +1502,12 @@ int KItemListController::nextRowIndex(int index) const
         return index;
     }
 
+    const bool reversed = m_view->layoutDirection() == Qt::RightToLeft && m_view->scrollOrientation() == Qt::Vertical;
+
     // Calculate the index of the last column inside the row of the current index
     int lastColumnIndex = index;
-    while (keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex)) {
+    while ((!reversed && keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex))
+           || (reversed && keyboardAnchorPos(lastColumnIndex + 1) < keyboardAnchorPos(lastColumnIndex))) {
         ++lastColumnIndex;
         if (lastColumnIndex >= maxIndex) {
             return index;
@@ -1484,7 +1519,9 @@ int KItemListController::nextRowIndex(int index) const
     int nextRowIndex = lastColumnIndex + 1;
     int searchIndex = nextRowIndex;
     qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(nextRowIndex));
-    while (searchIndex < maxIndex && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex)) {
+    while (searchIndex < maxIndex
+           && ((!reversed && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex))
+               || (reversed && keyboardAnchorPos(searchIndex + 1) < keyboardAnchorPos(searchIndex)))) {
         ++searchIndex;
         const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
         if (searchDiff < minDiff) {
@@ -1502,9 +1539,12 @@ int KItemListController::previousRowIndex(int index) const
         return index;
     }
 
+    const bool reversed = m_view->layoutDirection() == Qt::RightToLeft && m_view->scrollOrientation() == Qt::Vertical;
+
     // Calculate the index of the first column inside the row of the current index
     int firstColumnIndex = index;
-    while (keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex)) {
+    while ((!reversed && keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex))
+           || (reversed && keyboardAnchorPos(firstColumnIndex - 1) > keyboardAnchorPos(firstColumnIndex))) {
         --firstColumnIndex;
         if (firstColumnIndex <= 0) {
             return index;
@@ -1516,7 +1556,9 @@ int KItemListController::previousRowIndex(int index) const
     int previousRowIndex = firstColumnIndex - 1;
     int searchIndex = previousRowIndex;
     qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(previousRowIndex));
-    while (searchIndex > 0 && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex)) {
+    while (searchIndex > 0
+           && ((!reversed && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex))
+               || (reversed && keyboardAnchorPos(searchIndex - 1) > keyboardAnchorPos(searchIndex)))) {
         --searchIndex;
         const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
         if (searchDiff < minDiff) {
@@ -1550,7 +1592,7 @@ void KItemListController::updateExtendedSelectionRegion()
     }
 }
 
-bool KItemListController::onPress(const QPoint &screenPos, const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons)
+bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons)
 {
     Q_EMIT mouseButtonPressed(m_pressedIndex.value_or(-1), buttons);