case Qt::Key_Enter:
case Qt::Key_Return: {
- const QSet<int> selectedItems = m_selectionManager->selectedItems();
+ const KItemSet selectedItems = m_selectionManager->selectedItems();
if (selectedItems.count() >= 2) {
emit itemsActivated(selectedItems);
} else if (selectedItems.count() == 1) {
- emit itemActivated(selectedItems.toList().first());
+ emit itemActivated(selectedItems.first());
} else {
emit itemActivated(index);
}
break;
}
- case Qt::Key_Space:
- if (m_selectionBehavior == MultiSelection) {
- if (controlPressed) {
- m_selectionManager->endAnchoredSelection();
- m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
- m_selectionManager->beginAnchoredSelection(index);
- } else {
- const int current = m_selectionManager->currentItem();
- m_selectionManager->setSelected(current);
- }
- }
- break;
-
case Qt::Key_Menu: {
// Emit the signal itemContextMenuRequested() in case if at least one
// item is selected. Otherwise the signal viewContextMenuRequested() will be emitted.
- const QSet<int> selectedItems = m_selectionManager->selectedItems();
+ const KItemSet selectedItems = m_selectionManager->selectedItems();
int index = -1;
if (selectedItems.count() >= 2) {
const int currentItemIndex = m_selectionManager->currentItem();
index = selectedItems.contains(currentItemIndex)
- ? currentItemIndex : selectedItems.toList().first();
+ ? currentItemIndex : selectedItems.first();
} else if (selectedItems.count() == 1) {
- index = selectedItems.toList().first();
+ index = selectedItems.first();
}
if (index >= 0) {
m_selectionManager->clearSelection();
}
m_keyboardManager->cancelSearch();
+ emit escapePressed();
break;
+ case Qt::Key_Space:
+ if (m_selectionBehavior == MultiSelection) {
+ if (controlPressed) {
+ // Toggle the selection state of the current item.
+ m_selectionManager->endAnchoredSelection();
+ m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
+ m_selectionManager->beginAnchoredSelection(index);
+ break;
+ } else {
+ // Select the current item if it is not selected yet.
+ const int current = m_selectionManager->currentItem();
+ if (!m_selectionManager->isSelected(current)) {
+ m_selectionManager->setSelected(current);
+ break;
+ }
+ }
+ }
+ // Fall through to the default case and add the Space to the current search string.
+
default:
m_keyboardManager->addKeys(event->text());
// Make sure unconsumed events get propagated up the chain. #302329
}
if (index >= 0) {
m_selectionManager->setCurrentItem(index);
- m_selectionManager->clearSelection();
- m_selectionManager->setSelected(index, 1);
- m_selectionManager->beginAnchoredSelection(index);
+
+ if (m_selectionBehavior != NoSelection) {
+ m_selectionManager->clearSelection();
+ m_selectionManager->setSelected(index, 1);
+ m_selectionManager->beginAnchoredSelection(index);
+ }
+
m_view->scrollToItem(index);
}
}
m_pressedIndex = m_view->itemAt(m_pressedMousePos);
emit mouseButtonPressed(m_pressedIndex, event->buttons());
+ // TODO: Qt5: Replace Qt::XButton1 by Qt::BackButton and Qt::XButton2 by Qt::ForwardButton
+ if (event->buttons() & (Qt::XButton1 | Qt::XButton2)) {
+ // Do not select items when clicking the back/forward buttons, see
+ // https://bugs.kde.org/show_bug.cgi?id=327412.
+ return true;
+ }
+
if (m_view->isAboveExpansionToggle(m_pressedIndex, m_pressedMousePos)) {
m_selectionManager->endAnchoredSelection();
m_selectionManager->setCurrentItem(m_pressedIndex);
emit itemUnhovered(index);
}
}
+ } else {
+ m_view->hideDropIndicator();
}
return false;
if (newHoveredWidget) {
newHoveredWidget->setHovered(true);
+ const QPointF mappedPos = newHoveredWidget->mapFromItem(m_view, pos);
+ newHoveredWidget->setHoverPosition(mappedPos);
emit itemHovered(newHoveredWidget->index());
}
+ } else if (oldHoveredWidget) {
+ const QPointF mappedPos = oldHoveredWidget->mapFromItem(m_view, pos);
+ oldHoveredWidget->setHoverPosition(mappedPos);
}
return false;
}
}
- QSet<int> selectedItems;
+ KItemSet selectedItems;
// Select all visible items that intersect with the rubberband
foreach (const KItemListWidget* widget, m_view->visibleItemListWidgets()) {
// Therefore, the new selection contains:
// 1. All previously selected items which are not inside the rubberband, and
// 2. all items inside the rubberband which have not been selected previously.
- m_selectionManager->setSelectedItems((m_oldSelection - selectedItems) + (selectedItems - m_oldSelection));
+ m_selectionManager->setSelectedItems(m_oldSelection ^ selectedItems);
}
else {
m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
return;
}
- const QSet<int> selectedItems = m_selectionManager->selectedItems();
+ const KItemSet selectedItems = m_selectionManager->selectedItems();
if (selectedItems.isEmpty()) {
return;
}