KItemListController::KItemListController(QObject* parent) :
QObject(parent),
+ m_singleClickActivation(KGlobalSettings::singleClick()),
m_selectionTogglePressed(false),
+ m_clearSelectionIfItemsAreNotDragged(false),
m_selectionBehavior(NoSelection),
m_model(0),
m_view(0),
return m_autoActivationTimer->interval();
}
+void KItemListController::setSingleClickActivation(bool singleClick)
+{
+ m_singleClickActivation = singleClick;
+}
+
+bool KItemListController::singleClickActivation() const
+{
+ return m_singleClickActivation;
+}
+
bool KItemListController::showEvent(QShowEvent* event)
{
Q_UNUSED(event);
}
if (m_view->isAboveExpansionToggle(m_pressedIndex, m_pressedMousePos)) {
+ m_selectionManager->endAnchoredSelection();
m_selectionManager->setCurrentItem(m_pressedIndex);
+ m_selectionManager->beginAnchoredSelection(m_pressedIndex);
return true;
}
(!shiftOrControlPressed && !pressedItemAlreadySelected);
if (clearSelection) {
m_selectionManager->clearSelection();
+ } else if (pressedItemAlreadySelected && (event->buttons() & Qt::LeftButton)) {
+ // The user might want to start dragging multiple items, but if he clicks the item
+ // in order to trigger it instead, the other selected items must be deselected.
+ // However, we do not know yet what the user is going to do.
+ // -> remember that the user pressed an item which had been selected already and
+ // clear the selection in mouseReleaseEvent(), unless the items are dragged.
+ m_clearSelectionIfItemsAreNotDragged = true;
}
if (!shiftPressed) {
// done on the mouse-press event, but when using the selection-toggle on a
// selected item the dragged item is not selected yet.
m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle);
+ } else {
+ // A selected item has been clicked to drag all selected items
+ // -> the selection should not be cleared when the mouse button is released.
+ m_clearSelectionIfItemsAreNotDragged = false;
}
+
startDragging();
}
}
if (index >= 0 && index == m_pressedIndex) {
// The release event is done above the same item as the press event
+ if (m_clearSelectionIfItemsAreNotDragged) {
+ // A selected item has been clicked, but no drag operation has been started
+ // -> clear the rest of the selection.
+ m_selectionManager->clearSelection();
+ m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select);
+ m_selectionManager->beginAnchoredSelection(m_pressedIndex);
+ }
+
if (event->button() & Qt::LeftButton) {
bool emitItemActivated = true;
if (m_view->isAboveExpansionToggle(index, pos)) {
} else if (shiftOrControlPressed) {
// The mouse click should only update the selection, not trigger the item
emitItemActivated = false;
- } else if (!KGlobalSettings::singleClick()) {
+ } else if (!m_singleClickActivation) {
emitItemActivated = false;
}
if (emitItemActivated) {
m_pressedMousePos = QPointF();
m_pressedIndex = -1;
+ m_clearSelectionIfItemsAreNotDragged = false;
return false;
}
const QPointF pos = transform.map(event->pos());
const int index = m_view->itemAt(pos);
- bool emitItemActivated = !KGlobalSettings::singleClick() &&
+ bool emitItemActivated = !m_singleClickActivation &&
(event->button() & Qt::LeftButton) &&
index >= 0 && index < m_model->count();
if (emitItemActivated) {
const QPixmap pixmap = m_view->createDragPixmap(selectedItems);
drag->setPixmap(pixmap);
- drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::IgnoreAction);
+ drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction);
}
KItemListWidget* KItemListController::hoveredWidget() const