Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickshortcut_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKSHORTCUT_P_H
6#define QQUICKSHORTCUT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qobject.h>
20#include <QtCore/qvector.h>
21#include <QtCore/qvariant.h>
22#include <QtGui/qkeysequence.h>
23#include <QtQml/qqmlparserstatus.h>
24#include <QtQml/qqml.h>
25#include <QtCore/private/qglobal_p.h>
26#include <QtQuick/private/qtquickglobal_p.h>
27
28QT_BEGIN_NAMESPACE
29
30class QShortcutEvent;
31
32class Q_QUICK_EXPORT QQuickShortcut : public QObject, public QQmlParserStatus
33{
34 Q_OBJECT
35 Q_INTERFACES(QQmlParserStatus)
36 Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged FINAL)
37 Q_PROPERTY(QVariantList sequences READ sequences WRITE setSequences NOTIFY sequencesChanged FINAL REVISION(2, 9))
38 Q_PROPERTY(QString nativeText READ nativeText NOTIFY nativeTextChanged FINAL REVISION(2, 6))
39 Q_PROPERTY(QString portableText READ portableText NOTIFY portableTextChanged FINAL REVISION(2, 6))
40 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
41 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL)
42 Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext NOTIFY contextChanged FINAL)
43 QML_NAMED_ELEMENT(Shortcut)
44 QML_ADDED_IN_VERSION(2, 5)
45
46public:
47 explicit QQuickShortcut(QObject *parent = nullptr);
48 ~QQuickShortcut();
49
50 QVariant sequence() const;
51 void setSequence(const QVariant &sequence);
52
53 QVariantList sequences() const;
54 void setSequences(const QVariantList &sequences);
55
56 QString nativeText() const;
57 QString portableText() const;
58
59 bool isEnabled() const;
60 void setEnabled(bool enabled);
61
62 bool autoRepeat() const;
63 void setAutoRepeat(bool repeat);
64
65 Qt::ShortcutContext context() const;
66 void setContext(Qt::ShortcutContext context);
67
68Q_SIGNALS:
69 void sequenceChanged();
70 Q_REVISION(2, 9) void sequencesChanged();
71 Q_REVISION(6, 10) void nativeTextChanged();
72 Q_REVISION(6, 10) void portableTextChanged();
73 void enabledChanged();
74 void autoRepeatChanged();
75 void contextChanged();
76
77 void activated();
78 void activatedAmbiguously();
79
80protected:
81 void classBegin() override;
82 void componentComplete() override;
83 bool event(QEvent *event) override;
84
85 struct Shortcut {
86 Shortcut() : id(0) { }
87 bool matches(QShortcutEvent *event) const;
88 int id;
89 QVariant userValue;
90 QKeySequence keySequence;
91 };
92
93 void setEnabled(Shortcut &shortcut, bool enabled);
94 void setAutoRepeat(Shortcut &shortcut, bool repeat);
95
96 void grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context);
97 void ungrabShortcut(Shortcut &shortcut);
98
99private:
100 bool m_enabled;
101 bool m_completed;
102 bool m_autorepeat;
103 Qt::ShortcutContext m_context;
104 Shortcut m_shortcut;
105 QVector<Shortcut> m_shortcuts;
106};
107
108QT_END_NAMESPACE
109
110#endif // QQUICKSHORTCUT_P_H
static QKeySequence valueToKeySequence(const QVariant &value, const QQuickShortcut *const shortcut)
static QT_BEGIN_NAMESPACE bool qQuickShortcutContextMatcher(QObject *obj, Qt::ShortcutContext context)
\qmltype Shortcut \nativetype QQuickShortcut \inqmlmodule QtQuick
bool(* ContextMatcher)(QObject *, Qt::ShortcutContext)
static QList< QKeySequence > valueToKeySequences(const QVariant &value)
Q_QUICK_EXPORT void qt_quick_set_shortcut_context_matcher(ContextMatcher matcher)