Respect Shift- and Control-key for the rubberband selection

If the user has pressed the Shift- or Control-key during the
rubberband selection, the previous selection should not be cleared.
This commit is contained in:
Peter Penz 2011-08-20 23:11:55 +02:00
parent c9f4e1baae
commit 2f0ceedae0

View file

@ -26,6 +26,7 @@
#include "kitemlistrubberband_p.h"
#include "kitemlistselectionmanager.h"
#include <QApplication>
#include <QEvent>
#include <QGraphicsSceneEvent>
@ -576,6 +577,17 @@ void KItemListController::slotRubberBandChanged()
rubberBandRect.translate(-m_view->offset(), 0);
}
QSet<int> previousSelectedItems;
if (m_selectionManager->hasSelection()) {
// Don't clear the current selection in case if the user pressed the
// Shift- or Control-key during the rubberband selection
const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier ||
QApplication::keyboardModifiers() & Qt::ControlModifier;
if (shiftOrControlPressed) {
previousSelectedItems = m_selectionManager->selectedItems();
}
}
QSet<int> selectedItems;
// Select all visible items that intersect with the rubberband
@ -619,7 +631,7 @@ void KItemListController::slotRubberBandChanged()
}
} while (!selectionFinished);
m_selectionManager->setSelectedItems(selectedItems);
m_selectionManager->setSelectedItems(selectedItems + previousSelectedItems);
}
#include "kitemlistcontroller.moc"