┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/accessibility/kitemlistviewaccessible.cpp31
-rw-r--r--src/kitemviews/accessibility/kitemlistviewaccessible.h7
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp18
3 files changed, 51 insertions, 5 deletions
diff --git a/src/kitemviews/accessibility/kitemlistviewaccessible.cpp b/src/kitemviews/accessibility/kitemlistviewaccessible.cpp
index f8c14bf4a..f58527be6 100644
--- a/src/kitemviews/accessibility/kitemlistviewaccessible.cpp
+++ b/src/kitemviews/accessibility/kitemlistviewaccessible.cpp
@@ -280,8 +280,18 @@ QString KItemListViewAccessible::text(QAccessible::Text t) const
if (numberOfSelectedItems < 1 || (numberOfSelectedItems == 1 && isSelected(currentItem))) {
// We do not announce the number of selected items if the only selected item is the current item
// because the selection state of the current item is already announced elsewhere.
+ if (m_selectionMode) {
+ return i18nc("@info accessibility, 1 is path", "in a grid layout in selection mode in location %1", modelRootUrl.toDisplayString());
+ }
return i18nc("@info accessibility, 1 is path", "in a grid layout in location %1", modelRootUrl.toDisplayString());
}
+ if (m_selectionMode) {
+ return i18ncp("@info accessibility, 2 is path",
+ "%1 selected item in a grid layout in selection mode in location %2",
+ "%1 selected items in a grid layout in selection mode in location %2",
+ numberOfSelectedItems,
+ modelRootUrl.toDisplayString());
+ }
return i18ncp("@info accessibility, 2 is path",
"%1 selected item in a grid layout in location %2",
"%1 selected items in a grid layout in location %2",
@@ -293,8 +303,18 @@ QString KItemListViewAccessible::text(QAccessible::Text t) const
if (numberOfSelectedItems < 1 || (numberOfSelectedItems == 1 && isSelected(currentItem))) {
// We do not announce the number of selected items if the only selected item is the current item
// because the selection state of the current item is already announced elsewhere.
+ if (m_selectionMode) {
+ return i18nc("@info accessibility, 1 is path", "in selection mode in location %1", modelRootUrl.toDisplayString());
+ }
return i18nc("@info accessibility, 1 is path", "in location %1", modelRootUrl.toDisplayString());
}
+ if (m_selectionMode) {
+ return i18ncp("@info accessibility, 2 is path",
+ "%1 selected item in selection mode in location %2",
+ "%1 selected items in selection mode in location %2",
+ numberOfSelectedItems,
+ modelRootUrl.toDisplayString());
+ }
return i18ncp("@info accessibility, 2 is path",
"%1 selected item in location %2",
"%1 selected items in location %2",
@@ -490,3 +510,14 @@ void KItemListViewAccessible::slotAnnounceCurrentItemTimerTimeout()
QAccessible::updateAccessibility(&announceAccessibleDescriptionEvent);
}
}
+
+void KItemListViewAccessible::announceSelectionModeEnabled(const bool enabled)
+{
+ m_selectionMode = enabled;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) // QAccessibleAnnouncementEvent is only available since 6.8
+ QAccessibleAnnouncementEvent announceChangedControlsEvent(view(),
+ enabled ? i18nc("accessibility announcement", "Selection mode enabled")
+ : i18nc("accessibility announcement", "Selection mode disabled"));
+ QAccessible::updateAccessibility(&announceChangedControlsEvent);
+#endif
+}
diff --git a/src/kitemviews/accessibility/kitemlistviewaccessible.h b/src/kitemviews/accessibility/kitemlistviewaccessible.h
index db2832435..64b5a2442 100644
--- a/src/kitemviews/accessibility/kitemlistviewaccessible.h
+++ b/src/kitemviews/accessibility/kitemlistviewaccessible.h
@@ -124,6 +124,12 @@ public:
*/
void announceCurrentItem();
+ /**
+ * Toggling selection mode completely changes how the application controls, so it is absolutely necessary to communicate this change to users as soon as it
+ * happens.
+ */
+ void announceSelectionModeEnabled(bool enabled);
+
private:
/**
* @returns a KItemListDelegateAccessible representing the file or folder at the @index. Returns nullptr for invalid indices.
@@ -144,6 +150,7 @@ private Q_SLOTS:
private:
/** @see setPlaceholderMessage(). */
QString m_placeholderMessage;
+ bool m_selectionMode = false;
/**
* Is started by announceCurrentItem().
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index 821e1b75f..2ae4a1f25 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -270,7 +270,9 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
}
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;
@@ -467,7 +469,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
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);
@@ -503,13 +505,13 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
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);
}
@@ -540,10 +542,16 @@ void KItemListController::slotChangeCurrentItem(const QString &text, bool search
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);
}