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
27QT_BEGIN_NAMESPACE
28
29class QShortcutEvent;
30
31class 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 nativeTextChanged FINAL REVISION(2, 6))
38 Q_PROPERTY(QString portableText READ portableText NOTIFY portableTextChanged 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
45public:
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
67Q_SIGNALS:
68 void sequenceChanged();
69 Q_REVISION(2, 9) void sequencesChanged();
70 Q_REVISION(6, 10) void nativeTextChanged();
71 Q_REVISION(6, 10) void portableTextChanged();
72 void enabledChanged();
73 void autoRepeatChanged();
74 void contextChanged();
75
76 void activated();
77 void activatedAmbiguously();
78
79protected:
80 void classBegin() override;
81 void componentComplete() override;
82 bool event(QEvent *event) override;
83
84 struct Shortcut {
85 Shortcut() : id(0) { }
86 bool matches(QShortcutEvent *event) const;
87 int id;
88 QVariant userValue;
89 QKeySequence keySequence;
90 };
91
92 void setEnabled(Shortcut &shortcut, bool enabled);
93 void setAutoRepeat(Shortcut &shortcut, bool repeat);
94
95 void grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context);
96 void ungrabShortcut(Shortcut &shortcut);
97
98private:
99 bool m_enabled;
100 bool m_completed;
101 bool m_autorepeat;
102 Qt::ShortcutContext m_context;
103 Shortcut m_shortcut;
104 QVector<Shortcut> m_shortcuts;
105};
106
107QT_END_NAMESPACE
108
109#endif // QQUICKSHORTCUT_P_H
110

source code of qtdeclarative/src/quick/util/qquickshortcut_p.h