summaryrefslogtreecommitdiff
path: root/src/controls/qquickmenuitem.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-06-12 23:48:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-20 23:59:31 +0200
commitffbf8d724f39e9c8d05ae2049e8b79a61570e235 (patch)
treeb1bdf614d2063eb71cc50f0f21d58076e8f21a72 /src/controls/qquickmenuitem.cpp
parent0a3192fe4100dd790dc1467cc2cab200fb996ab0 (diff)
downloadqtquickcontrols-ffbf8d724f39e9c8d05ae2049e8b79a61570e235.tar.gz
Support StandardKeys for Action/MenuItem::shortcut
Change-Id: I2054a59fcda26795721e5d7d04cc644220da372b Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com> Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'src/controls/qquickmenuitem.cpp')
-rw-r--r--src/controls/qquickmenuitem.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/controls/qquickmenuitem.cpp b/src/controls/qquickmenuitem.cpp
index ed03b336..1834ffc1 100644
--- a/src/controls/qquickmenuitem.cpp
+++ b/src/controls/qquickmenuitem.cpp
@@ -340,9 +340,20 @@ void QQuickMenuText::updateIcon()
*/
/*!
- \qmlproperty string MenuItem::shortcut
+ \qmlproperty keysequence MenuItem::shortcut
- Shorcut bound to the menu item. Defaults to the empty string.
+ Shortcut bound to the menu item. The keysequence can be a string
+ or a \l {QKeySequence::StandardKey}{standard key}.
+
+ Defaults to an empty string.
+
+ \qml
+ MenuItem {
+ id: copyItem
+ text: qsTr("&Copy")
+ shortcut: StandardKey.Copy
+ }
+ \endqml
\sa Action::shortcut
*/
@@ -401,7 +412,7 @@ QQuickMenuItem::QQuickMenuItem(QObject *parent)
{
connect(this, SIGNAL(__textChanged()), this, SIGNAL(textChanged()));
- connect(action(), SIGNAL(shortcutChanged(QString)), this, SLOT(updateShortcut()));
+ connect(action(), SIGNAL(shortcutChanged(QVariant)), this, SLOT(updateShortcut()));
connect(action(), SIGNAL(triggered()), this, SIGNAL(triggered()));
connect(action(), SIGNAL(toggled(bool)), this, SLOT(updateChecked()));
if (platformItem())
@@ -433,7 +444,7 @@ void QQuickMenuItem::bindToAction(QQuickAction *action)
connect(m_boundAction, SIGNAL(exclusiveGroupChanged()), this, SIGNAL(exclusiveGroupChanged()));
connect(m_boundAction, SIGNAL(enabledChanged()), this, SLOT(updateEnabled()));
connect(m_boundAction, SIGNAL(textChanged()), this, SLOT(updateText()));
- connect(m_boundAction, SIGNAL(shortcutChanged(QString)), this, SLOT(updateShortcut()));
+ connect(m_boundAction, SIGNAL(shortcutChanged(QVariant)), this, SLOT(updateShortcut()));
connect(m_boundAction, SIGNAL(checkableChanged()), this, SIGNAL(checkableChanged()));
connect(m_boundAction, SIGNAL(iconNameChanged()), this, SLOT(updateIcon()));
connect(m_boundAction, SIGNAL(iconNameChanged()), this, SIGNAL(iconNameChanged()));
@@ -469,7 +480,7 @@ void QQuickMenuItem::unbindFromAction(QObject *o)
disconnect(action, SIGNAL(exclusiveGroupChanged()), this, SIGNAL(exclusiveGroupChanged()));
disconnect(action, SIGNAL(enabledChanged()), this, SLOT(updateEnabled()));
disconnect(action, SIGNAL(textChanged()), this, SLOT(updateText()));
- disconnect(action, SIGNAL(shortcutChanged(QString)), this, SLOT(updateShortcut()));
+ disconnect(action, SIGNAL(shortcutChanged(QVariant)), this, SLOT(updateShortcut()));
disconnect(action, SIGNAL(checkableChanged()), this, SIGNAL(checkableChanged()));
disconnect(action, SIGNAL(iconNameChanged()), this, SLOT(updateIcon()));
disconnect(action, SIGNAL(iconNameChanged()), this, SIGNAL(iconNameChanged()));
@@ -532,12 +543,12 @@ QIcon QQuickMenuItem::icon() const
return m_boundAction ? m_boundAction->icon() : QIcon();
}
-QString QQuickMenuItem::shortcut() const
+QVariant QQuickMenuItem::shortcut() const
{
return action()->shortcut();
}
-void QQuickMenuItem::setShortcut(const QString &shortcut)
+void QQuickMenuItem::setShortcut(const QVariant &shortcut)
{
if (!m_boundAction)
action()->setShortcut(shortcut);
@@ -546,7 +557,13 @@ void QQuickMenuItem::setShortcut(const QString &shortcut)
void QQuickMenuItem::updateShortcut()
{
if (platformItem()) {
- platformItem()->setShortcut(QKeySequence(shortcut()));
+ QKeySequence sequence;
+ QVariant var = shortcut();
+ if (var.type() == QVariant::Int)
+ sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(var.toInt()));
+ else
+ sequence = QKeySequence::fromString(var.toString(), QKeySequence::NativeText);
+ platformItem()->setShortcut(sequence);
syncWithPlatformMenu();
}
emit shortcutChanged();