diff options
author | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2015-08-07 10:52:36 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2015-09-03 08:18:20 +0000 |
commit | 8b09653cb22807f09ec4e6c0ffc7dcf7f11bc1a0 (patch) | |
tree | 0d9e717ce1b2874d7a29da0df002980b0955c481 | |
parent | 149ece7a0cfb4fc90fe4544379ee2772fde881fd (diff) |
Shortcut: add sequenceString property
If you set sequence to a StandardKey, then read back the property,
you will get an int, which is not suitable for display.
Now you can use sequenceString for tooltips, preference dialogs
for setting shortcuts, and such.
[ChangeLog][QtQuick] Added Shortcut.sequenceString property to read
back the key sequence as a displayable string
Change-Id: I63ee46f8a2c2da1b1c803282baa894fb1667fe67
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
-rw-r--r-- | src/quick/util/qquickshortcut.cpp | 14 | ||||
-rw-r--r-- | src/quick/util/qquickshortcut_p.h | 3 | ||||
-rw-r--r-- | src/quick/util/qquickutilmodule.cpp | 2 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/quick/util/qquickshortcut.cpp b/src/quick/util/qquickshortcut.cpp index 36c6933af4..9f32b6c180 100644 --- a/src/quick/util/qquickshortcut.cpp +++ b/src/quick/util/qquickshortcut.cpp @@ -134,6 +134,20 @@ void QQuickShortcut::setSequence(const QVariant &sequence) } /*! + \qmlproperty string QtQuick::Shortcut::sequenceString + \since 5.6 + + This property provides the shortcut's key sequence as a string, + for display purposes (tooltips, for example). + + \sa sequence +*/ +QString QQuickShortcut::sequenceString() const +{ + return m_shortcut.toString(QKeySequence::NativeText); +} + +/*! \qmlproperty bool QtQuick::Shortcut::enabled This property holds whether the shortcut is enabled. diff --git a/src/quick/util/qquickshortcut_p.h b/src/quick/util/qquickshortcut_p.h index e16ac9df20..db02f8afae 100644 --- a/src/quick/util/qquickshortcut_p.h +++ b/src/quick/util/qquickshortcut_p.h @@ -57,6 +57,7 @@ class QQuickShortcut : public QObject, public QQmlParserStatus Q_OBJECT Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged FINAL) + Q_PROPERTY(QString sequenceString READ sequenceString NOTIFY sequenceChanged FINAL REVISION 1) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL) Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext NOTIFY contextChanged FINAL) @@ -68,6 +69,8 @@ public: QVariant sequence() const; void setSequence(const QVariant &sequence); + Q_REVISION(1) QString sequenceString() const; + bool isEnabled() const; void setEnabled(bool enabled); diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index 4f6e49fa7a..0af2343504 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -114,4 +114,6 @@ void QQuickUtilModule::defineModule() qmlRegisterType<QQuickTextMetrics>("QtQuick", 2, 4, "TextMetrics"); qmlRegisterType<QQuickShortcut>("QtQuick", 2, 5, "Shortcut"); + + qmlRegisterType<QQuickShortcut,1>("QtQuick", 2, 6, "Shortcut"); } |