Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kitemlistcontroller.cpp
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Line(s) | 225 | if (m_model->setExpanded(index, false)) { | |||
---|---|---|---|---|---|
226 | return true; | 226 | return true; | ||
227 | } | 227 | } | ||
228 | } | 228 | } | ||
229 | } | 229 | } | ||
230 | 230 | | |||
231 | const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; | 231 | const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; | ||
232 | const bool controlPressed = event->modifiers() & Qt::ControlModifier; | 232 | const bool controlPressed = event->modifiers() & Qt::ControlModifier; | ||
233 | const bool shiftOrControlPressed = shiftPressed || controlPressed; | 233 | const bool shiftOrControlPressed = shiftPressed || controlPressed; | ||
234 | const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || | ||||
235 | key == Qt::Key_Up || key == Qt::Key_Down || | ||||
236 | key == Qt::Key_Left || key == Qt::Key_Right; | ||||
234 | 237 | | |||
235 | const int itemCount = m_model->count(); | 238 | const int itemCount = m_model->count(); | ||
236 | 239 | | |||
237 | // For horizontal scroll orientation, transform | 240 | // For horizontal scroll orientation, transform | ||
238 | // the arrow keys to simplify the event handling. | 241 | // the arrow keys to simplify the event handling. | ||
239 | if (m_view->scrollOrientation() == Qt::Horizontal) { | 242 | if (m_view->scrollOrientation() == Qt::Horizontal) { | ||
240 | switch (key) { | 243 | switch (key) { | ||
241 | case Qt::Key_Up: key = Qt::Key_Left; break; | 244 | case Qt::Key_Up: key = Qt::Key_Left; break; | ||
242 | case Qt::Key_Down: key = Qt::Key_Right; break; | 245 | case Qt::Key_Down: key = Qt::Key_Right; break; | ||
243 | case Qt::Key_Left: key = Qt::Key_Up; break; | 246 | case Qt::Key_Left: key = Qt::Key_Up; break; | ||
244 | case Qt::Key_Right: key = Qt::Key_Down; break; | 247 | case Qt::Key_Right: key = Qt::Key_Down; break; | ||
245 | default: break; | 248 | default: break; | ||
246 | } | 249 | } | ||
247 | } | 250 | } | ||
248 | 251 | | |||
249 | const bool selectSingleItem = m_selectionBehavior != NoSelection && | 252 | const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed; | ||
250 | itemCount == 1 && | 253 | | ||
251 | (key == Qt::Key_Home || key == Qt::Key_End || | | |||
252 | key == Qt::Key_Up || key == Qt::Key_Down || | | |||
253 | key == Qt::Key_Left || key == Qt::Key_Right); | | |||
254 | if (selectSingleItem) { | 254 | if (selectSingleItem) { | ||
255 | const int current = m_selectionManager->currentItem(); | 255 | const int current = m_selectionManager->currentItem(); | ||
256 | m_selectionManager->setSelected(current); | 256 | m_selectionManager->setSelected(current); | ||
257 | return true; | 257 | return true; | ||
258 | } | 258 | } | ||
259 | 259 | | |||
260 | switch (key) { | 260 | switch (key) { | ||
261 | case Qt::Key_Home: | 261 | case Qt::Key_Home: | ||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Line(s) | 451 | if (!shiftOrControlPressed) { | |||
453 | m_selectionManager->setSelected(index, 1); | 453 | m_selectionManager->setSelected(index, 1); | ||
454 | } | 454 | } | ||
455 | 455 | | |||
456 | if (!shiftPressed) { | 456 | if (!shiftPressed) { | ||
457 | m_selectionManager->beginAnchoredSelection(index); | 457 | m_selectionManager->beginAnchoredSelection(index); | ||
458 | } | 458 | } | ||
459 | break; | 459 | break; | ||
460 | } | 460 | } | ||
461 | } | ||||
461 | 462 | | |||
463 | if (navigationPressed) { | ||||
464 | if (index < m_view->firstVisibleIndex() || index > m_view->lastVisibleIndex()) { | ||||
462 | m_view->scrollToItem(index); | 465 | m_view->scrollToItem(index); | ||
463 | } | 466 | } | ||
467 | } | ||||
464 | return true; | 468 | return true; | ||
465 | } | 469 | } | ||
466 | 470 | | |||
467 | void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem) | 471 | void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem) | ||
468 | { | 472 | { | ||
469 | if (!m_model || m_model->count() == 0) { | 473 | if (!m_model || m_model->count() == 0) { | ||
470 | return; | 474 | return; | ||
471 | } | 475 | } | ||
▲ Show 20 Lines • Show All 871 Lines • Show Last 20 Lines |