aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-07-29 14:26:50 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-25 04:59:00 +0000
commit235d68348998a56e425084eea244c5cc9b7e6d09 (patch)
tree2f7da73b5ed4f4ca9569030f9d32cdb69fc9277b /src
parentafb7440dcdb26623f0618be017bb8998d21f5cb2 (diff)
Platform: fix MenuItem being triggered when disabled
Ensure that we remove shortcuts for a MenuItem when it's disabled, not just when a new shortcut is set. Fixes: QTBUG-89567 Change-Id: I9c4eeda1a68a23317fe5e7bf517046e4e403c46a Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit acf2ed0c5fb7594ab01ff48e3dc5c3c16e203755) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/labs/platform/qquicklabsplatformmenuitem.cpp75
-rw-r--r--src/labs/platform/qquicklabsplatformmenuitem_p.h3
2 files changed, 45 insertions, 33 deletions
diff --git a/src/labs/platform/qquicklabsplatformmenuitem.cpp b/src/labs/platform/qquicklabsplatformmenuitem.cpp
index ece434455a..c999c63d27 100644
--- a/src/labs/platform/qquicklabsplatformmenuitem.cpp
+++ b/src/labs/platform/qquicklabsplatformmenuitem.cpp
@@ -126,16 +126,7 @@ QQuickLabsPlatformMenuItem::~QQuickLabsPlatformMenuItem()
m_menu->removeItem(this);
if (m_group)
m_group->removeItem(this);
-#if QT_CONFIG(shortcut)
- if (m_shortcutId != -1) {
- QKeySequence sequence;
- if (m_shortcut.metaType().id() == QMetaType::Int)
- sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
- else
- sequence = QKeySequence::fromString(m_shortcut.toString());
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId, this, sequence);
- }
-#endif
+ removeShortcut();
delete m_iconLoader;
m_iconLoader = nullptr;
delete m_handle;
@@ -302,8 +293,15 @@ void QQuickLabsPlatformMenuItem::setEnabled(bool enabled)
if (m_enabled == enabled)
return;
+ if (!enabled)
+ removeShortcut();
+
bool wasEnabled = isEnabled();
m_enabled = enabled;
+
+ if (enabled)
+ addShortcut();
+
sync();
if (isEnabled() != wasEnabled)
emit enabledChanged();
@@ -509,31 +507,10 @@ void QQuickLabsPlatformMenuItem::setShortcut(const QVariant& shortcut)
if (m_shortcut == shortcut)
return;
-#if QT_CONFIG(shortcut)
- if (m_shortcutId != -1) {
- QKeySequence sequence;
- if (m_shortcut.metaType().id() == QMetaType::Int)
- sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
- else
- sequence = QKeySequence::fromString(m_shortcut.toString());
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId, this, sequence);
- }
-#endif
+ removeShortcut();
m_shortcut = shortcut;
sync();
-#if QT_CONFIG(shortcut)
- QKeySequence sequence;
- if (m_shortcut.metaType().id() == QMetaType::Int)
- sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
- else
- sequence = QKeySequence::fromString(m_shortcut.toString());
- if (!sequence.isEmpty()) {
- m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, sequence,
- Qt::WindowShortcut, QQuickShortcutContext::matcher);
- } else {
- m_shortcutId = -1;
- }
-#endif
+ addShortcut();
emit shortcutChanged();
}
@@ -639,6 +616,38 @@ void QQuickLabsPlatformMenuItem::updateIcon()
sync();
}
+void QQuickLabsPlatformMenuItem::addShortcut()
+{
+#if QT_CONFIG(shortcut)
+ QKeySequence sequence;
+ if (m_shortcut.metaType().id() == QMetaType::Int)
+ sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
+ else
+ sequence = QKeySequence::fromString(m_shortcut.toString());
+ if (!sequence.isEmpty() && m_enabled) {
+ m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, sequence,
+ Qt::WindowShortcut, QQuickShortcutContext::matcher);
+ } else {
+ m_shortcutId = -1;
+ }
+#endif
+}
+
+void QQuickLabsPlatformMenuItem::removeShortcut()
+{
+#if QT_CONFIG(shortcut)
+ if (m_shortcutId == -1)
+ return;
+
+ QKeySequence sequence;
+ if (m_shortcut.metaType().id() == QMetaType::Int)
+ sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
+ else
+ sequence = QKeySequence::fromString(m_shortcut.toString());
+ QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId, this, sequence);
+#endif
+}
+
QT_END_NAMESPACE
#include "moc_qquicklabsplatformmenuitem_p.cpp"
diff --git a/src/labs/platform/qquicklabsplatformmenuitem_p.h b/src/labs/platform/qquicklabsplatformmenuitem_p.h
index 8daa7c0555..2f7840ce2c 100644
--- a/src/labs/platform/qquicklabsplatformmenuitem_p.h
+++ b/src/labs/platform/qquicklabsplatformmenuitem_p.h
@@ -166,6 +166,9 @@ private Q_SLOTS:
void updateIcon();
private:
+ void addShortcut();
+ void removeShortcut();
+
bool m_complete;
bool m_enabled;
bool m_visible;