Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qwidgetlinecontrol_p.h" | - |
41 | | - |
42 | #ifndef QT_NO_LINEEDIT | - |
43 | | - |
44 | #include "qabstractitemview.h" | - |
45 | #include "qclipboard.h" | - |
46 | #include <private/qguiapplication_p.h> | - |
47 | #include <qpa/qplatformtheme.h> | - |
48 | #include <qstylehints.h> | - |
49 | #ifndef QT_NO_ACCESSIBILITY | - |
50 | #include "qaccessible.h" | - |
51 | #endif | - |
52 | | - |
53 | #include "qapplication.h" | - |
54 | #ifndef QT_NO_GRAPHICSVIEW | - |
55 | #include "qgraphicssceneevent.h" | - |
56 | #endif | - |
57 | | - |
58 | QT_BEGIN_NAMESPACE | - |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - |
66 | | - |
67 | int QWidgetLineControl::redoTextLayout() const | - |
68 | { | - |
69 | m_textLayout.clearLayout(); | - |
70 | | - |
71 | m_textLayout.beginLayout(); | - |
72 | QTextLine l = m_textLayout.createLine(); | - |
73 | m_textLayout.endLayout(); | - |
74 | | - |
75 | #if defined(Q_DEAD_CODE_FROM_QT4_MAC) | - |
76 | if (m_threadChecks) | - |
77 | m_textLayoutThread = QThread::currentThread(); | - |
78 | #endif | - |
79 | | - |
80 | return qRound(l.ascent()); | - |
81 | } | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | void QWidgetLineControl::updateDisplayText(bool forceUpdate) | - |
90 | { | - |
91 | QString orig = m_textLayout.text(); | - |
92 | QString str; | - |
93 | if (m_echoMode == QLineEdit::NoEcho) | - |
94 | str = QString::fromLatin1(""); | - |
95 | else | - |
96 | str = m_text; | - |
97 | | - |
98 | if (m_echoMode == QLineEdit::Password) { | - |
99 | str.fill(m_passwordCharacter); | - |
100 | if (m_passwordEchoTimer != 0 && m_cursor > 0 && m_cursor <= m_text.length()) { | - |
101 | int cursor = m_cursor - 1; | - |
102 | QChar uc = m_text.at(cursor); | - |
103 | str[cursor] = uc; | - |
104 | if (cursor > 0 && uc.isLowSurrogate()) { | - |
105 | | - |
106 | | - |
107 | uc = m_text.at(cursor - 1); | - |
108 | if (uc.isHighSurrogate()) | - |
109 | str[cursor - 1] = uc; | - |
110 | } | - |
111 | } | - |
112 | } else if (m_echoMode == QLineEdit::PasswordEchoOnEdit && !m_passwordEchoEditing) { | - |
113 | str.fill(m_passwordCharacter); | - |
114 | } | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | QChar* uc = str.data(); | - |
120 | for (int i = 0; i < (int)str.length(); ++i) { | - |
121 | if ((uc[i].unicode() < 0x20 && uc[i].unicode() != 0x09) | - |
122 | || uc[i] == QChar::LineSeparator | - |
123 | || uc[i] == QChar::ParagraphSeparator | - |
124 | || uc[i] == QChar::ObjectReplacementCharacter) | - |
125 | uc[i] = QChar(0x0020); | - |
126 | } | - |
127 | | - |
128 | m_textLayout.setText(str); | - |
129 | | - |
130 | QTextOption option = m_textLayout.textOption(); | - |
131 | option.setTextDirection(m_layoutDirection); | - |
132 | option.setFlags(QTextOption::IncludeTrailingSpaces); | - |
133 | m_textLayout.setTextOption(option); | - |
134 | | - |
135 | m_ascent = redoTextLayout(); | - |
136 | | - |
137 | if (str != orig || forceUpdate) | - |
138 | emit displayTextChanged(str); | - |
139 | } | - |
140 | | - |
141 | #ifndef QT_NO_CLIPBOARD | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | void QWidgetLineControl::copy(QClipboard::Mode mode) const | - |
153 | { | - |
154 | QString t = selectedText(); | - |
155 | if (!t.isEmpty() && m_echoMode == QLineEdit::Normal) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
156 | disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, 0);QApplication::clipboard()->setText(t, mode); | - |
157 | connect(QApplication::clipboard(), SIGNAL(selectionChanged()), never executed: end of block | 0 |
| this, SLOT(_q_clipboardChanged())); never executed: end of block }never executed: end of block | |
158 | } never executed: end of block | 0 |
159 | | - |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | void QWidgetLineControl::paste(QClipboard::Mode clipboardMode) | - |
169 | { | - |
170 | QString clip = QApplication::clipboard()->text(clipboardMode); | - |
171 | if (!clip.isEmpty() || hasSelectedText()) { | - |
172 | separate(); | - |
173 | insert(clip); | - |
174 | separate(); | - |
175 | } | - |
176 | } | - |
177 | | - |
178 | #endif // !QT_NO_CLIPBOARD | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | void QWidgetLineControl::commitPreedit() | - |
184 | { | - |
185 | #ifndef QT_NO_IM | - |
186 | if (!composeMode()) | - |
187 | return; | - |
188 | | - |
189 | QGuiApplication::inputMethod()->commit(); | - |
190 | if (!composeMode()) | - |
191 | return; | - |
192 | | - |
193 | m_preeditCursor = 0; | - |
194 | setPreeditArea(-1, QString()); | - |
195 | m_textLayout.clearFormats(); | - |
196 | updateDisplayText( true); | - |
197 | #endif | - |
198 | } | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | void QWidgetLineControl::backspace() | - |
211 | { | - |
212 | int priorState = m_undoState; | - |
213 | if (hasSelectedText()) { | - |
214 | removeSelectedText(); | - |
215 | } else if (m_cursor) { | - |
216 | --m_cursor; | - |
217 | if (m_maskData) | - |
218 | m_cursor = prevMaskBlank(m_cursor); | - |
219 | QChar uc = m_text.at(m_cursor); | - |
220 | if (m_cursor > 0 && uc.isLowSurrogate()) { | - |
221 | | - |
222 | | - |
223 | uc = m_text.at(m_cursor - 1); | - |
224 | if (uc.isHighSurrogate()) { | - |
225 | internalDelete(true); | - |
226 | --m_cursor; | - |
227 | } | - |
228 | } | - |
229 | internalDelete(true); | - |
230 | } | - |
231 | finishChange(priorState); | - |
232 | } | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | void QWidgetLineControl::del() | - |
244 | { | - |
245 | int priorState = m_undoState; | - |
246 | if (hasSelectedText()) { | - |
247 | removeSelectedText(); | - |
248 | } else { | - |
249 | int n = textLayout()->nextCursorPosition(m_cursor) - m_cursor; | - |
250 | while (n--) | - |
251 | internalDelete(); | - |
252 | } | - |
253 | finishChange(priorState); | - |
254 | } | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | void QWidgetLineControl::insert(const QString &newText) | - |
264 | { | - |
265 | int priorState = m_undoState; | - |
266 | removeSelectedText(); | - |
267 | internalInsert(newText); | - |
268 | finishChange(priorState); | - |
269 | } | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | void QWidgetLineControl::clear() | - |
277 | { | - |
278 | int priorState = m_undoState; | - |
279 | m_selstart = 0; | - |
280 | m_selend = m_text.length(); | - |
281 | removeSelectedText(); | - |
282 | separate(); | - |
283 | finishChange(priorState, false, false); | - |
284 | } | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | void QWidgetLineControl::undo() | - |
292 | { | - |
293 | | - |
294 | if (m_echoMode == QLineEdit::Normal) { | - |
295 | internalUndo(); | - |
296 | finishChange(-1, true); | - |
297 | } else { | - |
298 | cancelPasswordEchoTimer(); | - |
299 | clear(); | - |
300 | } | - |
301 | } | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | void QWidgetLineControl::setSelection(int start, int length) | - |
312 | { | - |
313 | commitPreedit(); | - |
314 | | - |
315 | if (Q_UNLIKELY(start < 0 || start > (int)m_text.length()){size())) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
316 | qWarning("QWidgetLineControl::setSelection: Invalid start position"); | - |
317 | return; never executed: return; | 0 |
318 | } | - |
319 | | - |
320 | if (length > 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
321 | if (start == m_selstart && start + length == m_selend && m_cursor == m_selend)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
322 | return; never executed: return; | 0 |
323 | m_selstart = start; | - |
324 | m_selend = qMin(start + length, (int)m_text.length()); | - |
325 | m_cursor = m_selend; | - |
326 | } else if (length < 0){ never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
327 | if (start == m_selend && start + length == m_selstart && m_cursor == m_selstart)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
328 | return; never executed: return; | 0 |
329 | m_selstart = qMax(start + length, 0); | - |
330 | m_selend = start; | - |
331 | m_cursor = m_selstart; | - |
332 | } else if (m_selstart != m_selend) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
333 | m_selstart = 0; | - |
334 | m_selend = 0; | - |
335 | m_cursor = start; | - |
336 | } else { never executed: end of block | 0 |
337 | m_cursor = start; | - |
338 | emitCursorPositionChanged(); | - |
339 | return; never executed: return; | 0 |
340 | } | - |
341 | emit selectionChanged(); | - |
342 | emitCursorPositionChanged(); | - |
| } never executed: end of block | |
| | |
| void QWidgetLineControl::_q_clipboardChanged() never executed: end of block | |
| { never executed: end of block }never executed: end of block | |
344 | | - |
345 | void QWidgetLineControl::_q_deleteSelected() | - |
346 | { | - |
347 | if (!hasSelectedText()) | - |
348 | return; | - |
349 | | - |
350 | int priorState = m_undoState; | - |
351 | emit resetInputContext(); | - |
352 | removeSelectedText(); | - |
353 | separate(); | - |
354 | finishChange(priorState); | - |
355 | } | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
361 | | - |
362 | void QWidgetLineControl::init(const QString &txt) | - |
363 | { | - |
364 | m_textLayout.setCacheEnabled(true); | - |
365 | m_text = txt; | - |
366 | updateDisplayText(); | - |
367 | m_cursor = m_text.length(); | - |
368 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { | - |
369 | m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt(); | - |
370 | m_passwordMaskDelay = theme->themeHint(QPlatformTheme::PasswordMaskDelay).toInt(); | - |
371 | } | - |
372 | | - |
373 | if (m_keyboardScheme == QPlatformTheme::KdeKeyboardScheme | - |
374 | || m_keyboardScheme == QPlatformTheme::GnomeKeyboardScheme | - |
375 | || m_keyboardScheme == QPlatformTheme::CdeKeyboardScheme) { | - |
376 | m_keyboardScheme = QPlatformTheme::X11KeyboardScheme; | - |
377 | } | - |
378 | } | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | | - |
386 | | - |
387 | | - |
388 | void QWidgetLineControl::updatePasswordEchoEditing(bool editing) | - |
389 | { | - |
390 | cancelPasswordEchoTimer(); | - |
391 | m_passwordEchoEditing = editing; | - |
392 | updateDisplayText(); | - |
393 | } | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | | - |
402 | int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const | - |
403 | { | - |
404 | return textLayout()->lineAt(0).xToCursor(x, betweenOrOn); | - |
405 | } | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | QRect QWidgetLineControl::cursorRect()rectForPos(int pos) const | - |
413 | { | - |
414 | QTextLine l = textLayout()->lineAt(0); | - |
415 | int c = m_cursor;if (m_preeditCursor != -1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
416 | cpos += m_preeditCursor; never executed: pos += m_preeditCursor; | 0 |
417 | int cix = qRound(l.cursorToX(cpos)); | - |
418 | int w = m_cursorWidth; | - |
419 | int ch = l.height() + 1; | - |
420 | | - |
421 | return QRect(cix-5, 0, w+9, ch); never executed: return QRect(cix-5, 0, w+9, ch); | 0 |
422 | } | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | | - |
428 | | - |
429 | | - |
430 | QRect QWidgetLineControl::cursorRect() const | - |
431 | { | - |
432 | return rectForPos(m_cursor); never executed: return rectForPos(m_cursor); | 0 |
433 | } | - |
434 | | - |
435 | | - |
436 | | - |
437 | | - |
438 | | - |
439 | | - |
440 | QRect QWidgetLineControl::anchorRect() const | - |
441 | { | - |
442 | if (!hasSelectedText())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
443 | return cursorRect(); never executed: return cursorRect(); | 0 |
444 | return rectForPos(m_selstart < m_selend ? m_selstart : m_selend never executed: return rectForPos(m_selstart < m_selend ? m_selstart : m_selend); );never executed: return rectForPos(m_selstart < m_selend ? m_selstart : m_selend); | 0 |
445 | } | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | | - |
454 | bool QWidgetLineControl::fixup() | - |
455 | { | - |
456 | #ifndef QT_NO_VALIDATOR | - |
457 | if (m_validator) { | - |
458 | QString textCopy = m_text; | - |
459 | int cursorCopy = m_cursor; | - |
460 | m_validator->fixup(textCopy); | - |
461 | if (m_validator->validate(textCopy, cursorCopy) == QValidator::Acceptable) { | - |
462 | if (textCopy != m_text || cursorCopy != m_cursor) | - |
463 | internalSetText(textCopy, cursorCopy, false); | - |
464 | return true; | - |
465 | } | - |
466 | } | - |
467 | #endif | - |
468 | return false; | - |
469 | } | - |
470 | | - |
471 | | - |
472 | | - |
473 | | - |
474 | | - |
475 | | - |
476 | | - |
477 | void QWidgetLineControl::moveCursor(int pos, bool mark) | - |
478 | { | - |
479 | commitPreedit(); | - |
480 | | - |
481 | if (pos != m_cursor) { | - |
482 | separate(); | - |
483 | if (m_maskData) | - |
484 | pos = pos > m_cursor ? nextMaskBlank(pos) : prevMaskBlank(pos); | - |
485 | } | - |
486 | if (mark) { | - |
487 | int anchor; | - |
488 | if (m_selend > m_selstart && m_cursor == m_selstart) | - |
489 | anchor = m_selend; | - |
490 | else if (m_selend > m_selstart && m_cursor == m_selend) | - |
491 | anchor = m_selstart; | - |
492 | else | - |
493 | anchor = m_cursor; | - |
494 | m_selstart = qMin(anchor, pos); | - |
495 | m_selend = qMax(anchor, pos); | - |
496 | updateDisplayText(); | - |
497 | } else { | - |
498 | internalDeselect(); | - |
499 | } | - |
500 | m_cursor = pos; | - |
501 | if (mark || m_selDirty) { | - |
502 | m_selDirty = false; | - |
503 | emit selectionChanged(); | - |
504 | } | - |
505 | emitCursorPositionChanged(); | - |
506 | } | - |
507 | | - |
508 | | - |
509 | | - |
510 | | - |
511 | | - |
512 | | - |
513 | | - |
514 | void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) | - |
515 | { | - |
516 | int priorState = -1; | - |
517 | bool isGettingInput = !event->commitString().isEmpty() | - |
518 | || event->preeditString() != preeditAreaText() | - |
519 | || event->replacementLength() > 0; | - |
520 | bool cursorPositionChanged = false; | - |
521 | bool selectionChange = false; | - |
522 | | - |
523 | if (isGettingInput) { | - |
524 | | - |
525 | priorState = m_undoState; | - |
526 | if (echoMode() == QLineEdit::PasswordEchoOnEdit && !passwordEchoEditing()) { | - |
527 | updatePasswordEchoEditing(true); | - |
528 | m_selstart = 0; | - |
529 | m_selend = m_text.length(); | - |
530 | } | - |
531 | removeSelectedText(); | - |
532 | } | - |
533 | | - |
534 | int c = m_cursor; | - |
535 | if (event->replacementStart() <= 0) | - |
536 | c += event->commitString().length() - qMin(-event->replacementStart(), event->replacementLength()); | - |
537 | | - |
538 | m_cursor += event->replacementStart(); | - |
539 | if (m_cursor < 0) | - |
540 | m_cursor = 0; | - |
541 | | - |
542 | | - |
543 | if (event->replacementLength()) { | - |
544 | m_selstart = m_cursor; | - |
545 | m_selend = m_selstart + event->replacementLength(); | - |
546 | removeSelectedText(); | - |
547 | } | - |
548 | if (!event->commitString().isEmpty()) { | - |
549 | internalInsert(event->commitString()); | - |
550 | cursorPositionChanged = true; | - |
551 | } | - |
552 | | - |
553 | m_cursor = qBound(0, c, m_text.length()); | - |
554 | | - |
555 | for (int i = 0; i < event->attributes().size(); ++i) { | - |
556 | const QInputMethodEvent::Attribute &a = event->attributes().at(i); | - |
557 | if (a.type == QInputMethodEvent::Selection) { | - |
558 | m_cursor = qBound(0, a.start + a.length, m_text.length()); | - |
559 | if (a.length) { | - |
560 | m_selstart = qMax(0, qMin(a.start, m_text.length())); | - |
561 | m_selend = m_cursor; | - |
562 | if (m_selend < m_selstart) { | - |
563 | qSwap(m_selstart, m_selend); | - |
564 | } | - |
565 | selectionChange = true; | - |
566 | } else { | - |
567 | if (m_selstart != m_selend) | - |
568 | selectionChange = true; | - |
569 | m_selstart = m_selend = 0; | - |
570 | } | - |
571 | cursorPositionChanged = true; | - |
572 | } | - |
573 | } | - |
574 | #ifndef QT_NO_IM | - |
575 | setPreeditArea(m_cursor, event->preeditString()); | - |
576 | #endif //QT_NO_IM | - |
577 | const int oldPreeditCursor = m_preeditCursor; | - |
578 | m_preeditCursor = event->preeditString().length(); | - |
579 | m_hideCursor = false; | - |
580 | QVector<QTextLayout::FormatRange> formats; | - |
581 | formats.reserve(event->attributes().size()); | - |
582 | for (int i = 0; i < event->attributes().size(); ++i) { | - |
583 | const QInputMethodEvent::Attribute &a = event->attributes().at(i); | - |
584 | if (a.type == QInputMethodEvent::Cursor) { | - |
585 | m_preeditCursor = a.start; | - |
586 | m_hideCursor = !a.length; | - |
587 | } else if (a.type == QInputMethodEvent::TextFormat) { | - |
588 | QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); | - |
589 | if (f.isValid()) { | - |
590 | QTextLayout::FormatRange o; | - |
591 | o.start = a.start + m_cursor; | - |
592 | o.length = a.length; | - |
593 | o.format = f; | - |
594 | formats.append(o); | - |
595 | } | - |
596 | } | - |
597 | } | - |
598 | m_textLayout.setFormats(formats); | - |
599 | updateDisplayText( true); | - |
600 | if (cursorPositionChanged) | - |
601 | emitCursorPositionChanged(); | - |
602 | else if (m_preeditCursor != oldPreeditCursor) | - |
603 | emit updateMicroFocus(); | - |
604 | | - |
605 | if (isGettingInput) | - |
606 | finishChange(priorState); | - |
607 | | - |
608 | if (selectionChange) | - |
609 | emit selectionChanged(); | - |
610 | } | - |
611 | | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | | - |
617 | | - |
618 | | - |
619 | | - |
620 | | - |
621 | | - |
622 | | - |
623 | | - |
624 | | - |
625 | | - |
626 | | - |
627 | void QWidgetLineControl::draw(QPainter *painter, const QPoint &offset, const QRect &clip, int flags) | - |
628 | { | - |
629 | QVector<QTextLayout::FormatRange> selections; | - |
630 | if (flags & DrawSelections) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
631 | QTextLayout::FormatRange o; | - |
632 | if (m_selstart < m_selend) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
633 | o.start = m_selstart; | - |
634 | o.length = m_selend - m_selstart; | - |
635 | o.format.setBackground(m_palette.brush(QPalette::Highlight)); | - |
636 | o.format.setForeground(m_palette.brush(QPalette::HighlightedText)); | - |
637 | } else { never executed: end of block | 0 |
638 | | - |
639 | if (!m_blinkPeriod ||(m_blinkStatus){TRUE | never evaluated | FALSE | never evaluated |
| 0 |
640 | o.start = m_cursor; | - |
641 | o.length = 1; | - |
642 | o.format.setBackground(m_palette.brush(QPalette::Text)); | - |
643 | o.format.setForeground(m_palette.brush(QPalette::Window)); | - |
644 | } never executed: end of block | 0 |
645 | } never executed: end of block | 0 |
646 | selections.append(o); | - |
647 | } never executed: end of block | 0 |
648 | | - |
649 | if (flags & DrawText)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
650 | textLayout()->draw(painter, offset, selections, clip); never executed: textLayout()->draw(painter, offset, selections, clip); | 0 |
651 | | - |
652 | if (flags & DrawCursor){TRUE | never evaluated | FALSE | never evaluated |
| 0 |
653 | int cursor = m_cursor; | - |
654 | if (m_preeditCursor != -1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
655 | cursor += m_preeditCursor; never executed: cursor += m_preeditCursor; | 0 |
656 | if (!m_hideCursor && (!m_blinkPeriod ||m_blinkStatus)))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
657 | textLayout()->drawCursor(painter, offset, cursor, m_cursorWidth); never executed: textLayout()->drawCursor(painter, offset, cursor, m_cursorWidth); | 0 |
658 | } never executed: end of block | 0 |
659 | } never executed: end of block | 0 |
660 | | - |
661 | | - |
662 | | - |
663 | | - |
664 | | - |
665 | | - |
666 | | - |
667 | | - |
668 | void QWidgetLineControl::selectWordAtPos(int cursor) | - |
669 | { | - |
670 | int next = cursor + 1; | - |
671 | if(next > end()) | - |
672 | --next; | - |
673 | int c = textLayout()->previousCursorPosition(next, QTextLayout::SkipWords); | - |
674 | moveCursor(c, false); | - |
675 | | - |
676 | int end = textLayout()->nextCursorPosition(c, QTextLayout::SkipWords); | - |
677 | while (end > cursor && m_text[end-1].isSpace()) | - |
678 | --end; | - |
679 | moveCursor(end, true); | - |
680 | } | - |
681 | | - |
682 | | - |
683 | | - |
684 | | - |
685 | | - |
686 | | - |
687 | | - |
688 | | - |
689 | | - |
690 | | - |
691 | | - |
692 | | - |
693 | | - |
694 | bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool edited) | - |
695 | { | - |
696 | Q_UNUSED(update) | - |
697 | | - |
698 | if (m_textDirty) { | - |
699 | | - |
700 | bool wasValidInput = m_validInput; | - |
701 | m_validInput = true; | - |
702 | #ifndef QT_NO_VALIDATOR | - |
703 | if (m_validator) { | - |
704 | QString textCopy = m_text; | - |
705 | int cursorCopy = m_cursor; | - |
706 | m_validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid); | - |
707 | if (m_validInput) { | - |
708 | if (m_text != textCopy) { | - |
709 | internalSetText(textCopy, cursorCopy, false); | - |
710 | return true; | - |
711 | } | - |
712 | m_cursor = cursorCopy; | - |
713 | } | - |
714 | } | - |
715 | #endif | - |
716 | if (validateFromState >= 0 && wasValidInput && !m_validInput) { | - |
717 | if (m_transactions.count()) | - |
718 | return false; | - |
719 | internalUndo(validateFromState); | - |
720 | m_history.erase(m_history.begin() + m_undoState, m_history.end()); | - |
721 | if (m_modifiedState > m_undoState) | - |
722 | m_modifiedState = -1; | - |
723 | m_validInput = true; | - |
724 | m_textDirty = false; | - |
725 | } | - |
726 | updateDisplayText(); | - |
727 | | - |
728 | if (m_textDirty) { | - |
729 | m_textDirty = false; | - |
730 | QString actualText = text(); | - |
731 | if (edited) | - |
732 | emit textEdited(actualText); | - |
733 | emit textChanged(actualText); | - |
734 | } | - |
735 | } | - |
736 | if (m_selDirty) { | - |
737 | m_selDirty = false; | - |
738 | emit selectionChanged(); | - |
739 | } | - |
740 | if (m_cursor == m_lastCursorPos) | - |
741 | updateMicroFocus(); | - |
742 | emitCursorPositionChanged(); | - |
743 | return true; | - |
744 | } | - |
745 | | - |
746 | | - |
747 | | - |
748 | | - |
749 | | - |
750 | | - |
751 | void QWidgetLineControl::internalSetText(const QString &txt, int pos, bool edited) | - |
752 | { | - |
753 | cancelPasswordEchoTimer(); | - |
754 | internalDeselect(); | - |
755 | emit resetInputContext(); | - |
756 | QString oldText = m_text; | - |
757 | if (m_maskData) { | - |
758 | m_text = maskString(0, txt, true); | - |
759 | m_text += clearString(m_text.length(), m_maxLength - m_text.length()); | - |
760 | } else { | - |
761 | m_text = txt.isEmpty() ? txt : txt.left(m_maxLength); | - |
762 | } | - |
763 | m_history.clear(); | - |
764 | m_modifiedState = m_undoState = 0; | - |
765 | m_cursor = (pos < 0 || pos > m_text.length()) ? m_text.length() : pos; | - |
766 | m_textDirty = (oldText != m_text); | - |
767 | const bool changed = finishChange(-1, true, edited); | - |
768 | | - |
769 | #ifndef QT_NO_ACCESSIBILITY | - |
770 | if (changed) { | - |
771 | if (oldText.isEmpty()) { | - |
772 | QAccessibleTextInsertEvent event(accessibleObject(), 0, txt); | - |
773 | event.setCursorPosition(m_cursor); | - |
774 | QAccessible::updateAccessibility(&event); | - |
775 | } else if (txt.isEmpty()) { | - |
776 | QAccessibleTextRemoveEvent event(accessibleObject(), 0, oldText); | - |
777 | event.setCursorPosition(m_cursor); | - |
778 | QAccessible::updateAccessibility(&event); | - |
779 | } else { | - |
780 | QAccessibleTextUpdateEvent event(accessibleObject(), 0, oldText, txt); | - |
781 | event.setCursorPosition(m_cursor); | - |
782 | QAccessible::updateAccessibility(&event); | - |
783 | } | - |
784 | } | - |
785 | #else | - |
786 | Q_UNUSED(changed) | - |
787 | #endif | - |
788 | } | - |
789 | | - |
790 | | - |
791 | | - |
792 | | - |
793 | | - |
794 | | - |
795 | | - |
796 | | - |
797 | void QWidgetLineControl::addCommand(const Command &cmd) | - |
798 | { | - |
799 | m_history.erase(m_history.begin() + m_undoState, m_history.end()); | - |
800 | | - |
801 | if (m_separator && m_undoState && m_history[m_undoState - 1].type != Separator) | - |
802 | m_history.push_back(Command(Separator, m_cursor, 0, m_selstart, m_selend)); | - |
803 | | - |
804 | m_separator = false; | - |
805 | m_history.push_back(cmd); | - |
806 | m_undoState = int(m_history.size()); | - |
807 | } | - |
808 | | - |
809 | | - |
810 | | - |
811 | | - |
812 | | - |
813 | | - |
814 | | - |
815 | | - |
816 | | - |
817 | | - |
818 | | - |
819 | void QWidgetLineControl::internalInsert(const QString &s) | - |
820 | { | - |
821 | if (m_echoMode == QLineEdit::Password) { | - |
822 | if (m_passwordEchoTimer != 0) | - |
823 | killTimer(m_passwordEchoTimer); | - |
824 | int delay = m_passwordMaskDelay; | - |
825 | #ifdef QT_BUILD_INTERNAL | - |
826 | if (m_passwordMaskDelayOverride >= 0) | - |
827 | delay = m_passwordMaskDelayOverride; | - |
828 | #endif | - |
829 | | - |
830 | if (delay > 0) | - |
831 | m_passwordEchoTimer = startTimer(delay); | - |
832 | } | - |
833 | if (hasSelectedText()) | - |
834 | addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend)); | - |
835 | if (m_maskData) { | - |
836 | QString ms = maskString(m_cursor, s); | - |
837 | #ifndef QT_NO_ACCESSIBILITY | - |
838 | QAccessibleTextInsertEvent insertEvent(accessibleObject(), m_cursor, ms); | - |
839 | QAccessible::updateAccessibility(&insertEvent); | - |
840 | #endif | - |
841 | for (int i = 0; i < (int) ms.length(); ++i) { | - |
842 | addCommand (Command(DeleteSelection, m_cursor + i, m_text.at(m_cursor + i), -1, -1)); | - |
843 | addCommand(Command(Insert, m_cursor + i, ms.at(i), -1, -1)); | - |
844 | } | - |
845 | m_text.replace(m_cursor, ms.length(), ms); | - |
846 | m_cursor += ms.length(); | - |
847 | m_cursor = nextMaskBlank(m_cursor); | - |
848 | m_textDirty = true; | - |
849 | #ifndef QT_NO_ACCESSIBILITY | - |
850 | QAccessibleTextCursorEvent event(accessibleObject(), m_cursor); | - |
851 | QAccessible::updateAccessibility(&event); | - |
852 | #endif | - |
853 | } else { | - |
854 | int remaining = m_maxLength - m_text.length(); | - |
855 | if (remaining != 0) { | - |
856 | #ifndef QT_NO_ACCESSIBILITY | - |
857 | QAccessibleTextInsertEvent insertEvent(accessibleObject(), m_cursor, s); | - |
858 | QAccessible::updateAccessibility(&insertEvent); | - |
859 | #endif | - |
860 | m_text.insert(m_cursor, s.left(remaining)); | - |
861 | for (int i = 0; i < (int) s.left(remaining).length(); ++i) | - |
862 | addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1)); | - |
863 | m_textDirty = true; | - |
864 | } | - |
865 | } | - |
866 | } | - |
867 | | - |
868 | | - |
869 | | - |
870 | | - |
871 | | - |
872 | | - |
873 | | - |
874 | | - |
875 | | - |
876 | | - |
877 | | - |
878 | | - |
879 | void QWidgetLineControl::internalDelete(bool wasBackspace) | - |
880 | { | - |
881 | if (m_cursor < (int) m_text.length()) { | - |
882 | cancelPasswordEchoTimer(); | - |
883 | if (hasSelectedText()) | - |
884 | addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend)); | - |
885 | addCommand(Command((CommandType)((m_maskData ? 2 : 0) + (wasBackspace ? Remove : Delete)), | - |
886 | m_cursor, m_text.at(m_cursor), -1, -1)); | - |
887 | #ifndef QT_NO_ACCESSIBILITY | - |
888 | QAccessibleTextRemoveEvent event(accessibleObject(), m_cursor, m_text.at(m_cursor)); | - |
889 | QAccessible::updateAccessibility(&event); | - |
890 | #endif | - |
891 | if (m_maskData) { | - |
892 | m_text.replace(m_cursor, 1, clearString(m_cursor, 1)); | - |
893 | addCommand(Command(Insert, m_cursor, m_text.at(m_cursor), -1, -1)); | - |
894 | } else { | - |
895 | m_text.remove(m_cursor, 1); | - |
896 | } | - |
897 | m_textDirty = true; | - |
898 | } | - |
899 | } | - |
900 | | - |
901 | | - |
902 | | - |
903 | | - |
904 | | - |
905 | | - |
906 | | - |
907 | | - |
908 | | - |
909 | | - |
910 | void QWidgetLineControl::removeSelectedText() | - |
911 | { | - |
912 | if (m_selstart < m_selend && m_selend <= (int) m_text.length()) { | - |
913 | cancelPasswordEchoTimer(); | - |
914 | separate(); | - |
915 | int i ; | - |
916 | addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend)); | - |
917 | if (m_selstart <= m_cursor && m_cursor < m_selend) { | - |
918 | | - |
919 | | - |
920 | for (i = m_cursor; i >= m_selstart; --i) | - |
921 | addCommand (Command(DeleteSelection, i, m_text.at(i), -1, 1)); | - |
922 | for (i = m_selend - 1; i > m_cursor; --i) | - |
923 | addCommand (Command(DeleteSelection, i - m_cursor + m_selstart - 1, m_text.at(i), -1, -1)); | - |
924 | } else { | - |
925 | for (i = m_selend-1; i >= m_selstart; --i) | - |
926 | addCommand (Command(RemoveSelection, i, m_text.at(i), -1, -1)); | - |
927 | } | - |
928 | #ifndef QT_NO_ACCESSIBILITY | - |
929 | QAccessibleTextRemoveEvent event(accessibleObject(), m_selstart, m_text.mid(m_selstart, m_selend - m_selstart)); | - |
930 | QAccessible::updateAccessibility(&event); | - |
931 | #endif | - |
932 | if (m_maskData) { | - |
933 | m_text.replace(m_selstart, m_selend - m_selstart, clearString(m_selstart, m_selend - m_selstart)); | - |
934 | for (int i = 0; i < m_selend - m_selstart; ++i) | - |
935 | addCommand(Command(Insert, m_selstart + i, m_text.at(m_selstart + i), -1, -1)); | - |
936 | } else { | - |
937 | m_text.remove(m_selstart, m_selend - m_selstart); | - |
938 | } | - |
939 | if (m_cursor > m_selstart) | - |
940 | m_cursor -= qMin(m_cursor, m_selend) - m_selstart; | - |
941 | internalDeselect(); | - |
942 | m_textDirty = true; | - |
943 | } | - |
944 | } | - |
945 | | - |
946 | | - |
947 | | - |
948 | | - |
949 | | - |
950 | | - |
951 | | - |
952 | void QWidgetLineControl::parseInputMask(const QString &maskFields) | - |
953 | { | - |
954 | int delimiter = maskFields.indexOf(QLatin1Char(';')); | - |
955 | if (maskFields.isEmpty() || delimiter == 0) { | - |
956 | if (m_maskData) { | - |
957 | delete [] m_maskData; | - |
958 | m_maskData = 0; | - |
959 | m_maxLength = 32767; | - |
960 | internalSetText(QString(), -1, false); | - |
961 | } | - |
962 | return; | - |
963 | } | - |
964 | | - |
965 | if (delimiter == -1) { | - |
966 | m_blank = QLatin1Char(' '); | - |
967 | m_inputMask = maskFields; | - |
968 | } else { | - |
969 | m_inputMask = maskFields.left(delimiter); | - |
970 | m_blank = (delimiter + 1 < maskFields.length()) ? maskFields[delimiter + 1] : QLatin1Char(' '); | - |
971 | } | - |
972 | | - |
973 | | - |
974 | m_maxLength = 0; | - |
975 | QChar c = 0; | - |
976 | for (int i=0; i<m_inputMask.length(); i++) { | - |
977 | c = m_inputMask.at(i); | - |
978 | if (i > 0 && m_inputMask.at(i-1) == QLatin1Char('\\')) { | - |
979 | m_maxLength++; | - |
980 | continue; | - |
981 | } | - |
982 | if (c != QLatin1Char('\\') && c != QLatin1Char('!') && | - |
983 | c != QLatin1Char('<') && c != QLatin1Char('>') && | - |
984 | c != QLatin1Char('{') && c != QLatin1Char('}') && | - |
985 | c != QLatin1Char('[') && c != QLatin1Char(']')) | - |
986 | m_maxLength++; | - |
987 | } | - |
988 | | - |
989 | delete [] m_maskData; | - |
990 | m_maskData = new MaskInputData[m_maxLength]; | - |
991 | | - |
992 | MaskInputData::Casemode m = MaskInputData::NoCaseMode; | - |
993 | c = 0; | - |
994 | bool s; | - |
995 | bool escape = false; | - |
996 | int index = 0; | - |
997 | for (int i = 0; i < m_inputMask.length(); i++) { | - |
998 | c = m_inputMask.at(i); | - |
999 | if (escape) { | - |
1000 | s = true; | - |
1001 | m_maskData[index].maskChar = c; | - |
1002 | m_maskData[index].separator = s; | - |
1003 | m_maskData[index].caseMode = m; | - |
1004 | index++; | - |
1005 | escape = false; | - |
1006 | } else if (c == QLatin1Char('<')) { | - |
1007 | m = MaskInputData::Lower; | - |
1008 | } else if (c == QLatin1Char('>')) { | - |
1009 | m = MaskInputData::Upper; | - |
1010 | } else if (c == QLatin1Char('!')) { | - |
1011 | m = MaskInputData::NoCaseMode; | - |
1012 | } else if (c != QLatin1Char('{') && c != QLatin1Char('}') && c != QLatin1Char('[') && c != QLatin1Char(']')) { | - |
1013 | switch (c.unicode()) { | - |
1014 | case 'A': | - |
1015 | case 'a': | - |
1016 | case 'N': | - |
1017 | case 'n': | - |
1018 | case 'X': | - |
1019 | case 'x': | - |
1020 | case '9': | - |
1021 | case '0': | - |
1022 | case 'D': | - |
1023 | case 'd': | - |
1024 | case '#': | - |
1025 | case 'H': | - |
1026 | case 'h': | - |
1027 | case 'B': | - |
1028 | case 'b': | - |
1029 | s = false; | - |
1030 | break; | - |
1031 | case '\\': | - |
1032 | escape = true; | - |
1033 | default: | - |
1034 | s = true; | - |
1035 | break; | - |
1036 | } | - |
1037 | | - |
1038 | if (!escape) { | - |
1039 | m_maskData[index].maskChar = c; | - |
1040 | m_maskData[index].separator = s; | - |
1041 | m_maskData[index].caseMode = m; | - |
1042 | index++; | - |
1043 | } | - |
1044 | } | - |
1045 | } | - |
1046 | internalSetText(m_text, -1, false); | - |
1047 | } | - |
1048 | | - |
1049 | | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | | - |
1054 | | - |
1055 | bool QWidgetLineControl::isValidInput(QChar key, QChar mask) const | - |
1056 | { | - |
1057 | switch (mask.unicode()) { | - |
1058 | case 'A': | - |
1059 | if (key.isLetter()) | - |
1060 | return true; | - |
1061 | break; | - |
1062 | case 'a': | - |
1063 | if (key.isLetter() || key == m_blank) | - |
1064 | return true; | - |
1065 | break; | - |
1066 | case 'N': | - |
1067 | if (key.isLetterOrNumber()) | - |
1068 | return true; | - |
1069 | break; | - |
1070 | case 'n': | - |
1071 | if (key.isLetterOrNumber() || key == m_blank) | - |
1072 | return true; | - |
1073 | break; | - |
1074 | case 'X': | - |
1075 | if (key.isPrint()) | - |
1076 | return true; | - |
1077 | break; | - |
1078 | case 'x': | - |
1079 | if (key.isPrint() || key == m_blank) | - |
1080 | return true; | - |
1081 | break; | - |
1082 | case '9': | - |
1083 | if (key.isNumber()) | - |
1084 | return true; | - |
1085 | break; | - |
1086 | case '0': | - |
1087 | if (key.isNumber() || key == m_blank) | - |
1088 | return true; | - |
1089 | break; | - |
1090 | case 'D': | - |
1091 | if (key.isNumber() && key.digitValue() > 0) | - |
1092 | return true; | - |
1093 | break; | - |
1094 | case 'd': | - |
1095 | if ((key.isNumber() && key.digitValue() > 0) || key == m_blank) | - |
1096 | return true; | - |
1097 | break; | - |
1098 | case '#': | - |
1099 | if (key.isNumber() || key == QLatin1Char('+') || key == QLatin1Char('-') || key == m_blank) | - |
1100 | return true; | - |
1101 | break; | - |
1102 | case 'B': | - |
1103 | if (key == QLatin1Char('0') || key == QLatin1Char('1')) | - |
1104 | return true; | - |
1105 | break; | - |
1106 | case 'b': | - |
1107 | if (key == QLatin1Char('0') || key == QLatin1Char('1') || key == m_blank) | - |
1108 | return true; | - |
1109 | break; | - |
1110 | case 'H': | - |
1111 | if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F'))) | - |
1112 | return true; | - |
1113 | break; | - |
1114 | case 'h': | - |
1115 | if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')) || key == m_blank) | - |
1116 | return true; | - |
1117 | break; | - |
1118 | default: | - |
1119 | break; | - |
1120 | } | - |
1121 | return false; | - |
1122 | } | - |
1123 | | - |
1124 | | - |
1125 | | - |
1126 | | - |
1127 | | - |
1128 | | - |
1129 | | - |
1130 | | - |
1131 | | - |
1132 | bool QWidgetLineControl::hasAcceptableInput(const QString &str) const | - |
1133 | { | - |
1134 | #ifndef QT_NO_VALIDATOR | - |
1135 | QString textCopy = str; | - |
1136 | int cursorCopy = m_cursor; | - |
1137 | if (m_validator && m_validator->validate(textCopy, cursorCopy) | - |
1138 | != QValidator::Acceptable) | - |
1139 | return false; | - |
1140 | #endif | - |
1141 | | - |
1142 | if (!m_maskData) | - |
1143 | return true; | - |
1144 | | - |
1145 | if (str.length() != m_maxLength) | - |
1146 | return false; | - |
1147 | | - |
1148 | for (int i=0; i < m_maxLength; ++i) { | - |
1149 | if (m_maskData[i].separator) { | - |
1150 | if (str.at(i) != m_maskData[i].maskChar) | - |
1151 | return false; | - |
1152 | } else { | - |
1153 | if (!isValidInput(str.at(i), m_maskData[i].maskChar)) | - |
1154 | return false; | - |
1155 | } | - |
1156 | } | - |
1157 | return true; | - |
1158 | } | - |
1159 | | - |
1160 | | - |
1161 | | - |
1162 | | - |
1163 | | - |
1164 | | - |
1165 | | - |
1166 | | - |
1167 | | - |
1168 | QString QWidgetLineControl::maskString(uint pos, const QString &str, bool clear) const | - |
1169 | { | - |
1170 | if (pos >= (uint)m_maxLength)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1171 | return QString::fromLatin1(""); never executed: return QString::fromLatin1(""); | 0 |
1172 | | - |
1173 | QString fill; | - |
1174 | fill = clear ? clearString(0, m_maxLength) : m_text;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1175 | | - |
1176 | int strIndex = 0; | - |
1177 | QString s = QString::fromLatin1(""); | - |
1178 | int i = pos; | - |
1179 | while (i < m_maxLength) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1180 | if (strIndex < str.length()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1181 | if (m_maskData[i].separator) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1182 | s += m_maskData[i].maskChar; | - |
1183 | if (str[(int)strIndex] == m_maskData[i].maskChar)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1184 | strIndex++; never executed: strIndex++; | 0 |
1185 | ++i; | - |
1186 | } else { never executed: end of block | 0 |
1187 | if (isValidInput(str[(int)strIndex], m_maskData[i].maskChar)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1188 | switch (m_maskData[i].caseMode) { | - |
1189 | case MaskInputData::Upper: never executed: case MaskInputData::Upper: | 0 |
1190 | s += str[(int)strIndex].toUpper(); | - |
1191 | break; never executed: break; | 0 |
1192 | case MaskInputData::Lower: never executed: case MaskInputData::Lower: | 0 |
1193 | s += str[(int)strIndex].toLower(); | - |
1194 | break; never executed: break; | 0 |
1195 | default: never executed: default: | 0 |
1196 | s += str[(int)strIndex]; | - |
1197 | } never executed: end of block | 0 |
1198 | ++i; | - |
1199 | } else { never executed: end of block | 0 |
1200 | | - |
1201 | int n = findInMask(i, true, true, str[(int)strIndex]); | - |
1202 | if (n != -1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1203 | if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1204 | s += fill.midmidRef(i, n - i + 1); | - |
1205 | i = n + 1; | - |
1206 | } never executed: end of block | 0 |
1207 | } else { never executed: end of block | 0 |
1208 | | - |
1209 | n = findInMask(i, true, false, str[(int)strIndex]); | - |
1210 | if (n != -1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1211 | s += fill.midmidRef(i, n - i); | - |
1212 | switch (m_maskData[n].caseMode) { | - |
1213 | case MaskInputData::Upper: never executed: case MaskInputData::Upper: | 0 |
1214 | s += str[(int)strIndex].toUpper(); | - |
1215 | break; never executed: break; | 0 |
1216 | case MaskInputData::Lower: never executed: case MaskInputData::Lower: | 0 |
1217 | s += str[(int)strIndex].toLower(); | - |
1218 | break; never executed: break; | 0 |
1219 | default: never executed: default: | 0 |
1220 | s += str[(int)strIndex]; | - |
1221 | } never executed: end of block | 0 |
1222 | i = n + 1; | - |
1223 | } never executed: end of block | 0 |
1224 | } never executed: end of block | 0 |
1225 | } | - |
1226 | ++strIndex; | - |
1227 | } never executed: end of block | 0 |
1228 | } else | - |
1229 | break; never executed: break; | 0 |
1230 | } | - |
1231 | | - |
1232 | return s; never executed: return s; | 0 |
1233 | } | - |
1234 | | - |
1235 | | - |
1236 | | - |
1237 | | - |
1238 | | - |
1239 | | - |
1240 | | - |
1241 | | - |
1242 | | - |
1243 | QString QWidgetLineControl::clearString(uint pos, uint len) const | - |
1244 | { | - |
1245 | if (pos >= (uint)m_maxLength) | - |
1246 | return QString(); | - |
1247 | | - |
1248 | QString s; | - |
1249 | int end = qMin((uint)m_maxLength, pos + len); | - |
1250 | for (int i = pos; i < end; ++i) | - |
1251 | if (m_maskData[i].separator) | - |
1252 | s += m_maskData[i].maskChar; | - |
1253 | else | - |
1254 | s += m_blank; | - |
1255 | | - |
1256 | return s; | - |
1257 | } | - |
1258 | | - |
1259 | | - |
1260 | | - |
1261 | | - |
1262 | | - |
1263 | | - |
1264 | | - |
1265 | QString QWidgetLineControl::stripString(const QString &str) const | - |
1266 | { | - |
1267 | if (!m_maskData) | - |
1268 | return str; | - |
1269 | | - |
1270 | QString s; | - |
1271 | int end = qMin(m_maxLength, (int)str.length()); | - |
1272 | for (int i = 0; i < end; ++i) | - |
1273 | if (m_maskData[i].separator) | - |
1274 | s += m_maskData[i].maskChar; | - |
1275 | else | - |
1276 | if (str[i] != m_blank) | - |
1277 | s += str[i]; | - |
1278 | | - |
1279 | return s; | - |
1280 | } | - |
1281 | | - |
1282 | | - |
1283 | | - |
1284 | | - |
1285 | | - |
1286 | int QWidgetLineControl::findInMask(int pos, bool forward, bool findSeparator, QChar searchChar) const | - |
1287 | { | - |
1288 | if (pos >= m_maxLength || pos < 0) | - |
1289 | return -1; | - |
1290 | | - |
1291 | int end = forward ? m_maxLength : -1; | - |
1292 | int step = forward ? 1 : -1; | - |
1293 | int i = pos; | - |
1294 | | - |
1295 | while (i != end) { | - |
1296 | if (findSeparator) { | - |
1297 | if (m_maskData[i].separator && m_maskData[i].maskChar == searchChar) | - |
1298 | return i; | - |
1299 | } else { | - |
1300 | if (!m_maskData[i].separator) { | - |
1301 | if (searchChar.isNull()) | - |
1302 | return i; | - |
1303 | else if (isValidInput(searchChar, m_maskData[i].maskChar)) | - |
1304 | return i; | - |
1305 | } | - |
1306 | } | - |
1307 | i += step; | - |
1308 | } | - |
1309 | return -1; | - |
1310 | } | - |
1311 | | - |
1312 | void QWidgetLineControl::internalUndo(int until) | - |
1313 | { | - |
1314 | if (!isUndoAvailable()) | - |
1315 | return; | - |
1316 | cancelPasswordEchoTimer(); | - |
1317 | internalDeselect(); | - |
1318 | | - |
1319 | while (m_undoState && m_undoState > until) { | - |
1320 | Command& cmd = m_history[--m_undoState]; | - |
1321 | switch (cmd.type) { | - |
1322 | case Insert: | - |
1323 | m_text.remove(cmd.pos, 1); | - |
1324 | m_cursor = cmd.pos; | - |
1325 | break; | - |
1326 | case SetSelection: | - |
1327 | m_selstart = cmd.selStart; | - |
1328 | m_selend = cmd.selEnd; | - |
1329 | m_cursor = cmd.pos; | - |
1330 | break; | - |
1331 | case Remove: | - |
1332 | case RemoveSelection: | - |
1333 | m_text.insert(cmd.pos, cmd.uc); | - |
1334 | m_cursor = cmd.pos + 1; | - |
1335 | break; | - |
1336 | case Delete: | - |
1337 | case DeleteSelection: | - |
1338 | m_text.insert(cmd.pos, cmd.uc); | - |
1339 | m_cursor = cmd.pos; | - |
1340 | break; | - |
1341 | case Separator: | - |
1342 | continue; | - |
1343 | } | - |
1344 | if (until < 0 && m_undoState) { | - |
1345 | Command& next = m_history[m_undoState-1]; | - |
1346 | if (next.type != cmd.type && next.type < RemoveSelection | - |
1347 | && (cmd.type < RemoveSelection || next.type == Separator)) | - |
1348 | break; | - |
1349 | } | - |
1350 | } | - |
1351 | m_textDirty = true; | - |
1352 | emitCursorPositionChanged(); | - |
1353 | } | - |
1354 | | - |
1355 | void QWidgetLineControl::internalRedo() | - |
1356 | { | - |
1357 | if (!isRedoAvailable()) | - |
1358 | return; | - |
1359 | internalDeselect(); | - |
1360 | while (m_undoState < (int)m_history.size()) { | - |
1361 | Command& cmd = m_history[m_undoState++]; | - |
1362 | switch (cmd.type) { | - |
1363 | case Insert: | - |
1364 | m_text.insert(cmd.pos, cmd.uc); | - |
1365 | m_cursor = cmd.pos + 1; | - |
1366 | break; | - |
1367 | case SetSelection: | - |
1368 | m_selstart = cmd.selStart; | - |
1369 | m_selend = cmd.selEnd; | - |
1370 | m_cursor = cmd.pos; | - |
1371 | break; | - |
1372 | case Remove: | - |
1373 | case Delete: | - |
1374 | case RemoveSelection: | - |
1375 | case DeleteSelection: | - |
1376 | m_text.remove(cmd.pos, 1); | - |
1377 | m_selstart = cmd.selStart; | - |
1378 | m_selend = cmd.selEnd; | - |
1379 | m_cursor = cmd.pos; | - |
1380 | break; | - |
1381 | case Separator: | - |
1382 | m_selstart = cmd.selStart; | - |
1383 | m_selend = cmd.selEnd; | - |
1384 | m_cursor = cmd.pos; | - |
1385 | break; | - |
1386 | } | - |
1387 | if (m_undoState < (int)m_history.size()) { | - |
1388 | Command& next = m_history[m_undoState]; | - |
1389 | if (next.type != cmd.type && cmd.type < RemoveSelection && next.type != Separator | - |
1390 | && (next.type < RemoveSelection || cmd.type == Separator)) | - |
1391 | break; | - |
1392 | } | - |
1393 | } | - |
1394 | m_textDirty = true; | - |
1395 | emitCursorPositionChanged(); | - |
1396 | } | - |
1397 | | - |
1398 | | - |
1399 | | - |
1400 | | - |
1401 | | - |
1402 | | - |
1403 | | - |
1404 | void QWidgetLineControl::emitCursorPositionChanged() | - |
1405 | { | - |
1406 | if (m_cursor != m_lastCursorPos) { | - |
1407 | const int oldLast = m_lastCursorPos; | - |
1408 | m_lastCursorPos = m_cursor; | - |
1409 | cursorPositionChanged(oldLast, m_cursor); | - |
1410 | #ifndef QT_NO_ACCESSIBILITY | - |
1411 | | - |
1412 | if (!hasSelectedText()) { | - |
1413 | QAccessibleTextCursorEvent event(accessibleObject(), m_cursor); | - |
1414 | QAccessible::updateAccessibility(&event); | - |
1415 | } | - |
1416 | #endif | - |
1417 | } | - |
1418 | } | - |
1419 | | - |
1420 | #ifndef QT_NO_COMPLETER | - |
1421 | | - |
1422 | | - |
1423 | bool QWidgetLineControl::advanceToEnabledItem(int dir) | - |
1424 | { | - |
1425 | int start = m_completer->currentRow(); | - |
1426 | if (start == -1) | - |
1427 | return false; | - |
1428 | int i = start + dir; | - |
1429 | if (dir == 0) dir = 1; | - |
1430 | do { | - |
1431 | if (!m_completer->setCurrentRow(i)) { | - |
1432 | if (!m_completer->wrapAround()) | - |
1433 | break; | - |
1434 | i = i > 0 ? 0 : m_completer->completionCount() - 1; | - |
1435 | } else { | - |
1436 | QModelIndex currentIndex = m_completer->currentIndex(); | - |
1437 | if (m_completer->completionModel()->flags(currentIndex) & Qt::ItemIsEnabled) | - |
1438 | return true; | - |
1439 | i += dir; | - |
1440 | } | - |
1441 | } while (i != start); | - |
1442 | | - |
1443 | m_completer->setCurrentRow(start); | - |
1444 | return false; | - |
1445 | } | - |
1446 | | - |
1447 | void QWidgetLineControl::complete(int key) | - |
1448 | { | - |
1449 | if (!m_completer || isReadOnly() || echoMode() != QLineEdit::Normal) | - |
1450 | return; | - |
1451 | | - |
1452 | QString text = this->text(); | - |
1453 | if (m_completer->completionMode() == QCompleter::InlineCompletion) { | - |
1454 | if (key == Qt::Key_Backspace) | - |
1455 | return; | - |
1456 | int n = 0; | - |
1457 | if (key == Qt::Key_Up || key == Qt::Key_Down) { | - |
1458 | if (textAfterSelection().length()) | - |
1459 | return; | - |
1460 | QString prefix = hasSelectedText() ? textBeforeSelection() | - |
1461 | : text; | - |
1462 | if (text.compare(m_completer->currentCompletion(), m_completer->caseSensitivity()) != 0 | - |
1463 | || prefix.compare(m_completer->completionPrefix(), m_completer->caseSensitivity()) != 0) { | - |
1464 | m_completer->setCompletionPrefix(prefix); | - |
1465 | } else { | - |
1466 | n = (key == Qt::Key_Up) ? -1 : +1; | - |
1467 | } | - |
1468 | } else { | - |
1469 | m_completer->setCompletionPrefix(text); | - |
1470 | } | - |
1471 | if (!advanceToEnabledItem(n)) | - |
1472 | return; | - |
1473 | } else { | - |
1474 | #ifndef QT_KEYPAD_NAVIGATION | - |
1475 | if (text.isEmpty()) { | - |
1476 | m_completer->popup()->hide(); | - |
1477 | return; | - |
1478 | } | - |
1479 | #endif | - |
1480 | m_completer->setCompletionPrefix(text); | - |
1481 | } | - |
1482 | | - |
1483 | m_completer->complete(); | - |
1484 | } | - |
1485 | #endif | - |
1486 | | - |
1487 | void QWidgetLineControl::setReadOnly(bool enable) | - |
1488 | { | - |
1489 | if (m_readOnly == enable)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1490 | return; never executed: return; | 0 |
1491 | | - |
1492 | m_readOnly = enable; | - |
1493 | updateCursorBlinking(); | - |
1494 | } never executed: end of block | 0 |
1495 | | - |
1496 | void QWidgetLineControl::setBlinkingCursorEnabled(bool enable) | - |
1497 | { | - |
1498 | if (m_blinkEnabled == enable)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1499 | setCursorBlinkPeriodreturn; never executed: return; | 0 |
1500 | | - |
1501 | m_blinkEnabled = enable; | - |
1502 | | - |
1503 | ifTRUE | never evaluated | FALSE | never evaluated |
(0enable)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1504 | connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking); );never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking); | 0 |
1505 | else | - |
1506 | setCursorBlinkPerioddisconnect(QApplicationqApp->styleHints(), &QStyleHints::cursorFlashTime());cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking); never executed: disconnect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking); | 0 |
1507 | | - |
1508 | updateCursorBlinking(); | - |
1509 | } never executed: end of block | 0 |
1510 | | - |
1511 | void QWidgetLineControl::setCursorBlinkPeriod(int msec)updateCursorBlinking() | - |
1512 | { | - |
1513 | if (msec == m_blinkPeriod)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| return;TRUE | never evaluated | FALSE | never evaluated |
if (m_blinkTimer) {TRUE | never evaluated | FALSE | never evaluated |
| |
1514 | killTimer(m_blinkTimer); | - |
1515 | m_blinkTimer = 0; | - |
1516 | } never executed: end of block | 0 |
1517 | | - |
1518 | if (msec > 0m_blinkEnabled && !m_readOnly) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1519 | int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); | - |
1520 | if (flashTime >= 2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1521 | m_blinkTimer = startTimer(msecflashTime / 2); never executed: m_blinkTimer = startTimer(flashTime / 2); | 0 |
1522 | } never executed: end of block | 0 |
1523 | | - |
1524 | m_blinkStatus = 1; | - |
| } else { | |
| m_blinkTimer = 0; | |
1525 | if (m_blinkStatus == 1)emit updateNeeded(inputMask().isEmpty() ? cursorRect() : QRect()); | - |
| } never executed: end of block | |
| m_blinkPeriod = msec; never executed: end of block }never executed: end of block | |
1527 | | - |
1528 | | - |
1529 | void QWidgetLineControl::resetCursorBlinkTimer() | - |
1530 | { | - |
1531 | if (m_blinkPeriod == 0(!m_blinkEnabled || m_blinkTimer == 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1532 | return; never executed: return; | 0 |
1533 | killTimer(m_blinkTimer); | - |
1534 | m_blinkTimer = 0; | - |
1535 | int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); | - |
1536 | if (flashTime >= 2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1537 | m_blinkTimer = startTimer(m_blinkPeriodflashTime / 2); never executed: m_blinkTimer = startTimer(flashTime / 2); | 0 |
1538 | m_blinkStatus = 1; | - |
1539 | } never executed: end of block | 0 |
1540 | | - |
1541 | void QWidgetLineControl::timerEvent(QTimerEvent *event) | - |
1542 | { | - |
1543 | if (event->timerId() == m_blinkTimer) { | - |
1544 | m_blinkStatus = !m_blinkStatus; | - |
1545 | emit updateNeeded(inputMask().isEmpty() ? cursorRect() : QRect()); | - |
1546 | } else if (event->timerId() == m_deleteAllTimer) { | - |
1547 | killTimer(m_deleteAllTimer); | - |
1548 | m_deleteAllTimer = 0; | - |
1549 | clear(); | - |
1550 | } else if (event->timerId() == m_tripleClickTimer) { | - |
1551 | killTimer(m_tripleClickTimer); | - |
1552 | m_tripleClickTimer = 0; | - |
1553 | } else if (event->timerId() == m_passwordEchoTimer) { | - |
1554 | killTimer(m_passwordEchoTimer); | - |
1555 | m_passwordEchoTimer = 0; | - |
1556 | updateDisplayText(); | - |
1557 | } | - |
1558 | } | - |
1559 | | - |
1560 | #ifndef QT_NO_SHORTCUT | - |
1561 | void QWidgetLineControl::processShortcutOverrideEvent(QKeyEvent *ke) | - |
1562 | { | - |
1563 | if (isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| return;TRUE | never evaluated | FALSE | never evaluated |
if (ke == QKeySequence::CopyTRUE | never evaluated | FALSE | never evaluated |
| |
1564 | || ke == QKeySequence::PasteMoveToNextWordTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1565 | || ke == QKeySequence::CutMoveToPreviousWordTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1566 | || ke == QKeySequence::RedoMoveToStartOfLineTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1567 | || ke == QKeySequence::UndoMoveToEndOfLineTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1568 | || ke == QKeySequence::MoveToNextWordMoveToStartOfDocumentTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1569 | || ke == QKeySequence::MoveToPreviousWordMoveToEndOfDocumentTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1570 | || ke == QKeySequence::MoveToStartOfLineSelectNextWordTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1571 | || ke == QKeySequence::MoveToEndOfLineSelectPreviousWordTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1572 | || ke == QKeySequence::MoveToStartOfDocumentSelectStartOfLineTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1573 | || ke == QKeySequence::MoveToEndOfDocumentSelectEndOfLineTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1574 | || ke == QKeySequence::SelectNextWordSelectStartOfBlockTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1575 | || ke == QKeySequence::SelectPreviousWordSelectEndOfBlockTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1576 | || ke == QKeySequence::SelectStartOfLineSelectStartOfDocumentTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1577 | || ke == QKeySequence::SelectEndOfLineSelectAllTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1578 | || ke == QKeySequence::SelectStartOfBlockTRUE | never evaluated | FALSE | never evaluated |
| 0 |
| ||TRUE | never evaluated | FALSE | never evaluated |
SelectEndOfDocument) {TRUE | never evaluated | FALSE | never evaluated |
| |
1579 | ke->accept(); | - |
1580 | } else if ( never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
ke == QKeySequence::SelectEndOfBlockPastenever executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1581 | || ke == QKeySequence::SelectStartOfDocumentCutTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1582 | || ke == QKeySequence::SelectAllRedoTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1583 | || ke == QKeySequence::SelectEndOfDocumentUndoTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1584 | || ke == QKeySequence::DeleteCompleteLine) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1585 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1586 | ke->accept(); never executed: ke->accept(); | 0 |
1587 | } else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1588 | || ke->modifiers() == Qt::KeypadModifier) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1589 | if (ke->key() < Qt::Key_Escape) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1590 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1591 | ke->accept(); never executed: ke->accept(); | 0 |
1592 | } else { never executed: end of block | 0 |
1593 | switch (ke->key()) { | - |
1594 | case Qt::Key_Delete: never executed: case Qt::Key_Delete: | 0 |
1595 | case Qt::Key_HomeKey_Backspace: never executed: case Qt::Key_Backspace: | 0 |
1596 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1597 | ke->accept(); never executed: ke->accept(); | 0 |
1598 | break; never executed: break; | 0 |
1599 | | - |
1600 | case Qt::Key_EndKey_Home: never executed: case Qt::Key_Home: | 0 |
1601 | case Qt::Key_BackspaceKey_End: never executed: case Qt::Key_End: | 0 |
1602 | case Qt::Key_Left: never executed: case Qt::Key_Left: | 0 |
1603 | case Qt::Key_Right: never executed: case Qt::Key_Right: | 0 |
1604 | ke->accept(); | - |
1605 | break; never executed: break; | 0 |
1606 | | - |
1607 | default: never executed: default: | 0 |
1608 | break; never executed: break; | 0 |
1609 | } | - |
1610 | } | - |
1611 | } | - |
1612 | } never executed: end of block | 0 |
1613 | #endif | - |
1614 | | - |
1615 | void QWidgetLineControl::processKeyEvent(QKeyEvent* event) | - |
1616 | { | - |
1617 | bool inlineCompletionAccepted = false; | - |
1618 | | - |
1619 | #ifndef QT_NO_COMPLETER | - |
1620 | if (m_completer) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1621 | QCompleter::CompletionMode completionMode = m_completer->completionMode(); | - |
1622 | if ((completionMode == QCompleter::PopupCompletionTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1623 | || completionMode == QCompleter::UnfilteredPopupCompletion)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1624 | && m_completer->popup()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1625 | && m_completer->popup()->isVisible()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1626 | | - |
1627 | | - |
1628 | switch (event->key()) { | - |
1629 | case Qt::Key_Escape: never executed: case Qt::Key_Escape: | 0 |
1630 | event->ignore(); | - |
1631 | return; never executed: return; | 0 |
1632 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 |
1633 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 |
1634 | case Qt::Key_F4: never executed: case Qt::Key_F4: | 0 |
1635 | #ifdef QT_KEYPAD_NAVIGATION | - |
1636 | case Qt::Key_Select: | - |
1637 | if (!QApplication::keypadNavigationEnabled()) | - |
1638 | break; | - |
1639 | #endif | - |
1640 | m_completer->popup()->hide(); | - |
1641 | default: code before this statement never executed: default: never executed: default: | 0 |
1642 | break; never executed: break; | 0 |
1643 | } | - |
1644 | } else if (completionMode == QCompleter::InlineCompletion) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1645 | switch (event->key()) { | - |
1646 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 |
1647 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 |
1648 | case Qt::Key_F4: never executed: case Qt::Key_F4: | 0 |
1649 | #ifdef QT_KEYPAD_NAVIGATION | - |
1650 | case Qt::Key_Select: | - |
1651 | if (!QApplication::keypadNavigationEnabled()) | - |
1652 | break; | - |
1653 | #endif | - |
1654 | if (!m_completer->currentCompletion().isEmpty() && hasSelectedText()TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1655 | && textAfterSelection().isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1656 | setText(m_completer->currentCompletion()); | - |
1657 | inlineCompletionAccepted = true; | - |
1658 | } never executed: end of block | 0 |
1659 | default: code before this statement never executed: default: never executed: default: | 0 |
1660 | break; never executed: break; | 0 |
1661 | } | - |
1662 | } | - |
1663 | } never executed: end of block | 0 |
1664 | #endif // QT_NO_COMPLETER | - |
1665 | | - |
1666 | if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1667 | if (hasAcceptableInput() || fixup()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1668 | | - |
1669 | QInputMethod *inputMethod = QApplication::inputMethod(); | - |
1670 | inputMethod->commit(); | - |
1671 | QWidget *lineEdit = qobject_cast<QWidget *>(parent()); | - |
1672 | if (!(lineEdit && lineEdit->inputMethodHints() & Qt::ImhMultiLine))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1673 | inputMethod->hide(); never executed: inputMethod->hide(); | 0 |
1674 | | - |
1675 | emit accepted(); | - |
1676 | emit editingFinished(); | - |
1677 | } never executed: end of block | 0 |
1678 | if (inlineCompletionAccepted)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1679 | event->accept(); never executed: event->accept(); | 0 |
1680 | else | - |
1681 | event->ignore(); never executed: event->ignore(); | 0 |
1682 | return; never executed: return; | 0 |
1683 | } | - |
1684 | | - |
1685 | if (echoMode() == QLineEdit::PasswordEchoOnEditTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1686 | && !passwordEchoEditing()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1687 | && !isReadOnly()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1688 | && !event->text().isEmpty()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1689 | #ifdef QT_KEYPAD_NAVIGATION | - |
1690 | && event->key() != Qt::Key_Select | - |
1691 | && event->key() != Qt::Key_Up | - |
1692 | && event->key() != Qt::Key_Down | - |
1693 | && event->key() != Qt::Key_Back | - |
1694 | #endif | - |
1695 | && !(event->modifiers() & Qt::ControlModifier)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1696 | | - |
1697 | | - |
1698 | | - |
1699 | | - |
1700 | | - |
1701 | updatePasswordEchoEditing(true); | - |
1702 | clear(); | - |
1703 | } never executed: end of block | 0 |
1704 | | - |
1705 | bool unknown = false; | - |
1706 | bool visual = cursorMoveStyle() == Qt::VisualMoveStyle; | - |
1707 | | - |
1708 | if (false) { dead code: { } | - |
1709 | } dead code: { } | - |
1710 | #ifndef QT_NO_SHORTCUT | - |
1711 | else if (event == QKeySequence::Undo) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1712 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1713 | undo(); never executed: undo(); | 0 |
1714 | } never executed: end of block | 0 |
1715 | else if (event == QKeySequence::Redo) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1716 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1717 | redo(); never executed: redo(); | 0 |
1718 | } never executed: end of block | 0 |
1719 | else if (event == QKeySequence::SelectAll) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1720 | selectAll(); | - |
1721 | } never executed: end of block | 0 |
1722 | #ifndef QT_NO_CLIPBOARD | - |
1723 | else if (event == QKeySequence::Copy) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1724 | copy(); | - |
1725 | } never executed: end of block | 0 |
1726 | else if (event == QKeySequence::Paste) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1727 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1728 | QClipboard::Mode mode = QClipboard::Clipboard; | - |
1729 | if (m_keyboardScheme == QPlatformTheme::X11KeyboardSchemeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1730 | && event->modifiers() == (Qt::CTRL | Qt::SHIFT)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1731 | && event->key() == Qt::Key_Insert) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1732 | mode = QClipboard::Selection; | - |
1733 | } never executed: end of block | 0 |
1734 | paste(mode); | - |
1735 | } never executed: end of block | 0 |
1736 | } never executed: end of block | 0 |
1737 | else if (event == QKeySequence::Cut) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1738 | if (!isReadOnly() && hasSelectedText()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1739 | copy(); | - |
1740 | del(); | - |
1741 | } never executed: end of block | 0 |
1742 | } never executed: end of block | 0 |
1743 | else if (event == QKeySequence::DeleteEndOfLine) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1744 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1745 | setSelection(cursor(), end()); | - |
1746 | copy(); | - |
1747 | del(); | - |
1748 | } never executed: end of block | 0 |
1749 | } never executed: end of block | 0 |
1750 | #endif //QT_NO_CLIPBOARD | - |
1751 | else if (event == QKeySequence::MoveToStartOfLine || event == QKeySequence::MoveToStartOfBlock) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1752 | home(0); | - |
1753 | } never executed: end of block | 0 |
1754 | else if (event == QKeySequence::MoveToEndOfLine || event == QKeySequence::MoveToEndOfBlock) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1755 | end(0); | - |
1756 | } never executed: end of block | 0 |
1757 | else if (event == QKeySequence::SelectStartOfLine || event == QKeySequence::SelectStartOfBlock) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1758 | home(1); | - |
1759 | } never executed: end of block | 0 |
1760 | else if (event == QKeySequence::SelectEndOfLine || event == QKeySequence::SelectEndOfBlock) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1761 | end(1); | - |
1762 | } never executed: end of block | 0 |
1763 | else if (event == QKeySequence::MoveToNextChar) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1764 | #if defined(QT_NO_COMPLETER) | - |
1765 | const bool inlineCompletion = false; | - |
1766 | #else | - |
1767 | const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion;TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1768 | #endif | - |
1769 | if (hasSelectedText()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1770 | && (m_keyboardScheme != QPlatformTheme::WindowsKeyboardSchemeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1771 | || inlineCompletion)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1772 | moveCursor(selectionEnd(), false); | - |
1773 | } else { never executed: end of block | 0 |
1774 | cursorForward(0, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1)); | - |
1775 | } never executed: end of block | 0 |
1776 | } | - |
1777 | else if (event == QKeySequence::SelectNextChar) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1778 | cursorForward(1, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1)); | - |
1779 | } never executed: end of block | 0 |
1780 | else if (event == QKeySequence::MoveToPreviousChar) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1781 | #if defined(QT_NO_COMPLETER) | - |
1782 | const bool inlineCompletion = false; | - |
1783 | #else | - |
1784 | const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion;TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1785 | #endif | - |
1786 | if (hasSelectedText()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1787 | && (m_keyboardScheme != QPlatformTheme::WindowsKeyboardSchemeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1788 | || inlineCompletion)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1789 | moveCursor(selectionStart(), false); | - |
1790 | } else { never executed: end of block | 0 |
1791 | cursorForward(0, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1)); | - |
1792 | } never executed: end of block | 0 |
1793 | } | - |
1794 | else if (event == QKeySequence::SelectPreviousChar) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1795 | cursorForward(1, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1)); | - |
1796 | } never executed: end of block | 0 |
1797 | else if (event == QKeySequence::MoveToNextWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1798 | if (echoMode() == QLineEdit::Normal)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1799 | layoutDirection() == Qt::LeftToRight ? cursorWordForward(0) : cursorWordBackward(0); never executed: layoutDirection() == Qt::LeftToRight ? cursorWordForward(0) : cursorWordBackward(0); | 0 |
1800 | else | - |
1801 | layoutDirection() == Qt::LeftToRight ? end(0) : home(0); never executed: layoutDirection() == Qt::LeftToRight ? end(0) : home(0); | 0 |
1802 | } | - |
1803 | else if (event == QKeySequence::MoveToPreviousWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1804 | if (echoMode() == QLineEdit::Normal)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1805 | layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0); never executed: layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0); | 0 |
1806 | else if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1807 | layoutDirection() == Qt::LeftToRight ? home(0) : end(0); | - |
1808 | } never executed: end of block | 0 |
1809 | } never executed: end of block | 0 |
1810 | else if (event == QKeySequence::SelectNextWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1811 | if (echoMode() == QLineEdit::Normal)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1812 | layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1); never executed: layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1); | 0 |
1813 | else | - |
1814 | layoutDirection() == Qt::LeftToRight ? end(1) : home(1); never executed: layoutDirection() == Qt::LeftToRight ? end(1) : home(1); | 0 |
1815 | } | - |
1816 | else if (event == QKeySequence::SelectPreviousWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1817 | if (echoMode() == QLineEdit::Normal)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1818 | layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1); never executed: layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1); | 0 |
1819 | else | - |
1820 | layoutDirection() == Qt::LeftToRight ? home(1) : end(1); never executed: layoutDirection() == Qt::LeftToRight ? home(1) : end(1); | 0 |
1821 | } | - |
1822 | else if (event == QKeySequence::Delete) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1823 | if (!isReadOnly())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1824 | del(); never executed: del(); | 0 |
1825 | } never executed: end of block | 0 |
1826 | else if (event == QKeySequence::DeleteEndOfWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1827 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1828 | cursorWordForward(true); | - |
1829 | del(); | - |
1830 | } never executed: end of block | 0 |
1831 | } never executed: end of block | 0 |
1832 | else if (event == QKeySequence::DeleteStartOfWord) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1833 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1834 | cursorWordBackward(true); | - |
1835 | del(); | - |
1836 | } never executed: end of block | 0 |
1837 | } else if (event == QKeySequence::DeleteCompleteLine) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1838 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1839 | setSelection(0, text().size()); | - |
1840 | #ifndef QT_NO_CLIPBOARD | - |
1841 | copy(); | - |
1842 | #endif | - |
1843 | del(); | - |
1844 | } never executed: end of block | 0 |
1845 | } never executed: end of block | 0 |
1846 | #endif // QT_NO_SHORTCUT | - |
1847 | else { | - |
1848 | bool handled = false; | - |
1849 | if (m_keyboardScheme == QPlatformTheme::MacKeyboardSchemeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1850 | && (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1851 | Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier); | - |
1852 | if (myModifiers & Qt::ShiftModifier) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1853 | if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1854 | || myModifiers == (Qt::AltModifier|Qt::ShiftModifier)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1855 | || myModifiers == Qt::ShiftModifier) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1856 | | - |
1857 | event->key() == Qt::Key_Up ? home(1) : end(1); | - |
1858 | } never executed: end of block | 0 |
1859 | } else { never executed: end of block | 0 |
1860 | if ((myModifiers == Qt::ControlModifierTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1861 | || myModifiers == Qt::AltModifierTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1862 | || myModifiers == Qt::NoModifier)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1863 | event->key() == Qt::Key_Up ? home(0) : end(0); | - |
1864 | } never executed: end of block | 0 |
1865 | } never executed: end of block | 0 |
1866 | handled = true; | - |
1867 | } never executed: end of block | 0 |
1868 | if (event->modifiers() & Qt::ControlModifier) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1869 | switch (event->key()) { | - |
1870 | case Qt::Key_Backspace: never executed: case Qt::Key_Backspace: | 0 |
1871 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1872 | cursorWordBackward(true); | - |
1873 | del(); | - |
1874 | } never executed: end of block | 0 |
1875 | break; never executed: break; | 0 |
1876 | #ifndef QT_NO_COMPLETER | - |
1877 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 |
1878 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 |
1879 | complete(event->key()); | - |
1880 | break; never executed: break; | 0 |
1881 | #endif | - |
1882 | default: never executed: default: | 0 |
1883 | if (!handled)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1884 | unknown = true; never executed: unknown = true; | 0 |
1885 | } never executed: end of block | 0 |
1886 | } else { | - |
1887 | switch (event->key()) { | - |
1888 | case Qt::Key_Backspace: never executed: case Qt::Key_Backspace: | 0 |
1889 | if (!isReadOnly()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1890 | backspace(); | - |
1891 | #ifndef QT_NO_COMPLETER | - |
1892 | complete(Qt::Key_Backspace); | - |
1893 | #endif | - |
1894 | } never executed: end of block | 0 |
1895 | break; never executed: break; | 0 |
1896 | #ifdef QT_KEYPAD_NAVIGATION | - |
1897 | case Qt::Key_Back: | - |
1898 | if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat() | - |
1899 | && !isReadOnly()) { | - |
1900 | if (text().length() == 0) { | - |
1901 | setText(m_cancelText); | - |
1902 | | - |
1903 | if (passwordEchoEditing()) | - |
1904 | updatePasswordEchoEditing(false); | - |
1905 | | - |
1906 | emit editFocusChange(false); | - |
1907 | } else if (!m_deleteAllTimer) { | - |
1908 | m_deleteAllTimer = startTimer(750); | - |
1909 | } | - |
1910 | } else { | - |
1911 | unknown = true; | - |
1912 | } | - |
1913 | break; | - |
1914 | #endif | - |
1915 | default: never executed: default: | 0 |
1916 | if (!handled)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1917 | unknown = true; never executed: unknown = true; | 0 |
1918 | } never executed: end of block | 0 |
1919 | } | - |
1920 | } | - |
1921 | | - |
1922 | if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1923 | setLayoutDirection((event->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft); | - |
1924 | unknown = false; | - |
1925 | } never executed: end of block | 0 |
1926 | | - |
1927 | | - |
1928 | if (unknown && !isReadOnly()TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1929 | && isAcceptableInput(event->modifiers() != Qt::ControlModifierTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1930 | &&TRUE | never evaluated | FALSE | never evaluated |
event->modifiers() != (Qt::ControlModifier | Qt::ShiftModifier)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1931 | insert(QString t = event->text());(); | - |
1932 | if (!t.isEmpty() && t.at(0).isPrint()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1933 | insert(t); | - |
1934 | #ifndef QT_NO_COMPLETER | - |
1935 | complete(event->key()); | - |
1936 | #endif | - |
1937 | event->accept(); | - |
1938 | return; never executed: return; | 0 |
1939 | } | - |
1940 | } never executed: end of block | 0 |
1941 | | - |
1942 | if (unknown)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1943 | event->ignore(); never executed: event->ignore(); | 0 |
1944 | else | - |
1945 | event->accept(); never executed: event->accept(); | 0 |
1946 | } | - |
1947 | | - |
1948 | bool QWidgetLineControl::isUndoAvailable() const | - |
1949 | { | - |
1950 | | - |
1951 | | - |
1952 | return !m_readOnly && m_undoState | - |
1953 | && (m_echoMode == QLineEdit::Normal || m_history[m_undoState - 1].type == QWidgetLineControl::Insert); | - |
1954 | } | - |
1955 | | - |
1956 | bool QWidgetLineControl::isRedoAvailable() const | - |
1957 | { | - |
1958 | | - |
1959 | return !m_readOnly | - |
1960 | && m_echoMode == QLineEdit::Normal | - |
1961 | && m_undoState < int(m_history.size()); | - |
1962 | } | - |
1963 | | - |
1964 | QT_END_NAMESPACE | - |
1965 | | - |
1966 | #include "moc_qwidgetlinecontrol_p.cpp" | - |
1967 | | - |
1968 | #endif | - |
| | |