diff options
author | Noah Davis <noahadvs@gmail.com> | 2022-02-16 16:57:50 -0500 |
---|---|---|
committer | Noah Davis <noahadvs@gmail.com> | 2022-03-04 17:12:14 -0500 |
commit | b3e9d51997d7a7cf879e576d9faa5d024df72b70 (patch) | |
tree | c70f5c81c668ec209f67629ec4fda5afadb72e16 | |
parent | 52f687d0671e1353f8f19c92cfc81da86b8986e8 (diff) |
Qt Quick Controls: use QPlatformTheme::ButtonPressKeys for buttons
ComboBox changes are included because it is button-like when not
editable. MenuItem changes are included because it is an AbstractButton
subclass.
Change-Id: I30a540bc9e277cddc111cbc2400c4130dadedb3c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
10 files changed, 52 insertions, 23 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 2e5ac9a576..7febf39c69 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -51,6 +51,7 @@ # include <QtGui/private/qshortcutmap_p.h> #endif #include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformtheme.h> #include <QtQuick/private/qquickevents_p_p.h> #include <QtQml/qqmllist.h> @@ -235,7 +236,8 @@ void QQuickAbstractButtonPrivate::handleUngrab() bool QQuickAbstractButtonPrivate::acceptKeyClick(Qt::Key key) const { - return key == Qt::Key_Space; + const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>(); + return buttonPressKeys.contains(key); } bool QQuickAbstractButtonPrivate::isPressAndHoldConnected() diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 234ba5def8..0ffecd6fc6 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -49,6 +49,7 @@ #include <QtCore/qglobal.h> #include <QtGui/qinputmethod.h> #include <QtGui/qguiapplication.h> +#include <QtGui/private/qguiapplication_p.h> #include <QtGui/qpa/qplatformtheme.h> #include <QtQml/qjsvalue.h> #include <QtQml/qqmlcontext.h> @@ -1985,17 +1986,23 @@ void QQuickComboBox::keyPressEvent(QKeyEvent *event) Q_D(QQuickComboBox); QQuickControl::keyPressEvent(event); - switch (event->key()) { + const auto key = event->key(); + if (!isEditable()) { + const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>(); + if (buttonPressKeys.contains(key)) { + if (!event->isAutoRepeat()) + setPressed(true); + event->accept(); + return; + } + } + + switch (key) { case Qt::Key_Escape: case Qt::Key_Back: if (d->isPopupVisible()) event->accept(); break; - case Qt::Key_Space: - if (!event->isAutoRepeat()) - setPressed(true); - event->accept(); - break; case Qt::Key_Enter: case Qt::Key_Return: if (d->isPopupVisible()) @@ -2045,13 +2052,19 @@ void QQuickComboBox::keyReleaseEvent(QKeyEvent *event) if (event->isAutoRepeat()) return; - switch (event->key()) { - case Qt::Key_Space: - if (!isEditable()) - d->togglePopup(true); - setPressed(false); - event->accept(); - break; + const auto key = event->key(); + if (!isEditable()) { + const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>(); + if (buttonPressKeys.contains(key)) { + if (!isEditable()) + d->togglePopup(true); + setPressed(false); + event->accept(); + return; + } + } + + switch (key) { case Qt::Key_Enter: case Qt::Key_Return: if (!isEditable() || d->isPopupVisible()) diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index 5ba2d792d4..c8bd1c363c 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -152,7 +152,8 @@ void QQuickMenuItemPrivate::executeArrow(bool complete) bool QQuickMenuItemPrivate::acceptKeyClick(Qt::Key key) const { - return key == Qt::Key_Space || key == Qt::Key_Return || key == Qt::Key_Enter; + return key == Qt::Key_Return || key == Qt::Key_Enter + || QQuickAbstractButtonPrivate::acceptKeyClick(key); } QPalette QQuickMenuItemPrivate::defaultPalette() const diff --git a/tests/auto/quickcontrols2/controls/data/tst_button.qml b/tests/auto/quickcontrols2/controls/data/tst_button.qml index a6ec4faad9..f26a050dfc 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_button.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_button.qml @@ -272,7 +272,9 @@ TestCase { // no change sequenceSpy.expectedSequence = [] - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) diff --git a/tests/auto/quickcontrols2/controls/data/tst_checkbox.qml b/tests/auto/quickcontrols2/controls/data/tst_checkbox.qml index be68ac0d1f..ff6b7ec8b8 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_checkbox.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_checkbox.qml @@ -313,7 +313,9 @@ TestCase { // no change sequenceSpy.expectedSequence = [] - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) diff --git a/tests/auto/quickcontrols2/controls/data/tst_combobox.qml b/tests/auto/quickcontrols2/controls/data/tst_combobox.qml index 100ec45a40..e8e24652de 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_combobox.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_combobox.qml @@ -641,14 +641,15 @@ TestCase { } function test_keys_space_enter_escape_data() { + // Not testing Key_Enter + Key_Enter and Key_Return + Key_Return because + // QGnomeTheme uses Key_Enter and Key_Return for pressing buttons/comboboxes + // and the CI uses the QGnomeTheme platform theme. return [ { tag: "space-space", key1: Qt.Key_Space, key2: Qt.Key_Space, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-enter", key1: Qt.Key_Space, key2: Qt.Key_Enter, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-return", key1: Qt.Key_Space, key2: Qt.Key_Return, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-escape", key1: Qt.Key_Space, key2: Qt.Key_Escape, showPopup: true, showPress: true, hidePopup: true, hidePress: false }, { tag: "space-0", key1: Qt.Key_Space, key2: Qt.Key_0, showPopup: true, showPress: true, hidePopup: false, hidePress: false }, - { tag: "enter-enter", key1: Qt.Key_Enter, key2: Qt.Key_Enter, showPopup: false, showPress: false, hidePopup: true, hidePress: false }, - { tag: "return-return", key1: Qt.Key_Return, key2: Qt.Key_Return, showPopup: false, showPress: false, hidePopup: true, hidePress: false }, { tag: "escape-escape", key1: Qt.Key_Escape, key2: Qt.Key_Escape, showPopup: false, showPress: false, hidePopup: true, hidePress: false } ] } diff --git a/tests/auto/quickcontrols2/controls/data/tst_delaybutton.qml b/tests/auto/quickcontrols2/controls/data/tst_delaybutton.qml index 0e8d188dd2..7350b54320 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_delaybutton.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_delaybutton.qml @@ -307,7 +307,9 @@ TestCase { // no change sequenceSpy.expectedSequence = [] - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) diff --git a/tests/auto/quickcontrols2/controls/data/tst_radiobutton.qml b/tests/auto/quickcontrols2/controls/data/tst_radiobutton.qml index 973e56a360..d0ff56207d 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_radiobutton.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_radiobutton.qml @@ -258,7 +258,9 @@ TestCase { // no change sequenceSpy.expectedSequence = [] - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) diff --git a/tests/auto/quickcontrols2/controls/data/tst_switch.qml b/tests/auto/quickcontrols2/controls/data/tst_switch.qml index bf25fcacff..a4e1f813a0 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_switch.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_switch.qml @@ -570,7 +570,9 @@ TestCase { // no change spy.expectedSequence = [] - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { keyClick(keys[i]) compare(control.checked, false) diff --git a/tests/auto/quickcontrols2/controls/data/tst_toolbutton.qml b/tests/auto/quickcontrols2/controls/data/tst_toolbutton.qml index a7acd05ae4..f85a9193e8 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_toolbutton.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_toolbutton.qml @@ -169,7 +169,9 @@ TestCase { compare(clickedSpy.count, 2) // no change - var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for + // pressing buttons and the CI uses the QGnomeTheme platform theme. + var keys = [Qt.Key_Escape, Qt.Key_Tab] for (var i = 0; i < keys.length; ++i) { keyClick(keys[i]) compare(clickedSpy.count, 2) |