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) Q_DECL_NOTHROW;
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#ifdef Q_COMPILER_RVALUE_REFS
190 QKeySequence &operator=(QKeySequence &&other) Q_DECL_NOTHROW { swap(other); return *this; }
191#endif
192 void swap(QKeySequence &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
193
194 bool operator==(const QKeySequence &other) const;
195 inline bool operator!= (const QKeySequence &other) const
196 { return !(*this == other); }
197 bool operator< (const QKeySequence &ks) const;
198 inline bool operator> (const QKeySequence &other) const
199 { return other < *this; }
200 inline bool operator<= (const QKeySequence &other) const
201 { return !(other < *this); }
202 inline bool operator>= (const QKeySequence &other) const
203 { return !(*this < other); }
204
205 bool isDetached() const;
206private:
207 static int decodeString(const QString &ks);
208 static QString encodeString(int key);
209 int assign(const QString &str);
210 int assign(const QString &str, SequenceFormat format);
211 void setKey(int key, int index);
212
213 QKeySequencePrivate *d;
214
215 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
216 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QKeySequence &ks);
217 friend Q_GUI_EXPORT uint qHash(const QKeySequence &key, uint seed) Q_DECL_NOTHROW;
218 friend class QShortcutMap;
219 friend class QShortcut;
220
221public:
222 typedef QKeySequencePrivate * DataPtr;
223 inline DataPtr &data_ptr() { return d; }
224};
225
226Q_DECLARE_SHARED(QKeySequence)
227
228#if !defined(QT_NO_DEBUG_STREAM) || defined(Q_CLANG_QDOC)
229Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &);
230#endif
231
232#else
233
234class Q_GUI_EXPORT QKeySequence
235{
236public:
237 QKeySequence() {}
238 QKeySequence(int) {}
239};
240
241#endif // QT_NO_SHORTCUT
242
243QT_END_NAMESPACE
244
245#endif // QKEYSEQUENCE_H
246