Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kitemlistcontroller.cpp
Show All 37 Lines | |||||
38 | #include <QMimeData> | 38 | #include <QMimeData> | ||
39 | #include <QTimer> | 39 | #include <QTimer> | ||
40 | 40 | | |||
41 | KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : | 41 | KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : | ||
42 | QObject(parent), | 42 | QObject(parent), | ||
43 | m_singleClickActivationEnforced(false), | 43 | m_singleClickActivationEnforced(false), | ||
44 | m_selectionTogglePressed(false), | 44 | m_selectionTogglePressed(false), | ||
45 | m_clearSelectionIfItemsAreNotDragged(false), | 45 | m_clearSelectionIfItemsAreNotDragged(false), | ||
46 | m_selectionBehavior(NoSelection), | 46 | m_selectionBehavior(SelectionBehavior::NoSelection), | ||
47 | m_autoActivationBehavior(ActivationAndExpansion), | 47 | m_autoActivationBehavior(AutoActivationBehavior::ActivationAndExpansion), | ||
48 | m_mouseDoubleClickAction(ActivateItemOnly), | 48 | m_mouseDoubleClickAction(MouseDoubleClickAction::ActivateItemOnly), | ||
49 | m_model(nullptr), | 49 | m_model(nullptr), | ||
50 | m_view(nullptr), | 50 | m_view(nullptr), | ||
51 | m_selectionManager(new KItemListSelectionManager(this)), | 51 | m_selectionManager(new KItemListSelectionManager(this)), | ||
52 | m_keyboardManager(new KItemListKeyboardSearchManager(this)), | 52 | m_keyboardManager(new KItemListKeyboardSearchManager(this)), | ||
53 | m_pressedIndex(-1), | 53 | m_pressedIndex(-1), | ||
54 | m_pressedMousePos(), | 54 | m_pressedMousePos(), | ||
55 | m_autoActivationTimer(nullptr), | 55 | m_autoActivationTimer(nullptr), | ||
56 | m_oldSelection(), | 56 | m_oldSelection(), | ||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Line(s) | 251 | if (m_view->scrollOrientation() == Qt::Horizontal) { | |||
253 | case Qt::Key_Up: key = Qt::Key_Left; break; | 253 | case Qt::Key_Up: key = Qt::Key_Left; break; | ||
254 | case Qt::Key_Down: key = Qt::Key_Right; break; | 254 | case Qt::Key_Down: key = Qt::Key_Right; break; | ||
255 | case Qt::Key_Left: key = Qt::Key_Up; break; | 255 | case Qt::Key_Left: key = Qt::Key_Up; break; | ||
256 | case Qt::Key_Right: key = Qt::Key_Down; break; | 256 | case Qt::Key_Right: key = Qt::Key_Down; break; | ||
257 | default: break; | 257 | default: break; | ||
258 | } | 258 | } | ||
259 | } | 259 | } | ||
260 | 260 | | |||
261 | const bool selectSingleItem = m_selectionBehavior != NoSelection && | 261 | const bool selectSingleItem = m_selectionBehavior != SelectionBehavior::NoSelection && | ||
262 | itemCount == 1 && | 262 | itemCount == 1 && | ||
263 | (key == Qt::Key_Home || key == Qt::Key_End || | 263 | (key == Qt::Key_Home || key == Qt::Key_End || | ||
264 | key == Qt::Key_Up || key == Qt::Key_Down || | 264 | key == Qt::Key_Up || key == Qt::Key_Down || | ||
265 | key == Qt::Key_Left || key == Qt::Key_Right); | 265 | key == Qt::Key_Left || key == Qt::Key_Right); | ||
266 | if (selectSingleItem) { | 266 | if (selectSingleItem) { | ||
267 | const int current = m_selectionManager->currentItem(); | 267 | const int current = m_selectionManager->currentItem(); | ||
268 | m_selectionManager->setSelected(current); | 268 | m_selectionManager->setSelected(current); | ||
269 | return true; | 269 | return true; | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 401 | if (index >= 0) { | |||
404 | emit itemContextMenuRequested(index, pos); | 404 | emit itemContextMenuRequested(index, pos); | ||
405 | } else { | 405 | } else { | ||
406 | emit viewContextMenuRequested(QCursor::pos()); | 406 | emit viewContextMenuRequested(QCursor::pos()); | ||
407 | } | 407 | } | ||
408 | break; | 408 | break; | ||
409 | } | 409 | } | ||
410 | 410 | | |||
411 | case Qt::Key_Escape: | 411 | case Qt::Key_Escape: | ||
412 | if (m_selectionBehavior != SingleSelection) { | 412 | if (m_selectionBehavior != SelectionBehavior::SingleSelection) { | ||
413 | m_selectionManager->clearSelection(); | 413 | m_selectionManager->clearSelection(); | ||
414 | } | 414 | } | ||
415 | m_keyboardManager->cancelSearch(); | 415 | m_keyboardManager->cancelSearch(); | ||
416 | emit escapePressed(); | 416 | emit escapePressed(); | ||
417 | break; | 417 | break; | ||
418 | 418 | | |||
419 | case Qt::Key_Space: | 419 | case Qt::Key_Space: | ||
420 | if (m_selectionBehavior == MultiSelection) { | 420 | if (m_selectionBehavior == SelectionBehavior::MultiSelection) { | ||
421 | if (controlPressed) { | 421 | if (controlPressed) { | ||
422 | // Toggle the selection state of the current item. | 422 | // Toggle the selection state of the current item. | ||
423 | m_selectionManager->endAnchoredSelection(); | 423 | m_selectionManager->endAnchoredSelection(); | ||
424 | m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); | 424 | m_selectionManager->setSelected(index, 1, KItemListSelectionManager::SelectionMode::Toggle); | ||
425 | m_selectionManager->beginAnchoredSelection(index); | 425 | m_selectionManager->beginAnchoredSelection(index); | ||
426 | break; | 426 | break; | ||
427 | } else { | 427 | } else { | ||
428 | // Select the current item if it is not selected yet. | 428 | // Select the current item if it is not selected yet. | ||
429 | const int current = m_selectionManager->currentItem(); | 429 | const int current = m_selectionManager->currentItem(); | ||
430 | if (!m_selectionManager->isSelected(current)) { | 430 | if (!m_selectionManager->isSelected(current)) { | ||
431 | m_selectionManager->setSelected(current); | 431 | m_selectionManager->setSelected(current); | ||
432 | break; | 432 | break; | ||
433 | } | 433 | } | ||
434 | } | 434 | } | ||
435 | } | 435 | } | ||
436 | // Fall through to the default case and add the Space to the current search string. | 436 | // Fall through to the default case and add the Space to the current search string. | ||
437 | 437 | | |||
438 | default: | 438 | default: | ||
439 | m_keyboardManager->addKeys(event->text()); | 439 | m_keyboardManager->addKeys(event->text()); | ||
440 | // Make sure unconsumed events get propagated up the chain. #302329 | 440 | // Make sure unconsumed events get propagated up the chain. #302329 | ||
441 | event->ignore(); | 441 | event->ignore(); | ||
442 | return false; | 442 | return false; | ||
443 | } | 443 | } | ||
444 | 444 | | |||
445 | if (m_selectionManager->currentItem() != index) { | 445 | if (m_selectionManager->currentItem() != index) { | ||
446 | switch (m_selectionBehavior) { | 446 | switch (m_selectionBehavior) { | ||
447 | case NoSelection: | 447 | case SelectionBehavior::NoSelection: | ||
448 | m_selectionManager->setCurrentItem(index); | 448 | m_selectionManager->setCurrentItem(index); | ||
449 | break; | 449 | break; | ||
450 | 450 | | |||
451 | case SingleSelection: | 451 | case SelectionBehavior::SingleSelection: | ||
452 | m_selectionManager->setCurrentItem(index); | 452 | m_selectionManager->setCurrentItem(index); | ||
453 | m_selectionManager->clearSelection(); | 453 | m_selectionManager->clearSelection(); | ||
454 | m_selectionManager->setSelected(index, 1); | 454 | m_selectionManager->setSelected(index, 1); | ||
455 | break; | 455 | break; | ||
456 | 456 | | |||
457 | case MultiSelection: | 457 | case SelectionBehavior::MultiSelection: | ||
458 | if (controlPressed) { | 458 | if (controlPressed) { | ||
459 | m_selectionManager->endAnchoredSelection(); | 459 | m_selectionManager->endAnchoredSelection(); | ||
460 | } | 460 | } | ||
461 | 461 | | |||
462 | m_selectionManager->setCurrentItem(index); | 462 | m_selectionManager->setCurrentItem(index); | ||
463 | 463 | | |||
464 | if (!shiftOrControlPressed) { | 464 | if (!shiftOrControlPressed) { | ||
465 | m_selectionManager->clearSelection(); | 465 | m_selectionManager->clearSelection(); | ||
Show All 21 Lines | 481 | { | |||
487 | if (searchFromNextItem) { | 487 | if (searchFromNextItem) { | ||
488 | index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); | 488 | index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); | ||
489 | } else { | 489 | } else { | ||
490 | index = m_model->indexForKeyboardSearch(text, currentIndex); | 490 | index = m_model->indexForKeyboardSearch(text, currentIndex); | ||
491 | } | 491 | } | ||
492 | if (index >= 0) { | 492 | if (index >= 0) { | ||
493 | m_selectionManager->setCurrentItem(index); | 493 | m_selectionManager->setCurrentItem(index); | ||
494 | 494 | | |||
495 | if (m_selectionBehavior != NoSelection) { | 495 | if (m_selectionBehavior != SelectionBehavior::NoSelection) { | ||
496 | m_selectionManager->clearSelection(); | 496 | m_selectionManager->clearSelection(); | ||
497 | m_selectionManager->setSelected(index, 1); | 497 | m_selectionManager->setSelected(index, 1); | ||
498 | m_selectionManager->beginAnchoredSelection(index); | 498 | m_selectionManager->beginAnchoredSelection(index); | ||
499 | } | 499 | } | ||
500 | 500 | | |||
501 | m_view->scrollToItem(index); | 501 | m_view->scrollToItem(index); | ||
502 | } | 502 | } | ||
503 | } | 503 | } | ||
Show All 17 Lines | 506 | { | |||
521 | * item still becomes activated/expanded. | 521 | * item still becomes activated/expanded. | ||
522 | * | 522 | * | ||
523 | * See Bug 293200 and 305783 | 523 | * See Bug 293200 and 305783 | ||
524 | */ | 524 | */ | ||
525 | if (m_model->supportsDropping(index) && m_view->isUnderMouse()) { | 525 | if (m_model->supportsDropping(index) && m_view->isUnderMouse()) { | ||
526 | if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | 526 | if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | ||
527 | const bool expanded = m_model->isExpanded(index); | 527 | const bool expanded = m_model->isExpanded(index); | ||
528 | m_model->setExpanded(index, !expanded); | 528 | m_model->setExpanded(index, !expanded); | ||
529 | } else if (m_autoActivationBehavior != ExpansionOnly) { | 529 | } else if (m_autoActivationBehavior != AutoActivationBehavior::ExpansionOnly) { | ||
530 | emit itemActivated(index); | 530 | emit itemActivated(index); | ||
531 | } | 531 | } | ||
532 | } | 532 | } | ||
533 | } | 533 | } | ||
534 | 534 | | |||
535 | bool KItemListController::inputMethodEvent(QInputMethodEvent* event) | 535 | bool KItemListController::inputMethodEvent(QInputMethodEvent* event) | ||
536 | { | 536 | { | ||
537 | Q_UNUSED(event); | 537 | Q_UNUSED(event); | ||
Show All 20 Lines | 557 | if (m_view->isAboveExpansionToggle(m_pressedIndex, m_pressedMousePos)) { | |||
558 | m_selectionManager->endAnchoredSelection(); | 558 | m_selectionManager->endAnchoredSelection(); | ||
559 | m_selectionManager->setCurrentItem(m_pressedIndex); | 559 | m_selectionManager->setCurrentItem(m_pressedIndex); | ||
560 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | 560 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | ||
561 | return true; | 561 | return true; | ||
562 | } | 562 | } | ||
563 | 563 | | |||
564 | m_selectionTogglePressed = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); | 564 | m_selectionTogglePressed = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); | ||
565 | if (m_selectionTogglePressed) { | 565 | if (m_selectionTogglePressed) { | ||
566 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); | 566 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); | ||
567 | // The previous anchored selection has been finished already in | 567 | // The previous anchored selection has been finished already in | ||
568 | // KItemListSelectionManager::setSelected(). We can safely change | 568 | // KItemListSelectionManager::setSelected(). We can safely change | ||
569 | // the current item and start a new anchored selection now. | 569 | // the current item and start a new anchored selection now. | ||
570 | m_selectionManager->setCurrentItem(m_pressedIndex); | 570 | m_selectionManager->setCurrentItem(m_pressedIndex); | ||
571 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | 571 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | ||
572 | return true; | 572 | return true; | ||
573 | } | 573 | } | ||
574 | 574 | | |||
575 | const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; | 575 | const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; | ||
576 | const bool controlPressed = event->modifiers() & Qt::ControlModifier; | 576 | const bool controlPressed = event->modifiers() & Qt::ControlModifier; | ||
577 | 577 | | |||
578 | // The previous selection is cleared if either | 578 | // The previous selection is cleared if either | ||
579 | // 1. The selection mode is SingleSelection, or | 579 | // 1. The selection mode is SingleSelection, or | ||
580 | // 2. the selection mode is MultiSelection, and *none* of the following conditions are met: | 580 | // 2. the selection mode is MultiSelection, and *none* of the following conditions are met: | ||
581 | // a) Shift or Control are pressed. | 581 | // a) Shift or Control are pressed. | ||
582 | // b) The clicked item is selected already. In that case, the user might want to: | 582 | // b) The clicked item is selected already. In that case, the user might want to: | ||
583 | // - start dragging multiple items, or | 583 | // - start dragging multiple items, or | ||
584 | // - open the context menu and perform an action for all selected items. | 584 | // - open the context menu and perform an action for all selected items. | ||
585 | const bool shiftOrControlPressed = shiftPressed || controlPressed; | 585 | const bool shiftOrControlPressed = shiftPressed || controlPressed; | ||
586 | const bool pressedItemAlreadySelected = m_pressedIndex >= 0 && m_selectionManager->isSelected(m_pressedIndex); | 586 | const bool pressedItemAlreadySelected = m_pressedIndex >= 0 && m_selectionManager->isSelected(m_pressedIndex); | ||
587 | const bool clearSelection = m_selectionBehavior == SingleSelection || | 587 | const bool clearSelection = m_selectionBehavior == SelectionBehavior::SingleSelection || | ||
588 | (!shiftOrControlPressed && !pressedItemAlreadySelected); | 588 | (!shiftOrControlPressed && !pressedItemAlreadySelected); | ||
589 | if (clearSelection) { | 589 | if (clearSelection) { | ||
590 | m_selectionManager->clearSelection(); | 590 | m_selectionManager->clearSelection(); | ||
591 | } else if (pressedItemAlreadySelected && !shiftOrControlPressed && (event->buttons() & Qt::LeftButton)) { | 591 | } else if (pressedItemAlreadySelected && !shiftOrControlPressed && (event->buttons() & Qt::LeftButton)) { | ||
592 | // The user might want to start dragging multiple items, but if he clicks the item | 592 | // The user might want to start dragging multiple items, but if he clicks the item | ||
593 | // in order to trigger it instead, the other selected items must be deselected. | 593 | // in order to trigger it instead, the other selected items must be deselected. | ||
594 | // However, we do not know yet what the user is going to do. | 594 | // However, we do not know yet what the user is going to do. | ||
595 | // -> remember that the user pressed an item which had been selected already and | 595 | // -> remember that the user pressed an item which had been selected already and | ||
Show All 9 Lines | 604 | if (!shiftPressed) { | |||
605 | // Finish the anchored selection before the current index is changed | 605 | // Finish the anchored selection before the current index is changed | ||
606 | m_selectionManager->endAnchoredSelection(); | 606 | m_selectionManager->endAnchoredSelection(); | ||
607 | } | 607 | } | ||
608 | 608 | | |||
609 | if (m_pressedIndex >= 0) { | 609 | if (m_pressedIndex >= 0) { | ||
610 | m_selectionManager->setCurrentItem(m_pressedIndex); | 610 | m_selectionManager->setCurrentItem(m_pressedIndex); | ||
611 | 611 | | |||
612 | switch (m_selectionBehavior) { | 612 | switch (m_selectionBehavior) { | ||
613 | case NoSelection: | 613 | case SelectionBehavior::NoSelection: | ||
614 | break; | 614 | break; | ||
615 | 615 | | |||
616 | case SingleSelection: | 616 | case SelectionBehavior::SingleSelection: | ||
617 | m_selectionManager->setSelected(m_pressedIndex); | 617 | m_selectionManager->setSelected(m_pressedIndex); | ||
618 | break; | 618 | break; | ||
619 | 619 | | |||
620 | case MultiSelection: | 620 | case SelectionBehavior::MultiSelection: | ||
621 | if (controlPressed && !shiftPressed) { | 621 | if (controlPressed && !shiftPressed) { | ||
622 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); | 622 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); | ||
623 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | 623 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | ||
624 | } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { | 624 | } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { | ||
625 | // Select the pressed item and start a new anchored selection | 625 | // Select the pressed item and start a new anchored selection | ||
626 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); | 626 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Select); | ||
627 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | 627 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | ||
628 | } | 628 | } | ||
629 | break; | 629 | break; | ||
630 | 630 | | |||
631 | default: | 631 | default: | ||
632 | Q_ASSERT(false); | 632 | Q_ASSERT(false); | ||
633 | break; | 633 | break; | ||
634 | } | 634 | } | ||
Show All 10 Lines | 643 | if (event->buttons() & Qt::RightButton) { | |||
645 | if (headerBounds.contains(event->pos())) { | 645 | if (headerBounds.contains(event->pos())) { | ||
646 | emit headerContextMenuRequested(event->screenPos()); | 646 | emit headerContextMenuRequested(event->screenPos()); | ||
647 | } else { | 647 | } else { | ||
648 | emit viewContextMenuRequested(event->screenPos()); | 648 | emit viewContextMenuRequested(event->screenPos()); | ||
649 | } | 649 | } | ||
650 | return true; | 650 | return true; | ||
651 | } | 651 | } | ||
652 | 652 | | |||
653 | if (m_selectionBehavior == MultiSelection) { | 653 | if (m_selectionBehavior == SelectionBehavior::MultiSelection) { | ||
654 | QPointF startPos = m_pressedMousePos; | 654 | QPointF startPos = m_pressedMousePos; | ||
655 | if (m_view->scrollOrientation() == Qt::Vertical) { | 655 | if (m_view->scrollOrientation() == Qt::Vertical) { | ||
656 | startPos.ry() += m_view->scrollOffset(); | 656 | startPos.ry() += m_view->scrollOffset(); | ||
657 | if (m_view->itemSize().width() < 0) { | 657 | if (m_view->itemSize().width() < 0) { | ||
658 | // Use a special rubberband for views that have only one column and | 658 | // Use a special rubberband for views that have only one column and | ||
659 | // expand the rubberband to use the whole width of the view. | 659 | // expand the rubberband to use the whole width of the view. | ||
660 | startPos.setX(0); | 660 | startPos.setX(0); | ||
661 | } | 661 | } | ||
Show All 23 Lines | 684 | if (m_pressedIndex >= 0) { | |||
685 | // Check whether a dragging should be started | 685 | // Check whether a dragging should be started | ||
686 | if (event->buttons() & Qt::LeftButton) { | 686 | if (event->buttons() & Qt::LeftButton) { | ||
687 | const QPointF pos = transform.map(event->pos()); | 687 | const QPointF pos = transform.map(event->pos()); | ||
688 | if ((pos - m_pressedMousePos).manhattanLength() >= QApplication::startDragDistance()) { | 688 | if ((pos - m_pressedMousePos).manhattanLength() >= QApplication::startDragDistance()) { | ||
689 | if (!m_selectionManager->isSelected(m_pressedIndex)) { | 689 | if (!m_selectionManager->isSelected(m_pressedIndex)) { | ||
690 | // Always assure that the dragged item gets selected. Usually this is already | 690 | // Always assure that the dragged item gets selected. Usually this is already | ||
691 | // done on the mouse-press event, but when using the selection-toggle on a | 691 | // done on the mouse-press event, but when using the selection-toggle on a | ||
692 | // selected item the dragged item is not selected yet. | 692 | // selected item the dragged item is not selected yet. | ||
693 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); | 693 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); | ||
694 | } else { | 694 | } else { | ||
695 | // A selected item has been clicked to drag all selected items | 695 | // A selected item has been clicked to drag all selected items | ||
696 | // -> the selection should not be cleared when the mouse button is released. | 696 | // -> the selection should not be cleared when the mouse button is released. | ||
697 | m_clearSelectionIfItemsAreNotDragged = false; | 697 | m_clearSelectionIfItemsAreNotDragged = false; | ||
698 | } | 698 | } | ||
699 | 699 | | |||
700 | startDragging(); | 700 | startDragging(); | ||
701 | } | 701 | } | ||
Show All 39 Lines | 735 | { | |||
741 | 741 | | |||
742 | const bool isAboveSelectionToggle = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); | 742 | const bool isAboveSelectionToggle = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); | ||
743 | if (isAboveSelectionToggle) { | 743 | if (isAboveSelectionToggle) { | ||
744 | m_selectionTogglePressed = false; | 744 | m_selectionTogglePressed = false; | ||
745 | return true; | 745 | return true; | ||
746 | } | 746 | } | ||
747 | 747 | | |||
748 | if (!isAboveSelectionToggle && m_selectionTogglePressed) { | 748 | if (!isAboveSelectionToggle && m_selectionTogglePressed) { | ||
749 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); | 749 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); | ||
750 | m_selectionTogglePressed = false; | 750 | m_selectionTogglePressed = false; | ||
751 | return true; | 751 | return true; | ||
752 | } | 752 | } | ||
753 | 753 | | |||
754 | const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier || | 754 | const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier || | ||
755 | event->modifiers() & Qt::ControlModifier; | 755 | event->modifiers() & Qt::ControlModifier; | ||
756 | 756 | | |||
757 | KItemListRubberBand* rubberBand = m_view->rubberBand(); | 757 | KItemListRubberBand* rubberBand = m_view->rubberBand(); | ||
Show All 9 Lines | |||||
767 | 767 | | |||
768 | if (index >= 0 && index == m_pressedIndex) { | 768 | if (index >= 0 && index == m_pressedIndex) { | ||
769 | // The release event is done above the same item as the press event | 769 | // The release event is done above the same item as the press event | ||
770 | 770 | | |||
771 | if (m_clearSelectionIfItemsAreNotDragged) { | 771 | if (m_clearSelectionIfItemsAreNotDragged) { | ||
772 | // A selected item has been clicked, but no drag operation has been started | 772 | // A selected item has been clicked, but no drag operation has been started | ||
773 | // -> clear the rest of the selection. | 773 | // -> clear the rest of the selection. | ||
774 | m_selectionManager->clearSelection(); | 774 | m_selectionManager->clearSelection(); | ||
775 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); | 775 | m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Select); | ||
776 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | 776 | m_selectionManager->beginAnchoredSelection(m_pressedIndex); | ||
777 | } | 777 | } | ||
778 | 778 | | |||
779 | if (event->button() & Qt::LeftButton) { | 779 | if (event->button() & Qt::LeftButton) { | ||
780 | bool emitItemActivated = true; | 780 | bool emitItemActivated = true; | ||
781 | if (m_view->isAboveExpansionToggle(index, pos)) { | 781 | if (m_view->isAboveExpansionToggle(index, pos)) { | ||
782 | const bool expanded = m_model->isExpanded(index); | 782 | const bool expanded = m_model->isExpanded(index); | ||
783 | m_model->setExpanded(index, !expanded); | 783 | m_model->setExpanded(index, !expanded); | ||
Show All 21 Lines | |||||
805 | } | 805 | } | ||
806 | 806 | | |||
807 | bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) | 807 | bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) | ||
808 | { | 808 | { | ||
809 | const QPointF pos = transform.map(event->pos()); | 809 | const QPointF pos = transform.map(event->pos()); | ||
810 | const int index = m_view->itemAt(pos); | 810 | const int index = m_view->itemAt(pos); | ||
811 | 811 | | |||
812 | // Expand item if desired - See Bug 295573 | 812 | // Expand item if desired - See Bug 295573 | ||
813 | if (m_mouseDoubleClickAction != ActivateItemOnly) { | 813 | if (m_mouseDoubleClickAction != MouseDoubleClickAction::ActivateItemOnly) { | ||
814 | if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | 814 | if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | ||
815 | const bool expanded = m_model->isExpanded(index); | 815 | const bool expanded = m_model->isExpanded(index); | ||
816 | m_model->setExpanded(index, !expanded); | 816 | m_model->setExpanded(index, !expanded); | ||
817 | } | 817 | } | ||
818 | } | 818 | } | ||
819 | 819 | | |||
820 | if (event->button() & Qt::RightButton) { | 820 | if (event->button() & Qt::RightButton) { | ||
821 | m_selectionManager->clearSelection(); | 821 | m_selectionManager->clearSelection(); | ||
▲ Show 20 Lines • Show All 517 Lines • ▼ Show 20 Line(s) | 1335 | { | |||
1339 | } | 1339 | } | ||
1340 | 1340 | | |||
1341 | return 0; | 1341 | return 0; | ||
1342 | } | 1342 | } | ||
1343 | 1343 | | |||
1344 | void KItemListController::updateExtendedSelectionRegion() | 1344 | void KItemListController::updateExtendedSelectionRegion() | ||
1345 | { | 1345 | { | ||
1346 | if (m_view) { | 1346 | if (m_view) { | ||
1347 | const bool extend = (m_selectionBehavior != MultiSelection); | 1347 | const bool extend = (m_selectionBehavior != SelectionBehavior::MultiSelection); | ||
1348 | KItemListStyleOption option = m_view->styleOption(); | 1348 | KItemListStyleOption option = m_view->styleOption(); | ||
1349 | if (option.extendedSelectionRegion != extend) { | 1349 | if (option.extendedSelectionRegion != extend) { | ||
1350 | option.extendedSelectionRegion = extend; | 1350 | option.extendedSelectionRegion = extend; | ||
1351 | m_view->setStyleOption(option); | 1351 | m_view->setStyleOption(option); | ||
1352 | } | 1352 | } | ||
1353 | } | 1353 | } | ||
1354 | } | 1354 | } | ||
1355 | 1355 | |