| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKSHORTCUT_P_H |
| 5 | #define QQUICKSHORTCUT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qobject.h> |
| 19 | #include <QtCore/qvector.h> |
| 20 | #include <QtCore/qvariant.h> |
| 21 | #include <QtGui/qkeysequence.h> |
| 22 | #include <QtQml/qqmlparserstatus.h> |
| 23 | #include <QtQml/qqml.h> |
| 24 | #include <QtCore/private/qglobal_p.h> |
| 25 | #include <QtQuick/private/qtquickglobal_p.h> |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QShortcutEvent; |
| 30 | |
| 31 | class Q_QUICK_EXPORT QQuickShortcut : public QObject, public QQmlParserStatus |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | Q_INTERFACES(QQmlParserStatus) |
| 35 | Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged FINAL) |
| 36 | Q_PROPERTY(QVariantList sequences READ sequences WRITE setSequences NOTIFY sequencesChanged FINAL REVISION(2, 9)) |
| 37 | Q_PROPERTY(QString nativeText READ nativeText NOTIFY sequenceChanged FINAL REVISION(2, 6)) |
| 38 | Q_PROPERTY(QString portableText READ portableText NOTIFY sequenceChanged FINAL REVISION(2, 6)) |
| 39 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
| 40 | Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL) |
| 41 | Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext NOTIFY contextChanged FINAL) |
| 42 | QML_NAMED_ELEMENT(Shortcut) |
| 43 | QML_ADDED_IN_VERSION(2, 5) |
| 44 | |
| 45 | public: |
| 46 | explicit QQuickShortcut(QObject *parent = nullptr); |
| 47 | ~QQuickShortcut(); |
| 48 | |
| 49 | QVariant sequence() const; |
| 50 | void setSequence(const QVariant &sequence); |
| 51 | |
| 52 | QVariantList sequences() const; |
| 53 | void setSequences(const QVariantList &sequences); |
| 54 | |
| 55 | QString nativeText() const; |
| 56 | QString portableText() const; |
| 57 | |
| 58 | bool isEnabled() const; |
| 59 | void setEnabled(bool enabled); |
| 60 | |
| 61 | bool autoRepeat() const; |
| 62 | void setAutoRepeat(bool repeat); |
| 63 | |
| 64 | Qt::ShortcutContext context() const; |
| 65 | void setContext(Qt::ShortcutContext context); |
| 66 | |
| 67 | Q_SIGNALS: |
| 68 | void sequenceChanged(); |
| 69 | Q_REVISION(2, 9) void sequencesChanged(); |
| 70 | void enabledChanged(); |
| 71 | void autoRepeatChanged(); |
| 72 | void contextChanged(); |
| 73 | |
| 74 | void activated(); |
| 75 | void activatedAmbiguously(); |
| 76 | |
| 77 | protected: |
| 78 | void classBegin() override; |
| 79 | void componentComplete() override; |
| 80 | bool event(QEvent *event) override; |
| 81 | |
| 82 | struct Shortcut { |
| 83 | Shortcut() : id(0) { } |
| 84 | bool matches(QShortcutEvent *event) const; |
| 85 | int id; |
| 86 | QVariant userValue; |
| 87 | QKeySequence keySequence; |
| 88 | }; |
| 89 | |
| 90 | void setEnabled(Shortcut &shortcut, bool enabled); |
| 91 | void setAutoRepeat(Shortcut &shortcut, bool repeat); |
| 92 | |
| 93 | void grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context); |
| 94 | void ungrabShortcut(Shortcut &shortcut); |
| 95 | |
| 96 | private: |
| 97 | bool m_enabled; |
| 98 | bool m_completed; |
| 99 | bool m_autorepeat; |
| 100 | Qt::ShortcutContext m_context; |
| 101 | Shortcut m_shortcut; |
| 102 | QVector<Shortcut> m_shortcuts; |
| 103 | }; |
| 104 | |
| 105 | QT_END_NAMESPACE |
| 106 | |
| 107 | #endif // QQUICKSHORTCUT_P_H |
| 108 | |