| 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 | |
| 11 | QT_REQUIRE_CONFIG(shortcut); |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | class QKeySequence; |
| 16 | |
| 17 | /***************************************************************************** |
| 18 | QKeySequence stream functions |
| 19 | *****************************************************************************/ |
| 20 | #if !defined(QT_NO_DATASTREAM) || defined(Q_QDOC) |
| 21 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks); |
| 22 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks); |
| 23 | #endif |
| 24 | |
| 25 | #if defined(Q_QDOC) |
| 26 | void qt_set_sequence_auto_mnemonic(bool b); |
| 27 | #endif |
| 28 | |
| 29 | class QVariant; |
| 30 | class QKeySequencePrivate; |
| 31 | |
| 32 | Q_GUI_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QKeySequence &key, size_t seed = 0) noexcept; |
| 33 | |
| 34 | class Q_GUI_EXPORT QKeySequence |
| 35 | { |
| 36 | Q_GADGET |
| 37 | |
| 38 | public: |
| 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 | Q_ENUM(SequenceFormat) |
| 119 | |
| 120 | QKeySequence(); |
| 121 | QKeySequence(const QString &key, SequenceFormat format = NativeText); |
| 122 | QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0); |
| 123 | QKeySequence(QKeyCombination k1, |
| 124 | QKeyCombination k2 = QKeyCombination::fromCombined(combined: 0), |
| 125 | QKeyCombination k3 = QKeyCombination::fromCombined(combined: 0), |
| 126 | QKeyCombination k4 = QKeyCombination::fromCombined(combined: 0)); |
| 127 | QKeySequence(const QKeySequence &ks); |
| 128 | QKeySequence(StandardKey key); |
| 129 | ~QKeySequence(); |
| 130 | |
| 131 | int count() const; |
| 132 | bool isEmpty() const; |
| 133 | |
| 134 | enum SequenceMatch { |
| 135 | NoMatch, |
| 136 | PartialMatch, |
| 137 | ExactMatch |
| 138 | }; |
| 139 | Q_ENUM(SequenceMatch) |
| 140 | |
| 141 | QString toString(SequenceFormat format = PortableText) const; |
| 142 | static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText); |
| 143 | |
| 144 | static QList<QKeySequence> listFromString(const QString &str, SequenceFormat format = PortableText); |
| 145 | static QString listToString(const QList<QKeySequence> &list, SequenceFormat format = PortableText); |
| 146 | |
| 147 | SequenceMatch matches(const QKeySequence &seq) const; |
| 148 | static QKeySequence mnemonic(const QString &text); |
| 149 | static QList<QKeySequence> keyBindings(StandardKey key); |
| 150 | |
| 151 | operator QVariant() const; |
| 152 | QKeyCombination operator[](uint i) const; |
| 153 | QKeySequence &operator=(const QKeySequence &other); |
| 154 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QKeySequence) |
| 155 | void swap(QKeySequence &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
| 156 | |
| 157 | bool operator==(const QKeySequence &other) const; |
| 158 | inline bool operator!= (const QKeySequence &other) const |
| 159 | { return !(*this == other); } |
| 160 | bool operator< (const QKeySequence &ks) const; |
| 161 | inline bool operator> (const QKeySequence &other) const |
| 162 | { return other < *this; } |
| 163 | inline bool operator<= (const QKeySequence &other) const |
| 164 | { return !(other < *this); } |
| 165 | inline bool operator>= (const QKeySequence &other) const |
| 166 | { return !(*this < other); } |
| 167 | |
| 168 | bool isDetached() const; |
| 169 | private: |
| 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 | |
| 182 | public: |
| 183 | typedef QKeySequencePrivate * DataPtr; |
| 184 | inline DataPtr &data_ptr() { return d; } |
| 185 | }; |
| 186 | |
| 187 | Q_DECLARE_SHARED(QKeySequence) |
| 188 | |
| 189 | #if !defined(QT_NO_DEBUG_STREAM) || defined(Q_QDOC) |
| 190 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &); |
| 191 | #endif |
| 192 | |
| 193 | QT_END_NAMESPACE |
| 194 | |
| 195 | #endif // QKEYSEQUENCE_H |
| 196 | |