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
47QT_BEGIN_NAMESPACE
48
49
50#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC)
51
52class QKeySequence;
53
54/*****************************************************************************
55 QKeySequence stream functions
56 *****************************************************************************/
57#if !defined(QT_NO_DATASTREAM) || defined(Q_CLANG_QDOC)
58Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
59Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks);
60#endif
61
62#if defined(Q_CLANG_QDOC)
63void qt_set_sequence_auto_mnemonic(bool b);
64#endif
65
66class QVariant;
67class QKeySequencePrivate;
68
69Q_GUI_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QKeySequence &key, uint seed = 0) noexcept;
70
71class Q_GUI_EXPORT QKeySequence
72{
73 Q_GADGET
74
75public:
76 enum StandardKey {
77 UnknownKey,
78 HelpContents,
79 WhatsThis,
80 Open,
81 Close,
82 Save,
83 New,
84 Delete,
85 Cut,
86 Copy,
87 Paste,
88 Undo,
89 Redo,
90 Back,
91 Forward,
92 Refresh,
93 ZoomIn,
94 ZoomOut,
95 Print,
96 AddTab,
97 NextChild,
98 PreviousChild,
99 Find,
100 FindNext,
101 FindPrevious,
102 Replace,
103 SelectAll,
104 Bold,
105 Italic,
106 Underline,
107 MoveToNextChar,
108 MoveToPreviousChar,
109 MoveToNextWord,
110 MoveToPreviousWord,
111 MoveToNextLine,
112 MoveToPreviousLine,
113 MoveToNextPage,
114 MoveToPreviousPage,
115 MoveToStartOfLine,
116 MoveToEndOfLine,
117 MoveToStartOfBlock,
118 MoveToEndOfBlock,
119 MoveToStartOfDocument,
120 MoveToEndOfDocument,
121 SelectNextChar,
122 SelectPreviousChar,
123 SelectNextWord,
124 SelectPreviousWord,
125 SelectNextLine,
126 SelectPreviousLine,
127 SelectNextPage,
128 SelectPreviousPage,
129 SelectStartOfLine,
130 SelectEndOfLine,
131 SelectStartOfBlock,
132 SelectEndOfBlock,
133 SelectStartOfDocument,
134 SelectEndOfDocument,
135 DeleteStartOfWord,
136 DeleteEndOfWord,
137 DeleteEndOfLine,
138 InsertParagraphSeparator,
139 InsertLineSeparator,
140 SaveAs,
141 Preferences,
142 Quit,
143 FullScreen,
144 Deselect,
145 DeleteCompleteLine,
146 Backspace,
147 Cancel
148 };
149 Q_ENUM(StandardKey)
150
151 enum SequenceFormat {
152 NativeText,
153 PortableText
154 };
155
156 QKeySequence();
157 QKeySequence(const QString &key, SequenceFormat format = NativeText);
158 QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0);
159 QKeySequence(const QKeySequence &ks);
160 QKeySequence(StandardKey key);
161 ~QKeySequence();
162
163 int count() const;
164 bool isEmpty() const;
165
166 enum SequenceMatch {
167 NoMatch,
168 PartialMatch,
169 ExactMatch
170 };
171
172 QString toString(SequenceFormat format = PortableText) const;
173 static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText);
174
175 static QList<QKeySequence> listFromString(const QString &str, SequenceFormat format = PortableText);
176 static QString listToString(const QList<QKeySequence> &list, SequenceFormat format = PortableText);
177
178 SequenceMatch matches(const QKeySequence &seq) const;
179 static QKeySequence mnemonic(const QString &text);
180 static QList<QKeySequence> keyBindings(StandardKey key);
181
182#if QT_DEPRECATED_SINCE(5, 0)
183 QT_DEPRECATED operator QString() const { return toString(QKeySequence::NativeText); }
184 QT_DEPRECATED operator int() const { if (1 <= count()) return operator [](0); return 0; }
185#endif
186 operator QVariant() const;
187 int operator[](uint i) const;
188 QKeySequence &operator=(const QKeySequence &other);
189 QKeySequence &operator=(QKeySequence &&other) noexcept { swap(other); return *this; }
190 void swap(QKeySequence &other) noexcept { qSwap(value1&: d, value2&: other.d); }
191
192 bool operator==(const QKeySequence &other) const;
193 inline bool operator!= (const QKeySequence &other) const
194 { return !(*this == other); }
195 bool operator< (const QKeySequence &ks) const;
196 inline bool operator> (const QKeySequence &other) const
197 { return other < *this; }
198 inline bool operator<= (const QKeySequence &other) const
199 { return !(other < *this); }
200 inline bool operator>= (const QKeySequence &other) const
201 { return !(*this < other); }
202
203 bool isDetached() const;
204private:
205 static int decodeString(const QString &ks);
206 static QString encodeString(int key);
207 int assign(const QString &str);
208 int assign(const QString &str, SequenceFormat format);
209 void setKey(int key, int index);
210
211 QKeySequencePrivate *d;
212
213 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
214 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QKeySequence &ks);
215 friend Q_GUI_EXPORT uint qHash(const QKeySequence &key, uint seed) noexcept;
216 friend class QShortcutMap;
217 friend class QShortcut;
218
219public:
220 typedef QKeySequencePrivate * DataPtr;
221 inline DataPtr &data_ptr() { return d; }
222};
223
224Q_DECLARE_SHARED(QKeySequence)
225
226#if !defined(QT_NO_DEBUG_STREAM) || defined(Q_CLANG_QDOC)
227Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &);
228#endif
229
230#else
231
232class Q_GUI_EXPORT QKeySequence
233{
234public:
235 QKeySequence() {}
236 QKeySequence(int) {}
237};
238
239#endif // QT_NO_SHORTCUT
240
241QT_END_NAMESPACE
242
243#endif // QKEYSEQUENCE_H
244

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