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