mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Dragging and selection fixes
- Don't clear the selection on mouse-press events, do it (if allowed) in the mouse-release-event. Otherwise dragging of multiple selected items would not be possible. - Don't clear the selection when the context-menu gets opened by a right-click. - Fix issue that dragging is not possible after the first drop that has been canceled.
This commit is contained in:
parent
649cfb02af
commit
bf20b404c8
2 changed files with 50 additions and 34 deletions
|
@ -238,6 +238,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_dragging = false;
|
||||||
m_pressedMousePos = transform.map(event->pos());
|
m_pressedMousePos = transform.map(event->pos());
|
||||||
m_pressedIndex = m_view->itemAt(m_pressedMousePos);
|
m_pressedIndex = m_view->itemAt(m_pressedMousePos);
|
||||||
|
|
||||||
|
@ -247,9 +248,8 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
|
||||||
|
|
||||||
const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
||||||
const bool controlPressed = event->modifiers() & Qt::ControlModifier;
|
const bool controlPressed = event->modifiers() & Qt::ControlModifier;
|
||||||
const bool shiftOrControlPressed = shiftPressed || controlPressed;
|
|
||||||
|
|
||||||
if (!shiftOrControlPressed || m_selectionBehavior == SingleSelection) {
|
if (m_selectionBehavior == SingleSelection) {
|
||||||
m_selectionManager->clearSelection();
|
m_selectionManager->clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,13 +318,13 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const
|
||||||
|
|
||||||
if (m_pressedIndex >= 0) {
|
if (m_pressedIndex >= 0) {
|
||||||
// Check whether a dragging should be started
|
// Check whether a dragging should be started
|
||||||
if (!m_dragging) {
|
if (!m_dragging && (event->buttons() & Qt::LeftButton)) {
|
||||||
const QPointF pos = transform.map(event->pos());
|
const QPointF pos = transform.map(event->pos());
|
||||||
const qreal minDragDiff = 4;
|
const qreal minDragDiff = 4;
|
||||||
m_dragging = qAbs(pos.x() - m_pressedMousePos.x()) >= minDragDiff ||
|
const bool hasMinDragDiff = qAbs(pos.x() - m_pressedMousePos.x()) >= minDragDiff ||
|
||||||
qAbs(pos.y() - m_pressedMousePos.y()) >= minDragDiff;
|
qAbs(pos.y() - m_pressedMousePos.y()) >= minDragDiff;
|
||||||
if (m_dragging) {
|
if (hasMinDragDiff && startDragging()) {
|
||||||
startDragging();
|
m_dragging = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -354,38 +354,51 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier ||
|
||||||
|
event->modifiers() & Qt::ControlModifier;
|
||||||
|
|
||||||
|
bool clearSelection = !shiftOrControlPressed && !m_dragging && !(event->button() == Qt::RightButton);
|
||||||
|
|
||||||
KItemListRubberBand* rubberBand = m_view->rubberBand();
|
KItemListRubberBand* rubberBand = m_view->rubberBand();
|
||||||
if (rubberBand->isActive()) {
|
if (rubberBand->isActive()) {
|
||||||
disconnect(rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandChanged()));
|
disconnect(rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandChanged()));
|
||||||
rubberBand->setActive(false);
|
rubberBand->setActive(false);
|
||||||
m_oldSelection.clear();
|
m_oldSelection.clear();
|
||||||
} else {
|
|
||||||
const QPointF pos = transform.map(event->pos());
|
|
||||||
const int index = m_view->itemAt(pos);
|
|
||||||
const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier ||
|
|
||||||
event->modifiers() & Qt::ControlModifier;
|
|
||||||
|
|
||||||
if (index >= 0 && index == m_pressedIndex) {
|
if (rubberBand->startPosition() != rubberBand->endPosition()) {
|
||||||
// The release event is done above the same item as the press event
|
clearSelection = false;
|
||||||
bool emitItemClicked = true;
|
|
||||||
if (event->button() & Qt::LeftButton) {
|
|
||||||
if (m_view->isAboveExpansionToggle(index, pos)) {
|
|
||||||
emit itemExpansionToggleClicked(index);
|
|
||||||
emitItemClicked = false;
|
|
||||||
} else if (shiftOrControlPressed) {
|
|
||||||
// The mouse click should only update the selection, not trigger the item
|
|
||||||
emitItemClicked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (emitItemClicked) {
|
|
||||||
emit itemClicked(index, event->button());
|
|
||||||
}
|
|
||||||
} else if (!shiftOrControlPressed) {
|
|
||||||
m_selectionManager->clearSelection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QPointF pos = transform.map(event->pos());
|
||||||
|
const int index = m_view->itemAt(pos);
|
||||||
|
|
||||||
|
if (index >= 0 && index == m_pressedIndex) {
|
||||||
|
// The release event is done above the same item as the press event
|
||||||
|
|
||||||
|
if (clearSelection) {
|
||||||
|
// Clear the previous selection but reselect the current index
|
||||||
|
m_selectionManager->setSelectedItems(QSet<int>() << index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool emitItemClicked = true;
|
||||||
|
if (event->button() & Qt::LeftButton) {
|
||||||
|
if (m_view->isAboveExpansionToggle(index, pos)) {
|
||||||
|
emit itemExpansionToggleClicked(index);
|
||||||
|
emitItemClicked = false;
|
||||||
|
} else if (shiftOrControlPressed) {
|
||||||
|
// The mouse click should only update the selection, not trigger the item
|
||||||
|
emitItemClicked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emitItemClicked) {
|
||||||
|
emit itemClicked(index, event->button());
|
||||||
|
}
|
||||||
|
} else if (clearSelection) {
|
||||||
|
m_selectionManager->clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
m_pressedMousePos = QPointF();
|
m_pressedMousePos = QPointF();
|
||||||
m_pressedIndex = -1;
|
m_pressedIndex = -1;
|
||||||
|
@ -656,16 +669,16 @@ void KItemListController::slotRubberBandChanged()
|
||||||
m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
|
m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListController::startDragging()
|
bool KItemListController::startDragging()
|
||||||
{
|
{
|
||||||
if (!m_view || !m_model) {
|
if (!m_view || !m_model) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QSet<int> selectedItems = m_selectionManager->selectedItems();
|
const QSet<int> selectedItems = m_selectionManager->selectedItems();
|
||||||
QMimeData* data = m_model->createMimeData(selectedItems);
|
QMimeData* data = m_model->createMimeData(selectedItems);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The created drag object will be owned and deleted
|
// The created drag object will be owned and deleted
|
||||||
|
@ -677,6 +690,7 @@ void KItemListController::startDragging()
|
||||||
drag->setPixmap(pixmap);
|
drag->setPixmap(pixmap);
|
||||||
|
|
||||||
drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::IgnoreAction);
|
drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::IgnoreAction);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "kitemlistcontroller.moc"
|
#include "kitemlistcontroller.moc"
|
||||||
|
|
|
@ -135,8 +135,10 @@ private slots:
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Creates a QDrag object to start a drag-operation.
|
* Creates a QDrag object to start a drag-operation.
|
||||||
|
* @return True if the QDrag object has been created. If false is returned
|
||||||
|
* there is no implementation available for KItemModelBase::createMimeData().
|
||||||
*/
|
*/
|
||||||
void startDragging();
|
bool startDragging();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_dragging;
|
bool m_dragging;
|
||||||
|
|
Loading…
Reference in a new issue