1// Copyright (C) 2016 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 QKEYSEQUENCE_H
5#define QKEYSEQUENCE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qstring.h>
9#include <QtCore/qobjectdefs.h>
10
11QT_REQUIRE_CONFIG(shortcut);
12
13QT_BEGIN_NAMESPACE
14
15class QKeySequence;
16
17/*****************************************************************************
18 QKeySequence stream functions
19 *****************************************************************************/
20#if !defined(QT_NO_DATASTREAM) || defined(Q_QDOC)
21Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
22Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks);
23#endif
24
25#if defined(Q_QDOC)
26void qt_set_sequence_auto_mnemonic(bool b);
27#endif
28
29class QVariant;
30class QKeySequencePrivate;
31
32Q_GUI_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QKeySequence &key, size_t seed = 0) noexcept;
33
34class Q_GUI_EXPORT QKeySequence
35{
36 Q_GADGET
37
38public:
39 enum StandardKey {
40 UnknownKey,
41 HelpContents,
42 WhatsThis,
43 Open,
44 Close,
45 Save,
46 New,
47 Delete,
48 Cut,
49 Copy,
50 Paste,
51 Undo,
52 Redo,
53 Back,
54 Forward,
55 Refresh,
56 ZoomIn,
57 ZoomOut,
58 Print,
59 AddTab,
60 NextChild,
61 PreviousChild,
62 Find,
63 FindNext,
64 FindPrevious,
65 Replace,
66 SelectAll,
67 Bold,
68 Italic,
69 Underline,
70 MoveToNextChar,
71 MoveToPreviousChar,
72 MoveToNextWord,
73 MoveToPreviousWord,
74 MoveToNextLine,
75 MoveToPreviousLine,
76 MoveToNextPage,
77 MoveToPreviousPage,
78 MoveToStartOfLine,
79 MoveToEndOfLine,
80 MoveToStartOfBlock,
81 MoveToEndOfBlock,
82 MoveToStartOfDocument,
83 MoveToEndOfDocument,
84 SelectNextChar,
85 SelectPreviousChar,
86 SelectNextWord,
87 SelectPreviousWord,
88 SelectNextLine,
89 SelectPreviousLine,
90 SelectNextPage,
91 SelectPreviousPage,
92 SelectStartOfLine,
93 SelectEndOfLine,
94 SelectStartOfBlock,
95 SelectEndOfBlock,
96 SelectStartOfDocument,
97 SelectEndOfDocument,
98 DeleteStartOfWord,
99 DeleteEndOfWord,
100 DeleteEndOfLine,
101 InsertParagraphSeparator,
102 InsertLineSeparator,
103 SaveAs,
104 Preferences,
105 Quit,
106 FullScreen,
107 Deselect,
108 DeleteCompleteLine,
109 Backspace,
110 Cancel
111 };
112 Q_ENUM(StandardKey)
113
114 enum SequenceFormat {
115 NativeText,
116 PortableText
117 };
118
119 QKeySequence();
120 QKeySequence(const QString &key, SequenceFormat format = NativeText);
121 QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0);
122 QKeySequence(QKeyCombination k1,
123 QKeyCombination k2 = QKeyCombination::fromCombined(combined: 0),
124 QKeyCombination k3 = QKeyCombination::fromCombined(combined: 0),
125 QKeyCombination k4 = QKeyCombination::fromCombined(combined: 0));
126 QKeySequence(const QKeySequence &ks);
127 QKeySequence(StandardKey key);
128 ~QKeySequence();
129
130 int count() const;
131 bool isEmpty() const;
132
133 enum SequenceMatch {
134 NoMatch,
135 PartialMatch,
136 ExactMatch
137 };
138
139 QString toString(SequenceFormat format = PortableText) const;
140 static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText);
141
142 static QList<QKeySequence> listFromString(const QString &str, SequenceFormat format = PortableText);
143 static QString listToString(const QList<QKeySequence> &list, SequenceFormat format = PortableText);
144
145 SequenceMatch matches(const QKeySequence &seq) const;
146 static QKeySequence mnemonic(const QString &text);
147 static QList<QKeySequence> keyBindings(StandardKey key);
148
149 operator QVariant() const;
150 QKeyCombination operator[](uint i) const;
151 QKeySequence &operator=(const QKeySequence &other);
152 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QKeySequence)
153 void swap(QKeySequence &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); }
154
155 bool operator==(const QKeySequence &other) const;
156 inline bool operator!= (const QKeySequence &other) const
157 { return !(*this == other); }
158 bool operator< (const QKeySequence &ks) const;
159 inline bool operator> (const QKeySequence &other) const
160 { return other < *this; }
161 inline bool operator<= (const QKeySequence &other) const
162 { return !(other < *this); }
163 inline bool operator>= (const QKeySequence &other) const
164 { return !(*this < other); }
165
166 bool isDetached() const;
167private:
168 static int decodeString(const QString &ks);
169 static QString encodeString(int key);
170 int assign(const QString &str);
171 int assign(const QString &str, SequenceFormat format);
172 void setKey(QKeyCombination key, int index);
173
174 QKeySequencePrivate *d;
175
176 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
177 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QKeySequence &ks);
178 friend Q_GUI_EXPORT size_t qHash(const QKeySequence &key, size_t seed) noexcept;
179 friend class QShortcutMap;
180 friend class QShortcut;
181
182public:
183 typedef QKeySequencePrivate * DataPtr;
184 inline DataPtr &data_ptr() { return d; }
185};
186
187Q_DECLARE_SHARED(QKeySequence)
188
189#if !defined(QT_NO_DEBUG_STREAM) || defined(Q_QDOC)
190Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &);
191#endif
192
193QT_END_NAMESPACE
194
195#endif // QKEYSEQUENCE_H
196

source code of qtbase/src/gui/kernel/qkeysequence.h