diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/qquickaction.cpp | 26 | ||||
-rw-r--r-- | src/controls/qquickaction_p.h | 8 | ||||
-rw-r--r-- | src/controls/qquickmenuitem.cpp | 33 | ||||
-rw-r--r-- | src/controls/qquickmenuitem_p.h | 6 |
4 files changed, 53 insertions, 20 deletions
diff --git a/src/controls/qquickaction.cpp b/src/controls/qquickaction.cpp index e240d111..aaae51c5 100644 --- a/src/controls/qquickaction.cpp +++ b/src/controls/qquickaction.cpp @@ -156,9 +156,20 @@ QT_BEGIN_NAMESPACE */ /*! - \qmlproperty string Action::shortcut + \qmlproperty keysequence Action::shortcut - Shortcut bound to the action. Defaults to the empty string. + Shortcut bound to the action. The keysequence can be a string + or a \l {QKeySequence::StandardKey}{standard key}. + + Defaults to an empty string. + + \qml + Action { + id: copyAction + text: qsTr("&Copy") + shortcut: StandardKey.Copy + } + \endqml */ /*! \qmlsignal Action::triggered() @@ -226,14 +237,19 @@ bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context) return false; } -QString QQuickAction::shortcut() const +QVariant QQuickAction::shortcut() const { return m_shortcut.toString(QKeySequence::NativeText); } -void QQuickAction::setShortcut(const QString &arg) +void QQuickAction::setShortcut(const QVariant &arg) { - QKeySequence sequence = QKeySequence::fromString(arg); + QKeySequence sequence; + if (arg.type() == QVariant::Int) + sequence = QKeySequence(static_cast<QKeySequence::StandardKey>(arg.toInt())); + else + sequence = QKeySequence::fromString(arg.toString()); + if (sequence == m_shortcut) return; diff --git a/src/controls/qquickaction_p.h b/src/controls/qquickaction_p.h index aa63b408..373627d1 100644 --- a/src/controls/qquickaction_p.h +++ b/src/controls/qquickaction_p.h @@ -68,7 +68,7 @@ class QQuickAction : public QObject Q_PROPERTY(QQuickExclusiveGroup *exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup NOTIFY exclusiveGroupChanged) #ifndef QT_NO_SHORTCUT - Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged) + Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged) #endif public: @@ -79,8 +79,8 @@ public: void resetText() { setText(QString()); } void setText(const QString &text); - QString shortcut() const; - void setShortcut(const QString &shortcut); + QVariant shortcut() const; + void setShortcut(const QVariant &shortcut); void setMnemonicFromText(const QString &mnemonic); @@ -121,7 +121,7 @@ Q_SIGNALS: void toggled(bool checked); void textChanged(); - void shortcutChanged(QString shortcut); + void shortcutChanged(QVariant shortcut); void iconChanged(); void iconNameChanged(); 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(); diff --git a/src/controls/qquickmenuitem_p.h b/src/controls/qquickmenuitem_p.h index 02e7f5e3..2751c25b 100644 --- a/src/controls/qquickmenuitem_p.h +++ b/src/controls/qquickmenuitem_p.h @@ -178,7 +178,7 @@ class QQuickMenuItem : public QQuickMenuText Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged) Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY toggled) Q_PROPERTY(QQuickExclusiveGroup *exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup NOTIFY exclusiveGroupChanged) - Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged) + Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged) Q_PROPERTY(QQuickAction *action READ boundAction WRITE setBoundAction NOTIFY actionChanged) public Q_SLOTS: @@ -208,8 +208,8 @@ public: QQuickAction *boundAction() { return m_boundAction; } void setBoundAction(QQuickAction *a); - QString shortcut() const; - void setShortcut(const QString &shortcut); + QVariant shortcut() const; + void setShortcut(const QVariant &shortcut); bool checkable() const; void setCheckable(bool checkable); |