diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -319,6 +319,10 @@ QTimer* m_autoActivationTimer; + QTimer* m_dndTimer; + Qt::KeyboardModifiers m_cachedModifiers; + QPointF m_dragPos; + /** * When starting a rubberband selection during a Shift- or Control-key has been * pressed the current selection should never be deleted. To be able to restore diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -52,6 +52,7 @@ m_pressedIndex(-1), m_pressedMousePos(), m_autoActivationTimer(nullptr), + m_dndTimer(nullptr), m_oldSelection(), m_keyboardAnchorIndex(-1), m_keyboardAnchorPos(0) @@ -68,6 +69,17 @@ m_autoActivationTimer->setInterval(-1); connect(m_autoActivationTimer, &QTimer::timeout, this, &KItemListController::slotAutoActivationTimeout); + m_dndTimer = new QTimer(this); + m_dndTimer->setInterval(0); + connect(m_dndTimer, &QTimer::timeout, this, [=]() { + auto modifiers = QGuiApplication::queryKeyboardModifiers(); + if (m_cachedModifiers != modifiers) { + m_cachedModifiers = modifiers; + QMouseEvent *event = new QMouseEvent(QEvent::MouseMove, m_dragPos, Qt::NoButton, Qt::LeftButton, m_cachedModifiers); + QGuiApplication::postEvent(this, event); + } + }); + setModel(model); setView(view); } @@ -875,11 +887,12 @@ return false; } - QUrl hoveredDir = m_model->directory(); KItemListWidget* oldHoveredWidget = hoveredWidget(); const QPointF pos = transform.map(event->pos()); + m_dragPos = pos; + KItemListWidget* newHoveredWidget = widgetForPos(pos); if (oldHoveredWidget != newHoveredWidget) { @@ -929,8 +942,13 @@ m_view->hideDropIndicator(); } - event->setAccepted(!DragAndDropHelper::urlListMatchesUrl(event->mimeData()->urls(), hoveredDir)); - + if (DragAndDropHelper::urlListMatchesUrl(event->mimeData()->urls(), hoveredDir)) { + event->setDropAction(Qt::IgnoreAction); + event->ignore(); + } else { + event->setDropAction(event->proposedAction()); + event->accept(); + } return false; } @@ -1214,7 +1232,9 @@ const QPoint hotSpot((pixmap.width() / pixmap.devicePixelRatio()) / 2, 0); drag->setHotSpot(hotSpot); + m_dndTimer->start(); drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); + m_dndTimer->stop(); QAccessibleEvent accessibilityEvent(view(), QAccessible::DragDropStart); QAccessible::updateAccessibility(&accessibilityEvent);