m_pressedMousePos(),
m_oldSelection()
{
- connect(m_keyboardManager, SIGNAL(requestItemActivation(QString,bool)), this, SLOT(slotKeyboardActivationRequested(QString,bool)));
+ connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)),
+ this, SLOT(slotChangeCurrentItem(QString,bool)));
}
KItemListController::~KItemListController()
}
break;
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ emit itemActivated(index);
+ break;
+
case Qt::Key_Space:
if (controlPressed) {
m_selectionManager->endAnchoredSelection();
return true;
}
-void KItemListController::slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem)
+void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem)
{
if (!m_model) {
return;
const int currentIndex = m_selectionManager->currentItem();
int index;
if (searchFromNextItem) {
- index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
+ index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
}
else {
index = m_model->indexForKeyboardSearch(text, currentIndex);
if (controlPressed) {
m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle);
m_selectionManager->beginAnchoredSelection(m_pressedIndex);
+ } else if (event->buttons() & Qt::RightButton) {
+ // Only clear the selection if a context menu is requested above a non-selected item
+ if (!m_selectionManager->selectedItems().contains(m_pressedIndex)) {
+ m_selectionManager->setSelectedItems(QSet<int>() << m_pressedIndex);
+ }
} else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
// Select the pressed item and start a new anchored selection
m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select);
return true;
} else {
+ if (event->buttons() & Qt::RightButton) {
+ m_selectionManager->clearSelection();
+ }
+
KItemListRubberBand* rubberBand = m_view->rubberBand();
QPointF startPos = m_pressedMousePos;
if (m_view->scrollOrientation() == Qt::Vertical) {
const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier ||
event->modifiers() & Qt::ControlModifier;
- bool clearSelection = !shiftOrControlPressed && !m_dragging && !(event->button() == Qt::RightButton);
+ bool clearSelection = !shiftOrControlPressed && !m_dragging && event->button() != Qt::RightButton;
KItemListRubberBand* rubberBand = m_view->rubberBand();
if (rubberBand->isActive()) {
m_selectionManager->setSelectedItems(QSet<int>() << index);
}
- bool emitItemClicked = true;
if (event->button() & Qt::LeftButton) {
+ bool emitItemActivated = true;
if (m_view->isAboveExpansionToggle(index, pos)) {
emit itemExpansionToggleClicked(index);
- emitItemClicked = false;
- } else if (shiftOrControlPressed || !KGlobalSettings::singleClick()) {
- emitItemClicked = false;
+ emitItemActivated = false;
+ } else if (shiftOrControlPressed) {
+ // The mouse click should only update the selection, not trigger the item
+ emitItemActivated = false;
+ } else if (!KGlobalSettings::singleClick()) {
+ emitItemActivated = false;
}
- }
-
- if (emitItemClicked) {
- emit itemClicked(index, event->button());
+ if (emitItemActivated) {
+ emit itemActivated(index);
+ }
+ } else if (event->button() & Qt::MidButton) {
+ emit itemMiddleClicked(index);
+ } else if (event->button() & Qt::RightButton) {
+ emit contextMenuRequested(index, QPointF(event->pos()));
}
} else if (clearSelection) {
m_selectionManager->clearSelection();
const QPointF pos = transform.map(event->pos());
const int index = m_view->itemAt(pos);
- bool emitItemClicked = !KGlobalSettings::singleClick() &&
+ bool emitItemActivated = !KGlobalSettings::singleClick() &&
(event->button() & Qt::LeftButton) &&
index >= 0 && index < m_model->count();
- if (emitItemClicked) {
- emit itemClicked(index, event->button());
+ if (emitItemActivated) {
+ emit itemActivated(index);
}
return false;
}