1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QKEYSEQUENCE_H |
41 | #define QKEYSEQUENCE_H |
42 | |
43 | #include <QtGui/qtguiglobal.h> |
44 | #include <QtCore/qstring.h> |
45 | #include <QtCore/qobjectdefs.h> |
46 | |
47 | QT_REQUIRE_CONFIG(shortcut); |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QKeySequence; |
52 | |
53 | /***************************************************************************** |
54 | QKeySequence stream functions |
55 | *****************************************************************************/ |
56 | #if !defined(QT_NO_DATASTREAM) || defined(Q_CLANG_QDOC) |
57 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks); |
58 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks); |
59 | #endif |
60 | |
61 | #if defined(Q_CLANG_QDOC) |
62 | void qt_set_sequence_auto_mnemonic(bool b); |
63 | #endif |
64 | |
65 | class QVariant; |
66 | class QKeySequencePrivate; |
67 | |
68 | Q_GUI_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QKeySequence &key, size_t seed = 0) noexcept; |
69 | |
70 | class Q_GUI_EXPORT QKeySequence |
71 | { |
72 | Q_GADGET |
73 | |
74 | public: |
75 | enum StandardKey { |
76 | UnknownKey, |
77 | HelpContents, |
78 | WhatsThis, |
79 | Open, |
80 | Close, |
81 | Save, |
82 | New, |
83 | Delete, |
84 | Cut, |
85 | Copy, |
86 | Paste, |
87 | Undo, |
88 | Redo, |
89 | Back, |
90 | Forward, |
91 | Refresh, |
92 | ZoomIn, |
93 | ZoomOut, |
94 | Print, |
95 | AddTab, |
96 | NextChild, |
97 | PreviousChild, |
98 | Find, |
99 | FindNext, |
100 | FindPrevious, |
101 | Replace, |
102 | SelectAll, |
103 | Bold, |
104 | Italic, |
105 | Underline, |
106 | MoveToNextChar, |
107 | MoveToPreviousChar, |
108 | MoveToNextWord, |
109 | MoveToPreviousWord, |
110 | MoveToNextLine, |
111 | MoveToPreviousLine, |
112 | MoveToNextPage, |
113 | MoveToPreviousPage, |
114 | MoveToStartOfLine, |
115 | MoveToEndOfLine, |
116 | MoveToStartOfBlock, |
117 | MoveToEndOfBlock, |
118 | MoveToStartOfDocument, |
119 | MoveToEndOfDocument, |
120 | SelectNextChar, |
121 | SelectPreviousChar, |
122 | SelectNextWord, |
123 | SelectPreviousWord, |
124 | SelectNextLine, |
125 | SelectPreviousLine, |
126 | SelectNextPage, |
127 | SelectPreviousPage, |
128 | SelectStartOfLine, |
129 | SelectEndOfLine, |
130 | SelectStartOfBlock, |
131 | SelectEndOfBlock, |
132 | SelectStartOfDocument, |
133 | SelectEndOfDocument, |
134 | DeleteStartOfWord, |
135 | DeleteEndOfWord, |
136 | DeleteEndOfLine, |
137 | InsertParagraphSeparator, |
138 | InsertLineSeparator, |
139 | SaveAs, |
140 | Preferences, |
141 | Quit, |
142 | FullScreen, |
143 | Deselect, |
144 | DeleteCompleteLine, |
145 | Backspace, |
146 | Cancel |
147 | }; |
148 | Q_ENUM(StandardKey) |
149 | |
150 | enum SequenceFormat { |
151 | NativeText, |
152 | PortableText |
153 | }; |
154 | |
155 | QKeySequence(); |
156 | QKeySequence(const QString &key, SequenceFormat format = NativeText); |
157 | QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0); |
158 | QKeySequence(QKeyCombination k1, |
159 | QKeyCombination k2 = QKeyCombination::fromCombined(0), |
160 | QKeyCombination k3 = QKeyCombination::fromCombined(0), |
161 | QKeyCombination k4 = QKeyCombination::fromCombined(0)); |
162 | QKeySequence(const QKeySequence &ks); |
163 | QKeySequence(StandardKey key); |
164 | ~QKeySequence(); |
165 | |
166 | int count() const; |
167 | bool isEmpty() const; |
168 | |
169 | enum SequenceMatch { |
170 | NoMatch, |
171 | PartialMatch, |
172 | ExactMatch |
173 | }; |
174 | |
175 | QString toString(SequenceFormat format = PortableText) const; |
176 | static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText); |
177 | |
178 | static QList<QKeySequence> listFromString(const QString &str, SequenceFormat format = PortableText); |
179 | static QString listToString(const QList<QKeySequence> &list, SequenceFormat format = PortableText); |
180 | |
181 | SequenceMatch matches(const QKeySequence &seq) const; |
182 | static QKeySequence mnemonic(const QString &text); |
183 | static QList<QKeySequence> keyBindings(StandardKey key); |
184 | |
185 | operator QVariant() const; |
186 | QKeyCombination operator[](uint i) const; |
187 | QKeySequence &operator=(const QKeySequence &other); |
188 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QKeySequence) |
189 | void swap(QKeySequence &other) noexcept { qSwap(d, other.d); } |
190 | |
191 | bool operator==(const QKeySequence &other) const; |
192 | inline bool operator!= (const QKeySequence &other) const |
193 | { return !(*this == other); } |
194 | bool operator< (const QKeySequence &ks) const; |
195 | inline bool operator> (const QKeySequence &other) const |
196 | { return other < *this; } |
197 | inline bool operator<= (const QKeySequence &other) const |
198 | { return !(other < *this); } |
199 | inline bool operator>= (const QKeySequence &other) const |
200 | { return !(*this < other); } |
201 | |
202 | bool isDetached() const; |
203 | private: |
204 | static int decodeString(const QString &ks); |
205 | static QString encodeString(int key); |
206 | int assign(const QString &str); |
207 | int assign(const QString &str, SequenceFormat format); |
208 | void setKey(QKeyCombination key, int index); |
209 | |
210 | QKeySequencePrivate *d; |
211 | |
212 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks); |
213 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QKeySequence &ks); |
214 | friend Q_GUI_EXPORT size_t qHash(const QKeySequence &key, size_t seed) noexcept; |
215 | friend class QShortcutMap; |
216 | friend class QShortcut; |
217 | |
218 | public: |
219 | typedef QKeySequencePrivate * DataPtr; |
220 | inline DataPtr &data_ptr() { return d; } |
221 | }; |
222 | |
223 | Q_DECLARE_SHARED(QKeySequence) |
224 | |
225 | #if !defined(QT_NO_DEBUG_STREAM) || defined(Q_CLANG_QDOC) |
226 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &); |
227 | #endif |
228 | |
229 | QT_END_NAMESPACE |
230 | |
231 | #endif // QKEYSEQUENCE_H |
232 | |