1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QKEYSEQUENCE_H |
43 | #define QKEYSEQUENCE_H |
44 | |
45 | #include <QtCore/qnamespace.h> |
46 | #include <QtCore/qstring.h> |
47 | |
48 | QT_BEGIN_HEADER |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | QT_MODULE(Gui) |
53 | |
54 | #ifndef QT_NO_SHORTCUT |
55 | |
56 | /***************************************************************************** |
57 | QKeySequence stream functions |
58 | *****************************************************************************/ |
59 | #ifndef QT_NO_DATASTREAM |
60 | class QKeySequence; |
61 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks); |
62 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks); |
63 | #endif |
64 | |
65 | #ifdef qdoc |
66 | void qt_set_sequence_auto_mnemonic(bool b); |
67 | #endif |
68 | |
69 | class QVariant; |
70 | class QKeySequencePrivate; |
71 | |
72 | class Q_GUI_EXPORT QKeySequence |
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 | }; |
143 | |
144 | enum SequenceFormat { |
145 | NativeText, |
146 | PortableText |
147 | }; |
148 | |
149 | QKeySequence(); |
150 | QKeySequence(const QString &key); |
151 | QKeySequence(const QString &key, SequenceFormat format); |
152 | QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0); |
153 | QKeySequence(const QKeySequence &ks); |
154 | QKeySequence(StandardKey key); |
155 | ~QKeySequence(); |
156 | |
157 | uint count() const; // ### Qt 5: return 'int' |
158 | bool isEmpty() const; |
159 | |
160 | enum SequenceMatch { |
161 | NoMatch, |
162 | PartialMatch, |
163 | ExactMatch |
164 | #ifdef QT3_SUPPORT |
165 | , Identical = ExactMatch |
166 | #endif |
167 | }; |
168 | |
169 | QString toString(SequenceFormat format = PortableText) const; |
170 | static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText); |
171 | |
172 | SequenceMatch matches(const QKeySequence &seq) const; |
173 | static QKeySequence mnemonic(const QString &text); |
174 | static QList<QKeySequence> keyBindings(StandardKey key); |
175 | |
176 | // ### Qt 5: kill 'operator QString' - it's evil |
177 | operator QString() const; |
178 | operator QVariant() const; |
179 | operator int() const; |
180 | int operator[](uint i) const; |
181 | QKeySequence &operator=(const QKeySequence &other); |
182 | #ifdef Q_COMPILER_RVALUE_REFS |
183 | inline QKeySequence &operator=(QKeySequence &&other) |
184 | { qSwap(d, other.d); return *this; } |
185 | #endif |
186 | inline void swap(QKeySequence &other) { qSwap(d, other.d); } |
187 | bool operator==(const QKeySequence &other) const; |
188 | inline bool operator!= (const QKeySequence &other) const |
189 | { return !(*this == other); } |
190 | bool operator< (const QKeySequence &ks) const; |
191 | inline bool operator> (const QKeySequence &other) const |
192 | { return other < *this; } |
193 | inline bool operator<= (const QKeySequence &other) const |
194 | { return !(other < *this); } |
195 | inline bool operator>= (const QKeySequence &other) const |
196 | { return !(*this < other); } |
197 | |
198 | bool isDetached() const; |
199 | private: |
200 | static int decodeString(const QString &ks); |
201 | static QString encodeString(int key); |
202 | int assign(const QString &str); |
203 | int assign(const QString &str, SequenceFormat format); |
204 | void setKey(int key, int index); |
205 | |
206 | QKeySequencePrivate *d; |
207 | |
208 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks); |
209 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QKeySequence &ks); |
210 | friend class Q3AccelManager; |
211 | friend class QShortcutMap; |
212 | friend class QShortcut; |
213 | |
214 | public: |
215 | typedef QKeySequencePrivate * DataPtr; |
216 | inline DataPtr &data_ptr() { return d; } |
217 | }; |
218 | Q_DECLARE_TYPEINFO(QKeySequence, Q_MOVABLE_TYPE); |
219 | Q_DECLARE_SHARED(QKeySequence) |
220 | |
221 | #ifndef QT_NO_DEBUG_STREAM |
222 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &); |
223 | #endif |
224 | |
225 | #else |
226 | |
227 | class Q_GUI_EXPORT QKeySequence |
228 | { |
229 | public: |
230 | QKeySequence() {} |
231 | QKeySequence(int) {} |
232 | }; |
233 | |
234 | #endif // QT_NO_SHORTCUT |
235 | |
236 | QT_END_NAMESPACE |
237 | |
238 | QT_END_HEADER |
239 | |
240 | #endif // QKEYSEQUENCE_H |
241 | |