Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qshortcutmap.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||||||||
7 | struct QShortcutEntry | - | ||||||||||||||||||||||||||||||
8 | { | - | ||||||||||||||||||||||||||||||
9 | QShortcutEntry() | - | ||||||||||||||||||||||||||||||
10 | : keyseq(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0), contextMatcher(0) | - | ||||||||||||||||||||||||||||||
11 | {} never executed: end of block | 0 | ||||||||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||||||||
13 | QShortcutEntry(const QKeySequence &k) | - | ||||||||||||||||||||||||||||||
14 | : keyseq(k), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0), contextMatcher(0) | - | ||||||||||||||||||||||||||||||
15 | {} never executed: end of block | 0 | ||||||||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||||||||
17 | QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i, bool a, QShortcutMap::ContextMatcher m) | - | ||||||||||||||||||||||||||||||
18 | : keyseq(k), context(c), enabled(true), autorepeat(a), id(i), owner(o), contextMatcher(m) | - | ||||||||||||||||||||||||||||||
19 | {} never executed: end of block | 0 | ||||||||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||||||||
21 | bool correctContext() const { return never executed: contextMatcher(owner, context);return contextMatcher(owner, context); never executed: }return contextMatcher(owner, context); | 0 | ||||||||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||||||||
23 | bool operator<(const QShortcutEntry &f) const | - | ||||||||||||||||||||||||||||||
24 | { return never executed: keyseq < f.keyseq;return keyseq < f.keyseq; never executed: }return keyseq < f.keyseq; | 0 | ||||||||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||||||||
26 | QKeySequence keyseq; | - | ||||||||||||||||||||||||||||||
27 | Qt::ShortcutContext context; | - | ||||||||||||||||||||||||||||||
28 | bool enabled : 1; | - | ||||||||||||||||||||||||||||||
29 | bool autorepeat : 1; | - | ||||||||||||||||||||||||||||||
30 | signed int id; | - | ||||||||||||||||||||||||||||||
31 | QObject *owner; | - | ||||||||||||||||||||||||||||||
32 | QShortcutMap::ContextMatcher contextMatcher; | - | ||||||||||||||||||||||||||||||
33 | }; | - | ||||||||||||||||||||||||||||||
34 | template<> class QTypeInfo<QShortcutEntry > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QShortcutEntry)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QShortcutEntry >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QShortcutEntry) }; static inline const char *name() { return "QShortcutEntry"; } }; | - | ||||||||||||||||||||||||||||||
35 | class QShortcutMapPrivate | - | ||||||||||||||||||||||||||||||
36 | { | - | ||||||||||||||||||||||||||||||
37 | inline QShortcutMap* q_func() { return static_cast<QShortcutMap *>(q_ptr); } inline const QShortcutMap* q_func() const { return static_cast<const QShortcutMap *>(q_ptr); } friend class QShortcutMap; | - | ||||||||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||||||||
39 | public: | - | ||||||||||||||||||||||||||||||
40 | QShortcutMapPrivate(QShortcutMap* parent) | - | ||||||||||||||||||||||||||||||
41 | : q_ptr(parent), currentId(0), ambigCount(0), currentState(QKeySequence::NoMatch) | - | ||||||||||||||||||||||||||||||
42 | { | - | ||||||||||||||||||||||||||||||
43 | identicals.reserve(10); | - | ||||||||||||||||||||||||||||||
44 | currentSequences.reserve(10); | - | ||||||||||||||||||||||||||||||
45 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
46 | QShortcutMap *q_ptr; | - | ||||||||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||||||||
48 | QVector<QShortcutEntry> sequences; | - | ||||||||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||||||||
50 | int currentId; | - | ||||||||||||||||||||||||||||||
51 | int ambigCount; | - | ||||||||||||||||||||||||||||||
52 | QKeySequence::SequenceMatch currentState; | - | ||||||||||||||||||||||||||||||
53 | QVector<QKeySequence> currentSequences; | - | ||||||||||||||||||||||||||||||
54 | QVector<QKeySequence> newEntries; | - | ||||||||||||||||||||||||||||||
55 | QKeySequence prevSequence; | - | ||||||||||||||||||||||||||||||
56 | QVector<const QShortcutEntry*> identicals; | - | ||||||||||||||||||||||||||||||
57 | }; | - | ||||||||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||||||||
63 | QShortcutMap::QShortcutMap() | - | ||||||||||||||||||||||||||||||
64 | : d_ptr(new QShortcutMapPrivate(this)) | - | ||||||||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||||||||
66 | resetState(); | - | ||||||||||||||||||||||||||||||
67 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||||||||
72 | QShortcutMap::~QShortcutMap() | - | ||||||||||||||||||||||||||||||
73 | { | - | ||||||||||||||||||||||||||||||
74 | } | - | ||||||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||
80 | int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context, ContextMatcher matcher) | - | ||||||||||||||||||||||||||||||
81 | { | - | ||||||||||||||||||||||||||||||
82 | ((!(owner)) ? qt_assert_x("QShortcutMap::addShortcut", "All shortcuts need an owner",__FILE__,161) : qt_noop()); | - | ||||||||||||||||||||||||||||||
83 | ((!(!key.isEmpty())) ? qt_assert_x("QShortcutMap::addShortcut", "Cannot add keyless shortcuts to map",__FILE__,162) : qt_noop()); | - | ||||||||||||||||||||||||||||||
84 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||||||||
86 | QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher); | - | ||||||||||||||||||||||||||||||
87 | const auto it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry); | - | ||||||||||||||||||||||||||||||
88 | d->sequences.insert(it, newEntry); | - | ||||||||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||||||||
94 | return never executed: d->currentId;return d->currentId; never executed: return d->currentId; | 0 | ||||||||||||||||||||||||||||||
95 | } | - | ||||||||||||||||||||||||||||||
96 | int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key) | - | ||||||||||||||||||||||||||||||
97 | { | - | ||||||||||||||||||||||||||||||
98 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
99 | int itemsRemoved = 0; | - | ||||||||||||||||||||||||||||||
100 | bool allOwners = (owner == 0); | - | ||||||||||||||||||||||||||||||
101 | bool allKeys = key.isEmpty(); | - | ||||||||||||||||||||||||||||||
102 | bool allIds = id == 0; | - | ||||||||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||||||||
105 | if (allOwners
| 0 | ||||||||||||||||||||||||||||||
106 | itemsRemoved = d->sequences.size(); | - | ||||||||||||||||||||||||||||||
107 | d->sequences.clear(); | - | ||||||||||||||||||||||||||||||
108 | return never executed: itemsRemoved;return itemsRemoved; never executed: return itemsRemoved; | 0 | ||||||||||||||||||||||||||||||
109 | } | - | ||||||||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||||||||
111 | int i = d->sequences.size()-1; | - | ||||||||||||||||||||||||||||||
112 | while (i>=0
| 0 | ||||||||||||||||||||||||||||||
113 | { | - | ||||||||||||||||||||||||||||||
114 | const QShortcutEntry &entry = d->sequences.at(i); | - | ||||||||||||||||||||||||||||||
115 | int entryId = entry.id; | - | ||||||||||||||||||||||||||||||
116 | if ((allOwners
| 0 | ||||||||||||||||||||||||||||||
117 | && (allIds
| 0 | ||||||||||||||||||||||||||||||
118 | && (allKeys
| 0 | ||||||||||||||||||||||||||||||
119 | d->sequences.removeAt(i); | - | ||||||||||||||||||||||||||||||
120 | ++itemsRemoved; | - | ||||||||||||||||||||||||||||||
121 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
122 | if (id == entryId
| 0 | ||||||||||||||||||||||||||||||
123 | return never executed: itemsRemoved;return itemsRemoved; never executed: return itemsRemoved; | 0 | ||||||||||||||||||||||||||||||
124 | --i; | - | ||||||||||||||||||||||||||||||
125 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||
131 | return never executed: itemsRemoved;return itemsRemoved; never executed: return itemsRemoved; | 0 | ||||||||||||||||||||||||||||||
132 | } | - | ||||||||||||||||||||||||||||||
133 | int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key) | - | ||||||||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||||||||
135 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
136 | int itemsChanged = 0; | - | ||||||||||||||||||||||||||||||
137 | bool allOwners = (owner == 0); | - | ||||||||||||||||||||||||||||||
138 | bool allKeys = key.isEmpty(); | - | ||||||||||||||||||||||||||||||
139 | bool allIds = id == 0; | - | ||||||||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||||||||
141 | int i = d->sequences.size()-1; | - | ||||||||||||||||||||||||||||||
142 | while (i>=0
| 0 | ||||||||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||||||||
144 | QShortcutEntry entry = d->sequences.at(i); | - | ||||||||||||||||||||||||||||||
145 | if ((allOwners
| 0 | ||||||||||||||||||||||||||||||
146 | && (allIds
| 0 | ||||||||||||||||||||||||||||||
147 | && (allKeys
| 0 | ||||||||||||||||||||||||||||||
148 | d->sequences[i].enabled = enable; | - | ||||||||||||||||||||||||||||||
149 | ++itemsChanged; | - | ||||||||||||||||||||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
151 | if (id == entry.id
| 0 | ||||||||||||||||||||||||||||||
152 | return never executed: itemsChanged;return itemsChanged; never executed: return itemsChanged; | 0 | ||||||||||||||||||||||||||||||
153 | --i; | - | ||||||||||||||||||||||||||||||
154 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||||||||
160 | return never executed: itemsChanged;return itemsChanged; never executed: return itemsChanged; | 0 | ||||||||||||||||||||||||||||||
161 | } | - | ||||||||||||||||||||||||||||||
162 | int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key) | - | ||||||||||||||||||||||||||||||
163 | { | - | ||||||||||||||||||||||||||||||
164 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
165 | int itemsChanged = 0; | - | ||||||||||||||||||||||||||||||
166 | bool allOwners = (owner == 0); | - | ||||||||||||||||||||||||||||||
167 | bool allKeys = key.isEmpty(); | - | ||||||||||||||||||||||||||||||
168 | bool allIds = id == 0; | - | ||||||||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||||||||
170 | int i = d->sequences.size()-1; | - | ||||||||||||||||||||||||||||||
171 | while (i>=0
| 0 | ||||||||||||||||||||||||||||||
172 | { | - | ||||||||||||||||||||||||||||||
173 | QShortcutEntry entry = d->sequences.at(i); | - | ||||||||||||||||||||||||||||||
174 | if ((allOwners
| 0 | ||||||||||||||||||||||||||||||
175 | && (allIds
| 0 | ||||||||||||||||||||||||||||||
176 | && (allKeys
| 0 | ||||||||||||||||||||||||||||||
177 | d->sequences[i].autorepeat = on; | - | ||||||||||||||||||||||||||||||
178 | ++itemsChanged; | - | ||||||||||||||||||||||||||||||
179 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
180 | if (id == entry.id
| 0 | ||||||||||||||||||||||||||||||
181 | return never executed: itemsChanged;return itemsChanged; never executed: return itemsChanged; | 0 | ||||||||||||||||||||||||||||||
182 | --i; | - | ||||||||||||||||||||||||||||||
183 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||||||||
189 | return never executed: itemsChanged;return itemsChanged; never executed: return itemsChanged; | 0 | ||||||||||||||||||||||||||||||
190 | } | - | ||||||||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||
195 | void QShortcutMap::resetState() | - | ||||||||||||||||||||||||||||||
196 | { | - | ||||||||||||||||||||||||||||||
197 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
198 | d->currentState = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
199 | clearSequence(d->currentSequences); | - | ||||||||||||||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||||||||
205 | QKeySequence::SequenceMatch QShortcutMap::state() | - | ||||||||||||||||||||||||||||||
206 | { | - | ||||||||||||||||||||||||||||||
207 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
208 | return never executed: d->currentState;return d->currentState; never executed: return d->currentState; | 0 | ||||||||||||||||||||||||||||||
209 | } | - | ||||||||||||||||||||||||||||||
210 | bool QShortcutMap::tryShortcut(QKeyEvent *e) | - | ||||||||||||||||||||||||||||||
211 | { | - | ||||||||||||||||||||||||||||||
212 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||||||||
214 | if (e->key() == Qt::Key_unknown
| 0 | ||||||||||||||||||||||||||||||
215 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||||||||
217 | QKeySequence::SequenceMatch previousState = state(); | - | ||||||||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||||||||
219 | switch (nextState(e)) { | - | ||||||||||||||||||||||||||||||
220 | case never executed: QKeySequence::NoMatch:case QKeySequence::NoMatch: never executed: case QKeySequence::NoMatch: | 0 | ||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||||||||
224 | return never executed: previousState == QKeySequence::PartialMatch;return previousState == QKeySequence::PartialMatch; never executed: return previousState == QKeySequence::PartialMatch; | 0 | ||||||||||||||||||||||||||||||
225 | case never executed: QKeySequence::PartialMatch:case QKeySequence::PartialMatch: never executed: case QKeySequence::PartialMatch: | 0 | ||||||||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||||||||
228 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
229 | case never executed: QKeySequence::ExactMatch:case QKeySequence::ExactMatch: never executed: {case QKeySequence::ExactMatch: | 0 | ||||||||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||
232 | const int identicalMatches = d->identicals.count(); | - | ||||||||||||||||||||||||||||||
233 | resetState(); | - | ||||||||||||||||||||||||||||||
234 | dispatchEvent(e); | - | ||||||||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||||||||
237 | return never executed: identicalMatches > 0;return identicalMatches > 0; never executed: return identicalMatches > 0; | 0 | ||||||||||||||||||||||||||||||
238 | } | - | ||||||||||||||||||||||||||||||
239 | } | - | ||||||||||||||||||||||||||||||
240 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,357) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||||||||||||||||||||
241 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
242 | } | - | ||||||||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||||||||
250 | QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e) | - | ||||||||||||||||||||||||||||||
251 | { | - | ||||||||||||||||||||||||||||||
252 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||||||||
254 | if (e->key() >= Qt::Key_Shift
| 0 | ||||||||||||||||||||||||||||||
255 | e->key() <= Qt::Key_Alt
| 0 | ||||||||||||||||||||||||||||||
256 | return never executed: d->currentState;return d->currentState; never executed: return d->currentState; | 0 | ||||||||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||||||||
258 | QKeySequence::SequenceMatch result = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||||||||
261 | d->identicals.clear(); | - | ||||||||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||||||||
263 | result = find(e); | - | ||||||||||||||||||||||||||||||
264 | if (result == QKeySequence::NoMatch
| 0 | ||||||||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||||||||
266 | result = find(e, Qt::KeypadModifier); | - | ||||||||||||||||||||||||||||||
267 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
268 | if (result == QKeySequence::NoMatch
| 0 | ||||||||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||||||||
270 | if (e->key() == Qt::Key_Backtab
| 0 | ||||||||||||||||||||||||||||||
271 | QKeyEvent pe = QKeyEvent(e->type(), Qt::Key_Tab, e->modifiers(), e->text()); | - | ||||||||||||||||||||||||||||||
272 | result = find(&pe); | - | ||||||||||||||||||||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
274 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||||||||
277 | if (result == QKeySequence::NoMatch
| 0 | ||||||||||||||||||||||||||||||
278 | clearSequence(d->currentSequences); never executed: clearSequence(d->currentSequences); | 0 | ||||||||||||||||||||||||||||||
279 | d->currentState = result; | - | ||||||||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||||||||
282 | - | |||||||||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||||||||
284 | return never executed: result;return result; never executed: return result; | 0 | ||||||||||||||||||||||||||||||
285 | } | - | ||||||||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||||||||
287 | - | |||||||||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||||||||
289 | - | |||||||||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||||||||
291 | bool QShortcutMap::hasShortcutForKeySequence(const QKeySequence &seq) const | - | ||||||||||||||||||||||||||||||
292 | { | - | ||||||||||||||||||||||||||||||
293 | const QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
294 | QShortcutEntry entry(seq); | - | ||||||||||||||||||||||||||||||
295 | const auto itEnd = d->sequences.cend(); | - | ||||||||||||||||||||||||||||||
296 | auto it = std::lower_bound(d->sequences.cbegin(), itEnd, entry); | - | ||||||||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||||||||
298 | for (;it != itEnd
| 0 | ||||||||||||||||||||||||||||||
299 | if (matches(entry.keyseq, (*it).keyseq) == QKeySequence::ExactMatch
| 0 | ||||||||||||||||||||||||||||||
300 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
301 | } | - | ||||||||||||||||||||||||||||||
302 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||||||||
305 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
306 | } | - | ||||||||||||||||||||||||||||||
307 | QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifiers) | - | ||||||||||||||||||||||||||||||
308 | { | - | ||||||||||||||||||||||||||||||
309 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
310 | if (!d->sequences.count()
| 0 | ||||||||||||||||||||||||||||||
311 | return never executed: QKeySequence::NoMatch;return QKeySequence::NoMatch; never executed: return QKeySequence::NoMatch; | 0 | ||||||||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||||||||
313 | createNewSequences(e, d->newEntries, ignoredModifiers); | - | ||||||||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||||||||
317 | - | |||||||||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||||||||
319 | if (d->newEntries == d->currentSequences
| 0 | ||||||||||||||||||||||||||||||
320 | ((!(e->key() != Qt::Key_unknown || e->text().length())) ? qt_assert_x("QShortcutMap::find", "New sequence to find identical to previous", | - | ||||||||||||||||||||||||||||||
321 | __FILE__ | - | ||||||||||||||||||||||||||||||
322 | , | - | ||||||||||||||||||||||||||||||
323 | 446 | - | ||||||||||||||||||||||||||||||
324 | ) : qt_noop()) | - | ||||||||||||||||||||||||||||||
325 | ; | - | ||||||||||||||||||||||||||||||
326 | return never executed: QKeySequence::NoMatch;return QKeySequence::NoMatch; never executed: return QKeySequence::NoMatch; | 0 | ||||||||||||||||||||||||||||||
327 | } | - | ||||||||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||||||||
329 | - | |||||||||||||||||||||||||||||||
330 | d->identicals.clear(); | - | ||||||||||||||||||||||||||||||
331 | - | |||||||||||||||||||||||||||||||
332 | bool partialFound = false; | - | ||||||||||||||||||||||||||||||
333 | bool identicalDisabledFound = false; | - | ||||||||||||||||||||||||||||||
334 | QVector<QKeySequence> okEntries; | - | ||||||||||||||||||||||||||||||
335 | int result = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
336 | for (int i = d->newEntries.count()-1; i >= 0
| 0 | ||||||||||||||||||||||||||||||
337 | QShortcutEntry entry(d->newEntries.at(i)); | - | ||||||||||||||||||||||||||||||
338 | const auto itEnd = d->sequences.constEnd(); | - | ||||||||||||||||||||||||||||||
339 | auto it = std::lower_bound(d->sequences.constBegin(), itEnd, entry); | - | ||||||||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||||||||
341 | int oneKSResult = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
342 | int tempRes = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
343 | do { | - | ||||||||||||||||||||||||||||||
344 | if (it == itEnd
| 0 | ||||||||||||||||||||||||||||||
345 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
346 | tempRes = matches(entry.keyseq, (*it).keyseq); | - | ||||||||||||||||||||||||||||||
347 | oneKSResult = qMax(oneKSResult, tempRes); | - | ||||||||||||||||||||||||||||||
348 | if (tempRes != QKeySequence::NoMatch
| 0 | ||||||||||||||||||||||||||||||
349 | if (tempRes == QKeySequence::ExactMatch
| 0 | ||||||||||||||||||||||||||||||
350 | if ((*
| 0 | ||||||||||||||||||||||||||||||
351 | d->identicals.append(&*it); never executed: d->identicals.append(&*it); | 0 | ||||||||||||||||||||||||||||||
352 | else | - | ||||||||||||||||||||||||||||||
353 | identicalDisabledFound = true; never executed: identicalDisabledFound = true; | 0 | ||||||||||||||||||||||||||||||
354 | } else if (tempRes == QKeySequence::PartialMatch
| 0 | ||||||||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||||||||
356 | if (d->identicals.size()
| 0 | ||||||||||||||||||||||||||||||
357 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||||||||
360 | partialFound |= (*it).enabled; | - | ||||||||||||||||||||||||||||||
361 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
362 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
363 | ++it; | - | ||||||||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||||||||
365 | - | |||||||||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||||||||
367 | } never executed: while (tempRes != QKeySequence::NoMatchend of block
| 0 | ||||||||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||||||||
370 | - | |||||||||||||||||||||||||||||||
371 | if (oneKSResult > result
| 0 | ||||||||||||||||||||||||||||||
372 | okEntries.clear(); | - | ||||||||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||||||||
374 | - | |||||||||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||||||||
376 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
377 | if (oneKSResult
| 0 | ||||||||||||||||||||||||||||||
378 | okEntries << d->newEntries.at(i); | - | ||||||||||||||||||||||||||||||
379 | - | |||||||||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||||||||
382 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||||||||
385 | if (d->identicals.size()
| 0 | ||||||||||||||||||||||||||||||
386 | result = QKeySequence::ExactMatch; | - | ||||||||||||||||||||||||||||||
387 | } never executed: else if (partialFoundend of block
| 0 | ||||||||||||||||||||||||||||||
388 | result = QKeySequence::PartialMatch; | - | ||||||||||||||||||||||||||||||
389 | } never executed: else if (identicalDisabledFoundend of block
| 0 | ||||||||||||||||||||||||||||||
390 | result = QKeySequence::ExactMatch; | - | ||||||||||||||||||||||||||||||
391 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||||||||
392 | clearSequence(d->currentSequences); | - | ||||||||||||||||||||||||||||||
393 | result = QKeySequence::NoMatch; | - | ||||||||||||||||||||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
395 | if (result != QKeySequence::NoMatch
| 0 | ||||||||||||||||||||||||||||||
396 | d->currentSequences = okEntries; never executed: d->currentSequences = okEntries; | 0 | ||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||||||||
400 | return never executed: QKeySequence::SequenceMatch(result);return QKeySequence::SequenceMatch(result); never executed: return QKeySequence::SequenceMatch(result); | 0 | ||||||||||||||||||||||||||||||
401 | } | - | ||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||||||||
405 | - | |||||||||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||||||||
408 | void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl) | - | ||||||||||||||||||||||||||||||
409 | { | - | ||||||||||||||||||||||||||||||
410 | ksl.clear(); | - | ||||||||||||||||||||||||||||||
411 | d_func()->newEntries.clear(); | - | ||||||||||||||||||||||||||||||
412 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
413 | - | |||||||||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||||||||
418 | void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl, int ignoredModifiers) | - | ||||||||||||||||||||||||||||||
419 | { | - | ||||||||||||||||||||||||||||||
420 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
421 | QList<int> possibleKeys = QKeyMapper::possibleKeys(e); | - | ||||||||||||||||||||||||||||||
422 | int pkTotal = possibleKeys.count(); | - | ||||||||||||||||||||||||||||||
423 | if (!pkTotal
| 0 | ||||||||||||||||||||||||||||||
424 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||||||||
426 | int ssActual = d->currentSequences.count(); | - | ||||||||||||||||||||||||||||||
427 | int ssTotal = qMax(1, ssActual); | - | ||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||
429 | ksl.resize(pkTotal * ssTotal); | - | ||||||||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||||||||
431 | int index = ssActual
| 0 | ||||||||||||||||||||||||||||||
432 | for (int pkNum = 0; pkNum < pkTotal
| 0 | ||||||||||||||||||||||||||||||
433 | for (int ssNum = 0; ssNum < ssTotal
| 0 | ||||||||||||||||||||||||||||||
434 | int i = (pkNum * ssTotal) + ssNum; | - | ||||||||||||||||||||||||||||||
435 | QKeySequence &curKsl = ksl[i]; | - | ||||||||||||||||||||||||||||||
436 | if (ssActual
| 0 | ||||||||||||||||||||||||||||||
437 | const QKeySequence &curSeq = d->currentSequences.at(ssNum); | - | ||||||||||||||||||||||||||||||
438 | curKsl.setKey(curSeq[0], 0); | - | ||||||||||||||||||||||||||||||
439 | curKsl.setKey(curSeq[1], 1); | - | ||||||||||||||||||||||||||||||
440 | curKsl.setKey(curSeq[2], 2); | - | ||||||||||||||||||||||||||||||
441 | curKsl.setKey(curSeq[3], 3); | - | ||||||||||||||||||||||||||||||
442 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||||||||
443 | curKsl.setKey(0, 0); | - | ||||||||||||||||||||||||||||||
444 | curKsl.setKey(0, 1); | - | ||||||||||||||||||||||||||||||
445 | curKsl.setKey(0, 2); | - | ||||||||||||||||||||||||||||||
446 | curKsl.setKey(0, 3); | - | ||||||||||||||||||||||||||||||
447 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
448 | curKsl.setKey(possibleKeys.at(pkNum) & ~ignoredModifiers, index); | - | ||||||||||||||||||||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
450 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
451 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||||||||
453 | - | |||||||||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||||||||
455 | - | |||||||||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||||||||
458 | QKeySequence::SequenceMatch QShortcutMap::matches(const QKeySequence &seq1, | - | ||||||||||||||||||||||||||||||
459 | const QKeySequence &seq2) const | - | ||||||||||||||||||||||||||||||
460 | { | - | ||||||||||||||||||||||||||||||
461 | uint userN = seq1.count(), | - | ||||||||||||||||||||||||||||||
462 | seqN = seq2.count(); | - | ||||||||||||||||||||||||||||||
463 | - | |||||||||||||||||||||||||||||||
464 | if (userN > seqN
| 0 | ||||||||||||||||||||||||||||||
465 | return never executed: QKeySequence::NoMatch;return QKeySequence::NoMatch; never executed: return QKeySequence::NoMatch; | 0 | ||||||||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||||||||
469 | QKeySequence::SequenceMatch match = (userN == seqN
| 0 | ||||||||||||||||||||||||||||||
470 | ? QKeySequence::ExactMatch | - | ||||||||||||||||||||||||||||||
471 | : QKeySequence::PartialMatch); | - | ||||||||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||||||||
473 | for (uint i = 0; i < userN
| 0 | ||||||||||||||||||||||||||||||
474 | int userKey = seq1[i], | - | ||||||||||||||||||||||||||||||
475 | sequenceKey = seq2[i]; | - | ||||||||||||||||||||||||||||||
476 | if ((
| 0 | ||||||||||||||||||||||||||||||
477 | userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; never executed: userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; | 0 | ||||||||||||||||||||||||||||||
478 | if ((
| 0 | ||||||||||||||||||||||||||||||
479 | sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; never executed: sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; | 0 | ||||||||||||||||||||||||||||||
480 | if (userKey != sequenceKey
| 0 | ||||||||||||||||||||||||||||||
481 | return never executed: QKeySequence::NoMatch;return QKeySequence::NoMatch; never executed: return QKeySequence::NoMatch; | 0 | ||||||||||||||||||||||||||||||
482 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
483 | return never executed: match;return match; never executed: return match; | 0 | ||||||||||||||||||||||||||||||
484 | } | - | ||||||||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||||||||
490 | int QShortcutMap::translateModifiers(Qt::KeyboardModifiers modifiers) | - | ||||||||||||||||||||||||||||||
491 | { | - | ||||||||||||||||||||||||||||||
492 | int result = 0; | - | ||||||||||||||||||||||||||||||
493 | if (modifiers & Qt::ShiftModifier
| 0 | ||||||||||||||||||||||||||||||
494 | result |= Qt::SHIFT; never executed: result |= Qt::SHIFT; | 0 | ||||||||||||||||||||||||||||||
495 | if (modifiers & Qt::ControlModifier
| 0 | ||||||||||||||||||||||||||||||
496 | result |= Qt::CTRL; never executed: result |= Qt::CTRL; | 0 | ||||||||||||||||||||||||||||||
497 | if (modifiers & Qt::MetaModifier
| 0 | ||||||||||||||||||||||||||||||
498 | result |= Qt::META; never executed: result |= Qt::META; | 0 | ||||||||||||||||||||||||||||||
499 | if (modifiers & Qt::AltModifier
| 0 | ||||||||||||||||||||||||||||||
500 | result |= Qt::ALT; never executed: result |= Qt::ALT; | 0 | ||||||||||||||||||||||||||||||
501 | return never executed: result;return result; never executed: return result; | 0 | ||||||||||||||||||||||||||||||
502 | } | - | ||||||||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||||||||
505 | - | |||||||||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||||||||
507 | QVector<const QShortcutEntry*> QShortcutMap::matches() const | - | ||||||||||||||||||||||||||||||
508 | { | - | ||||||||||||||||||||||||||||||
509 | const QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
510 | return never executed: d->identicals;return d->identicals; never executed: return d->identicals; | 0 | ||||||||||||||||||||||||||||||
511 | } | - | ||||||||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||||||||
516 | void QShortcutMap::dispatchEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||||||||
517 | { | - | ||||||||||||||||||||||||||||||
518 | QShortcutMapPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
519 | if (!d->identicals.size()
| 0 | ||||||||||||||||||||||||||||||
520 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
521 | - | |||||||||||||||||||||||||||||||
522 | const QKeySequence &curKey = d->identicals.at(0)->keyseq; | - | ||||||||||||||||||||||||||||||
523 | if (d->prevSequence != curKey
| 0 | ||||||||||||||||||||||||||||||
524 | d->ambigCount = 0; | - | ||||||||||||||||||||||||||||||
525 | d->prevSequence = curKey; | - | ||||||||||||||||||||||||||||||
526 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||||||||
528 | const QShortcutEntry *current = 0, *next = 0; | - | ||||||||||||||||||||||||||||||
529 | int i = 0, enabledShortcuts = 0; | - | ||||||||||||||||||||||||||||||
530 | while(i < d->identicals.size()
| 0 | ||||||||||||||||||||||||||||||
531 | current = d->identicals.at(i); | - | ||||||||||||||||||||||||||||||
532 | if (current->enabled
| 0 | ||||||||||||||||||||||||||||||
533 | ++enabledShortcuts; | - | ||||||||||||||||||||||||||||||
534 | if (enabledShortcuts > d->ambigCount + 1
| 0 | ||||||||||||||||||||||||||||||
535 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
536 | next = current; | - | ||||||||||||||||||||||||||||||
537 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
538 | ++i; | - | ||||||||||||||||||||||||||||||
539 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
540 | d->ambigCount = (d->identicals.size() == i
| 0 | ||||||||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||||||||
542 | - | |||||||||||||||||||||||||||||||
543 | if (!next
| 0 | ||||||||||||||||||||||||||||||
544 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||||||||
546 | - | |||||||||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||||||||
551 | - | |||||||||||||||||||||||||||||||
552 | QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1); | - | ||||||||||||||||||||||||||||||
553 | QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se); | - | ||||||||||||||||||||||||||||||
554 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |