diff options
| author | Felix Ernst <[email protected]> | 2024-12-29 11:27:18 +0000 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2024-12-29 11:27:18 +0000 |
| commit | 3696213ccbbe27e9ef3fc85eb97dd32fd669066f (patch) | |
| tree | 7b6db1a823da09b3bedab8aaf2ea0e82393ceab5 /src/selectionmode/topbar.cpp | |
| parent | 4f71b3c539eb54c3db184d85ebc9bfce5ecfb989 (diff) | |
Have special keyboard controls in selection mode
Prior to this commit keyboard controls and behaviour of Dolphin's main
view were identical no matter if selection mode was enabled or not.
While selection mode makes it impossible to accidentally clear the
selection by singular mouse clicks, any press of an arrow key on the
keyboard would still clear the full selection which goes against
selection mode's objective.
Furthermore, keyboard-only users had no reason to ever enable selection
mode because it made no difference to them.
This commit changes this by offering a changed control scheme for key
presses while in selection mode. Arrow key presses without modifier now
only move focus between items but do no longer clear or change the
selection. Similarly, Page Up/Down, Home, and End key presses only move
keyboard focus. Enter, Return, and Space key presses now only toggle
the selection for the current item.
The above controls are however mostly unchanged when combining them
with Modifier keys like Shift or Control.
The type-ahead feature is also changed in selection mode to only move
keyboard focus without changing the selection.
This way keyboard users are less likely to clear their selection by
mistake. Regression tests are added for these selection mode controls.
The code changes to change this keyboard behaviour are quite minimal.
Most of the added code is for making selection mode accessible. That's
because we need to make sure the changed control scheme is properly
announced and communicated or a blind user will be left utterly
confused why the normal keyboard controls "stopped working".
Enabling or disabling selection mode is announced to accessibility
software. Furthermore whenever focus goes to the main view, the
selection mode state is also mentioned when active.
BUG: 458091
Diffstat (limited to 'src/selectionmode/topbar.cpp')
| -rw-r--r-- | src/selectionmode/topbar.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/selectionmode/topbar.cpp b/src/selectionmode/topbar.cpp index 5d77a4c00..7ef507910 100644 --- a/src/selectionmode/topbar.cpp +++ b/src/selectionmode/topbar.cpp @@ -10,8 +10,8 @@ #include "backgroundcolorhelper.h" #include <KColorScheme> +#include <KContextualHelpButton> #include <KLocalizedString> -#include <KToolTipHelper> #include <QHBoxLayout> #include <QLabel> @@ -23,14 +23,6 @@ using namespace SelectionMode; TopBar::TopBar(QWidget *parent) : AnimatedHeightWidget{parent} { - setToolTip(KToolTipHelper::whatsThisHintOnly()); - setWhatsThis(xi18nc("@info:whatsthis", - "<title>Selection Mode</title><para>Select files or folders to manage or manipulate them." - "<list><item>Press on a file or folder to select it.</item><item>Press on an already selected file or folder to deselect it.</item>" - "<item>Pressing an empty area does <emphasis>not</emphasis> clear the selection.</item>" - "<item>Selection rectangles (created by dragging from an empty area) invert the selection status of items within.</item></list></para>" - "<para>The available action buttons at the bottom change depending on the current selection.</para>")); - QWidget *contentsContainer = prepareContentsContainer(); BackgroundColorHelper::instance()->controlBackgroundColor(this); @@ -39,8 +31,24 @@ TopBar::TopBar(QWidget *parent) m_shortLabelString = i18nc("@info label above the view explaining the state", "Selection Mode"); m_label = new QLabel(contentsContainer); m_label->setMinimumWidth(0); + m_label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard | Qt::LinksAccessibleByKeyboard); // for keyboard accessibility BackgroundColorHelper::instance()->controlBackgroundColor(m_label); + m_contextualHelpButton = new KContextualHelpButton{ + xi18nc("@info", + "<title>Selection Mode</title><para>Select files or folders to manage or manipulate them." + "<list><item>Press on a file or folder to select it.</item><item>Press on an already selected file or folder to deselect it.</item>" + "<item>Pressing an empty area does <emphasis>not</emphasis> clear the selection.</item>" + "<item>Selection rectangles (created by dragging from an empty area) invert the selection status of items within.</item>" + "<item>Moving with <shortcut>arrow keys</shortcut> does <emphasis>not</emphasis> change the selection.</item>" + "<item>Pressing <shortcut>%1</shortcut>, <shortcut>%2</shortcut>, or <shortcut>%3</shortcut> toggles the selection.</item></list></para>" + "<para>The available action buttons at the bottom change depending on the current selection.</para>", + QKeySequence{Qt::Key_Enter}.toString(QKeySequence::NativeText), + QKeySequence{Qt::Key_Return}.toString(QKeySequence::NativeText), + QKeySequence{Qt::CTRL | Qt::Key_Space}.toString(QKeySequence::NativeText)), + nullptr, + contentsContainer}; + m_closeButton = new QPushButton(QIcon::fromTheme(QStringLiteral("window-close-symbolic")), "", contentsContainer); m_closeButton->setText(i18nc("@action:button", "Exit Selection Mode")); m_closeButton->setFlat(true); @@ -54,6 +62,7 @@ TopBar::TopBar(QWidget *parent) layout->addStretch(); layout->addWidget(m_label); + layout->addWidget(m_contextualHelpButton); layout->addStretch(); layout->addWidget(m_closeButton); } @@ -67,8 +76,8 @@ void TopBar::resizeEvent(QResizeEvent *resizeEvent) void TopBar::updateLabelString() { QFontMetrics fontMetrics = m_label->fontMetrics(); - if (fontMetrics.horizontalAdvance(m_fullLabelString) + m_closeButton->sizeHint().width() + style()->pixelMetric(QStyle::PM_LayoutLeftMargin) * 2 - + style()->pixelMetric(QStyle::PM_LayoutRightMargin) * 2 + if (fontMetrics.horizontalAdvance(m_fullLabelString) + m_contextualHelpButton->sizeHint().width() + m_closeButton->sizeHint().width() + + style()->pixelMetric(QStyle::PM_LayoutLeftMargin) * 2 + style()->pixelMetric(QStyle::PM_LayoutRightMargin) * 2 < width()) { m_label->setText(m_fullLabelString); } else { |
