m_autoActivationTimer = new QTimer(this);
m_autoActivationTimer->setSingleShot(true);
- m_autoActivationTimer->setInterval(-1);
+ m_autoActivationTimer->setInterval(750);
connect(m_autoActivationTimer, &QTimer::timeout, this, &KItemListController::slotAutoActivationTimeout);
setModel(model);
return -1;
}
-void KItemListController::setAutoActivationDelay(int delay)
+void KItemListController::setAutoActivationEnabled(bool enabled)
{
- m_autoActivationTimer->setInterval(delay);
+ m_autoActivationEnabled = enabled;
}
-int KItemListController::autoActivationDelay() const
+bool KItemListController::isAutoActivationEnabled() const
{
- return m_autoActivationTimer->interval();
+ return m_autoActivationEnabled;
}
void KItemListController::setSingleClickActivationEnforced(bool singleClick)
int key = event->key();
const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
+ const bool horizontalScrolling = m_view->scrollOrientation() == Qt::Horizontal;
+
+ if (m_view->layoutDirection() == Qt::RightToLeft) {
+ // swap left and right arrow keys
+ switch (key) {
+ case Qt::Key_Left:
+ key = Qt::Key_Right;
+ break;
+ case Qt::Key_Right:
+ key = Qt::Key_Left;
+ break;
+ default:
+ break;
+ }
+ }
+
// Handle the expanding/collapsing of items
// expand / collapse all selected directories
if (m_view->supportsItemExpanding() && m_model->isExpandable(index) && (key == Qt::Key_Right || key == Qt::Key_Left)) {
}
const bool controlPressed = event->modifiers() & Qt::ControlModifier;
- const bool shiftOrControlPressed = shiftPressed || controlPressed;
+ if (m_selectionMode && !controlPressed && !shiftPressed && (key == Qt::Key_Enter || key == Qt::Key_Return)) {
+ key = Qt::Key_Space; // In selection mode one moves around with arrow keys and toggles selection with Enter.
+ }
const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageUp || key == Qt::Key_PageDown || key == Qt::Key_Up
|| key == Qt::Key_Down || key == Qt::Key_Left || key == Qt::Key_Right;
// For horizontal scroll orientation, transform
// the arrow keys to simplify the event handling.
- if (m_view->scrollOrientation() == Qt::Horizontal) {
+ if (horizontalScrolling) {
switch (key) {
case Qt::Key_Up:
key = Qt::Key_Left;
}
}
- // For right to left languages, exchange right and left arrow keys.
- if (m_view->layoutDirection() == Qt::RightToLeft) {
- switch (key) {
- case Qt::Key_Left:
- key = Qt::Key_Right;
- break;
- case Qt::Key_Right:
- key = Qt::Key_Left;
- break;
- default:
- break;
- }
- }
-
const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed;
if (selectSingleItem) {
break;
case Qt::Key_PageUp:
- if (m_view->scrollOrientation() == Qt::Horizontal) {
+ if (horizontalScrolling) {
// The new current index should correspond to the first item in the current column.
int newIndex = qMax(index - 1, 0);
while (newIndex != index && m_view->itemRect(newIndex).topLeft().y() < m_view->itemRect(index).topLeft().y()) {
break;
case Qt::Key_PageDown:
- if (m_view->scrollOrientation() == Qt::Horizontal) {
+ if (horizontalScrolling) {
// The new current index should correspond to the last item in the current column.
int newIndex = qMin(index + 1, m_model->count() - 1);
while (newIndex != index && m_view->itemRect(newIndex).topLeft().y() > m_view->itemRect(index).topLeft().y()) {
case Qt::Key_Space:
if (m_selectionBehavior == MultiSelection) {
- if (controlPressed) {
+ if (controlPressed || m_selectionMode) {
// Toggle the selection state of the current item.
m_selectionManager->endAnchoredSelection();
m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
break;
case MultiSelection:
- if (controlPressed) {
+ if (controlPressed || (m_selectionMode && !shiftPressed)) {
m_selectionManager->endAnchoredSelection();
}
m_selectionManager->setCurrentItem(index);
- if (!shiftOrControlPressed) {
+ if (!shiftPressed && !controlPressed && !m_selectionMode) {
m_selectionManager->clearSelection();
m_selectionManager->setSelected(index, 1);
}
return;
}
int index;
- if (searchFromNextItem) {
- const int currentIndex = m_selectionManager->currentItem();
- index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
+ // In selection mode, always use the current (underlined) item, or the next item, for search start position.
+ if (m_selectionBehavior == NoSelection || m_selectionMode || m_selectionManager->hasSelection()) {
+ index = m_model->indexForKeyboardSearch(text, searchFromNextItem ? m_selectionManager->currentItem() + 1 : m_selectionManager->currentItem());
} else {
index = m_model->indexForKeyboardSearch(text, 0);
}
if (index >= 0) {
+ if (m_selectionMode) {
+ m_selectionManager->endAnchoredSelection();
+ }
+
m_selectionManager->setCurrentItem(index);
if (m_selectionBehavior != NoSelection) {
- m_selectionManager->replaceSelection(index);
+ if (!m_selectionMode) { // Don't clear the selection in selection mode.
+ m_selectionManager->replaceSelection(index);
+ }
m_selectionManager->beginAnchoredSelection(index);
}
const Qt::MouseButtons buttons = event->buttons();
- if (!onPress(event->screenPos(), event->pos(), event->modifiers(), buttons)) {
+ if (!onPress(event->pos(), event->modifiers(), buttons)) {
startRubberBand();
return false;
}
const QPointF pos = transform.map(event->pos());
const std::optional<int> index = m_view->itemAt(pos);
+ if (event->button() & (Qt::ForwardButton | Qt::BackButton)) {
+ // "Forward" and "Back" are reserved for quickly navigating through the
+ // history. Double-clicking those buttons should be interpreted as two
+ // separate button presses. We arrive here for the second click, which
+ // we now react to just as we would for a singular click
+ Q_EMIT mouseButtonPressed(index.value_or(-1), event->button());
+ return false;
+ }
+
+ if (!index.has_value()) {
+ Q_EMIT doubleClickViewBackground(event->button());
+ return false;
+ }
+
// Expand item if desired - See Bug 295573
if (m_mouseDoubleClickAction != ActivateItemOnly) {
if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index.value_or(-1))) {
}
}
- if (event->button() & Qt::RightButton) {
+ if (event->button() & ~Qt::LeftButton) {
+ return false;
+ }
+
+ if (m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) {
return false;
}
- bool emitItemActivated = !(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced)
- && (event->button() & Qt::LeftButton) && index.has_value() && index.value() < m_model->count();
+ const bool emitItemActivated = index.has_value() && index.value() < m_model->count() && !m_view->isAboveExpansionToggle(index.value(), pos);
if (emitItemActivated) {
+ if (!QApplication::keyboardModifiers()) {
+ m_selectionManager->clearSelection(); // The user does not want to manage/manipulate the item currently, only activate it.
+ }
Q_EMIT itemActivated(index.value());
}
return false;
// That's because the same click might have de-selected the item or because the press was only in the row of the item but not on it.
if (pressedItem && m_selectionManager->selectedItems().contains(pressedItem.value())) {
// The selection rectangle for an item was clicked
- Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), globalPos);
+ Q_EMIT itemContextMenuRequested(pressedItem.value(), globalPos);
return true;
}
Q_EMIT itemHovered(index);
}
- if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
+ if (m_autoActivationEnabled && !m_autoActivationTimer->isActive() && m_model->canEnterOnHover(index)) {
m_autoActivationTimer->setProperty("index", index);
m_autoActivationTimer->start();
+ newHoveredWidget->startActivateSoonAnimation(m_autoActivationTimer->remainingTime());
}
+
} else {
m_autoActivationTimer->stop();
if (newHoveredWidget && newHoveredWidget->isHovered()) {
if (m_dragActionOrRightClick) {
m_dragActionOrRightClick = false;
} else {
- onPress(m_pressedMouseGlobalPos.toPoint(), tap->position().toPoint(), Qt::NoModifier, Qt::LeftButton);
+ onPress(tap->position().toPoint(), Qt::NoModifier, Qt::LeftButton);
onRelease(transform.map(tap->position()), Qt::NoModifier, Qt::LeftButton, true);
}
m_isTouchEvent = false;
const QPointF pressedMousePos = transform.map(twoTap->pos());
m_pressedIndex = m_view->itemAt(pressedMousePos);
if (m_pressedIndex.has_value()) {
- onPress(twoTap->screenPos().toPoint(), twoTap->pos().toPoint(), Qt::ControlModifier, Qt::LeftButton);
+ onPress(twoTap->pos().toPoint(), Qt::ControlModifier, Qt::LeftButton);
onRelease(transform.map(twoTap->pos()), Qt::ControlModifier, Qt::LeftButton, false);
}
}
return index;
}
- const bool leftToRight = m_view->layoutDirection() != Qt::RightToLeft;
+ const bool reversed = m_view->layoutDirection() == Qt::RightToLeft && m_view->scrollOrientation() == Qt::Vertical;
// Calculate the index of the last column inside the row of the current index
int lastColumnIndex = index;
- while ((leftToRight && keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex))
- || (!leftToRight && keyboardAnchorPos(lastColumnIndex + 1) < keyboardAnchorPos(lastColumnIndex))) {
+ while ((!reversed && keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex))
+ || (reversed && keyboardAnchorPos(lastColumnIndex + 1) < keyboardAnchorPos(lastColumnIndex))) {
++lastColumnIndex;
if (lastColumnIndex >= maxIndex) {
return index;
int searchIndex = nextRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(nextRowIndex));
while (searchIndex < maxIndex
- && ((leftToRight && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex))
- || (!leftToRight && keyboardAnchorPos(searchIndex + 1) < keyboardAnchorPos(searchIndex)))) {
+ && ((!reversed && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex))
+ || (reversed && keyboardAnchorPos(searchIndex + 1) < keyboardAnchorPos(searchIndex)))) {
++searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {
return index;
}
- const bool leftToRight = m_view->layoutDirection() != Qt::RightToLeft;
+ const bool reversed = m_view->layoutDirection() == Qt::RightToLeft && m_view->scrollOrientation() == Qt::Vertical;
// Calculate the index of the first column inside the row of the current index
int firstColumnIndex = index;
- while ((leftToRight && keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex))
- || (!leftToRight && keyboardAnchorPos(firstColumnIndex - 1) > keyboardAnchorPos(firstColumnIndex))) {
+ while ((!reversed && keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex))
+ || (reversed && keyboardAnchorPos(firstColumnIndex - 1) > keyboardAnchorPos(firstColumnIndex))) {
--firstColumnIndex;
if (firstColumnIndex <= 0) {
return index;
int searchIndex = previousRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(previousRowIndex));
while (searchIndex > 0
- && ((leftToRight && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex))
- || (!leftToRight && keyboardAnchorPos(searchIndex - 1) > keyboardAnchorPos(searchIndex)))) {
+ && ((!reversed && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex))
+ || (reversed && keyboardAnchorPos(searchIndex - 1) > keyboardAnchorPos(searchIndex)))) {
--searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {
}
}
-bool KItemListController::onPress(const QPoint &screenPos, const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons)
+bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons)
{
Q_EMIT mouseButtonPressed(m_pressedIndex.value_or(-1), buttons);
// or we just keep going for double-click activation
if (m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) {
if (!pressedItemAlreadySelected) {
- // An unselected item was clicked directly while deselecting multiple other items so we select it.
- m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
+ // An unselected item was clicked directly while deselecting multiple other items so we mark it "current".
m_selectionManager->setCurrentItem(m_pressedIndex.value());
m_selectionManager->beginAnchoredSelection(m_pressedIndex.value());
+ if (!leftClick) {
+ // We select the item here because this press is not meant to directly activate the item.
+ // We do not want to select items unless the user wants to edit them.
+ m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
+ }
}
return true; // event handled, don't create rubber band
}
rubberBand->setActive(false);
m_view->setAutoScroll(false);
}
+
+ if (!m_pressedIndex.has_value()) {
+ // We have a right-click in an empty region, don't create rubber band.
+ return true;
+ }
}
if (m_pressedIndex.has_value()) {
break;
case SingleSelection:
- m_selectionManager->setSelected(m_pressedIndex.value());
+ if (!leftClick || shiftOrControlPressed
+ || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+ m_selectionManager->setSelected(m_pressedIndex.value());
+ }
break;
case MultiSelection:
}
} else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
// Select the pressed item and start a new anchored selection
- m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select);
+ if (!leftClick || shiftOrControlPressed
+ || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+ m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select);
+ }
m_selectionManager->beginAnchoredSelection(m_pressedIndex.value());
}
break;