diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-05-30 17:06:58 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-01 18:02:33 +0200 |
commit | ea045d82a3a837f83fec82462feebf2bc262f9d9 (patch) | |
tree | 5236ec962b89f3fdc883fc2fa813bdbe9317ba81 /src | |
parent | 101a5185138f4eb4d1ed0e69065d8e4c30a7fff7 (diff) |
Add bool QQuickKeyEvent::matches(QKeySequence::StandardKey)
Change-Id: Iaa8392c1b113856fa80cd2507f8640050eb9bec2
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickevents.cpp | 20 | ||||
-rw-r--r-- | src/quick/items/qquickevents_p_p.h | 3 | ||||
-rw-r--r-- | src/quick/util/qquickutilmodule.cpp | 6 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 50c5697487..6ee5e6d046 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -147,6 +147,26 @@ Item { \endqml */ +/*! + \qmlmethod bool QtQuick2::KeyEvent::matches(StandardKey key) + \since QtQuick 2.2 + + Returns \c true if the key event matches the given standard \a key; otherwise returns \c false. + + \qml + Item { + focus: true + Keys.onPressed: { + if (event.matches(StandardKey.Undo)) + myModel.undo(); + else if (event.matches(StandardKey.Redo)) + myModel.redo(); + } + } + \endqml + + \sa QKeySequence::StandardKey +*/ /*! \qmltype MouseEvent diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h index 6f1b152ad3..f14e035857 100644 --- a/src/quick/items/qquickevents_p_p.h +++ b/src/quick/items/qquickevents_p_p.h @@ -59,6 +59,7 @@ #include <QtCore/qobject.h> #include <QtGui/qvector2d.h> #include <QtGui/qevent.h> +#include <QtGui/qkeysequence.h> QT_BEGIN_NAMESPACE @@ -89,6 +90,8 @@ public: bool isAccepted() { return event.isAccepted(); } void setAccepted(bool accepted) { event.setAccepted(accepted); } + Q_REVISION(2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const { return event.matches(key); } + private: QKeyEvent event; }; diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index a45ec4ef15..fdf8314145 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -58,6 +58,9 @@ #include <private/qquickanimationcontroller_p.h> #include <QtCore/qcoreapplication.h> #include <QtGui/QInputMethod> +#include <QtGui/QKeySequence> + +Q_DECLARE_METATYPE(QKeySequence::StandardKey) void QQuickUtilModule::defineModule() { @@ -91,4 +94,7 @@ void QQuickUtilModule::defineModule() qmlRegisterType<QQuickStateOperation>(); qmlRegisterCustomType<QQuickPropertyChanges>("QtQuick",2,0,"PropertyChanges", new QQuickPropertyChangesParser); + + qRegisterMetaType<QKeySequence::StandardKey>(); + qmlRegisterUncreatableType<QKeySequence, 2>("QtQuick", 2, 2, "StandardKey", QStringLiteral("Cannot create an instance of StandardKey.")); } |