Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qwidgettextcontrol.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||||||||||||||
24 | ** | - | ||||||||||||||||||||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||||||||||||||
35 | ** | - | ||||||||||||||||||||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||||||||
37 | ** | - | ||||||||||||||||||||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||||||||||||||
40 | #include "qwidgettextcontrol_p.h" | - | ||||||||||||||||||||||||||||||||||||
41 | #include "qwidgettextcontrol_p_p.h" | - | ||||||||||||||||||||||||||||||||||||
42 | - | |||||||||||||||||||||||||||||||||||||
43 | #ifndef QT_NO_TEXTCONTROL | - | ||||||||||||||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||||||||||||||
45 | #include <qfont.h> | - | ||||||||||||||||||||||||||||||||||||
46 | #include <qpainter.h> | - | ||||||||||||||||||||||||||||||||||||
47 | #include <qevent.h> | - | ||||||||||||||||||||||||||||||||||||
48 | #include <qdebug.h> | - | ||||||||||||||||||||||||||||||||||||
49 | #include <qdrag.h> | - | ||||||||||||||||||||||||||||||||||||
50 | #include <qclipboard.h> | - | ||||||||||||||||||||||||||||||||||||
51 | #include <qmenu.h> | - | ||||||||||||||||||||||||||||||||||||
52 | #include <qstyle.h> | - | ||||||||||||||||||||||||||||||||||||
53 | #include <qtimer.h> | - | ||||||||||||||||||||||||||||||||||||
54 | #include "private/qtextdocumentlayout_p.h" | - | ||||||||||||||||||||||||||||||||||||
55 | #include "private/qabstracttextdocumentlayout_p.h" | - | ||||||||||||||||||||||||||||||||||||
56 | #include "private/qtextedit_p.h" | - | ||||||||||||||||||||||||||||||||||||
57 | #include "qtextdocument.h" | - | ||||||||||||||||||||||||||||||||||||
58 | #include "private/qtextdocument_p.h" | - | ||||||||||||||||||||||||||||||||||||
59 | #include "qtextlist.h" | - | ||||||||||||||||||||||||||||||||||||
60 | #include "private/qwidgettextcontrol_p.h" | - | ||||||||||||||||||||||||||||||||||||
61 | #include "qgraphicssceneevent.h" | - | ||||||||||||||||||||||||||||||||||||
62 | #include "qpagedpaintdevice.h" | - | ||||||||||||||||||||||||||||||||||||
63 | #include "private/qpagedpaintdevice_p.h" | - | ||||||||||||||||||||||||||||||||||||
64 | #include "qtextdocumentwriter.h" | - | ||||||||||||||||||||||||||||||||||||
65 | #include "qstylehints.h" | - | ||||||||||||||||||||||||||||||||||||
66 | #include "private/qtextcursor_p.h" | - | ||||||||||||||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||||||||||||||
68 | #include <qtextformat.h> | - | ||||||||||||||||||||||||||||||||||||
69 | #include <qdatetime.h> | - | ||||||||||||||||||||||||||||||||||||
70 | #include <qbuffer.h> | - | ||||||||||||||||||||||||||||||||||||
71 | #include <qapplication.h> | - | ||||||||||||||||||||||||||||||||||||
72 | #include <limits.h> | - | ||||||||||||||||||||||||||||||||||||
73 | #include <qtexttable.h> | - | ||||||||||||||||||||||||||||||||||||
74 | #include <qvariant.h> | - | ||||||||||||||||||||||||||||||||||||
75 | #include <qurl.h> | - | ||||||||||||||||||||||||||||||||||||
76 | #include <qdesktopservices.h> | - | ||||||||||||||||||||||||||||||||||||
77 | #include <qinputmethod.h> | - | ||||||||||||||||||||||||||||||||||||
78 | #include <qtooltip.h> | - | ||||||||||||||||||||||||||||||||||||
79 | #include <qstyleoption.h> | - | ||||||||||||||||||||||||||||||||||||
80 | #include <QtWidgets/qlineedit.h> | - | ||||||||||||||||||||||||||||||||||||
81 | #include <QtGui/qaccessible.h> | - | ||||||||||||||||||||||||||||||||||||
82 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||||||||||||||
84 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
85 | #include "private/qapplication_p.h" | - | ||||||||||||||||||||||||||||||||||||
86 | #include "private/qshortcutmap_p.h" | - | ||||||||||||||||||||||||||||||||||||
87 | #include <qkeysequence.h> | - | ||||||||||||||||||||||||||||||||||||
88 | #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ | - | ||||||||||||||||||||||||||||||||||||
89 | QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) | - | ||||||||||||||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||||||||||||||
91 | #else | - | ||||||||||||||||||||||||||||||||||||
92 | #define ACCEL_KEY(k) QString() | - | ||||||||||||||||||||||||||||||||||||
93 | #endif | - | ||||||||||||||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||||||||||||||
95 | #include <algorithm> | - | ||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||
97 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||||||||||||||
99 | // could go into QTextCursor... | - | ||||||||||||||||||||||||||||||||||||
100 | static QTextLine currentTextLine(const QTextCursor &cursor) | - | ||||||||||||||||||||||||||||||||||||
101 | { | - | ||||||||||||||||||||||||||||||||||||
102 | const QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
103 | if (!block.isValid()) | - | ||||||||||||||||||||||||||||||||||||
104 | return QTextLine(); | - | ||||||||||||||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||||||||||||||
106 | const QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||||||||||||||
107 | if (!layout) | - | ||||||||||||||||||||||||||||||||||||
108 | return QTextLine(); | - | ||||||||||||||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||||||||||||||
110 | const int relativePos = cursor.position() - block.position(); | - | ||||||||||||||||||||||||||||||||||||
111 | return layout->lineForTextPosition(relativePos); | - | ||||||||||||||||||||||||||||||||||||
112 | } | - | ||||||||||||||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||||||||||||||
114 | QWidgetTextControlPrivate::QWidgetTextControlPrivate() | - | ||||||||||||||||||||||||||||||||||||
115 | : doc(0), cursorOn(false), cursorVisible(false), cursorIsFocusIndicator(false), | - | ||||||||||||||||||||||||||||||||||||
116 | #ifndef Q_OS_ANDROID | - | ||||||||||||||||||||||||||||||||||||
117 | interactionFlags(Qt::TextEditorInteraction), | - | ||||||||||||||||||||||||||||||||||||
118 | #else | - | ||||||||||||||||||||||||||||||||||||
119 | interactionFlags(Qt::TextEditable | Qt::TextSelectableByKeyboard), | - | ||||||||||||||||||||||||||||||||||||
120 | #endif | - | ||||||||||||||||||||||||||||||||||||
121 | dragEnabled(true), | - | ||||||||||||||||||||||||||||||||||||
122 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
123 | mousePressed(false), mightStartDrag(false), | - | ||||||||||||||||||||||||||||||||||||
124 | #endif | - | ||||||||||||||||||||||||||||||||||||
125 | lastSelectionPosition(0), lastSelectionAnchor(0), | - | ||||||||||||||||||||||||||||||||||||
126 | ignoreAutomaticScrollbarAdjustement(false), | - | ||||||||||||||||||||||||||||||||||||
127 | overwriteMode(false), | - | ||||||||||||||||||||||||||||||||||||
128 | acceptRichText(true), | - | ||||||||||||||||||||||||||||||||||||
129 | preeditCursor(0), hideCursor(false), | - | ||||||||||||||||||||||||||||||||||||
130 | hasFocus(false), | - | ||||||||||||||||||||||||||||||||||||
131 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
132 | hasEditFocus(false), | - | ||||||||||||||||||||||||||||||||||||
133 | #endif | - | ||||||||||||||||||||||||||||||||||||
134 | isEnabled(true), | - | ||||||||||||||||||||||||||||||||||||
135 | hadSelectionOnMousePress(false), | - | ||||||||||||||||||||||||||||||||||||
136 | ignoreUnusedNavigationEvents(false), | - | ||||||||||||||||||||||||||||||||||||
137 | openExternalLinks(false), | - | ||||||||||||||||||||||||||||||||||||
138 | wordSelectionEnabled(false) | - | ||||||||||||||||||||||||||||||||||||
139 | {} never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||||||||||||||
141 | bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||||||||||||||
142 | { | - | ||||||||||||||||||||||||||||||||||||
143 | #ifdef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
144 | Q_UNUSED(e); | - | ||||||||||||||||||||||||||||||||||||
145 | #endif | - | ||||||||||||||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||||||||||||||
147 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
148 | if (cursor.isNull()) | - | ||||||||||||||||||||||||||||||||||||
149 | return false; | - | ||||||||||||||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||||||||||||||
151 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
152 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||||||||||||||
154 | QTextCursor::MoveMode mode = QTextCursor::MoveAnchor; | - | ||||||||||||||||||||||||||||||||||||
155 | QTextCursor::MoveOperation op = QTextCursor::NoMove; | - | ||||||||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||||||||
157 | if (false) { dead code: { } | - | ||||||||||||||||||||||||||||||||||||
158 | } dead code: { } | - | ||||||||||||||||||||||||||||||||||||
159 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
160 | if (e == QKeySequence::MoveToNextChar) { | - | ||||||||||||||||||||||||||||||||||||
161 | op = QTextCursor::Right; | - | ||||||||||||||||||||||||||||||||||||
162 | } | - | ||||||||||||||||||||||||||||||||||||
163 | else if (e == QKeySequence::MoveToPreviousChar) { | - | ||||||||||||||||||||||||||||||||||||
164 | op = QTextCursor::Left; | - | ||||||||||||||||||||||||||||||||||||
165 | } | - | ||||||||||||||||||||||||||||||||||||
166 | else if (e == QKeySequence::SelectNextChar) { | - | ||||||||||||||||||||||||||||||||||||
167 | op = QTextCursor::Right; | - | ||||||||||||||||||||||||||||||||||||
168 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
169 | } | - | ||||||||||||||||||||||||||||||||||||
170 | else if (e == QKeySequence::SelectPreviousChar) { | - | ||||||||||||||||||||||||||||||||||||
171 | op = QTextCursor::Left; | - | ||||||||||||||||||||||||||||||||||||
172 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
173 | } | - | ||||||||||||||||||||||||||||||||||||
174 | else if (e == QKeySequence::SelectNextWord) { | - | ||||||||||||||||||||||||||||||||||||
175 | op = QTextCursor::WordRight; | - | ||||||||||||||||||||||||||||||||||||
176 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
177 | } | - | ||||||||||||||||||||||||||||||||||||
178 | else if (e == QKeySequence::SelectPreviousWord) { | - | ||||||||||||||||||||||||||||||||||||
179 | op = QTextCursor::WordLeft; | - | ||||||||||||||||||||||||||||||||||||
180 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
181 | } | - | ||||||||||||||||||||||||||||||||||||
182 | else if (e == QKeySequence::SelectStartOfLine) { | - | ||||||||||||||||||||||||||||||||||||
183 | op = QTextCursor::StartOfLine; | - | ||||||||||||||||||||||||||||||||||||
184 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
185 | } | - | ||||||||||||||||||||||||||||||||||||
186 | else if (e == QKeySequence::SelectEndOfLine) { | - | ||||||||||||||||||||||||||||||||||||
187 | op = QTextCursor::EndOfLine; | - | ||||||||||||||||||||||||||||||||||||
188 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
189 | } | - | ||||||||||||||||||||||||||||||||||||
190 | else if (e == QKeySequence::SelectStartOfBlock) { | - | ||||||||||||||||||||||||||||||||||||
191 | op = QTextCursor::StartOfBlock; | - | ||||||||||||||||||||||||||||||||||||
192 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
193 | } | - | ||||||||||||||||||||||||||||||||||||
194 | else if (e == QKeySequence::SelectEndOfBlock) { | - | ||||||||||||||||||||||||||||||||||||
195 | op = QTextCursor::EndOfBlock; | - | ||||||||||||||||||||||||||||||||||||
196 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
197 | } | - | ||||||||||||||||||||||||||||||||||||
198 | else if (e == QKeySequence::SelectStartOfDocument) { | - | ||||||||||||||||||||||||||||||||||||
199 | op = QTextCursor::Start; | - | ||||||||||||||||||||||||||||||||||||
200 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
201 | } | - | ||||||||||||||||||||||||||||||||||||
202 | else if (e == QKeySequence::SelectEndOfDocument) { | - | ||||||||||||||||||||||||||||||||||||
203 | op = QTextCursor::End; | - | ||||||||||||||||||||||||||||||||||||
204 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
205 | } | - | ||||||||||||||||||||||||||||||||||||
206 | else if (e == QKeySequence::SelectPreviousLine) { | - | ||||||||||||||||||||||||||||||||||||
207 | op = QTextCursor::Up; | - | ||||||||||||||||||||||||||||||||||||
208 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
209 | } | - | ||||||||||||||||||||||||||||||||||||
210 | else if (e == QKeySequence::SelectNextLine) { | - | ||||||||||||||||||||||||||||||||||||
211 | op = QTextCursor::Down; | - | ||||||||||||||||||||||||||||||||||||
212 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||||||||||||||
213 | { | - | ||||||||||||||||||||||||||||||||||||
214 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
215 | QTextLine line = currentTextLine(cursor); | - | ||||||||||||||||||||||||||||||||||||
216 | if (!block.next().isValid() | - | ||||||||||||||||||||||||||||||||||||
217 | && line.isValid() | - | ||||||||||||||||||||||||||||||||||||
218 | && line.lineNumber() == block.layout()->lineCount() - 1) | - | ||||||||||||||||||||||||||||||||||||
219 | op = QTextCursor::End; | - | ||||||||||||||||||||||||||||||||||||
220 | } | - | ||||||||||||||||||||||||||||||||||||
221 | } | - | ||||||||||||||||||||||||||||||||||||
222 | else if (e == QKeySequence::MoveToNextWord) { | - | ||||||||||||||||||||||||||||||||||||
223 | op = QTextCursor::WordRight; | - | ||||||||||||||||||||||||||||||||||||
224 | } | - | ||||||||||||||||||||||||||||||||||||
225 | else if (e == QKeySequence::MoveToPreviousWord) { | - | ||||||||||||||||||||||||||||||||||||
226 | op = QTextCursor::WordLeft; | - | ||||||||||||||||||||||||||||||||||||
227 | } | - | ||||||||||||||||||||||||||||||||||||
228 | else if (e == QKeySequence::MoveToEndOfBlock) { | - | ||||||||||||||||||||||||||||||||||||
229 | op = QTextCursor::EndOfBlock; | - | ||||||||||||||||||||||||||||||||||||
230 | } | - | ||||||||||||||||||||||||||||||||||||
231 | else if (e == QKeySequence::MoveToStartOfBlock) { | - | ||||||||||||||||||||||||||||||||||||
232 | op = QTextCursor::StartOfBlock; | - | ||||||||||||||||||||||||||||||||||||
233 | } | - | ||||||||||||||||||||||||||||||||||||
234 | else if (e == QKeySequence::MoveToNextLine) { | - | ||||||||||||||||||||||||||||||||||||
235 | op = QTextCursor::Down; | - | ||||||||||||||||||||||||||||||||||||
236 | } | - | ||||||||||||||||||||||||||||||||||||
237 | else if (e == QKeySequence::MoveToPreviousLine) { | - | ||||||||||||||||||||||||||||||||||||
238 | op = QTextCursor::Up; | - | ||||||||||||||||||||||||||||||||||||
239 | } | - | ||||||||||||||||||||||||||||||||||||
240 | else if (e == QKeySequence::MoveToStartOfLine) { | - | ||||||||||||||||||||||||||||||||||||
241 | op = QTextCursor::StartOfLine; | - | ||||||||||||||||||||||||||||||||||||
242 | } | - | ||||||||||||||||||||||||||||||||||||
243 | else if (e == QKeySequence::MoveToEndOfLine) { | - | ||||||||||||||||||||||||||||||||||||
244 | op = QTextCursor::EndOfLine; | - | ||||||||||||||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||||||||||||||
246 | else if (e == QKeySequence::MoveToStartOfDocument) { | - | ||||||||||||||||||||||||||||||||||||
247 | op = QTextCursor::Start; | - | ||||||||||||||||||||||||||||||||||||
248 | } | - | ||||||||||||||||||||||||||||||||||||
249 | else if (e == QKeySequence::MoveToEndOfDocument) { | - | ||||||||||||||||||||||||||||||||||||
250 | op = QTextCursor::End; | - | ||||||||||||||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||||||||||||||
252 | #endif // QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
253 | else { | - | ||||||||||||||||||||||||||||||||||||
254 | return false; | - | ||||||||||||||||||||||||||||||||||||
255 | } | - | ||||||||||||||||||||||||||||||||||||
256 | - | |||||||||||||||||||||||||||||||||||||
257 | // Except for pageup and pagedown, OS X has very different behavior, we don't do it all, but | - | ||||||||||||||||||||||||||||||||||||
258 | // here's the breakdown: | - | ||||||||||||||||||||||||||||||||||||
259 | // Shift still works as an anchor, but only one of the other keys can be down Ctrl (Command), | - | ||||||||||||||||||||||||||||||||||||
260 | // Alt (Option), or Meta (Control). | - | ||||||||||||||||||||||||||||||||||||
261 | // Command/Control + Left/Right -- Move to left or right of the line | - | ||||||||||||||||||||||||||||||||||||
262 | // + Up/Down -- Move to top bottom of the file. (Control doesn't move the cursor) | - | ||||||||||||||||||||||||||||||||||||
263 | // Option + Left/Right -- Move one word Left/right. | - | ||||||||||||||||||||||||||||||||||||
264 | // + Up/Down -- Begin/End of Paragraph. | - | ||||||||||||||||||||||||||||||||||||
265 | // Home/End Top/Bottom of file. (usually don't move the cursor, but will select) | - | ||||||||||||||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||||||||||||||
267 | bool visualNavigation = cursor.visualNavigation(); | - | ||||||||||||||||||||||||||||||||||||
268 | cursor.setVisualNavigation(true); | - | ||||||||||||||||||||||||||||||||||||
269 | const bool moved = cursor.movePosition(op, mode); | - | ||||||||||||||||||||||||||||||||||||
270 | cursor.setVisualNavigation(visualNavigation); | - | ||||||||||||||||||||||||||||||||||||
271 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
272 | - | |||||||||||||||||||||||||||||||||||||
273 | bool ignoreNavigationEvents = ignoreUnusedNavigationEvents; | - | ||||||||||||||||||||||||||||||||||||
274 | bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down; | - | ||||||||||||||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||||||||||||||
276 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
277 | ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled(); | - | ||||||||||||||||||||||||||||||||||||
278 | isNavigationEvent = isNavigationEvent || | - | ||||||||||||||||||||||||||||||||||||
279 | (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional | - | ||||||||||||||||||||||||||||||||||||
280 | && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)); | - | ||||||||||||||||||||||||||||||||||||
281 | #else | - | ||||||||||||||||||||||||||||||||||||
282 | isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right; | - | ||||||||||||||||||||||||||||||||||||
283 | #endif | - | ||||||||||||||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||||||||||||||
285 | if (moved) { | - | ||||||||||||||||||||||||||||||||||||
286 | if (cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
287 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
288 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
289 | } else if (ignoreNavigationEvents && isNavigationEvent && oldSelection.anchor() == cursor.anchor()) { | - | ||||||||||||||||||||||||||||||||||||
290 | return false; | - | ||||||||||||||||||||||||||||||||||||
291 | } | - | ||||||||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||||||||
293 | selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor)); | - | ||||||||||||||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||||||||||||||
295 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
296 | - | |||||||||||||||||||||||||||||||||||||
297 | return true; | - | ||||||||||||||||||||||||||||||||||||
298 | } | - | ||||||||||||||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||||||||||||||
300 | void QWidgetTextControlPrivate::updateCurrentCharFormat() | - | ||||||||||||||||||||||||||||||||||||
301 | { | - | ||||||||||||||||||||||||||||||||||||
302 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||||||||||||||
304 | QTextCharFormat fmt = cursor.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
305 | if (fmt == lastCharFormat) | - | ||||||||||||||||||||||||||||||||||||
306 | return; | - | ||||||||||||||||||||||||||||||||||||
307 | lastCharFormat = fmt; | - | ||||||||||||||||||||||||||||||||||||
308 | - | |||||||||||||||||||||||||||||||||||||
309 | emit q->currentCharFormatChanged(fmt); | - | ||||||||||||||||||||||||||||||||||||
310 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
311 | } | - | ||||||||||||||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||||||||||||||
313 | void QWidgetTextControlPrivate::indent() | - | ||||||||||||||||||||||||||||||||||||
314 | { | - | ||||||||||||||||||||||||||||||||||||
315 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||||||||||||||
317 | QTextList *list = cursor.currentList(); | - | ||||||||||||||||||||||||||||||||||||
318 | if (!list) { | - | ||||||||||||||||||||||||||||||||||||
319 | QTextBlockFormat modifier; | - | ||||||||||||||||||||||||||||||||||||
320 | modifier.setIndent(blockFmt.indent() + 1); | - | ||||||||||||||||||||||||||||||||||||
321 | cursor.mergeBlockFormat(modifier); | - | ||||||||||||||||||||||||||||||||||||
322 | } else { | - | ||||||||||||||||||||||||||||||||||||
323 | QTextListFormat format = list->format(); | - | ||||||||||||||||||||||||||||||||||||
324 | format.setIndent(format.indent() + 1); | - | ||||||||||||||||||||||||||||||||||||
325 | - | |||||||||||||||||||||||||||||||||||||
326 | if (list->itemNumber(cursor.block()) == 1) | - | ||||||||||||||||||||||||||||||||||||
327 | list->setFormat(format); | - | ||||||||||||||||||||||||||||||||||||
328 | else | - | ||||||||||||||||||||||||||||||||||||
329 | cursor.createList(format); | - | ||||||||||||||||||||||||||||||||||||
330 | } | - | ||||||||||||||||||||||||||||||||||||
331 | } | - | ||||||||||||||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||||||||||||||
333 | void QWidgetTextControlPrivate::outdent() | - | ||||||||||||||||||||||||||||||||||||
334 | { | - | ||||||||||||||||||||||||||||||||||||
335 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||||||||||||||
337 | QTextList *list = cursor.currentList(); | - | ||||||||||||||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||||||||||||||
339 | if (!list) { | - | ||||||||||||||||||||||||||||||||||||
340 | QTextBlockFormat modifier; | - | ||||||||||||||||||||||||||||||||||||
341 | modifier.setIndent(blockFmt.indent() - 1); | - | ||||||||||||||||||||||||||||||||||||
342 | cursor.mergeBlockFormat(modifier); | - | ||||||||||||||||||||||||||||||||||||
343 | } else { | - | ||||||||||||||||||||||||||||||||||||
344 | QTextListFormat listFmt = list->format(); | - | ||||||||||||||||||||||||||||||||||||
345 | listFmt.setIndent(listFmt.indent() - 1); | - | ||||||||||||||||||||||||||||||||||||
346 | list->setFormat(listFmt); | - | ||||||||||||||||||||||||||||||||||||
347 | } | - | ||||||||||||||||||||||||||||||||||||
348 | } | - | ||||||||||||||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||||||||||||||
350 | void QWidgetTextControlPrivate::gotoNextTableCell() | - | ||||||||||||||||||||||||||||||||||||
351 | { | - | ||||||||||||||||||||||||||||||||||||
352 | QTextTable *table = cursor.currentTable(); | - | ||||||||||||||||||||||||||||||||||||
353 | QTextTableCell cell = table->cellAt(cursor); | - | ||||||||||||||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||||||||||||||
355 | int newColumn = cell.column() + cell.columnSpan(); | - | ||||||||||||||||||||||||||||||||||||
356 | int newRow = cell.row(); | - | ||||||||||||||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||||||||||||||
358 | if (newColumn >= table->columns()) { | - | ||||||||||||||||||||||||||||||||||||
359 | newColumn = 0; | - | ||||||||||||||||||||||||||||||||||||
360 | ++newRow; | - | ||||||||||||||||||||||||||||||||||||
361 | if (newRow >= table->rows()) | - | ||||||||||||||||||||||||||||||||||||
362 | table->insertRows(table->rows(), 1); | - | ||||||||||||||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||||||||||||||
365 | cell = table->cellAt(newRow, newColumn); | - | ||||||||||||||||||||||||||||||||||||
366 | cursor = cell.firstCursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||||||||||||||
369 | void QWidgetTextControlPrivate::gotoPreviousTableCell() | - | ||||||||||||||||||||||||||||||||||||
370 | { | - | ||||||||||||||||||||||||||||||||||||
371 | QTextTable *table = cursor.currentTable(); | - | ||||||||||||||||||||||||||||||||||||
372 | QTextTableCell cell = table->cellAt(cursor); | - | ||||||||||||||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||||||||||||||
374 | int newColumn = cell.column() - 1; | - | ||||||||||||||||||||||||||||||||||||
375 | int newRow = cell.row(); | - | ||||||||||||||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||||||||||||||
377 | if (newColumn < 0) { | - | ||||||||||||||||||||||||||||||||||||
378 | newColumn = table->columns() - 1; | - | ||||||||||||||||||||||||||||||||||||
379 | --newRow; | - | ||||||||||||||||||||||||||||||||||||
380 | if (newRow < 0) | - | ||||||||||||||||||||||||||||||||||||
381 | return; | - | ||||||||||||||||||||||||||||||||||||
382 | } | - | ||||||||||||||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||||||||||||||
384 | cell = table->cellAt(newRow, newColumn); | - | ||||||||||||||||||||||||||||||||||||
385 | cursor = cell.firstCursorPosition(); | - | ||||||||||||||||||||||||||||||||||||
386 | } | - | ||||||||||||||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||||||||||||||
388 | void QWidgetTextControlPrivate::createAutoBulletList() | - | ||||||||||||||||||||||||||||||||||||
389 | { | - | ||||||||||||||||||||||||||||||||||||
390 | cursor.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||||||||||||||
392 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||||||||||||||
394 | QTextListFormat listFmt; | - | ||||||||||||||||||||||||||||||||||||
395 | listFmt.setStyle(QTextListFormat::ListDisc); | - | ||||||||||||||||||||||||||||||||||||
396 | listFmt.setIndent(blockFmt.indent() + 1); | - | ||||||||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||||||||
398 | blockFmt.setIndent(0); | - | ||||||||||||||||||||||||||||||||||||
399 | cursor.setBlockFormat(blockFmt); | - | ||||||||||||||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||||||||||||||
401 | cursor.createList(listFmt); | - | ||||||||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||||||||
403 | cursor.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
404 | } | - | ||||||||||||||||||||||||||||||||||||
405 | - | |||||||||||||||||||||||||||||||||||||
406 | void QWidgetTextControlPrivate::init(Qt::TextFormat format, const QString &text, QTextDocument *document) | - | ||||||||||||||||||||||||||||||||||||
407 | { | - | ||||||||||||||||||||||||||||||||||||
408 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
409 | setContent(format, text, document); | - | ||||||||||||||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||||||||||||||
411 | doc->setUndoRedoEnabled(interactionFlags & Qt::TextEditable); | - | ||||||||||||||||||||||||||||||||||||
412 | q->setCursorWidth(-1); | - | ||||||||||||||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||||||||||||||
415 | void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString &text, QTextDocument *document) | - | ||||||||||||||||||||||||||||||||||||
416 | { | - | ||||||||||||||||||||||||||||||||||||
417 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||||||||
419 | // for use when called from setPlainText. we may want to re-use the currently | - | ||||||||||||||||||||||||||||||||||||
420 | // set char format then. | - | ||||||||||||||||||||||||||||||||||||
421 | const QTextCharFormat charFormatForInsertion = cursor.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||||||||||||||
423 | bool clearDocument = true; | - | ||||||||||||||||||||||||||||||||||||
424 | if (!doc) { | - | ||||||||||||||||||||||||||||||||||||
425 | if (document) { | - | ||||||||||||||||||||||||||||||||||||
426 | doc = document; | - | ||||||||||||||||||||||||||||||||||||
427 | clearDocument = false; | - | ||||||||||||||||||||||||||||||||||||
428 | } else { | - | ||||||||||||||||||||||||||||||||||||
429 | palette = QApplication::palette("QWidgetTextControl"); | - | ||||||||||||||||||||||||||||||||||||
430 | doc = new QTextDocument(q); | - | ||||||||||||||||||||||||||||||||||||
431 | } | - | ||||||||||||||||||||||||||||||||||||
432 | _q_documentLayoutChanged(); | - | ||||||||||||||||||||||||||||||||||||
433 | cursor = QTextCursor(doc); | - | ||||||||||||||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||||||||||||||
435 | // #### doc->documentLayout()->setPaintDevice(viewport); | - | ||||||||||||||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||||||||||||||
437 | QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection())); | - | ||||||||||||||||||||||||||||||||||||
438 | QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor))); | - | ||||||||||||||||||||||||||||||||||||
439 | QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged())); | - | ||||||||||||||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||||||||||||||
441 | // convenience signal forwards | - | ||||||||||||||||||||||||||||||||||||
442 | QObject::connect(doc, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool))); | - | ||||||||||||||||||||||||||||||||||||
443 | QObject::connect(doc, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool))); | - | ||||||||||||||||||||||||||||||||||||
444 | QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool))); | - | ||||||||||||||||||||||||||||||||||||
445 | QObject::connect(doc, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int))); | - | ||||||||||||||||||||||||||||||||||||
446 | } | - | ||||||||||||||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||||||||||||||
448 | bool previousUndoRedoState = doc->isUndoRedoEnabled(); | - | ||||||||||||||||||||||||||||||||||||
449 | if (!document) | - | ||||||||||||||||||||||||||||||||||||
450 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||||||||||||||
452 | //Saving the index save some time. | - | ||||||||||||||||||||||||||||||||||||
453 | static int contentsChangedIndex = QMetaMethod::fromSignal(&QTextDocument::contentsChanged).methodIndex(); | - | ||||||||||||||||||||||||||||||||||||
454 | static int textChangedIndex = QMetaMethod::fromSignal(&QWidgetTextControl::textChanged).methodIndex(); | - | ||||||||||||||||||||||||||||||||||||
455 | // avoid multiple textChanged() signals being emitted | - | ||||||||||||||||||||||||||||||||||||
456 | QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex); | - | ||||||||||||||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||||||||||||||
458 | if (!text.isEmpty()) { | - | ||||||||||||||||||||||||||||||||||||
459 | // clear 'our' cursor for insertion to prevent | - | ||||||||||||||||||||||||||||||||||||
460 | // the emission of the cursorPositionChanged() signal. | - | ||||||||||||||||||||||||||||||||||||
461 | // instead we emit it only once at the end instead of | - | ||||||||||||||||||||||||||||||||||||
462 | // at the end of the document after loading and when | - | ||||||||||||||||||||||||||||||||||||
463 | // positioning the cursor again to the start of the | - | ||||||||||||||||||||||||||||||||||||
464 | // document. | - | ||||||||||||||||||||||||||||||||||||
465 | cursor = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
466 | if (format == Qt::PlainText) { | - | ||||||||||||||||||||||||||||||||||||
467 | QTextCursor formatCursor(doc); | - | ||||||||||||||||||||||||||||||||||||
468 | // put the setPlainText and the setCharFormat into one edit block, | - | ||||||||||||||||||||||||||||||||||||
469 | // so that the syntax highlight triggers only /once/ for the entire | - | ||||||||||||||||||||||||||||||||||||
470 | // document, not twice. | - | ||||||||||||||||||||||||||||||||||||
471 | formatCursor.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
472 | doc->setPlainText(text); | - | ||||||||||||||||||||||||||||||||||||
473 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||||||||||||||
474 | formatCursor.select(QTextCursor::Document); | - | ||||||||||||||||||||||||||||||||||||
475 | formatCursor.setCharFormat(charFormatForInsertion); | - | ||||||||||||||||||||||||||||||||||||
476 | formatCursor.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
477 | } else { | - | ||||||||||||||||||||||||||||||||||||
478 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
479 | doc->setHtml(text); | - | ||||||||||||||||||||||||||||||||||||
480 | #else | - | ||||||||||||||||||||||||||||||||||||
481 | doc->setPlainText(text); | - | ||||||||||||||||||||||||||||||||||||
482 | #endif | - | ||||||||||||||||||||||||||||||||||||
483 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||||||||||||||
484 | } | - | ||||||||||||||||||||||||||||||||||||
485 | cursor = QTextCursor(doc); | - | ||||||||||||||||||||||||||||||||||||
486 | } else if (clearDocument) { | - | ||||||||||||||||||||||||||||||||||||
487 | doc->clear(); | - | ||||||||||||||||||||||||||||||||||||
488 | } | - | ||||||||||||||||||||||||||||||||||||
489 | cursor.setCharFormat(charFormatForInsertion); | - | ||||||||||||||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||||||||||||||
491 | QMetaObject::connect(doc, contentsChangedIndex, q, textChangedIndex); | - | ||||||||||||||||||||||||||||||||||||
492 | emit q->textChanged(); | - | ||||||||||||||||||||||||||||||||||||
493 | if (!document) | - | ||||||||||||||||||||||||||||||||||||
494 | doc->setUndoRedoEnabled(previousUndoRedoState); | - | ||||||||||||||||||||||||||||||||||||
495 | _q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||||||||||||||
496 | if (!document) | - | ||||||||||||||||||||||||||||||||||||
497 | doc->setModified(false); | - | ||||||||||||||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||||||||||||||
499 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
500 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||||||||||||||
502 | QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q, SLOT(_q_contentsChanged(int,int,int)), Qt::UniqueConnection); | - | ||||||||||||||||||||||||||||||||||||
503 | } | - | ||||||||||||||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||||||||||||||
505 | void QWidgetTextControlPrivate::startDrag() | - | ||||||||||||||||||||||||||||||||||||
506 | { | - | ||||||||||||||||||||||||||||||||||||
507 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
508 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
509 | mousePressed = false; | - | ||||||||||||||||||||||||||||||||||||
510 | if (!contextWidget) | - | ||||||||||||||||||||||||||||||||||||
511 | return; | - | ||||||||||||||||||||||||||||||||||||
512 | QMimeData *data = q->createMimeDataFromSelection(); | - | ||||||||||||||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||||||||||||||
514 | QDrag *drag = new QDrag(contextWidget); | - | ||||||||||||||||||||||||||||||||||||
515 | drag->setMimeData(data); | - | ||||||||||||||||||||||||||||||||||||
516 | - | |||||||||||||||||||||||||||||||||||||
517 | Qt::DropActions actions = Qt::CopyAction; | - | ||||||||||||||||||||||||||||||||||||
518 | Qt::DropAction action; | - | ||||||||||||||||||||||||||||||||||||
519 | if (interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
520 | actions |= Qt::MoveAction; | - | ||||||||||||||||||||||||||||||||||||
521 | action = drag->exec(actions, Qt::MoveAction); | - | ||||||||||||||||||||||||||||||||||||
522 | } else { | - | ||||||||||||||||||||||||||||||||||||
523 | action = drag->exec(actions, Qt::CopyAction); | - | ||||||||||||||||||||||||||||||||||||
524 | } | - | ||||||||||||||||||||||||||||||||||||
525 | - | |||||||||||||||||||||||||||||||||||||
526 | if (action == Qt::MoveAction && drag->target() != contextWidget) | - | ||||||||||||||||||||||||||||||||||||
527 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
528 | #endif | - | ||||||||||||||||||||||||||||||||||||
529 | } | - | ||||||||||||||||||||||||||||||||||||
530 | - | |||||||||||||||||||||||||||||||||||||
531 | void QWidgetTextControlPrivate::setCursorPosition(const QPointF &pos) | - | ||||||||||||||||||||||||||||||||||||
532 | { | - | ||||||||||||||||||||||||||||||||||||
533 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
534 | const int cursorPos = q->hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
535 | if (cursorPos == -1) | - | ||||||||||||||||||||||||||||||||||||
536 | return; | - | ||||||||||||||||||||||||||||||||||||
537 | cursor.setPosition(cursorPos); | - | ||||||||||||||||||||||||||||||||||||
538 | } | - | ||||||||||||||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||||||||||||||
540 | void QWidgetTextControlPrivate::setCursorPosition(int pos, QTextCursor::MoveMode mode) | - | ||||||||||||||||||||||||||||||||||||
541 | { | - | ||||||||||||||||||||||||||||||||||||
542 | cursor.setPosition(pos, mode); | - | ||||||||||||||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||||||||||||||
544 | if (mode != QTextCursor::KeepAnchor) { | - | ||||||||||||||||||||||||||||||||||||
545 | selectedWordOnDoubleClick = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
546 | selectedBlockOnTrippleClick = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
547 | } | - | ||||||||||||||||||||||||||||||||||||
548 | } | - | ||||||||||||||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||||||||||||||
550 | void QWidgetTextControlPrivate::repaintCursor() | - | ||||||||||||||||||||||||||||||||||||
551 | { | - | ||||||||||||||||||||||||||||||||||||
552 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
553 | emit q->updateRequest(cursorRectPlusUnicodeDirectionMarkers(cursor)); | - | ||||||||||||||||||||||||||||||||||||
554 | } | - | ||||||||||||||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||||||||||||||
556 | void QWidgetTextControlPrivate::repaintOldAndNewSelection(const QTextCursor &oldSelection) | - | ||||||||||||||||||||||||||||||||||||
557 | { | - | ||||||||||||||||||||||||||||||||||||
558 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
559 | if (cursor.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
560 | && oldSelection.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
561 | && cursor.currentFrame() == oldSelection.currentFrame() | - | ||||||||||||||||||||||||||||||||||||
562 | && !cursor.hasComplexSelection() | - | ||||||||||||||||||||||||||||||||||||
563 | && !oldSelection.hasComplexSelection() | - | ||||||||||||||||||||||||||||||||||||
564 | && cursor.anchor() == oldSelection.anchor() | - | ||||||||||||||||||||||||||||||||||||
565 | ) { | - | ||||||||||||||||||||||||||||||||||||
566 | QTextCursor differenceSelection(doc); | - | ||||||||||||||||||||||||||||||||||||
567 | differenceSelection.setPosition(oldSelection.position()); | - | ||||||||||||||||||||||||||||||||||||
568 | differenceSelection.setPosition(cursor.position(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
569 | emit q->updateRequest(q->selectionRect(differenceSelection)); | - | ||||||||||||||||||||||||||||||||||||
570 | } else { | - | ||||||||||||||||||||||||||||||||||||
571 | if (!oldSelection.isNull()) | - | ||||||||||||||||||||||||||||||||||||
572 | emit q->updateRequest(q->selectionRect(oldSelection) | cursorRectPlusUnicodeDirectionMarkers(oldSelection)); | - | ||||||||||||||||||||||||||||||||||||
573 | emit q->updateRequest(q->selectionRect() | cursorRectPlusUnicodeDirectionMarkers(cursor)); | - | ||||||||||||||||||||||||||||||||||||
574 | } | - | ||||||||||||||||||||||||||||||||||||
575 | } | - | ||||||||||||||||||||||||||||||||||||
576 | - | |||||||||||||||||||||||||||||||||||||
577 | void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged /*=false*/) | - | ||||||||||||||||||||||||||||||||||||
578 | { | - | ||||||||||||||||||||||||||||||||||||
579 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
580 | if (forceEmitSelectionChanged) { | - | ||||||||||||||||||||||||||||||||||||
581 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
582 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
583 | if (q->parent() && q->parent()->isWidgetType()) { | - | ||||||||||||||||||||||||||||||||||||
584 | QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position()); | - | ||||||||||||||||||||||||||||||||||||
585 | QAccessible::updateAccessibility(&ev); | - | ||||||||||||||||||||||||||||||||||||
586 | } | - | ||||||||||||||||||||||||||||||||||||
587 | #endif | - | ||||||||||||||||||||||||||||||||||||
588 | } | - | ||||||||||||||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||||||||||||||
590 | if (cursor.position() == lastSelectionPosition | - | ||||||||||||||||||||||||||||||||||||
591 | && cursor.anchor() == lastSelectionAnchor) | - | ||||||||||||||||||||||||||||||||||||
592 | return; | - | ||||||||||||||||||||||||||||||||||||
593 | - | |||||||||||||||||||||||||||||||||||||
594 | bool selectionStateChange = (cursor.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
595 | != (lastSelectionPosition != lastSelectionAnchor)); | - | ||||||||||||||||||||||||||||||||||||
596 | if (selectionStateChange) | - | ||||||||||||||||||||||||||||||||||||
597 | emit q->copyAvailable(cursor.hasSelection()); | - | ||||||||||||||||||||||||||||||||||||
598 | - | |||||||||||||||||||||||||||||||||||||
599 | if (!forceEmitSelectionChanged | - | ||||||||||||||||||||||||||||||||||||
600 | && (selectionStateChange | - | ||||||||||||||||||||||||||||||||||||
601 | || (cursor.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
602 | && (cursor.position() != lastSelectionPosition | - | ||||||||||||||||||||||||||||||||||||
603 | || cursor.anchor() != lastSelectionAnchor)))) { | - | ||||||||||||||||||||||||||||||||||||
604 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
605 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
606 | if (q->parent() && q->parent()->isWidgetType()) { | - | ||||||||||||||||||||||||||||||||||||
607 | QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position()); | - | ||||||||||||||||||||||||||||||||||||
608 | QAccessible::updateAccessibility(&ev); | - | ||||||||||||||||||||||||||||||||||||
609 | } | - | ||||||||||||||||||||||||||||||||||||
610 | #endif | - | ||||||||||||||||||||||||||||||||||||
611 | } | - | ||||||||||||||||||||||||||||||||||||
612 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
613 | lastSelectionPosition = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
614 | lastSelectionAnchor = cursor.anchor(); | - | ||||||||||||||||||||||||||||||||||||
615 | } | - | ||||||||||||||||||||||||||||||||||||
616 | - | |||||||||||||||||||||||||||||||||||||
617 | void QWidgetTextControlPrivate::_q_updateCurrentCharFormatAndSelection() | - | ||||||||||||||||||||||||||||||||||||
618 | { | - | ||||||||||||||||||||||||||||||||||||
619 | updateCurrentCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
620 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
621 | } | - | ||||||||||||||||||||||||||||||||||||
622 | - | |||||||||||||||||||||||||||||||||||||
623 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
624 | void QWidgetTextControlPrivate::setClipboardSelection() | - | ||||||||||||||||||||||||||||||||||||
625 | { | - | ||||||||||||||||||||||||||||||||||||
626 | QClipboard *clipboard = QApplication::clipboard(); | - | ||||||||||||||||||||||||||||||||||||
627 | if (!cursor.hasSelection() || !clipboard->supportsSelection()) | - | ||||||||||||||||||||||||||||||||||||
628 | return; | - | ||||||||||||||||||||||||||||||||||||
629 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
630 | QMimeData *data = q->createMimeDataFromSelection(); | - | ||||||||||||||||||||||||||||||||||||
631 | clipboard->setMimeData(data, QClipboard::Selection); | - | ||||||||||||||||||||||||||||||||||||
632 | } | - | ||||||||||||||||||||||||||||||||||||
633 | #endif | - | ||||||||||||||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||||||||||||||
635 | void QWidgetTextControlPrivate::_q_emitCursorPosChanged(const QTextCursor &someCursor) | - | ||||||||||||||||||||||||||||||||||||
636 | { | - | ||||||||||||||||||||||||||||||||||||
637 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
638 | if (someCursor.isCopyOf(cursor)) { | - | ||||||||||||||||||||||||||||||||||||
639 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
640 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
641 | } | - | ||||||||||||||||||||||||||||||||||||
642 | } | - | ||||||||||||||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||||||||||||||
644 | void QWidgetTextControlPrivate::_q_contentsChanged(int from, int charsRemoved, int charsAdded) | - | ||||||||||||||||||||||||||||||||||||
645 | { | - | ||||||||||||||||||||||||||||||||||||
646 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
647 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||||||||||||||
649 | if (QAccessible::isActive() && q->parent() && q->parent()->isWidgetType()) { | - | ||||||||||||||||||||||||||||||||||||
650 | QTextCursor tmp(doc); | - | ||||||||||||||||||||||||||||||||||||
651 | tmp.setPosition(from); | - | ||||||||||||||||||||||||||||||||||||
652 | // when setting a new text document the length is off | - | ||||||||||||||||||||||||||||||||||||
653 | // QTBUG-32583 - characterCount is off by 1 requires the -1 | - | ||||||||||||||||||||||||||||||||||||
654 | tmp.setPosition(qMin(doc->characterCount() - 1, from + charsAdded), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
655 | QString newText = tmp.selectedText(); | - | ||||||||||||||||||||||||||||||||||||
656 | - | |||||||||||||||||||||||||||||||||||||
657 | // always report the right number of removed chars, but in lack of the real string use spaces | - | ||||||||||||||||||||||||||||||||||||
658 | QString oldText = QString(charsRemoved, QLatin1Char(' ')); | - | ||||||||||||||||||||||||||||||||||||
659 | - | |||||||||||||||||||||||||||||||||||||
660 | QAccessibleEvent *ev = 0; | - | ||||||||||||||||||||||||||||||||||||
661 | if (charsRemoved == 0) { | - | ||||||||||||||||||||||||||||||||||||
662 | ev = new QAccessibleTextInsertEvent(q->parent(), from, newText); | - | ||||||||||||||||||||||||||||||||||||
663 | } else if (charsAdded == 0) { | - | ||||||||||||||||||||||||||||||||||||
664 | ev = new QAccessibleTextRemoveEvent(q->parent(), from, oldText); | - | ||||||||||||||||||||||||||||||||||||
665 | } else { | - | ||||||||||||||||||||||||||||||||||||
666 | ev = new QAccessibleTextUpdateEvent(q->parent(), from, oldText, newText); | - | ||||||||||||||||||||||||||||||||||||
667 | } | - | ||||||||||||||||||||||||||||||||||||
668 | QAccessible::updateAccessibility(ev); | - | ||||||||||||||||||||||||||||||||||||
669 | delete ev; | - | ||||||||||||||||||||||||||||||||||||
670 | } | - | ||||||||||||||||||||||||||||||||||||
671 | #else | - | ||||||||||||||||||||||||||||||||||||
672 | Q_UNUSED(from) | - | ||||||||||||||||||||||||||||||||||||
673 | Q_UNUSED(charsRemoved) | - | ||||||||||||||||||||||||||||||||||||
674 | Q_UNUSED(charsAdded) | - | ||||||||||||||||||||||||||||||||||||
675 | #endif | - | ||||||||||||||||||||||||||||||||||||
676 | } | - | ||||||||||||||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||||||||||||||
678 | void QWidgetTextControlPrivate::_q_documentLayoutChanged() | - | ||||||||||||||||||||||||||||||||||||
679 | { | - | ||||||||||||||||||||||||||||||||||||
680 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
681 | QAbstractTextDocumentLayout *layout = doc->documentLayout(); | - | ||||||||||||||||||||||||||||||||||||
682 | QObject::connect(layout, SIGNAL(update(QRectF)), q, SIGNAL(updateRequest(QRectF))); | - | ||||||||||||||||||||||||||||||||||||
683 | QObject::connect(layout, SIGNAL(updateBlock(QTextBlock)), q, SLOT(_q_updateBlock(QTextBlock))); | - | ||||||||||||||||||||||||||||||||||||
684 | QObject::connect(layout, SIGNAL(documentSizeChanged(QSizeF)), q, SIGNAL(documentSizeChanged(QSizeF))); | - | ||||||||||||||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||||||||||||||
686 | } | - | ||||||||||||||||||||||||||||||||||||
687 | - | |||||||||||||||||||||||||||||||||||||
688 | void QWidgetTextControlPrivate::setBlinkingCursorEnabledsetCursorVisible(bool enablevisible) | - | ||||||||||||||||||||||||||||||||||||
689 | { | - | ||||||||||||||||||||||||||||||||||||
690 | Q_Qif (QWidgetTextControlcursorVisible == visible)
| 0 | ||||||||||||||||||||||||||||||||||||
691 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
692 | - | |||||||||||||||||||||||||||||||||||||
693 | cursorVisible = visible; | - | ||||||||||||||||||||||||||||||||||||
694 | updateCursorBlinking(); | - | ||||||||||||||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||||||||||||||
696 | if (cursorVisible)
| 0 | ||||||||||||||||||||||||||||||||||||
697 | connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); | 0 | ||||||||||||||||||||||||||||||||||||
698 | else | - | ||||||||||||||||||||||||||||||||||||
699 | disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking never executed: );disconnect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); never executed: disconnect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); | 0 | ||||||||||||||||||||||||||||||||||||
700 | } | - | ||||||||||||||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||||||||||||||
702 | void QWidgetTextControlPrivate::updateCursorBlinking() | - | ||||||||||||||||||||||||||||||||||||
703 | { | - | ||||||||||||||||||||||||||||||||||||
704 | cursorBlinkTimer.stop(); | - | ||||||||||||||||||||||||||||||||||||
705 | if (enable && QApplicationcursorVisible) {
| 0 | ||||||||||||||||||||||||||||||||||||
706 | int flashTime = QGuiApplication::styleHints()->cursorFlashTime() > 0(); | - | ||||||||||||||||||||||||||||||||||||
707 | if (flashTime >= 2
| 0 | ||||||||||||||||||||||||||||||||||||
708 | cursorBlinkTimer.start(QApplication::cursorFlashTime()flashTime / 2, q); never executed: cursorBlinkTimer.start(flashTime / 2, q_func()); | 0 | ||||||||||||||||||||||||||||||||||||
else never executed: cursorBlinkTimer.start(flashTime / 2, q_func()); | ||||||||||||||||||||||||||||||||||||||
cursorBlinkTimer.stop(); never executed: q_func());cursorBlinkTimer.start(flashTime / 2, q_func()); never executed: cursorBlinkTimer.start(flashTime / 2, q_func()); | ||||||||||||||||||||||||||||||||||||||
709 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
710 | - | |||||||||||||||||||||||||||||||||||||
711 | cursorOn = enablecursorVisible; | - | ||||||||||||||||||||||||||||||||||||
712 | repaintCursor(); | - | ||||||||||||||||||||||||||||||||||||
713 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||||||||||||||
715 | void QWidgetTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition) | - | ||||||||||||||||||||||||||||||||||||
716 | { | - | ||||||||||||||||||||||||||||||||||||
717 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||||||||||||||
719 | // if inside the initial selected word keep that | - | ||||||||||||||||||||||||||||||||||||
720 | if (suggestedNewPosition >= selectedWordOnDoubleClick.selectionStart() | - | ||||||||||||||||||||||||||||||||||||
721 | && suggestedNewPosition <= selectedWordOnDoubleClick.selectionEnd()) { | - | ||||||||||||||||||||||||||||||||||||
722 | q->setTextCursor(selectedWordOnDoubleClick); | - | ||||||||||||||||||||||||||||||||||||
723 | return; | - | ||||||||||||||||||||||||||||||||||||
724 | } | - | ||||||||||||||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||||||||||||||
726 | QTextCursor curs = selectedWordOnDoubleClick; | - | ||||||||||||||||||||||||||||||||||||
727 | curs.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||||||||||||||
729 | if (!curs.movePosition(QTextCursor::StartOfWord)) | - | ||||||||||||||||||||||||||||||||||||
730 | return; | - | ||||||||||||||||||||||||||||||||||||
731 | const int wordStartPos = curs.position(); | - | ||||||||||||||||||||||||||||||||||||
732 | - | |||||||||||||||||||||||||||||||||||||
733 | const int blockPos = curs.block().position(); | - | ||||||||||||||||||||||||||||||||||||
734 | const QPointF blockCoordinates = q->blockBoundingRect(curs.block()).topLeft(); | - | ||||||||||||||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||||||||||||||
736 | QTextLine line = currentTextLine(curs); | - | ||||||||||||||||||||||||||||||||||||
737 | if (!line.isValid()) | - | ||||||||||||||||||||||||||||||||||||
738 | return; | - | ||||||||||||||||||||||||||||||||||||
739 | - | |||||||||||||||||||||||||||||||||||||
740 | const qreal wordStartX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x(); | - | ||||||||||||||||||||||||||||||||||||
741 | - | |||||||||||||||||||||||||||||||||||||
742 | if (!curs.movePosition(QTextCursor::EndOfWord)) | - | ||||||||||||||||||||||||||||||||||||
743 | return; | - | ||||||||||||||||||||||||||||||||||||
744 | const int wordEndPos = curs.position(); | - | ||||||||||||||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||||||||||||||
746 | const QTextLine otherLine = currentTextLine(curs); | - | ||||||||||||||||||||||||||||||||||||
747 | if (otherLine.textStart() != line.textStart() | - | ||||||||||||||||||||||||||||||||||||
748 | || wordEndPos == wordStartPos) | - | ||||||||||||||||||||||||||||||||||||
749 | return; | - | ||||||||||||||||||||||||||||||||||||
750 | - | |||||||||||||||||||||||||||||||||||||
751 | const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x(); | - | ||||||||||||||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||||||||||||||
753 | if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX)) | - | ||||||||||||||||||||||||||||||||||||
754 | return; | - | ||||||||||||||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||||||||||||||
756 | if (wordSelectionEnabled) { | - | ||||||||||||||||||||||||||||||||||||
757 | if (suggestedNewPosition < selectedWordOnDoubleClick.position()) { | - | ||||||||||||||||||||||||||||||||||||
758 | cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); | - | ||||||||||||||||||||||||||||||||||||
759 | setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
760 | } else { | - | ||||||||||||||||||||||||||||||||||||
761 | cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
762 | setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
763 | } | - | ||||||||||||||||||||||||||||||||||||
764 | } else { | - | ||||||||||||||||||||||||||||||||||||
765 | // keep the already selected word even when moving to the left | - | ||||||||||||||||||||||||||||||||||||
766 | // (#39164) | - | ||||||||||||||||||||||||||||||||||||
767 | if (suggestedNewPosition < selectedWordOnDoubleClick.position()) | - | ||||||||||||||||||||||||||||||||||||
768 | cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); | - | ||||||||||||||||||||||||||||||||||||
769 | else | - | ||||||||||||||||||||||||||||||||||||
770 | cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
771 | - | |||||||||||||||||||||||||||||||||||||
772 | const qreal differenceToStart = mouseXPosition - wordStartX; | - | ||||||||||||||||||||||||||||||||||||
773 | const qreal differenceToEnd = wordEndX - mouseXPosition; | - | ||||||||||||||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||||||||||||||
775 | if (differenceToStart < differenceToEnd) | - | ||||||||||||||||||||||||||||||||||||
776 | setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
777 | else | - | ||||||||||||||||||||||||||||||||||||
778 | setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
779 | } | - | ||||||||||||||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||||||||||||||
781 | if (interactionFlags & Qt::TextSelectableByMouse) { | - | ||||||||||||||||||||||||||||||||||||
782 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
783 | setClipboardSelection(); | - | ||||||||||||||||||||||||||||||||||||
784 | #endif | - | ||||||||||||||||||||||||||||||||||||
785 | selectionChanged(true); | - | ||||||||||||||||||||||||||||||||||||
786 | } | - | ||||||||||||||||||||||||||||||||||||
787 | } | - | ||||||||||||||||||||||||||||||||||||
788 | - | |||||||||||||||||||||||||||||||||||||
789 | void QWidgetTextControlPrivate::extendBlockwiseSelection(int suggestedNewPosition) | - | ||||||||||||||||||||||||||||||||||||
790 | { | - | ||||||||||||||||||||||||||||||||||||
791 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||||||||||||||
793 | // if inside the initial selected line keep that | - | ||||||||||||||||||||||||||||||||||||
794 | if (suggestedNewPosition >= selectedBlockOnTrippleClick.selectionStart() | - | ||||||||||||||||||||||||||||||||||||
795 | && suggestedNewPosition <= selectedBlockOnTrippleClick.selectionEnd()) { | - | ||||||||||||||||||||||||||||||||||||
796 | q->setTextCursor(selectedBlockOnTrippleClick); | - | ||||||||||||||||||||||||||||||||||||
797 | return; | - | ||||||||||||||||||||||||||||||||||||
798 | } | - | ||||||||||||||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||||||||||||||
800 | if (suggestedNewPosition < selectedBlockOnTrippleClick.position()) { | - | ||||||||||||||||||||||||||||||||||||
801 | cursor.setPosition(selectedBlockOnTrippleClick.selectionEnd()); | - | ||||||||||||||||||||||||||||||||||||
802 | cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
803 | cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
804 | } else { | - | ||||||||||||||||||||||||||||||||||||
805 | cursor.setPosition(selectedBlockOnTrippleClick.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
806 | cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
807 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
808 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
809 | } | - | ||||||||||||||||||||||||||||||||||||
810 | - | |||||||||||||||||||||||||||||||||||||
811 | if (interactionFlags & Qt::TextSelectableByMouse) { | - | ||||||||||||||||||||||||||||||||||||
812 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
813 | setClipboardSelection(); | - | ||||||||||||||||||||||||||||||||||||
814 | #endif | - | ||||||||||||||||||||||||||||||||||||
815 | selectionChanged(true); | - | ||||||||||||||||||||||||||||||||||||
816 | } | - | ||||||||||||||||||||||||||||||||||||
817 | } | - | ||||||||||||||||||||||||||||||||||||
818 | - | |||||||||||||||||||||||||||||||||||||
819 | void QWidgetTextControlPrivate::_q_deleteSelected() | - | ||||||||||||||||||||||||||||||||||||
820 | { | - | ||||||||||||||||||||||||||||||||||||
821 | if (!(interactionFlags & Qt::TextEditable) || !cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
822 | return; | - | ||||||||||||||||||||||||||||||||||||
823 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
824 | } | - | ||||||||||||||||||||||||||||||||||||
825 | - | |||||||||||||||||||||||||||||||||||||
826 | void QWidgetTextControl::undo() | - | ||||||||||||||||||||||||||||||||||||
827 | { | - | ||||||||||||||||||||||||||||||||||||
828 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
829 | d->repaintSelection(); | - | ||||||||||||||||||||||||||||||||||||
830 | const int oldCursorPos = d->cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
831 | d->doc->undo(&d->cursor); | - | ||||||||||||||||||||||||||||||||||||
832 | if (d->cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
833 | emit cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
834 | emit microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
835 | ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
836 | } | - | ||||||||||||||||||||||||||||||||||||
837 | - | |||||||||||||||||||||||||||||||||||||
838 | void QWidgetTextControl::redo() | - | ||||||||||||||||||||||||||||||||||||
839 | { | - | ||||||||||||||||||||||||||||||||||||
840 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
841 | d->repaintSelection(); | - | ||||||||||||||||||||||||||||||||||||
842 | const int oldCursorPos = d->cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
843 | d->doc->redo(&d->cursor); | - | ||||||||||||||||||||||||||||||||||||
844 | if (d->cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
845 | emit cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
846 | emit microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
847 | ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
848 | } | - | ||||||||||||||||||||||||||||||||||||
849 | - | |||||||||||||||||||||||||||||||||||||
850 | QWidgetTextControl::QWidgetTextControl(QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
851 | : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent) | - | ||||||||||||||||||||||||||||||||||||
852 | { | - | ||||||||||||||||||||||||||||||||||||
853 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
854 | d->init(); | - | ||||||||||||||||||||||||||||||||||||
855 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
856 | - | |||||||||||||||||||||||||||||||||||||
857 | QWidgetTextControl::QWidgetTextControl(const QString &text, QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
858 | : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent) | - | ||||||||||||||||||||||||||||||||||||
859 | { | - | ||||||||||||||||||||||||||||||||||||
860 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
861 | d->init(Qt::RichText, text); | - | ||||||||||||||||||||||||||||||||||||
862 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
863 | - | |||||||||||||||||||||||||||||||||||||
864 | QWidgetTextControl::QWidgetTextControl(QTextDocument *doc, QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
865 | : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent) | - | ||||||||||||||||||||||||||||||||||||
866 | { | - | ||||||||||||||||||||||||||||||||||||
867 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
868 | d->init(Qt::RichText, QString(), doc); | - | ||||||||||||||||||||||||||||||||||||
869 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||||||||||||||
871 | QWidgetTextControl::~QWidgetTextControl() | - | ||||||||||||||||||||||||||||||||||||
872 | { | - | ||||||||||||||||||||||||||||||||||||
873 | } | - | ||||||||||||||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||||||||||||||
875 | void QWidgetTextControl::setDocument(QTextDocument *document) | - | ||||||||||||||||||||||||||||||||||||
876 | { | - | ||||||||||||||||||||||||||||||||||||
877 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
878 | if (d->doc == document) | - | ||||||||||||||||||||||||||||||||||||
879 | return; | - | ||||||||||||||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||||||||||||||
881 | d->doc->disconnect(this); | - | ||||||||||||||||||||||||||||||||||||
882 | d->doc->documentLayout()->disconnect(this); | - | ||||||||||||||||||||||||||||||||||||
883 | d->doc->documentLayout()->setPaintDevice(0); | - | ||||||||||||||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||||||||||||||
885 | if (d->doc->parent() == this) | - | ||||||||||||||||||||||||||||||||||||
886 | delete d->doc; | - | ||||||||||||||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||||||||||||||
888 | d->doc = 0; | - | ||||||||||||||||||||||||||||||||||||
889 | d->setContent(Qt::RichText, QString(), document); | - | ||||||||||||||||||||||||||||||||||||
890 | } | - | ||||||||||||||||||||||||||||||||||||
891 | - | |||||||||||||||||||||||||||||||||||||
892 | QTextDocument *QWidgetTextControl::document() const | - | ||||||||||||||||||||||||||||||||||||
893 | { | - | ||||||||||||||||||||||||||||||||||||
894 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
895 | return d->doc; | - | ||||||||||||||||||||||||||||||||||||
896 | } | - | ||||||||||||||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||||||||||||||
898 | void QWidgetTextControl::setTextCursor(const QTextCursor &cursor) | - | ||||||||||||||||||||||||||||||||||||
899 | { | - | ||||||||||||||||||||||||||||||||||||
900 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
901 | d->cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
902 | const bool posChanged = cursor.position() != d->cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
903 | const QTextCursor oldSelection = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
904 | d->cursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
905 | d->cursorOn = d->hasFocus | - | ||||||||||||||||||||||||||||||||||||
906 | && (d->interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable)); | - | ||||||||||||||||||||||||||||||||||||
907 | d->_q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||||||||||||||
908 | ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
909 | d->repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
910 | if (posChanged) | - | ||||||||||||||||||||||||||||||||||||
911 | emit cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
912 | } | - | ||||||||||||||||||||||||||||||||||||
913 | - | |||||||||||||||||||||||||||||||||||||
914 | QTextCursor QWidgetTextControl::textCursor() const | - | ||||||||||||||||||||||||||||||||||||
915 | { | - | ||||||||||||||||||||||||||||||||||||
916 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
917 | return d->cursor; | - | ||||||||||||||||||||||||||||||||||||
918 | } | - | ||||||||||||||||||||||||||||||||||||
919 | - | |||||||||||||||||||||||||||||||||||||
920 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||||||||||||||
922 | void QWidgetTextControl::cut() | - | ||||||||||||||||||||||||||||||||||||
923 | { | - | ||||||||||||||||||||||||||||||||||||
924 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
925 | if (!(d->interactionFlags & Qt::TextEditable) || !d->cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
926 | return; | - | ||||||||||||||||||||||||||||||||||||
927 | copy(); | - | ||||||||||||||||||||||||||||||||||||
928 | d->cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
929 | } | - | ||||||||||||||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||||||||||||||
931 | void QWidgetTextControl::copy() | - | ||||||||||||||||||||||||||||||||||||
932 | { | - | ||||||||||||||||||||||||||||||||||||
933 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
934 | if (!d->cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
935 | return; | - | ||||||||||||||||||||||||||||||||||||
936 | QMimeData *data = createMimeDataFromSelection(); | - | ||||||||||||||||||||||||||||||||||||
937 | QApplication::clipboard()->setMimeData(data); | - | ||||||||||||||||||||||||||||||||||||
938 | } | - | ||||||||||||||||||||||||||||||||||||
939 | - | |||||||||||||||||||||||||||||||||||||
940 | void QWidgetTextControl::paste(QClipboard::Mode mode) | - | ||||||||||||||||||||||||||||||||||||
941 | { | - | ||||||||||||||||||||||||||||||||||||
942 | const QMimeData *md = QApplication::clipboard()->mimeData(mode); | - | ||||||||||||||||||||||||||||||||||||
943 | if (md) | - | ||||||||||||||||||||||||||||||||||||
944 | insertFromMimeData(md); | - | ||||||||||||||||||||||||||||||||||||
945 | } | - | ||||||||||||||||||||||||||||||||||||
946 | #endif | - | ||||||||||||||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||||||||||||||
948 | void QWidgetTextControl::clear() | - | ||||||||||||||||||||||||||||||||||||
949 | { | - | ||||||||||||||||||||||||||||||||||||
950 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
951 | // clears and sets empty content | - | ||||||||||||||||||||||||||||||||||||
952 | d->extraSelections.clear(); | - | ||||||||||||||||||||||||||||||||||||
953 | d->setContent(); | - | ||||||||||||||||||||||||||||||||||||
954 | } | - | ||||||||||||||||||||||||||||||||||||
955 | - | |||||||||||||||||||||||||||||||||||||
956 | - | |||||||||||||||||||||||||||||||||||||
957 | void QWidgetTextControl::selectAll() | - | ||||||||||||||||||||||||||||||||||||
958 | { | - | ||||||||||||||||||||||||||||||||||||
959 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
960 | const int selectionLength = qAbs(d->cursor.position() - d->cursor.anchor()); | - | ||||||||||||||||||||||||||||||||||||
961 | d->cursor.select(QTextCursor::Document); | - | ||||||||||||||||||||||||||||||||||||
962 | d->selectionChanged(selectionLength != qAbs(d->cursor.position() - d->cursor.anchor())); | - | ||||||||||||||||||||||||||||||||||||
963 | d->cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
964 | emit updateRequest(); | - | ||||||||||||||||||||||||||||||||||||
965 | } | - | ||||||||||||||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||||||||||||||
967 | void QWidgetTextControl::processEvent(QEvent *e, const QPointF &coordinateOffset, QWidget *contextWidget) | - | ||||||||||||||||||||||||||||||||||||
968 | { | - | ||||||||||||||||||||||||||||||||||||
969 | QMatrix m; | - | ||||||||||||||||||||||||||||||||||||
970 | m.translate(coordinateOffset.x(), coordinateOffset.y()); | - | ||||||||||||||||||||||||||||||||||||
971 | processEvent(e, m, contextWidget); | - | ||||||||||||||||||||||||||||||||||||
972 | } | - | ||||||||||||||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||||||||||||||
974 | void QWidgetTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget) | - | ||||||||||||||||||||||||||||||||||||
975 | { | - | ||||||||||||||||||||||||||||||||||||
976 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
977 | if (d->interactionFlags == Qt::NoTextInteraction) { | - | ||||||||||||||||||||||||||||||||||||
978 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
979 | return; | - | ||||||||||||||||||||||||||||||||||||
980 | } | - | ||||||||||||||||||||||||||||||||||||
981 | - | |||||||||||||||||||||||||||||||||||||
982 | d->contextWidget = contextWidget; | - | ||||||||||||||||||||||||||||||||||||
983 | - | |||||||||||||||||||||||||||||||||||||
984 | if (!d->contextWidget) { | - | ||||||||||||||||||||||||||||||||||||
985 | switch (e->type()) { | - | ||||||||||||||||||||||||||||||||||||
986 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||
987 | case QEvent::GraphicsSceneMouseMove: | - | ||||||||||||||||||||||||||||||||||||
988 | case QEvent::GraphicsSceneMousePress: | - | ||||||||||||||||||||||||||||||||||||
989 | case QEvent::GraphicsSceneMouseRelease: | - | ||||||||||||||||||||||||||||||||||||
990 | case QEvent::GraphicsSceneMouseDoubleClick: | - | ||||||||||||||||||||||||||||||||||||
991 | case QEvent::GraphicsSceneContextMenu: | - | ||||||||||||||||||||||||||||||||||||
992 | case QEvent::GraphicsSceneHoverEnter: | - | ||||||||||||||||||||||||||||||||||||
993 | case QEvent::GraphicsSceneHoverMove: | - | ||||||||||||||||||||||||||||||||||||
994 | case QEvent::GraphicsSceneHoverLeave: | - | ||||||||||||||||||||||||||||||||||||
995 | case QEvent::GraphicsSceneHelp: | - | ||||||||||||||||||||||||||||||||||||
996 | case QEvent::GraphicsSceneDragEnter: | - | ||||||||||||||||||||||||||||||||||||
997 | case QEvent::GraphicsSceneDragMove: | - | ||||||||||||||||||||||||||||||||||||
998 | case QEvent::GraphicsSceneDragLeave: | - | ||||||||||||||||||||||||||||||||||||
999 | case QEvent::GraphicsSceneDrop: { | - | ||||||||||||||||||||||||||||||||||||
1000 | QGraphicsSceneEvent *ev = static_cast<QGraphicsSceneEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1001 | d->contextWidget = ev->widget(); | - | ||||||||||||||||||||||||||||||||||||
1002 | break; | - | ||||||||||||||||||||||||||||||||||||
1003 | } | - | ||||||||||||||||||||||||||||||||||||
1004 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||
1005 | default: break; | - | ||||||||||||||||||||||||||||||||||||
1006 | }; | - | ||||||||||||||||||||||||||||||||||||
1007 | } | - | ||||||||||||||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||||||||||||||
1009 | switch (e->type()) { | - | ||||||||||||||||||||||||||||||||||||
1010 | case QEvent::KeyPress: | - | ||||||||||||||||||||||||||||||||||||
1011 | d->keyPressEvent(static_cast<QKeyEvent *>(e)); | - | ||||||||||||||||||||||||||||||||||||
1012 | break; | - | ||||||||||||||||||||||||||||||||||||
1013 | case QEvent::MouseButtonPress: { | - | ||||||||||||||||||||||||||||||||||||
1014 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1015 | d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), | - | ||||||||||||||||||||||||||||||||||||
1016 | ev->buttons(), ev->globalPos()); | - | ||||||||||||||||||||||||||||||||||||
1017 | break; } | - | ||||||||||||||||||||||||||||||||||||
1018 | case QEvent::MouseMove: { | - | ||||||||||||||||||||||||||||||||||||
1019 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1020 | d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), | - | ||||||||||||||||||||||||||||||||||||
1021 | ev->buttons(), ev->globalPos()); | - | ||||||||||||||||||||||||||||||||||||
1022 | break; } | - | ||||||||||||||||||||||||||||||||||||
1023 | case QEvent::MouseButtonRelease: { | - | ||||||||||||||||||||||||||||||||||||
1024 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1025 | d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), | - | ||||||||||||||||||||||||||||||||||||
1026 | ev->buttons(), ev->globalPos()); | - | ||||||||||||||||||||||||||||||||||||
1027 | break; } | - | ||||||||||||||||||||||||||||||||||||
1028 | case QEvent::MouseButtonDblClick: { | - | ||||||||||||||||||||||||||||||||||||
1029 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1030 | d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), | - | ||||||||||||||||||||||||||||||||||||
1031 | ev->buttons(), ev->globalPos()); | - | ||||||||||||||||||||||||||||||||||||
1032 | break; } | - | ||||||||||||||||||||||||||||||||||||
1033 | case QEvent::InputMethod: | - | ||||||||||||||||||||||||||||||||||||
1034 | d->inputMethodEvent(static_cast<QInputMethodEvent *>(e)); | - | ||||||||||||||||||||||||||||||||||||
1035 | break; | - | ||||||||||||||||||||||||||||||||||||
1036 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
1037 | case QEvent::ContextMenu: { | - | ||||||||||||||||||||||||||||||||||||
1038 | QContextMenuEvent *ev = static_cast<QContextMenuEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1039 | d->contextMenuEvent(ev->globalPos(), matrix.map(ev->pos()), contextWidget); | - | ||||||||||||||||||||||||||||||||||||
1040 | break; } | - | ||||||||||||||||||||||||||||||||||||
1041 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
1042 | case QEvent::FocusIn: | - | ||||||||||||||||||||||||||||||||||||
1043 | case QEvent::FocusOut: | - | ||||||||||||||||||||||||||||||||||||
1044 | d->focusEvent(static_cast<QFocusEvent *>(e)); | - | ||||||||||||||||||||||||||||||||||||
1045 | break; | - | ||||||||||||||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||||||||||||||
1047 | case QEvent::EnabledChange: | - | ||||||||||||||||||||||||||||||||||||
1048 | d->isEnabled = e->isAccepted(); | - | ||||||||||||||||||||||||||||||||||||
1049 | break; | - | ||||||||||||||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||||||||||||||
1051 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||||||||
1052 | case QEvent::ToolTip: { | - | ||||||||||||||||||||||||||||||||||||
1053 | QHelpEvent *ev = static_cast<QHelpEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1054 | d->showToolTip(ev->globalPos(), matrix.map(ev->pos()), contextWidget); | - | ||||||||||||||||||||||||||||||||||||
1055 | break; | - | ||||||||||||||||||||||||||||||||||||
1056 | } | - | ||||||||||||||||||||||||||||||||||||
1057 | #endif // QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||||||||
1058 | - | |||||||||||||||||||||||||||||||||||||
1059 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
1060 | case QEvent::DragEnter: { | - | ||||||||||||||||||||||||||||||||||||
1061 | QDragEnterEvent *ev = static_cast<QDragEnterEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1062 | if (d->dragEnterEvent(e, ev->mimeData())) | - | ||||||||||||||||||||||||||||||||||||
1063 | ev->acceptProposedAction(); | - | ||||||||||||||||||||||||||||||||||||
1064 | break; | - | ||||||||||||||||||||||||||||||||||||
1065 | } | - | ||||||||||||||||||||||||||||||||||||
1066 | case QEvent::DragLeave: | - | ||||||||||||||||||||||||||||||||||||
1067 | d->dragLeaveEvent(); | - | ||||||||||||||||||||||||||||||||||||
1068 | break; | - | ||||||||||||||||||||||||||||||||||||
1069 | case QEvent::DragMove: { | - | ||||||||||||||||||||||||||||||||||||
1070 | QDragMoveEvent *ev = static_cast<QDragMoveEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1071 | if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos()))) | - | ||||||||||||||||||||||||||||||||||||
1072 | ev->acceptProposedAction(); | - | ||||||||||||||||||||||||||||||||||||
1073 | break; | - | ||||||||||||||||||||||||||||||||||||
1074 | } | - | ||||||||||||||||||||||||||||||||||||
1075 | case QEvent::Drop: { | - | ||||||||||||||||||||||||||||||||||||
1076 | QDropEvent *ev = static_cast<QDropEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1077 | if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source())) | - | ||||||||||||||||||||||||||||||||||||
1078 | ev->acceptProposedAction(); | - | ||||||||||||||||||||||||||||||||||||
1079 | break; | - | ||||||||||||||||||||||||||||||||||||
1080 | } | - | ||||||||||||||||||||||||||||||||||||
1081 | #endif | - | ||||||||||||||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||||||||||||||
1083 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||
1084 | case QEvent::GraphicsSceneMousePress: { | - | ||||||||||||||||||||||||||||||||||||
1085 | QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1086 | d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(), | - | ||||||||||||||||||||||||||||||||||||
1087 | ev->screenPos()); | - | ||||||||||||||||||||||||||||||||||||
1088 | break; } | - | ||||||||||||||||||||||||||||||||||||
1089 | case QEvent::GraphicsSceneMouseMove: { | - | ||||||||||||||||||||||||||||||||||||
1090 | QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1091 | d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(), | - | ||||||||||||||||||||||||||||||||||||
1092 | ev->screenPos()); | - | ||||||||||||||||||||||||||||||||||||
1093 | break; } | - | ||||||||||||||||||||||||||||||||||||
1094 | case QEvent::GraphicsSceneMouseRelease: { | - | ||||||||||||||||||||||||||||||||||||
1095 | QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1096 | d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(), | - | ||||||||||||||||||||||||||||||||||||
1097 | ev->screenPos()); | - | ||||||||||||||||||||||||||||||||||||
1098 | break; } | - | ||||||||||||||||||||||||||||||||||||
1099 | case QEvent::GraphicsSceneMouseDoubleClick: { | - | ||||||||||||||||||||||||||||||||||||
1100 | QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1101 | d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(), | - | ||||||||||||||||||||||||||||||||||||
1102 | ev->screenPos()); | - | ||||||||||||||||||||||||||||||||||||
1103 | break; } | - | ||||||||||||||||||||||||||||||||||||
1104 | case QEvent::GraphicsSceneContextMenu: { | - | ||||||||||||||||||||||||||||||||||||
1105 | QGraphicsSceneContextMenuEvent *ev = static_cast<QGraphicsSceneContextMenuEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1106 | d->contextMenuEvent(ev->screenPos(), matrix.map(ev->pos()), contextWidget); | - | ||||||||||||||||||||||||||||||||||||
1107 | break; } | - | ||||||||||||||||||||||||||||||||||||
1108 | - | |||||||||||||||||||||||||||||||||||||
1109 | case QEvent::GraphicsSceneHoverMove: { | - | ||||||||||||||||||||||||||||||||||||
1110 | QGraphicsSceneHoverEvent *ev = static_cast<QGraphicsSceneHoverEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1111 | d->mouseMoveEvent(ev, Qt::NoButton, matrix.map(ev->pos()), ev->modifiers(),Qt::NoButton, | - | ||||||||||||||||||||||||||||||||||||
1112 | ev->screenPos()); | - | ||||||||||||||||||||||||||||||||||||
1113 | break; } | - | ||||||||||||||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||||||||||||||
1115 | case QEvent::GraphicsSceneDragEnter: { | - | ||||||||||||||||||||||||||||||||||||
1116 | QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1117 | if (d->dragEnterEvent(e, ev->mimeData())) | - | ||||||||||||||||||||||||||||||||||||
1118 | ev->acceptProposedAction(); | - | ||||||||||||||||||||||||||||||||||||
1119 | break; } | - | ||||||||||||||||||||||||||||||||||||
1120 | case QEvent::GraphicsSceneDragLeave: | - | ||||||||||||||||||||||||||||||||||||
1121 | d->dragLeaveEvent(); | - | ||||||||||||||||||||||||||||||||||||
1122 | break; | - | ||||||||||||||||||||||||||||||||||||
1123 | case QEvent::GraphicsSceneDragMove: { | - | ||||||||||||||||||||||||||||||||||||
1124 | QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1125 | if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos()))) | - | ||||||||||||||||||||||||||||||||||||
1126 | ev->acceptProposedAction(); | - | ||||||||||||||||||||||||||||||||||||
1127 | break; } | - | ||||||||||||||||||||||||||||||||||||
1128 | case QEvent::GraphicsSceneDrop: { | - | ||||||||||||||||||||||||||||||||||||
1129 | QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1130 | if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source())) | - | ||||||||||||||||||||||||||||||||||||
1131 | ev->accept(); | - | ||||||||||||||||||||||||||||||||||||
1132 | break; } | - | ||||||||||||||||||||||||||||||||||||
1133 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||||||||
1134 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
1135 | case QEvent::EnterEditFocus: | - | ||||||||||||||||||||||||||||||||||||
1136 | case QEvent::LeaveEditFocus: | - | ||||||||||||||||||||||||||||||||||||
1137 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||||||||||||||||||||
1138 | d->editFocusEvent(e); | - | ||||||||||||||||||||||||||||||||||||
1139 | break; | - | ||||||||||||||||||||||||||||||||||||
1140 | #endif | - | ||||||||||||||||||||||||||||||||||||
1141 | case QEvent::ShortcutOverride: | - | ||||||||||||||||||||||||||||||||||||
1142 | if (d->interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
1143 | QKeyEvent* ke = static_cast<QKeyEvent *>(e); | - | ||||||||||||||||||||||||||||||||||||
1144 | if (ke->modifiers() == Qt::NoModifier | - | ||||||||||||||||||||||||||||||||||||
1145 | || ke->modifiers() == Qt::ShiftModifier | - | ||||||||||||||||||||||||||||||||||||
1146 | || ke->modifiers() == Qt::KeypadModifier) { | - | ||||||||||||||||||||||||||||||||||||
1147 | if (ke->key() < Qt::Key_Escape) { | - | ||||||||||||||||||||||||||||||||||||
1148 | ke->accept(); | - | ||||||||||||||||||||||||||||||||||||
1149 | } else { | - | ||||||||||||||||||||||||||||||||||||
1150 | switch (ke->key()) { | - | ||||||||||||||||||||||||||||||||||||
1151 | case Qt::Key_Return: | - | ||||||||||||||||||||||||||||||||||||
1152 | case Qt::Key_Enter: | - | ||||||||||||||||||||||||||||||||||||
1153 | case Qt::Key_Delete: | - | ||||||||||||||||||||||||||||||||||||
1154 | case Qt::Key_Home: | - | ||||||||||||||||||||||||||||||||||||
1155 | case Qt::Key_End: | - | ||||||||||||||||||||||||||||||||||||
1156 | case Qt::Key_Backspace: | - | ||||||||||||||||||||||||||||||||||||
1157 | case Qt::Key_Left: | - | ||||||||||||||||||||||||||||||||||||
1158 | case Qt::Key_Right: | - | ||||||||||||||||||||||||||||||||||||
1159 | case Qt::Key_Up: | - | ||||||||||||||||||||||||||||||||||||
1160 | case Qt::Key_Down: | - | ||||||||||||||||||||||||||||||||||||
1161 | case Qt::Key_Tab: | - | ||||||||||||||||||||||||||||||||||||
1162 | ke->accept(); | - | ||||||||||||||||||||||||||||||||||||
1163 | default: | - | ||||||||||||||||||||||||||||||||||||
1164 | break; | - | ||||||||||||||||||||||||||||||||||||
1165 | } | - | ||||||||||||||||||||||||||||||||||||
1166 | } | - | ||||||||||||||||||||||||||||||||||||
1167 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1168 | } else if (ke == QKeySequence::Copy | - | ||||||||||||||||||||||||||||||||||||
1169 | || ke == QKeySequence::Paste | - | ||||||||||||||||||||||||||||||||||||
1170 | || ke == QKeySequence::Cut | - | ||||||||||||||||||||||||||||||||||||
1171 | || ke == QKeySequence::Redo | - | ||||||||||||||||||||||||||||||||||||
1172 | || ke == QKeySequence::Undo | - | ||||||||||||||||||||||||||||||||||||
1173 | || ke == QKeySequence::MoveToNextWord | - | ||||||||||||||||||||||||||||||||||||
1174 | || ke == QKeySequence::MoveToPreviousWord | - | ||||||||||||||||||||||||||||||||||||
1175 | || ke == QKeySequence::MoveToStartOfDocument | - | ||||||||||||||||||||||||||||||||||||
1176 | || ke == QKeySequence::MoveToEndOfDocument | - | ||||||||||||||||||||||||||||||||||||
1177 | || ke == QKeySequence::SelectNextWord | - | ||||||||||||||||||||||||||||||||||||
1178 | || ke == QKeySequence::SelectPreviousWord | - | ||||||||||||||||||||||||||||||||||||
1179 | || ke == QKeySequence::SelectStartOfLine | - | ||||||||||||||||||||||||||||||||||||
1180 | || ke == QKeySequence::SelectEndOfLine | - | ||||||||||||||||||||||||||||||||||||
1181 | || ke == QKeySequence::SelectStartOfBlock | - | ||||||||||||||||||||||||||||||||||||
1182 | || ke == QKeySequence::SelectEndOfBlock | - | ||||||||||||||||||||||||||||||||||||
1183 | || ke == QKeySequence::SelectStartOfDocument | - | ||||||||||||||||||||||||||||||||||||
1184 | || ke == QKeySequence::SelectEndOfDocument | - | ||||||||||||||||||||||||||||||||||||
1185 | || ke == QKeySequence::SelectAll | - | ||||||||||||||||||||||||||||||||||||
1186 | ) { | - | ||||||||||||||||||||||||||||||||||||
1187 | ke->accept(); | - | ||||||||||||||||||||||||||||||||||||
1188 | #endif | - | ||||||||||||||||||||||||||||||||||||
1189 | } | - | ||||||||||||||||||||||||||||||||||||
1190 | } | - | ||||||||||||||||||||||||||||||||||||
1191 | break; | - | ||||||||||||||||||||||||||||||||||||
1192 | default: | - | ||||||||||||||||||||||||||||||||||||
1193 | break; | - | ||||||||||||||||||||||||||||||||||||
1194 | } | - | ||||||||||||||||||||||||||||||||||||
1195 | } | - | ||||||||||||||||||||||||||||||||||||
1196 | - | |||||||||||||||||||||||||||||||||||||
1197 | bool QWidgetTextControl::event(QEvent *e) | - | ||||||||||||||||||||||||||||||||||||
1198 | { | - | ||||||||||||||||||||||||||||||||||||
1199 | return QObject::event(e); | - | ||||||||||||||||||||||||||||||||||||
1200 | } | - | ||||||||||||||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||||||||||||||
1202 | void QWidgetTextControl::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||||||||||||||
1203 | { | - | ||||||||||||||||||||||||||||||||||||
1204 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1205 | if (e->timerId() == d->cursorBlinkTimer.timerId()) { | - | ||||||||||||||||||||||||||||||||||||
1206 | d->cursorOn = !d->cursorOn; | - | ||||||||||||||||||||||||||||||||||||
1207 | - | |||||||||||||||||||||||||||||||||||||
1208 | if (d->cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
1209 | d->cursorOn &= (QApplication::style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected) | - | ||||||||||||||||||||||||||||||||||||
1210 | != 0); | - | ||||||||||||||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||||||||||||||
1212 | d->repaintCursor(); | - | ||||||||||||||||||||||||||||||||||||
1213 | } else if (e->timerId() == d->trippleClickTimer.timerId()) { | - | ||||||||||||||||||||||||||||||||||||
1214 | d->trippleClickTimer.stop(); | - | ||||||||||||||||||||||||||||||||||||
1215 | } | - | ||||||||||||||||||||||||||||||||||||
1216 | } | - | ||||||||||||||||||||||||||||||||||||
1217 | - | |||||||||||||||||||||||||||||||||||||
1218 | void QWidgetTextControl::setPlainText(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
1219 | { | - | ||||||||||||||||||||||||||||||||||||
1220 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1221 | d->setContent(Qt::PlainText, text); | - | ||||||||||||||||||||||||||||||||||||
1222 | } | - | ||||||||||||||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||||||||||||||
1224 | void QWidgetTextControl::setHtml(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
1225 | { | - | ||||||||||||||||||||||||||||||||||||
1226 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1227 | d->setContent(Qt::RichText, text); | - | ||||||||||||||||||||||||||||||||||||
1228 | } | - | ||||||||||||||||||||||||||||||||||||
1229 | - | |||||||||||||||||||||||||||||||||||||
1230 | void QWidgetTextControlPrivate::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||||||||||||||
1231 | { | - | ||||||||||||||||||||||||||||||||||||
1232 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1233 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1234 | if (e == QKeySequence::SelectAll) {
| 0 | ||||||||||||||||||||||||||||||||||||
1235 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1236 | q->selectAll(); | - | ||||||||||||||||||||||||||||||||||||
1237 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1238 | } | - | ||||||||||||||||||||||||||||||||||||
1239 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
1240 | else if (e == QKeySequence::Copy) {
| 0 | ||||||||||||||||||||||||||||||||||||
1241 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1242 | q->copy(); | - | ||||||||||||||||||||||||||||||||||||
1243 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1244 | } | - | ||||||||||||||||||||||||||||||||||||
1245 | #endif | - | ||||||||||||||||||||||||||||||||||||
1246 | #endif // QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||||||||||||||
1248 | if (interactionFlags & Qt::TextSelectableByKeyboard
| 0 | ||||||||||||||||||||||||||||||||||||
1249 | && cursorMoveKeyEvent(e))
| 0 | ||||||||||||||||||||||||||||||||||||
1250 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1251 | - | |||||||||||||||||||||||||||||||||||||
1252 | if (interactionFlags & Qt::LinksAccessibleByKeyboard) {
| 0 | ||||||||||||||||||||||||||||||||||||
1253 | if ((e->key() == Qt::Key_Return
| 0 | ||||||||||||||||||||||||||||||||||||
1254 | || e->key() == Qt::Key_Enter
| 0 | ||||||||||||||||||||||||||||||||||||
1255 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
1256 | || e->key() == Qt::Key_Select | - | ||||||||||||||||||||||||||||||||||||
1257 | #endif | - | ||||||||||||||||||||||||||||||||||||
1258 | ) | - | ||||||||||||||||||||||||||||||||||||
1259 | && cursor.hasSelection()) {
| 0 | ||||||||||||||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||||||||||||||
1261 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1262 | activateLinkUnderCursor(); | - | ||||||||||||||||||||||||||||||||||||
1263 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1264 | } | - | ||||||||||||||||||||||||||||||||||||
1265 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||||||||||||||
1267 | if (!(interactionFlags & Qt::TextEditable)) {
| 0 | ||||||||||||||||||||||||||||||||||||
1268 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1269 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1270 | } | - | ||||||||||||||||||||||||||||||||||||
1271 | - | |||||||||||||||||||||||||||||||||||||
1272 | if (e->key() == Qt::Key_Direction_L || e->key() == Qt::Key_Direction_R) {
| 0 | ||||||||||||||||||||||||||||||||||||
1273 | QTextBlockFormat fmt; | - | ||||||||||||||||||||||||||||||||||||
1274 | fmt.setLayoutDirection((e->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft); | - | ||||||||||||||||||||||||||||||||||||
1275 | cursor.mergeBlockFormat(fmt); | - | ||||||||||||||||||||||||||||||||||||
1276 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1277 | } | - | ||||||||||||||||||||||||||||||||||||
1278 | - | |||||||||||||||||||||||||||||||||||||
1279 | // schedule a repaint of the region of the cursor, as when we move it we | - | ||||||||||||||||||||||||||||||||||||
1280 | // want to make sure the old cursor disappears (not noticeable when moving | - | ||||||||||||||||||||||||||||||||||||
1281 | // only a few pixels but noticeable when jumping between cells in tables for | - | ||||||||||||||||||||||||||||||||||||
1282 | // example) | - | ||||||||||||||||||||||||||||||||||||
1283 | repaintSelection(); | - | ||||||||||||||||||||||||||||||||||||
1284 | - | |||||||||||||||||||||||||||||||||||||
1285 | if (e->key() == Qt::Key_Backspace && !(e->modifiers() & ~Qt::ShiftModifier)) {
| 0 | ||||||||||||||||||||||||||||||||||||
1286 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||||||||||||||
1287 | QTextList *list = cursor.currentList(); | - | ||||||||||||||||||||||||||||||||||||
1288 | if (list && cursor.atBlockStart() && !cursor.hasSelection()) {
| 0 | ||||||||||||||||||||||||||||||||||||
1289 | list->remove(cursor.block()); | - | ||||||||||||||||||||||||||||||||||||
1290 | } else if (cursor.atBlockStart() && blockFmt.indent() > 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
1291 | blockFmt.setIndent(blockFmt.indent() - 1); | - | ||||||||||||||||||||||||||||||||||||
1292 | cursor.setBlockFormat(blockFmt); | - | ||||||||||||||||||||||||||||||||||||
1293 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1294 | QTextCursor localCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
1295 | localCursor.deletePreviousChar(); | - | ||||||||||||||||||||||||||||||||||||
1296 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1297 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1298 | } | - | ||||||||||||||||||||||||||||||||||||
1299 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1300 | else if (e == QKeySequence::InsertParagraphSeparator) {
| 0 | ||||||||||||||||||||||||||||||||||||
1301 | cursor.insertBlock(); | - | ||||||||||||||||||||||||||||||||||||
1302 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1303 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1304 | } else if (e == QKeySequence::InsertLineSeparator) {
| 0 | ||||||||||||||||||||||||||||||||||||
1305 | cursor.insertText(QString(QChar::LineSeparator)); | - | ||||||||||||||||||||||||||||||||||||
1306 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1307 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1308 | } | - | ||||||||||||||||||||||||||||||||||||
1309 | #endif | - | ||||||||||||||||||||||||||||||||||||
1310 | if (false) { dead code: { } | - | ||||||||||||||||||||||||||||||||||||
1311 | } dead code: { } | - | ||||||||||||||||||||||||||||||||||||
1312 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1313 | else if (e == QKeySequence::Undo) {
| 0 | ||||||||||||||||||||||||||||||||||||
1314 | q->undo(); | - | ||||||||||||||||||||||||||||||||||||
1315 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1316 | else if (e == QKeySequence::Redo) {
| 0 | ||||||||||||||||||||||||||||||||||||
1317 | q->redo(); | - | ||||||||||||||||||||||||||||||||||||
1318 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1319 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
1320 | else if (e == QKeySequence::Cut) {
| 0 | ||||||||||||||||||||||||||||||||||||
1321 | q->cut(); | - | ||||||||||||||||||||||||||||||||||||
1322 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1323 | else if (e == QKeySequence::Paste) {
| 0 | ||||||||||||||||||||||||||||||||||||
1324 | QClipboard::Mode mode = QClipboard::Clipboard; | - | ||||||||||||||||||||||||||||||||||||
1325 | if (QGuiApplication::clipboard()->supportsSelection()) {
| 0 | ||||||||||||||||||||||||||||||||||||
1326 | if (e->modifiers() == (Qt::CTRL | Qt::SHIFT) && e->key() == Qt::Key_Insert)
| 0 | ||||||||||||||||||||||||||||||||||||
1327 | mode = QClipboard::Selection; never executed: mode = QClipboard::Selection; | 0 | ||||||||||||||||||||||||||||||||||||
1328 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1329 | q->paste(mode); | - | ||||||||||||||||||||||||||||||||||||
1330 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1331 | #endif | - | ||||||||||||||||||||||||||||||||||||
1332 | else if (e == QKeySequence::Delete) {
| 0 | ||||||||||||||||||||||||||||||||||||
1333 | QTextCursor localCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
1334 | localCursor.deleteChar(); | - | ||||||||||||||||||||||||||||||||||||
1335 | } else if (e == QKeySequence::Backspace) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
1336 | QTextCursor localCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
1337 | localCursor.deletePreviousChar(); | - | ||||||||||||||||||||||||||||||||||||
1338 | }else if (e == QKeySequence::DeleteEndOfWord) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
1339 | if (!cursor.hasSelection())
| 0 | ||||||||||||||||||||||||||||||||||||
1340 | cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); never executed: cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); | 0 | ||||||||||||||||||||||||||||||||||||
1341 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
1342 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1343 | else if (e == QKeySequence::DeleteStartOfWord) {
| 0 | ||||||||||||||||||||||||||||||||||||
1344 | if (!cursor.hasSelection())
| 0 | ||||||||||||||||||||||||||||||||||||
1345 | cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); never executed: cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); | 0 | ||||||||||||||||||||||||||||||||||||
1346 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
1347 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1348 | else if (e == QKeySequence::DeleteEndOfLine) {
| 0 | ||||||||||||||||||||||||||||||||||||
1349 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
1350 | if (cursor.position() == block.position() + block.length() - 2)
| 0 | ||||||||||||||||||||||||||||||||||||
1351 | cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); never executed: cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); | 0 | ||||||||||||||||||||||||||||||||||||
1352 | else | - | ||||||||||||||||||||||||||||||||||||
1353 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); never executed: cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); | 0 | ||||||||||||||||||||||||||||||||||||
1354 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
1355 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1356 | #endif // QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||||||||
1357 | else { | - | ||||||||||||||||||||||||||||||||||||
1358 | goto process; never executed: goto process; | 0 | ||||||||||||||||||||||||||||||||||||
1359 | } | - | ||||||||||||||||||||||||||||||||||||
1360 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||||||||||||||
1361 | - | |||||||||||||||||||||||||||||||||||||
1362 | process: | - | ||||||||||||||||||||||||||||||||||||
1363 | { | - | ||||||||||||||||||||||||||||||||||||
1364 | // QTBUG-35734: ignore Ctrl/Ctrl+Shift; accept only AltGr (Alt+Ctrl) on German keyboards | - | ||||||||||||||||||||||||||||||||||||
1365 | if (qe->isAcceptableInput(modifiers() == Qt::ControlModifier
| 0 | ||||||||||||||||||||||||||||||||||||
1366 | ||
| 0 | ||||||||||||||||||||||||||||||||||||
1367 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1368 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1369 | } | - | ||||||||||||||||||||||||||||||||||||
1370 | QString text = e->text(); | - | ||||||||||||||||||||||||||||||||||||
1371 | if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t')))
| 0 | ||||||||||||||||||||||||||||||||||||
1372 | if (overwriteMode
| 0 | ||||||||||||||||||||||||||||||||||||
1373 | // no need to call deleteChar() if we have a selection, insertText | - | ||||||||||||||||||||||||||||||||||||
1374 | // does it already | - | ||||||||||||||||||||||||||||||||||||
1375 | && !cursor.hasSelection()
| 0 | ||||||||||||||||||||||||||||||||||||
1376 | && !cursor.atBlockEnd())
| 0 | ||||||||||||||||||||||||||||||||||||
1377 | cursor.deleteChar(); never executed: cursor.deleteChar(); | 0 | ||||||||||||||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||||||||||||||
1379 | cursor.insertText(e->text());); | - | ||||||||||||||||||||||||||||||||||||
1380 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1381 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1382 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1383 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
1384 | } | - | ||||||||||||||||||||||||||||||||||||
1385 | } | - | ||||||||||||||||||||||||||||||||||||
1386 | - | |||||||||||||||||||||||||||||||||||||
1387 | accept: code before this statement never executed: accept: | 0 | ||||||||||||||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||||||||||||||
1389 | e->accept(); | - | ||||||||||||||||||||||||||||||||||||
1390 | cursorOn = true; | - | ||||||||||||||||||||||||||||||||||||
1391 | - | |||||||||||||||||||||||||||||||||||||
1392 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
1393 | - | |||||||||||||||||||||||||||||||||||||
1394 | updateCurrentCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
1395 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1396 | - | |||||||||||||||||||||||||||||||||||||
1397 | QVariant QWidgetTextControl::loadResource(int type, const QUrl &name) | - | ||||||||||||||||||||||||||||||||||||
1398 | { | - | ||||||||||||||||||||||||||||||||||||
1399 | #ifdef QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||||||||||||||
1400 | Q_UNUSED(type); | - | ||||||||||||||||||||||||||||||||||||
1401 | Q_UNUSED(name); | - | ||||||||||||||||||||||||||||||||||||
1402 | #else | - | ||||||||||||||||||||||||||||||||||||
1403 | if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(parent())) { | - | ||||||||||||||||||||||||||||||||||||
1404 | QUrl resolvedName = textEdit->d_func()->resolveUrl(name); | - | ||||||||||||||||||||||||||||||||||||
1405 | return textEdit->loadResource(type, resolvedName); | - | ||||||||||||||||||||||||||||||||||||
1406 | } | - | ||||||||||||||||||||||||||||||||||||
1407 | #endif | - | ||||||||||||||||||||||||||||||||||||
1408 | return QVariant(); | - | ||||||||||||||||||||||||||||||||||||
1409 | } | - | ||||||||||||||||||||||||||||||||||||
1410 | - | |||||||||||||||||||||||||||||||||||||
1411 | void QWidgetTextControlPrivate::_q_updateBlock(const QTextBlock &block) | - | ||||||||||||||||||||||||||||||||||||
1412 | { | - | ||||||||||||||||||||||||||||||||||||
1413 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1414 | QRectF br = q->blockBoundingRect(block); | - | ||||||||||||||||||||||||||||||||||||
1415 | br.setRight(qreal(INT_MAX)); // the block might have shrunk | - | ||||||||||||||||||||||||||||||||||||
1416 | emit q->updateRequest(br); | - | ||||||||||||||||||||||||||||||||||||
1417 | } | - | ||||||||||||||||||||||||||||||||||||
1418 | - | |||||||||||||||||||||||||||||||||||||
1419 | QRectF QWidgetTextControlPrivate::rectForPosition(int position) const | - | ||||||||||||||||||||||||||||||||||||
1420 | { | - | ||||||||||||||||||||||||||||||||||||
1421 | Q_Q(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1422 | const QTextBlock block = doc->findBlock(position); | - | ||||||||||||||||||||||||||||||||||||
1423 | if (!block.isValid()) | - | ||||||||||||||||||||||||||||||||||||
1424 | return QRectF(); | - | ||||||||||||||||||||||||||||||||||||
1425 | const QAbstractTextDocumentLayout *docLayout = doc->documentLayout(); | - | ||||||||||||||||||||||||||||||||||||
1426 | const QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||||||||||||||
1427 | const QPointF layoutPos = q->blockBoundingRect(block).topLeft(); | - | ||||||||||||||||||||||||||||||||||||
1428 | int relativePos = position - block.position(); | - | ||||||||||||||||||||||||||||||||||||
1429 | if (preeditCursor != 0) { | - | ||||||||||||||||||||||||||||||||||||
1430 | int preeditPos = layout->preeditAreaPosition(); | - | ||||||||||||||||||||||||||||||||||||
1431 | if (relativePos == preeditPos) | - | ||||||||||||||||||||||||||||||||||||
1432 | relativePos += preeditCursor; | - | ||||||||||||||||||||||||||||||||||||
1433 | else if (relativePos > preeditPos) | - | ||||||||||||||||||||||||||||||||||||
1434 | relativePos += layout->preeditAreaText().length(); | - | ||||||||||||||||||||||||||||||||||||
1435 | } | - | ||||||||||||||||||||||||||||||||||||
1436 | QTextLine line = layout->lineForTextPosition(relativePos); | - | ||||||||||||||||||||||||||||||||||||
1437 | - | |||||||||||||||||||||||||||||||||||||
1438 | int cursorWidth; | - | ||||||||||||||||||||||||||||||||||||
1439 | { | - | ||||||||||||||||||||||||||||||||||||
1440 | bool ok = false; | - | ||||||||||||||||||||||||||||||||||||
1441 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||||||||||||||||||||
1442 | cursorWidth = docLayout->property("cursorWidth").toInt(&ok); | - | ||||||||||||||||||||||||||||||||||||
1443 | #endif | - | ||||||||||||||||||||||||||||||||||||
1444 | if (!ok) | - | ||||||||||||||||||||||||||||||||||||
1445 | cursorWidth = 1; | - | ||||||||||||||||||||||||||||||||||||
1446 | } | - | ||||||||||||||||||||||||||||||||||||
1447 | - | |||||||||||||||||||||||||||||||||||||
1448 | QRectF r; | - | ||||||||||||||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||||||||||||||
1450 | if (line.isValid()) { | - | ||||||||||||||||||||||||||||||||||||
1451 | qreal x = line.cursorToX(relativePos); | - | ||||||||||||||||||||||||||||||||||||
1452 | qreal w = 0; | - | ||||||||||||||||||||||||||||||||||||
1453 | if (overwriteMode) { | - | ||||||||||||||||||||||||||||||||||||
1454 | if (relativePos < line.textLength() - line.textStart()) | - | ||||||||||||||||||||||||||||||||||||
1455 | w = line.cursorToX(relativePos + 1) - x; | - | ||||||||||||||||||||||||||||||||||||
1456 | else | - | ||||||||||||||||||||||||||||||||||||
1457 | w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw() | - | ||||||||||||||||||||||||||||||||||||
1458 | } | - | ||||||||||||||||||||||||||||||||||||
1459 | r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), | - | ||||||||||||||||||||||||||||||||||||
1460 | cursorWidth + w, line.height()); | - | ||||||||||||||||||||||||||||||||||||
1461 | } else { | - | ||||||||||||||||||||||||||||||||||||
1462 | r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height | - | ||||||||||||||||||||||||||||||||||||
1463 | } | - | ||||||||||||||||||||||||||||||||||||
1464 | - | |||||||||||||||||||||||||||||||||||||
1465 | return r; | - | ||||||||||||||||||||||||||||||||||||
1466 | } | - | ||||||||||||||||||||||||||||||||||||
1467 | - | |||||||||||||||||||||||||||||||||||||
1468 | namespace { | - | ||||||||||||||||||||||||||||||||||||
1469 | struct QTextFrameComparator { | - | ||||||||||||||||||||||||||||||||||||
1470 | #if defined(Q_CC_MSVC) && _MSC_VER < 1600 | - | ||||||||||||||||||||||||||||||||||||
1471 | //The STL implementation of MSVC 2008 requires the definition | - | ||||||||||||||||||||||||||||||||||||
1472 | bool operator()(QTextFrame *frame1, QTextFrame *frame2) { return frame1->firstPosition() < frame2->firstPosition(); } | - | ||||||||||||||||||||||||||||||||||||
1473 | #endif | - | ||||||||||||||||||||||||||||||||||||
1474 | bool operator()(QTextFrame *frame, int position) { return frame->firstPosition() < position; } | - | ||||||||||||||||||||||||||||||||||||
1475 | bool operator()(int position, QTextFrame *frame) { return position < frame->firstPosition(); } | - | ||||||||||||||||||||||||||||||||||||
1476 | }; | - | ||||||||||||||||||||||||||||||||||||
1477 | } | - | ||||||||||||||||||||||||||||||||||||
1478 | - | |||||||||||||||||||||||||||||||||||||
1479 | static QRectF boundingRectOfFloatsInSelection(const QTextCursor &cursor) | - | ||||||||||||||||||||||||||||||||||||
1480 | { | - | ||||||||||||||||||||||||||||||||||||
1481 | QRectF r; | - | ||||||||||||||||||||||||||||||||||||
1482 | QTextFrame *frame = cursor.currentFrame(); | - | ||||||||||||||||||||||||||||||||||||
1483 | const QList<QTextFrame *> children = frame->childFrames(); | - | ||||||||||||||||||||||||||||||||||||
1484 | - | |||||||||||||||||||||||||||||||||||||
1485 | const QList<QTextFrame *>::ConstIterator firstFrame = std::lower_bound(children.constBegin(), children.constEnd(), | - | ||||||||||||||||||||||||||||||||||||
1486 | cursor.selectionStart(), QTextFrameComparator()); | - | ||||||||||||||||||||||||||||||||||||
1487 | const QList<QTextFrame *>::ConstIterator lastFrame = std::upper_bound(children.constBegin(), children.constEnd(), | - | ||||||||||||||||||||||||||||||||||||
1488 | cursor.selectionEnd(), QTextFrameComparator()); | - | ||||||||||||||||||||||||||||||||||||
1489 | for (QList<QTextFrame *>::ConstIterator it = firstFrame; it != lastFrame; ++it) { | - | ||||||||||||||||||||||||||||||||||||
1490 | if ((*it)->frameFormat().position() != QTextFrameFormat::InFlow) | - | ||||||||||||||||||||||||||||||||||||
1491 | r |= frame->document()->documentLayout()->frameBoundingRect(*it); | - | ||||||||||||||||||||||||||||||||||||
1492 | } | - | ||||||||||||||||||||||||||||||||||||
1493 | return r; | - | ||||||||||||||||||||||||||||||||||||
1494 | } | - | ||||||||||||||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||||||||||||||
1496 | QRectF QWidgetTextControl::selectionRect(const QTextCursor &cursor) const | - | ||||||||||||||||||||||||||||||||||||
1497 | { | - | ||||||||||||||||||||||||||||||||||||
1498 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1499 | - | |||||||||||||||||||||||||||||||||||||
1500 | QRectF r = d->rectForPosition(cursor.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
1501 | - | |||||||||||||||||||||||||||||||||||||
1502 | if (cursor.hasComplexSelection() && cursor.currentTable()) { | - | ||||||||||||||||||||||||||||||||||||
1503 | QTextTable *table = cursor.currentTable(); | - | ||||||||||||||||||||||||||||||||||||
1504 | - | |||||||||||||||||||||||||||||||||||||
1505 | r = d->doc->documentLayout()->frameBoundingRect(table); | - | ||||||||||||||||||||||||||||||||||||
1506 | /* | - | ||||||||||||||||||||||||||||||||||||
1507 | int firstRow, numRows, firstColumn, numColumns; | - | ||||||||||||||||||||||||||||||||||||
1508 | cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); | - | ||||||||||||||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||||||||||||||
1510 | const QTextTableCell firstCell = table->cellAt(firstRow, firstColumn); | - | ||||||||||||||||||||||||||||||||||||
1511 | const QTextTableCell lastCell = table->cellAt(firstRow + numRows - 1, firstColumn + numColumns - 1); | - | ||||||||||||||||||||||||||||||||||||
1512 | - | |||||||||||||||||||||||||||||||||||||
1513 | const QAbstractTextDocumentLayout * const layout = doc->documentLayout(); | - | ||||||||||||||||||||||||||||||||||||
1514 | - | |||||||||||||||||||||||||||||||||||||
1515 | QRectF tableSelRect = layout->blockBoundingRect(firstCell.firstCursorPosition().block()); | - | ||||||||||||||||||||||||||||||||||||
1516 | - | |||||||||||||||||||||||||||||||||||||
1517 | for (int col = firstColumn; col < firstColumn + numColumns; ++col) { | - | ||||||||||||||||||||||||||||||||||||
1518 | const QTextTableCell cell = table->cellAt(firstRow, col); | - | ||||||||||||||||||||||||||||||||||||
1519 | const qreal y = layout->blockBoundingRect(cell.firstCursorPosition().block()).top(); | - | ||||||||||||||||||||||||||||||||||||
1520 | - | |||||||||||||||||||||||||||||||||||||
1521 | tableSelRect.setTop(qMin(tableSelRect.top(), y)); | - | ||||||||||||||||||||||||||||||||||||
1522 | } | - | ||||||||||||||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||||||||||||||
1524 | for (int row = firstRow; row < firstRow + numRows; ++row) { | - | ||||||||||||||||||||||||||||||||||||
1525 | const QTextTableCell cell = table->cellAt(row, firstColumn); | - | ||||||||||||||||||||||||||||||||||||
1526 | const qreal x = layout->blockBoundingRect(cell.firstCursorPosition().block()).left(); | - | ||||||||||||||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||||||||||||||
1528 | tableSelRect.setLeft(qMin(tableSelRect.left(), x)); | - | ||||||||||||||||||||||||||||||||||||
1529 | } | - | ||||||||||||||||||||||||||||||||||||
1530 | - | |||||||||||||||||||||||||||||||||||||
1531 | for (int col = firstColumn; col < firstColumn + numColumns; ++col) { | - | ||||||||||||||||||||||||||||||||||||
1532 | const QTextTableCell cell = table->cellAt(firstRow + numRows - 1, col); | - | ||||||||||||||||||||||||||||||||||||
1533 | const qreal y = layout->blockBoundingRect(cell.lastCursorPosition().block()).bottom(); | - | ||||||||||||||||||||||||||||||||||||
1534 | - | |||||||||||||||||||||||||||||||||||||
1535 | tableSelRect.setBottom(qMax(tableSelRect.bottom(), y)); | - | ||||||||||||||||||||||||||||||||||||
1536 | } | - | ||||||||||||||||||||||||||||||||||||
1537 | - | |||||||||||||||||||||||||||||||||||||
1538 | for (int row = firstRow; row < firstRow + numRows; ++row) { | - | ||||||||||||||||||||||||||||||||||||
1539 | const QTextTableCell cell = table->cellAt(row, firstColumn + numColumns - 1); | - | ||||||||||||||||||||||||||||||||||||
1540 | const qreal x = layout->blockBoundingRect(cell.lastCursorPosition().block()).right(); | - | ||||||||||||||||||||||||||||||||||||
1541 | - | |||||||||||||||||||||||||||||||||||||
1542 | tableSelRect.setRight(qMax(tableSelRect.right(), x)); | - | ||||||||||||||||||||||||||||||||||||
1543 | } | - | ||||||||||||||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||||||||||||||
1545 | r = tableSelRect.toRect(); | - | ||||||||||||||||||||||||||||||||||||
1546 | */ | - | ||||||||||||||||||||||||||||||||||||
1547 | } else if (cursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
1548 | const int position = cursor.selectionStart(); | - | ||||||||||||||||||||||||||||||||||||
1549 | const int anchor = cursor.selectionEnd(); | - | ||||||||||||||||||||||||||||||||||||
1550 | const QTextBlock posBlock = d->doc->findBlock(position); | - | ||||||||||||||||||||||||||||||||||||
1551 | const QTextBlock anchorBlock = d->doc->findBlock(anchor); | - | ||||||||||||||||||||||||||||||||||||
1552 | if (posBlock == anchorBlock && posBlock.isValid() && posBlock.layout()->lineCount()) { | - | ||||||||||||||||||||||||||||||||||||
1553 | const QTextLine posLine = posBlock.layout()->lineForTextPosition(position - posBlock.position()); | - | ||||||||||||||||||||||||||||||||||||
1554 | const QTextLine anchorLine = anchorBlock.layout()->lineForTextPosition(anchor - anchorBlock.position()); | - | ||||||||||||||||||||||||||||||||||||
1555 | - | |||||||||||||||||||||||||||||||||||||
1556 | const int firstLine = qMin(posLine.lineNumber(), anchorLine.lineNumber()); | - | ||||||||||||||||||||||||||||||||||||
1557 | const int lastLine = qMax(posLine.lineNumber(), anchorLine.lineNumber()); | - | ||||||||||||||||||||||||||||||||||||
1558 | const QTextLayout *layout = posBlock.layout(); | - | ||||||||||||||||||||||||||||||||||||
1559 | r = QRectF(); | - | ||||||||||||||||||||||||||||||||||||
1560 | for (int i = firstLine; i <= lastLine; ++i) { | - | ||||||||||||||||||||||||||||||||||||
1561 | r |= layout->lineAt(i).rect(); | - | ||||||||||||||||||||||||||||||||||||
1562 | r |= layout->lineAt(i).naturalTextRect(); // might be bigger in the case of wrap not enabled | - | ||||||||||||||||||||||||||||||||||||
1563 | } | - | ||||||||||||||||||||||||||||||||||||
1564 | r.translate(blockBoundingRect(posBlock).topLeft()); | - | ||||||||||||||||||||||||||||||||||||
1565 | } else { | - | ||||||||||||||||||||||||||||||||||||
1566 | QRectF anchorRect = d->rectForPosition(cursor.selectionEnd()); | - | ||||||||||||||||||||||||||||||||||||
1567 | r |= anchorRect; | - | ||||||||||||||||||||||||||||||||||||
1568 | r |= boundingRectOfFloatsInSelection(cursor); | - | ||||||||||||||||||||||||||||||||||||
1569 | QRectF frameRect(d->doc->documentLayout()->frameBoundingRect(cursor.currentFrame())); | - | ||||||||||||||||||||||||||||||||||||
1570 | r.setLeft(frameRect.left()); | - | ||||||||||||||||||||||||||||||||||||
1571 | r.setRight(frameRect.right()); | - | ||||||||||||||||||||||||||||||||||||
1572 | } | - | ||||||||||||||||||||||||||||||||||||
1573 | if (r.isValid()) | - | ||||||||||||||||||||||||||||||||||||
1574 | r.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||||||||||||||||||||
1575 | } | - | ||||||||||||||||||||||||||||||||||||
1576 | - | |||||||||||||||||||||||||||||||||||||
1577 | return r; | - | ||||||||||||||||||||||||||||||||||||
1578 | } | - | ||||||||||||||||||||||||||||||||||||
1579 | - | |||||||||||||||||||||||||||||||||||||
1580 | QRectF QWidgetTextControl::selectionRect() const | - | ||||||||||||||||||||||||||||||||||||
1581 | { | - | ||||||||||||||||||||||||||||||||||||
1582 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1583 | return selectionRect(d->cursor); | - | ||||||||||||||||||||||||||||||||||||
1584 | } | - | ||||||||||||||||||||||||||||||||||||
1585 | - | |||||||||||||||||||||||||||||||||||||
1586 | void QWidgetTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, | - | ||||||||||||||||||||||||||||||||||||
1587 | Qt::MouseButtons buttons, const QPoint &globalPos) | - | ||||||||||||||||||||||||||||||||||||
1588 | { | - | ||||||||||||||||||||||||||||||||||||
1589 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1590 | - | |||||||||||||||||||||||||||||||||||||
1591 | mousePressPos = pos.toPoint(); | - | ||||||||||||||||||||||||||||||||||||
1592 | - | |||||||||||||||||||||||||||||||||||||
1593 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
1594 | mightStartDrag = false; | - | ||||||||||||||||||||||||||||||||||||
1595 | #endif | - | ||||||||||||||||||||||||||||||||||||
1596 | - | |||||||||||||||||||||||||||||||||||||
1597 | if (sendMouseEventToInputContext( | - | ||||||||||||||||||||||||||||||||||||
1598 | e, QEvent::MouseButtonPress, button, pos, modifiers, buttons, globalPos)) { | - | ||||||||||||||||||||||||||||||||||||
1599 | return; | - | ||||||||||||||||||||||||||||||||||||
1600 | } | - | ||||||||||||||||||||||||||||||||||||
1601 | - | |||||||||||||||||||||||||||||||||||||
1602 | if (interactionFlags & Qt::LinksAccessibleByMouse) { | - | ||||||||||||||||||||||||||||||||||||
1603 | anchorOnMousePress = q->anchorAt(pos); | - | ||||||||||||||||||||||||||||||||||||
1604 | - | |||||||||||||||||||||||||||||||||||||
1605 | if (cursorIsFocusIndicator) { | - | ||||||||||||||||||||||||||||||||||||
1606 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
1607 | repaintSelection(); | - | ||||||||||||||||||||||||||||||||||||
1608 | cursor.clearSelection(); | - | ||||||||||||||||||||||||||||||||||||
1609 | } | - | ||||||||||||||||||||||||||||||||||||
1610 | } | - | ||||||||||||||||||||||||||||||||||||
1611 | if (!(button & Qt::LeftButton) || | - | ||||||||||||||||||||||||||||||||||||
1612 | !((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) { | - | ||||||||||||||||||||||||||||||||||||
1613 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1614 | return; | - | ||||||||||||||||||||||||||||||||||||
1615 | } | - | ||||||||||||||||||||||||||||||||||||
1616 | - | |||||||||||||||||||||||||||||||||||||
1617 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
1618 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
1619 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
1620 | - | |||||||||||||||||||||||||||||||||||||
1621 | mousePressed = (interactionFlags & Qt::TextSelectableByMouse); | - | ||||||||||||||||||||||||||||||||||||
1622 | - | |||||||||||||||||||||||||||||||||||||
1623 | commitPreedit(); | - | ||||||||||||||||||||||||||||||||||||
1624 | - | |||||||||||||||||||||||||||||||||||||
1625 | if (trippleClickTimer.isActive() | - | ||||||||||||||||||||||||||||||||||||
1626 | && ((pos - trippleClickPoint).toPoint().manhattanLength() < QApplication::startDragDistance())) { | - | ||||||||||||||||||||||||||||||||||||
1627 | - | |||||||||||||||||||||||||||||||||||||
1628 | cursor.movePosition(QTextCursor::StartOfBlock); | - | ||||||||||||||||||||||||||||||||||||
1629 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
1630 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
1631 | selectedBlockOnTrippleClick = cursor; | - | ||||||||||||||||||||||||||||||||||||
1632 | - | |||||||||||||||||||||||||||||||||||||
1633 | anchorOnMousePress = QString(); | - | ||||||||||||||||||||||||||||||||||||
1634 | - | |||||||||||||||||||||||||||||||||||||
1635 | trippleClickTimer.stop(); | - | ||||||||||||||||||||||||||||||||||||
1636 | } else { | - | ||||||||||||||||||||||||||||||||||||
1637 | int cursorPos = q->hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1638 | if (cursorPos == -1) { | - | ||||||||||||||||||||||||||||||||||||
1639 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1640 | return; | - | ||||||||||||||||||||||||||||||||||||
1641 | } | - | ||||||||||||||||||||||||||||||||||||
1642 | - | |||||||||||||||||||||||||||||||||||||
1643 | if (modifiers == Qt::ShiftModifier && (interactionFlags & Qt::TextSelectableByMouse)) { | - | ||||||||||||||||||||||||||||||||||||
1644 | if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
1645 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||||||||||||||
1646 | selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||||||||||||||
1647 | } | - | ||||||||||||||||||||||||||||||||||||
1648 | - | |||||||||||||||||||||||||||||||||||||
1649 | if (selectedBlockOnTrippleClick.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
1650 | extendBlockwiseSelection(cursorPos); | - | ||||||||||||||||||||||||||||||||||||
1651 | else if (selectedWordOnDoubleClick.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
1652 | extendWordwiseSelection(cursorPos, pos.x()); | - | ||||||||||||||||||||||||||||||||||||
1653 | else if (!wordSelectionEnabled) | - | ||||||||||||||||||||||||||||||||||||
1654 | setCursorPosition(cursorPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
1655 | } else { | - | ||||||||||||||||||||||||||||||||||||
1656 | - | |||||||||||||||||||||||||||||||||||||
1657 | if (dragEnabled | - | ||||||||||||||||||||||||||||||||||||
1658 | && cursor.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
1659 | && !cursorIsFocusIndicator | - | ||||||||||||||||||||||||||||||||||||
1660 | && cursorPos >= cursor.selectionStart() | - | ||||||||||||||||||||||||||||||||||||
1661 | && cursorPos <= cursor.selectionEnd() | - | ||||||||||||||||||||||||||||||||||||
1662 | && q->hitTest(pos, Qt::ExactHit) != -1) { | - | ||||||||||||||||||||||||||||||||||||
1663 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
1664 | mightStartDrag = true; | - | ||||||||||||||||||||||||||||||||||||
1665 | #endif | - | ||||||||||||||||||||||||||||||||||||
1666 | return; | - | ||||||||||||||||||||||||||||||||||||
1667 | } | - | ||||||||||||||||||||||||||||||||||||
1668 | - | |||||||||||||||||||||||||||||||||||||
1669 | setCursorPosition(cursorPos); | - | ||||||||||||||||||||||||||||||||||||
1670 | } | - | ||||||||||||||||||||||||||||||||||||
1671 | } | - | ||||||||||||||||||||||||||||||||||||
1672 | - | |||||||||||||||||||||||||||||||||||||
1673 | if (interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
1674 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
1675 | if (cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
1676 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1677 | _q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||||||||||||||
1678 | } else { | - | ||||||||||||||||||||||||||||||||||||
1679 | if (cursor.position() != oldCursorPos) { | - | ||||||||||||||||||||||||||||||||||||
1680 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1681 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
1682 | } | - | ||||||||||||||||||||||||||||||||||||
1683 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1684 | } | - | ||||||||||||||||||||||||||||||||||||
1685 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
1686 | hadSelectionOnMousePress = cursor.hasSelection(); | - | ||||||||||||||||||||||||||||||||||||
1687 | } | - | ||||||||||||||||||||||||||||||||||||
1688 | - | |||||||||||||||||||||||||||||||||||||
1689 | void QWidgetTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, const QPointF &mousePos, Qt::KeyboardModifiers modifiers, | - | ||||||||||||||||||||||||||||||||||||
1690 | Qt::MouseButtons buttons, const QPoint &globalPos) | - | ||||||||||||||||||||||||||||||||||||
1691 | { | - | ||||||||||||||||||||||||||||||||||||
1692 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1693 | - | |||||||||||||||||||||||||||||||||||||
1694 | if (interactionFlags & Qt::LinksAccessibleByMouse) { | - | ||||||||||||||||||||||||||||||||||||
1695 | QString anchor = q->anchorAt(mousePos); | - | ||||||||||||||||||||||||||||||||||||
1696 | if (anchor != highlightedAnchor) { | - | ||||||||||||||||||||||||||||||||||||
1697 | highlightedAnchor = anchor; | - | ||||||||||||||||||||||||||||||||||||
1698 | emit q->linkHovered(anchor); | - | ||||||||||||||||||||||||||||||||||||
1699 | } | - | ||||||||||||||||||||||||||||||||||||
1700 | } | - | ||||||||||||||||||||||||||||||||||||
1701 | - | |||||||||||||||||||||||||||||||||||||
1702 | if (buttons & Qt::LeftButton) { | - | ||||||||||||||||||||||||||||||||||||
1703 | const bool editable = interactionFlags & Qt::TextEditable; | - | ||||||||||||||||||||||||||||||||||||
1704 | - | |||||||||||||||||||||||||||||||||||||
1705 | if (!(mousePressed | - | ||||||||||||||||||||||||||||||||||||
1706 | || editable | - | ||||||||||||||||||||||||||||||||||||
1707 | || mightStartDrag | - | ||||||||||||||||||||||||||||||||||||
1708 | || selectedWordOnDoubleClick.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
1709 | || selectedBlockOnTrippleClick.hasSelection())) | - | ||||||||||||||||||||||||||||||||||||
1710 | return; | - | ||||||||||||||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||||||||||||||
1712 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
1713 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
1714 | - | |||||||||||||||||||||||||||||||||||||
1715 | if (mightStartDrag) { | - | ||||||||||||||||||||||||||||||||||||
1716 | if ((mousePos.toPoint() - mousePressPos).manhattanLength() > QApplication::startDragDistance()) | - | ||||||||||||||||||||||||||||||||||||
1717 | startDrag(); | - | ||||||||||||||||||||||||||||||||||||
1718 | return; | - | ||||||||||||||||||||||||||||||||||||
1719 | } | - | ||||||||||||||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||||||||||||||
1721 | const qreal mouseX = qreal(mousePos.x()); | - | ||||||||||||||||||||||||||||||||||||
1722 | - | |||||||||||||||||||||||||||||||||||||
1723 | int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1724 | - | |||||||||||||||||||||||||||||||||||||
1725 | if (isPreediting()) { | - | ||||||||||||||||||||||||||||||||||||
1726 | // note: oldCursorPos not including preedit | - | ||||||||||||||||||||||||||||||||||||
1727 | int selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1728 | - | |||||||||||||||||||||||||||||||||||||
1729 | if (newCursorPos != selectionStartPos) { | - | ||||||||||||||||||||||||||||||||||||
1730 | commitPreedit(); | - | ||||||||||||||||||||||||||||||||||||
1731 | // commit invalidates positions | - | ||||||||||||||||||||||||||||||||||||
1732 | newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1733 | selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1734 | setCursorPosition(selectionStartPos); | - | ||||||||||||||||||||||||||||||||||||
1735 | } | - | ||||||||||||||||||||||||||||||||||||
1736 | } | - | ||||||||||||||||||||||||||||||||||||
1737 | - | |||||||||||||||||||||||||||||||||||||
1738 | if (newCursorPos == -1) | - | ||||||||||||||||||||||||||||||||||||
1739 | return; | - | ||||||||||||||||||||||||||||||||||||
1740 | - | |||||||||||||||||||||||||||||||||||||
1741 | if (mousePressed && wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
1742 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||||||||||||||
1743 | selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||||||||||||||
1744 | } | - | ||||||||||||||||||||||||||||||||||||
1745 | - | |||||||||||||||||||||||||||||||||||||
1746 | if (selectedBlockOnTrippleClick.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
1747 | extendBlockwiseSelection(newCursorPos); | - | ||||||||||||||||||||||||||||||||||||
1748 | else if (selectedWordOnDoubleClick.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
1749 | extendWordwiseSelection(newCursorPos, mouseX); | - | ||||||||||||||||||||||||||||||||||||
1750 | else if (mousePressed && !isPreediting()) | - | ||||||||||||||||||||||||||||||||||||
1751 | setCursorPosition(newCursorPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
1752 | - | |||||||||||||||||||||||||||||||||||||
1753 | if (interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
1754 | // don't call ensureVisible for the visible cursor to avoid jumping | - | ||||||||||||||||||||||||||||||||||||
1755 | // scrollbars. the autoscrolling ensures smooth scrolling if necessary. | - | ||||||||||||||||||||||||||||||||||||
1756 | //q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
1757 | if (cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
1758 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1759 | _q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||||||||||||||
1760 | #ifndef QT_NO_IM | - | ||||||||||||||||||||||||||||||||||||
1761 | if (contextWidget) | - | ||||||||||||||||||||||||||||||||||||
1762 | QGuiApplication::inputMethod()->update(Qt::ImQueryInput); | - | ||||||||||||||||||||||||||||||||||||
1763 | #endif //QT_NO_IM | - | ||||||||||||||||||||||||||||||||||||
1764 | } else { | - | ||||||||||||||||||||||||||||||||||||
1765 | //emit q->visibilityRequest(QRectF(mousePos, QSizeF(1, 1))); | - | ||||||||||||||||||||||||||||||||||||
1766 | if (cursor.position() != oldCursorPos) { | - | ||||||||||||||||||||||||||||||||||||
1767 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1768 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
1769 | } | - | ||||||||||||||||||||||||||||||||||||
1770 | } | - | ||||||||||||||||||||||||||||||||||||
1771 | selectionChanged(true); | - | ||||||||||||||||||||||||||||||||||||
1772 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
1773 | } | - | ||||||||||||||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||||||||||||||
1775 | sendMouseEventToInputContext(e, QEvent::MouseMove, button, mousePos, modifiers, buttons, globalPos); | - | ||||||||||||||||||||||||||||||||||||
1776 | } | - | ||||||||||||||||||||||||||||||||||||
1777 | - | |||||||||||||||||||||||||||||||||||||
1778 | void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, | - | ||||||||||||||||||||||||||||||||||||
1779 | Qt::MouseButtons buttons, const QPoint &globalPos) | - | ||||||||||||||||||||||||||||||||||||
1780 | { | - | ||||||||||||||||||||||||||||||||||||
1781 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||||||||||||||
1783 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
1784 | if (sendMouseEventToInputContext( | - | ||||||||||||||||||||||||||||||||||||
1785 | e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) { | - | ||||||||||||||||||||||||||||||||||||
1786 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
1787 | return; | - | ||||||||||||||||||||||||||||||||||||
1788 | } | - | ||||||||||||||||||||||||||||||||||||
1789 | - | |||||||||||||||||||||||||||||||||||||
1790 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
1791 | - | |||||||||||||||||||||||||||||||||||||
1792 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
1793 | if (mightStartDrag && (button & Qt::LeftButton)) { | - | ||||||||||||||||||||||||||||||||||||
1794 | mousePressed = false; | - | ||||||||||||||||||||||||||||||||||||
1795 | setCursorPosition(pos); | - | ||||||||||||||||||||||||||||||||||||
1796 | cursor.clearSelection(); | - | ||||||||||||||||||||||||||||||||||||
1797 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1798 | } | - | ||||||||||||||||||||||||||||||||||||
1799 | #endif | - | ||||||||||||||||||||||||||||||||||||
1800 | if (mousePressed) { | - | ||||||||||||||||||||||||||||||||||||
1801 | mousePressed = false; | - | ||||||||||||||||||||||||||||||||||||
1802 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
1803 | setClipboardSelection(); | - | ||||||||||||||||||||||||||||||||||||
1804 | selectionChanged(true); | - | ||||||||||||||||||||||||||||||||||||
1805 | } else if (button == Qt::MidButton | - | ||||||||||||||||||||||||||||||||||||
1806 | && (interactionFlags & Qt::TextEditable) | - | ||||||||||||||||||||||||||||||||||||
1807 | && QApplication::clipboard()->supportsSelection()) { | - | ||||||||||||||||||||||||||||||||||||
1808 | setCursorPosition(pos); | - | ||||||||||||||||||||||||||||||||||||
1809 | const QMimeData *md = QApplication::clipboard()->mimeData(QClipboard::Selection); | - | ||||||||||||||||||||||||||||||||||||
1810 | if (md) | - | ||||||||||||||||||||||||||||||||||||
1811 | q->insertFromMimeData(md); | - | ||||||||||||||||||||||||||||||||||||
1812 | #endif | - | ||||||||||||||||||||||||||||||||||||
1813 | } | - | ||||||||||||||||||||||||||||||||||||
1814 | - | |||||||||||||||||||||||||||||||||||||
1815 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
1816 | - | |||||||||||||||||||||||||||||||||||||
1817 | if (cursor.position() != oldCursorPos) { | - | ||||||||||||||||||||||||||||||||||||
1818 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1819 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
1820 | } | - | ||||||||||||||||||||||||||||||||||||
1821 | - | |||||||||||||||||||||||||||||||||||||
1822 | if (interactionFlags & Qt::LinksAccessibleByMouse) { | - | ||||||||||||||||||||||||||||||||||||
1823 | if (!(button & Qt::LeftButton)) | - | ||||||||||||||||||||||||||||||||||||
1824 | return; | - | ||||||||||||||||||||||||||||||||||||
1825 | - | |||||||||||||||||||||||||||||||||||||
1826 | const QString anchor = q->anchorAt(pos); | - | ||||||||||||||||||||||||||||||||||||
1827 | - | |||||||||||||||||||||||||||||||||||||
1828 | if (anchor.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
1829 | return; | - | ||||||||||||||||||||||||||||||||||||
1830 | - | |||||||||||||||||||||||||||||||||||||
1831 | if (!cursor.hasSelection() | - | ||||||||||||||||||||||||||||||||||||
1832 | || (anchor == anchorOnMousePress && hadSelectionOnMousePress)) { | - | ||||||||||||||||||||||||||||||||||||
1833 | - | |||||||||||||||||||||||||||||||||||||
1834 | const int anchorPos = q->hitTest(pos, Qt::ExactHit); | - | ||||||||||||||||||||||||||||||||||||
1835 | if (anchorPos != -1) { | - | ||||||||||||||||||||||||||||||||||||
1836 | cursor.setPosition(anchorPos); | - | ||||||||||||||||||||||||||||||||||||
1837 | - | |||||||||||||||||||||||||||||||||||||
1838 | QString anchor = anchorOnMousePress; | - | ||||||||||||||||||||||||||||||||||||
1839 | anchorOnMousePress = QString(); | - | ||||||||||||||||||||||||||||||||||||
1840 | activateLinkUnderCursor(anchor); | - | ||||||||||||||||||||||||||||||||||||
1841 | } | - | ||||||||||||||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||||||||||||||
1843 | } | - | ||||||||||||||||||||||||||||||||||||
1844 | } | - | ||||||||||||||||||||||||||||||||||||
1845 | - | |||||||||||||||||||||||||||||||||||||
1846 | void QWidgetTextControlPrivate::mouseDoubleClickEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, | - | ||||||||||||||||||||||||||||||||||||
1847 | Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, | - | ||||||||||||||||||||||||||||||||||||
1848 | const QPoint &globalPos) | - | ||||||||||||||||||||||||||||||||||||
1849 | { | - | ||||||||||||||||||||||||||||||||||||
1850 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1851 | - | |||||||||||||||||||||||||||||||||||||
1852 | if (button == Qt::LeftButton | - | ||||||||||||||||||||||||||||||||||||
1853 | && (interactionFlags & Qt::TextSelectableByMouse)) { | - | ||||||||||||||||||||||||||||||||||||
1854 | - | |||||||||||||||||||||||||||||||||||||
1855 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||||||||
1856 | mightStartDrag = false; | - | ||||||||||||||||||||||||||||||||||||
1857 | #endif | - | ||||||||||||||||||||||||||||||||||||
1858 | commitPreedit(); | - | ||||||||||||||||||||||||||||||||||||
1859 | - | |||||||||||||||||||||||||||||||||||||
1860 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
1861 | setCursorPosition(pos); | - | ||||||||||||||||||||||||||||||||||||
1862 | QTextLine line = currentTextLine(cursor); | - | ||||||||||||||||||||||||||||||||||||
1863 | bool doEmit = false; | - | ||||||||||||||||||||||||||||||||||||
1864 | if (line.isValid() && line.textLength()) { | - | ||||||||||||||||||||||||||||||||||||
1865 | cursor.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||||||||||||||
1866 | doEmit = true; | - | ||||||||||||||||||||||||||||||||||||
1867 | } | - | ||||||||||||||||||||||||||||||||||||
1868 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
1869 | - | |||||||||||||||||||||||||||||||||||||
1870 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
1871 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||||||||||||||
1872 | - | |||||||||||||||||||||||||||||||||||||
1873 | trippleClickPoint = pos; | - | ||||||||||||||||||||||||||||||||||||
1874 | trippleClickTimer.start(QApplication::doubleClickInterval(), q); | - | ||||||||||||||||||||||||||||||||||||
1875 | if (doEmit) { | - | ||||||||||||||||||||||||||||||||||||
1876 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1877 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
1878 | setClipboardSelection(); | - | ||||||||||||||||||||||||||||||||||||
1879 | #endif | - | ||||||||||||||||||||||||||||||||||||
1880 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
1881 | } | - | ||||||||||||||||||||||||||||||||||||
1882 | } else if (!sendMouseEventToInputContext(e, QEvent::MouseButtonDblClick, button, pos, | - | ||||||||||||||||||||||||||||||||||||
1883 | modifiers, buttons, globalPos)) { | - | ||||||||||||||||||||||||||||||||||||
1884 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1885 | } | - | ||||||||||||||||||||||||||||||||||||
1886 | } | - | ||||||||||||||||||||||||||||||||||||
1887 | - | |||||||||||||||||||||||||||||||||||||
1888 | bool QWidgetTextControlPrivate::sendMouseEventToInputContext( | - | ||||||||||||||||||||||||||||||||||||
1889 | QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, | - | ||||||||||||||||||||||||||||||||||||
1890 | Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos) | - | ||||||||||||||||||||||||||||||||||||
1891 | { | - | ||||||||||||||||||||||||||||||||||||
1892 | Q_UNUSED(eventType); | - | ||||||||||||||||||||||||||||||||||||
1893 | Q_UNUSED(button); | - | ||||||||||||||||||||||||||||||||||||
1894 | Q_UNUSED(pos); | - | ||||||||||||||||||||||||||||||||||||
1895 | Q_UNUSED(modifiers); | - | ||||||||||||||||||||||||||||||||||||
1896 | Q_UNUSED(buttons); | - | ||||||||||||||||||||||||||||||||||||
1897 | Q_UNUSED(globalPos); | - | ||||||||||||||||||||||||||||||||||||
1898 | #if !defined(QT_NO_IM) | - | ||||||||||||||||||||||||||||||||||||
1899 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1900 | - | |||||||||||||||||||||||||||||||||||||
1901 | if (isPreediting()) { | - | ||||||||||||||||||||||||||||||||||||
1902 | QTextLayout *layout = cursor.block().layout(); | - | ||||||||||||||||||||||||||||||||||||
1903 | int cursorPos = q->hitTest(pos, Qt::FuzzyHit) - cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
1904 | - | |||||||||||||||||||||||||||||||||||||
1905 | if (cursorPos < 0 || cursorPos > layout->preeditAreaText().length()) | - | ||||||||||||||||||||||||||||||||||||
1906 | cursorPos = -1; | - | ||||||||||||||||||||||||||||||||||||
1907 | - | |||||||||||||||||||||||||||||||||||||
1908 | if (cursorPos >= 0) { | - | ||||||||||||||||||||||||||||||||||||
1909 | if (eventType == QEvent::MouseButtonRelease) | - | ||||||||||||||||||||||||||||||||||||
1910 | QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, cursorPos); | - | ||||||||||||||||||||||||||||||||||||
1911 | - | |||||||||||||||||||||||||||||||||||||
1912 | e->setAccepted(true); | - | ||||||||||||||||||||||||||||||||||||
1913 | return true; | - | ||||||||||||||||||||||||||||||||||||
1914 | } | - | ||||||||||||||||||||||||||||||||||||
1915 | } | - | ||||||||||||||||||||||||||||||||||||
1916 | #else | - | ||||||||||||||||||||||||||||||||||||
1917 | Q_UNUSED(e); | - | ||||||||||||||||||||||||||||||||||||
1918 | #endif | - | ||||||||||||||||||||||||||||||||||||
1919 | return false; | - | ||||||||||||||||||||||||||||||||||||
1920 | } | - | ||||||||||||||||||||||||||||||||||||
1921 | - | |||||||||||||||||||||||||||||||||||||
1922 | void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget) | - | ||||||||||||||||||||||||||||||||||||
1923 | { | - | ||||||||||||||||||||||||||||||||||||
1924 | #ifdef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
1925 | Q_UNUSED(screenPos); | - | ||||||||||||||||||||||||||||||||||||
1926 | Q_UNUSED(docPos); | - | ||||||||||||||||||||||||||||||||||||
1927 | Q_UNUSED(contextWidget); | - | ||||||||||||||||||||||||||||||||||||
1928 | #else | - | ||||||||||||||||||||||||||||||||||||
1929 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1930 | if (!hasFocus) | - | ||||||||||||||||||||||||||||||||||||
1931 | return; | - | ||||||||||||||||||||||||||||||||||||
1932 | QMenu *menu = q->createStandardContextMenu(docPos, contextWidget); | - | ||||||||||||||||||||||||||||||||||||
1933 | if (!menu) | - | ||||||||||||||||||||||||||||||||||||
1934 | return; | - | ||||||||||||||||||||||||||||||||||||
1935 | menu->setAttribute(Qt::WA_DeleteOnClose); | - | ||||||||||||||||||||||||||||||||||||
1936 | menu->popup(screenPos); | - | ||||||||||||||||||||||||||||||||||||
1937 | #endif | - | ||||||||||||||||||||||||||||||||||||
1938 | } | - | ||||||||||||||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||||||||||||||
1940 | bool QWidgetTextControlPrivate::dragEnterEvent(QEvent *e, const QMimeData *mimeData) | - | ||||||||||||||||||||||||||||||||||||
1941 | { | - | ||||||||||||||||||||||||||||||||||||
1942 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1943 | if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) { | - | ||||||||||||||||||||||||||||||||||||
1944 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1945 | return false; | - | ||||||||||||||||||||||||||||||||||||
1946 | } | - | ||||||||||||||||||||||||||||||||||||
1947 | - | |||||||||||||||||||||||||||||||||||||
1948 | dndFeedbackCursor = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
1949 | - | |||||||||||||||||||||||||||||||||||||
1950 | return true; // accept proposed action | - | ||||||||||||||||||||||||||||||||||||
1951 | } | - | ||||||||||||||||||||||||||||||||||||
1952 | - | |||||||||||||||||||||||||||||||||||||
1953 | void QWidgetTextControlPrivate::dragLeaveEvent() | - | ||||||||||||||||||||||||||||||||||||
1954 | { | - | ||||||||||||||||||||||||||||||||||||
1955 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1956 | - | |||||||||||||||||||||||||||||||||||||
1957 | const QRectF crect = q->cursorRect(dndFeedbackCursor); | - | ||||||||||||||||||||||||||||||||||||
1958 | dndFeedbackCursor = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
1959 | - | |||||||||||||||||||||||||||||||||||||
1960 | if (crect.isValid()) | - | ||||||||||||||||||||||||||||||||||||
1961 | emit q->updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
1962 | } | - | ||||||||||||||||||||||||||||||||||||
1963 | - | |||||||||||||||||||||||||||||||||||||
1964 | bool QWidgetTextControlPrivate::dragMoveEvent(QEvent *e, const QMimeData *mimeData, const QPointF &pos) | - | ||||||||||||||||||||||||||||||||||||
1965 | { | - | ||||||||||||||||||||||||||||||||||||
1966 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1967 | if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) { | - | ||||||||||||||||||||||||||||||||||||
1968 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
1969 | return false; | - | ||||||||||||||||||||||||||||||||||||
1970 | } | - | ||||||||||||||||||||||||||||||||||||
1971 | - | |||||||||||||||||||||||||||||||||||||
1972 | const int cursorPos = q->hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
1973 | if (cursorPos != -1) { | - | ||||||||||||||||||||||||||||||||||||
1974 | QRectF crect = q->cursorRect(dndFeedbackCursor); | - | ||||||||||||||||||||||||||||||||||||
1975 | if (crect.isValid()) | - | ||||||||||||||||||||||||||||||||||||
1976 | emit q->updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
1977 | - | |||||||||||||||||||||||||||||||||||||
1978 | dndFeedbackCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
1979 | dndFeedbackCursor.setPosition(cursorPos); | - | ||||||||||||||||||||||||||||||||||||
1980 | - | |||||||||||||||||||||||||||||||||||||
1981 | crect = q->cursorRect(dndFeedbackCursor); | - | ||||||||||||||||||||||||||||||||||||
1982 | emit q->updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
1983 | } | - | ||||||||||||||||||||||||||||||||||||
1984 | - | |||||||||||||||||||||||||||||||||||||
1985 | return true; // accept proposed action | - | ||||||||||||||||||||||||||||||||||||
1986 | } | - | ||||||||||||||||||||||||||||||||||||
1987 | - | |||||||||||||||||||||||||||||||||||||
1988 | bool QWidgetTextControlPrivate::dropEvent(const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QObject *source) | - | ||||||||||||||||||||||||||||||||||||
1989 | { | - | ||||||||||||||||||||||||||||||||||||
1990 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
1991 | dndFeedbackCursor = QTextCursor(); | - | ||||||||||||||||||||||||||||||||||||
1992 | - | |||||||||||||||||||||||||||||||||||||
1993 | if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) | - | ||||||||||||||||||||||||||||||||||||
1994 | return false; | - | ||||||||||||||||||||||||||||||||||||
1995 | - | |||||||||||||||||||||||||||||||||||||
1996 | repaintSelection(); | - | ||||||||||||||||||||||||||||||||||||
1997 | - | |||||||||||||||||||||||||||||||||||||
1998 | QTextCursor insertionCursor = q->cursorForPosition(pos); | - | ||||||||||||||||||||||||||||||||||||
1999 | insertionCursor.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2000 | - | |||||||||||||||||||||||||||||||||||||
2001 | if (dropAction == Qt::MoveAction && source == contextWidget) | - | ||||||||||||||||||||||||||||||||||||
2002 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
2003 | - | |||||||||||||||||||||||||||||||||||||
2004 | cursor = insertionCursor; | - | ||||||||||||||||||||||||||||||||||||
2005 | q->insertFromMimeData(mimeData); | - | ||||||||||||||||||||||||||||||||||||
2006 | insertionCursor.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2007 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
2008 | return true; // accept proposed action | - | ||||||||||||||||||||||||||||||||||||
2009 | } | - | ||||||||||||||||||||||||||||||||||||
2010 | - | |||||||||||||||||||||||||||||||||||||
2011 | void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) | - | ||||||||||||||||||||||||||||||||||||
2012 | { | - | ||||||||||||||||||||||||||||||||||||
2013 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2014 | if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) { | - | ||||||||||||||||||||||||||||||||||||
2015 | e->ignore(); | - | ||||||||||||||||||||||||||||||||||||
2016 | return; | - | ||||||||||||||||||||||||||||||||||||
2017 | } | - | ||||||||||||||||||||||||||||||||||||
2018 | bool isGettingInput = !e->commitString().isEmpty() | - | ||||||||||||||||||||||||||||||||||||
2019 | || e->preeditString() != cursor.block().layout()->preeditAreaText() | - | ||||||||||||||||||||||||||||||||||||
2020 | || e->replacementLength() > 0; | - | ||||||||||||||||||||||||||||||||||||
2021 | - | |||||||||||||||||||||||||||||||||||||
2022 | cursor.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2023 | if (isGettingInput) { | - | ||||||||||||||||||||||||||||||||||||
2024 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||||||||
2025 | } | - | ||||||||||||||||||||||||||||||||||||
2026 | - | |||||||||||||||||||||||||||||||||||||
2027 | // insert commit string | - | ||||||||||||||||||||||||||||||||||||
2028 | if (!e->commitString().isEmpty() || e->replacementLength()) { | - | ||||||||||||||||||||||||||||||||||||
2029 | QTextCursor c = cursor; | - | ||||||||||||||||||||||||||||||||||||
2030 | c.setPosition(c.position() + e->replacementStart()); | - | ||||||||||||||||||||||||||||||||||||
2031 | c.setPosition(c.position() + e->replacementLength(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
2032 | c.insertText(e->commitString()); | - | ||||||||||||||||||||||||||||||||||||
2033 | } | - | ||||||||||||||||||||||||||||||||||||
2034 | - | |||||||||||||||||||||||||||||||||||||
2035 | for (int i = 0; i < e->attributes().size(); ++i) { | - | ||||||||||||||||||||||||||||||||||||
2036 | const QInputMethodEvent::Attribute &a = e->attributes().at(i); | - | ||||||||||||||||||||||||||||||||||||
2037 | if (a.type == QInputMethodEvent::Selection) { | - | ||||||||||||||||||||||||||||||||||||
2038 | QTextCursor oldCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
2039 | int blockStart = a.start + cursor.block().position(); | - | ||||||||||||||||||||||||||||||||||||
2040 | cursor.setPosition(blockStart, QTextCursor::MoveAnchor); | - | ||||||||||||||||||||||||||||||||||||
2041 | cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
2042 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
2043 | repaintOldAndNewSelection(oldCursor); | - | ||||||||||||||||||||||||||||||||||||
2044 | } | - | ||||||||||||||||||||||||||||||||||||
2045 | } | - | ||||||||||||||||||||||||||||||||||||
2046 | - | |||||||||||||||||||||||||||||||||||||
2047 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
2048 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||||||||||||||
2049 | if (isGettingInput) | - | ||||||||||||||||||||||||||||||||||||
2050 | layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); | - | ||||||||||||||||||||||||||||||||||||
2051 | QVector<QTextLayout::FormatRange> overrides; | - | ||||||||||||||||||||||||||||||||||||
2052 | overrides.reserve(e->attributes().size()); | - | ||||||||||||||||||||||||||||||||||||
2053 | const int oldPreeditCursor = preeditCursor; | - | ||||||||||||||||||||||||||||||||||||
2054 | preeditCursor = e->preeditString().length(); | - | ||||||||||||||||||||||||||||||||||||
2055 | hideCursor = false; | - | ||||||||||||||||||||||||||||||||||||
2056 | for (int i = 0; i < e->attributes().size(); ++i) { | - | ||||||||||||||||||||||||||||||||||||
2057 | const QInputMethodEvent::Attribute &a = e->attributes().at(i); | - | ||||||||||||||||||||||||||||||||||||
2058 | if (a.type == QInputMethodEvent::Cursor) { | - | ||||||||||||||||||||||||||||||||||||
2059 | preeditCursor = a.start; | - | ||||||||||||||||||||||||||||||||||||
2060 | hideCursor = !a.length; | - | ||||||||||||||||||||||||||||||||||||
2061 | } else if (a.type == QInputMethodEvent::TextFormat) { | - | ||||||||||||||||||||||||||||||||||||
2062 | QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
2063 | if (f.isValid()) { | - | ||||||||||||||||||||||||||||||||||||
2064 | QTextLayout::FormatRange o; | - | ||||||||||||||||||||||||||||||||||||
2065 | o.start = a.start + cursor.position() - block.position(); | - | ||||||||||||||||||||||||||||||||||||
2066 | o.length = a.length; | - | ||||||||||||||||||||||||||||||||||||
2067 | o.format = f; | - | ||||||||||||||||||||||||||||||||||||
2068 | overrides.append(o); | - | ||||||||||||||||||||||||||||||||||||
2069 | } | - | ||||||||||||||||||||||||||||||||||||
2070 | } | - | ||||||||||||||||||||||||||||||||||||
2071 | } | - | ||||||||||||||||||||||||||||||||||||
2072 | layout->setFormats(overrides); | - | ||||||||||||||||||||||||||||||||||||
2073 | - | |||||||||||||||||||||||||||||||||||||
2074 | cursor.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2075 | - | |||||||||||||||||||||||||||||||||||||
2076 | if (cursor.d) | - | ||||||||||||||||||||||||||||||||||||
2077 | cursor.d->setX(); | - | ||||||||||||||||||||||||||||||||||||
2078 | if (oldPreeditCursor != preeditCursor) | - | ||||||||||||||||||||||||||||||||||||
2079 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
2080 | } | - | ||||||||||||||||||||||||||||||||||||
2081 | - | |||||||||||||||||||||||||||||||||||||
2082 | QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const | - | ||||||||||||||||||||||||||||||||||||
2083 | { | - | ||||||||||||||||||||||||||||||||||||
2084 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2085 | QTextBlock block = d->cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
2086 | switch(property) { | - | ||||||||||||||||||||||||||||||||||||
2087 | case Qt::ImCursorRectangle: never executed: case Qt::ImCursorRectangle: | 0 | ||||||||||||||||||||||||||||||||||||
2088 | return cursorRect(); never executed: return cursorRect(); | 0 | ||||||||||||||||||||||||||||||||||||
2089 | case Qt::ImAnchorRectangle: never executed: case Qt::ImAnchorRectangle: | 0 | ||||||||||||||||||||||||||||||||||||
2090 | return d->rectForPosition(d->cursor.anchor()); never executed: return d->rectForPosition(d->cursor.anchor()); | 0 | ||||||||||||||||||||||||||||||||||||
2091 | case Qt::ImFont: never executed: case Qt::ImFont: | 0 | ||||||||||||||||||||||||||||||||||||
2092 | return QVariant(d->cursor.charFormat().font()); never executed: return QVariant(d->cursor.charFormat().font()); | 0 | ||||||||||||||||||||||||||||||||||||
2093 | case Qt::ImCursorPosition: { never executed: case Qt::ImCursorPosition: | 0 | ||||||||||||||||||||||||||||||||||||
2094 | const QPointF pt = argument.toPointF(); | - | ||||||||||||||||||||||||||||||||||||
2095 | if (!pt.isNull())
| 0 | ||||||||||||||||||||||||||||||||||||
2096 | return QVariant(cursorForPosition(pt).position() - block.position()); never executed: return QVariant(cursorForPosition(pt).position() - block.position()); | 0 | ||||||||||||||||||||||||||||||||||||
2097 | return QVariant(d->cursor.position() - block.position()); } never executed: return QVariant(d->cursor.position() - block.position()); | 0 | ||||||||||||||||||||||||||||||||||||
2098 | case Qt::ImSurroundingText: never executed: case Qt::ImSurroundingText: | 0 | ||||||||||||||||||||||||||||||||||||
2099 | return QVariant(block.text()); never executed: return QVariant(block.text()); | 0 | ||||||||||||||||||||||||||||||||||||
2100 | case Qt::ImCurrentSelection: never executed: case Qt::ImCurrentSelection: | 0 | ||||||||||||||||||||||||||||||||||||
2101 | return QVariant(d->cursor.selectedText()); never executed: return QVariant(d->cursor.selectedText()); | 0 | ||||||||||||||||||||||||||||||||||||
2102 | case Qt::ImMaximumTextLength: never executed: case Qt::ImMaximumTextLength: | 0 | ||||||||||||||||||||||||||||||||||||
2103 | return QVariant(); // No limit. never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||||||||
2104 | case Qt::ImAnchorPosition: never executed: case Qt::ImAnchorPosition: | 0 | ||||||||||||||||||||||||||||||||||||
2105 | return QVariant(d->cursor.anchor() - block.position()); never executed: return QVariant(d->cursor.anchor() - block.position()); | 0 | ||||||||||||||||||||||||||||||||||||
2106 | case Qt::ImAbsolutePosition: { never executed: case Qt::ImAbsolutePosition: | 0 | ||||||||||||||||||||||||||||||||||||
2107 | const QPointF pt = argument.toPointF(); | - | ||||||||||||||||||||||||||||||||||||
2108 | if (!pt.isNull())
| 0 | ||||||||||||||||||||||||||||||||||||
2109 | return QVariant(cursorForPosition(pt).position()); never executed: return QVariant(cursorForPosition(pt).position()); | 0 | ||||||||||||||||||||||||||||||||||||
2110 | return QVariant(d->cursor.position()); } never executed: return QVariant(d->cursor.position()); | 0 | ||||||||||||||||||||||||||||||||||||
2111 | case Qt::ImTextAfterCursor: never executed: case Qt::ImTextAfterCursor: | 0 | ||||||||||||||||||||||||||||||||||||
2112 | { | - | ||||||||||||||||||||||||||||||||||||
2113 | int maxLength = argument.isValid() ? argument.toInt() : 1024;
| 0 | ||||||||||||||||||||||||||||||||||||
2114 | QTextCursor tmpCursor = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
2115 | int localPos = d->cursor.position() - block.position(); | - | ||||||||||||||||||||||||||||||||||||
2116 | QString result = block.text().mid(localPos); | - | ||||||||||||||||||||||||||||||||||||
2117 | while (result.length() < maxLength) {
| 0 | ||||||||||||||||||||||||||||||||||||
2118 | int currentBlock = tmpCursor.blockNumber(); | - | ||||||||||||||||||||||||||||||||||||
2119 | tmpCursor.movePosition(QTextCursor::NextBlock); | - | ||||||||||||||||||||||||||||||||||||
2120 | if (tmpCursor.blockNumber() == currentBlock)
| 0 | ||||||||||||||||||||||||||||||||||||
2121 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
2122 | result += QLatin1Char('\n') + tmpCursor.block().text(); | - | ||||||||||||||||||||||||||||||||||||
2123 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2124 | return QVariant(result); never executed: return QVariant(result); | 0 | ||||||||||||||||||||||||||||||||||||
2125 | } | - | ||||||||||||||||||||||||||||||||||||
2126 | case Qt::ImTextBeforeCursor: never executed: case Qt::ImTextBeforeCursor: | 0 | ||||||||||||||||||||||||||||||||||||
2127 | { | - | ||||||||||||||||||||||||||||||||||||
2128 | int maxLength = argument.isValid() ? argument.toInt() : 1024;
| 0 | ||||||||||||||||||||||||||||||||||||
2129 | QTextCursor tmpCursor = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
2130 | int localPos = d->cursor.position() - block.position(); | - | ||||||||||||||||||||||||||||||||||||
2131 | int numBlocks = 0; | - | ||||||||||||||||||||||||||||||||||||
2132 | int resultLen = localPos; | - | ||||||||||||||||||||||||||||||||||||
2133 | while (resultLen < maxLength) {
| 0 | ||||||||||||||||||||||||||||||||||||
2134 | int currentBlock = tmpCursor.blockNumber(); | - | ||||||||||||||||||||||||||||||||||||
2135 | tmpCursor.movePosition(QTextCursor::PreviousBlock); | - | ||||||||||||||||||||||||||||||||||||
2136 | if (tmpCursor.blockNumber() == currentBlock)
| 0 | ||||||||||||||||||||||||||||||||||||
2137 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
2138 | numBlocks++; | - | ||||||||||||||||||||||||||||||||||||
2139 | resultLen += tmpCursor.block().length(); | - | ||||||||||||||||||||||||||||||||||||
2140 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2141 | QString result; | - | ||||||||||||||||||||||||||||||||||||
2142 | while (numBlocks) {
| 0 | ||||||||||||||||||||||||||||||||||||
2143 | result += tmpCursor.block().text() + QLatin1Char('\n'); | - | ||||||||||||||||||||||||||||||||||||
2144 | tmpCursor.movePosition(QTextCursor::NextBlock); | - | ||||||||||||||||||||||||||||||||||||
2145 | --numBlocks; | - | ||||||||||||||||||||||||||||||||||||
2146 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2147 | result += block.text().midmidRef(0, localPos); | - | ||||||||||||||||||||||||||||||||||||
2148 | return QVariant(result); never executed: return QVariant(result); | 0 | ||||||||||||||||||||||||||||||||||||
2149 | } | - | ||||||||||||||||||||||||||||||||||||
2150 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
2151 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||||||||
2152 | } | - | ||||||||||||||||||||||||||||||||||||
2153 | } | - | ||||||||||||||||||||||||||||||||||||
2154 | - | |||||||||||||||||||||||||||||||||||||
2155 | void QWidgetTextControl::setFocus(bool focus, Qt::FocusReason reason) | - | ||||||||||||||||||||||||||||||||||||
2156 | { | - | ||||||||||||||||||||||||||||||||||||
2157 | QFocusEvent ev(focus ? QEvent::FocusIn : QEvent::FocusOut, | - | ||||||||||||||||||||||||||||||||||||
2158 | reason); | - | ||||||||||||||||||||||||||||||||||||
2159 | processEvent(&ev); | - | ||||||||||||||||||||||||||||||||||||
2160 | } | - | ||||||||||||||||||||||||||||||||||||
2161 | - | |||||||||||||||||||||||||||||||||||||
2162 | void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e) | - | ||||||||||||||||||||||||||||||||||||
2163 | { | - | ||||||||||||||||||||||||||||||||||||
2164 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2165 | emit q->updateRequest(q->selectionRect()); | - | ||||||||||||||||||||||||||||||||||||
2166 | if (e->gotFocus()) {
| 0 | ||||||||||||||||||||||||||||||||||||
2167 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
2168 | if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) { | - | ||||||||||||||||||||||||||||||||||||
2169 | #endif | - | ||||||||||||||||||||||||||||||||||||
2170 | cursorOn = (interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable)); | - | ||||||||||||||||||||||||||||||||||||
2171 | if (interactionFlags & Qt::TextEditable) {
| 0 | ||||||||||||||||||||||||||||||||||||
2172 | setBlinkingCursorEnabledsetCursorVisible(true); | - | ||||||||||||||||||||||||||||||||||||
2173 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2174 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
2175 | } | - | ||||||||||||||||||||||||||||||||||||
2176 | #endif | - | ||||||||||||||||||||||||||||||||||||
2177 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2178 | setBlinkingCursorEnabledsetCursorVisible(false); | - | ||||||||||||||||||||||||||||||||||||
2179 | - | |||||||||||||||||||||||||||||||||||||
2180 | if (cursorIsFocusIndicator
| 0 | ||||||||||||||||||||||||||||||||||||
2181 | && e->reason() != Qt::ActiveWindowFocusReason
| 0 | ||||||||||||||||||||||||||||||||||||
2182 | && e->reason() != Qt::PopupFocusReason
| 0 | ||||||||||||||||||||||||||||||||||||
2183 | && cursor.hasSelection()) {
| 0 | ||||||||||||||||||||||||||||||||||||
2184 | cursor.clearSelection(); | - | ||||||||||||||||||||||||||||||||||||
2185 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2186 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2187 | hasFocus = e->gotFocus(); | - | ||||||||||||||||||||||||||||||||||||
2188 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2189 | - | |||||||||||||||||||||||||||||||||||||
2190 | QString QWidgetTextControlPrivate::anchorForCursor(const QTextCursor &anchorCursor) const | - | ||||||||||||||||||||||||||||||||||||
2191 | { | - | ||||||||||||||||||||||||||||||||||||
2192 | if (anchorCursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
2193 | QTextCursor cursor = anchorCursor; | - | ||||||||||||||||||||||||||||||||||||
2194 | if (cursor.selectionStart() != cursor.position()) | - | ||||||||||||||||||||||||||||||||||||
2195 | cursor.setPosition(cursor.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
2196 | cursor.movePosition(QTextCursor::NextCharacter); | - | ||||||||||||||||||||||||||||||||||||
2197 | QTextCharFormat fmt = cursor.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
2198 | if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) | - | ||||||||||||||||||||||||||||||||||||
2199 | return fmt.stringProperty(QTextFormat::AnchorHref); | - | ||||||||||||||||||||||||||||||||||||
2200 | } | - | ||||||||||||||||||||||||||||||||||||
2201 | return QString(); | - | ||||||||||||||||||||||||||||||||||||
2202 | } | - | ||||||||||||||||||||||||||||||||||||
2203 | - | |||||||||||||||||||||||||||||||||||||
2204 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
2205 | void QWidgetTextControlPrivate::editFocusEvent(QEvent *e) | - | ||||||||||||||||||||||||||||||||||||
2206 | { | - | ||||||||||||||||||||||||||||||||||||
2207 | Q_Q(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2208 | - | |||||||||||||||||||||||||||||||||||||
2209 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||||||||||||||
2210 | if (e->type() == QEvent::EnterEditFocus && interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
2211 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||||||||||||||
2212 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
2213 | const bool moved = cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); | - | ||||||||||||||||||||||||||||||||||||
2214 | q->ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
2215 | if (moved) { | - | ||||||||||||||||||||||||||||||||||||
2216 | if (cursor.position() != oldCursorPos) | - | ||||||||||||||||||||||||||||||||||||
2217 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
2218 | emit q->microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
2219 | } | - | ||||||||||||||||||||||||||||||||||||
2220 | selectionChanged(); | - | ||||||||||||||||||||||||||||||||||||
2221 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
2222 | - | |||||||||||||||||||||||||||||||||||||
2223 | setBlinkingCursorEnabled(true); | - | ||||||||||||||||||||||||||||||||||||
2224 | } else | - | ||||||||||||||||||||||||||||||||||||
2225 | setBlinkingCursorEnabled(false); | - | ||||||||||||||||||||||||||||||||||||
2226 | } | - | ||||||||||||||||||||||||||||||||||||
2227 | - | |||||||||||||||||||||||||||||||||||||
2228 | hasEditFocus = e->type() == QEvent::EnterEditFocus; | - | ||||||||||||||||||||||||||||||||||||
2229 | } | - | ||||||||||||||||||||||||||||||||||||
2230 | #endif | - | ||||||||||||||||||||||||||||||||||||
2231 | - | |||||||||||||||||||||||||||||||||||||
2232 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
2233 | static inline void setActionIcon(QAction *action, const QString &name) | - | ||||||||||||||||||||||||||||||||||||
2234 | { | - | ||||||||||||||||||||||||||||||||||||
2235 | const QIcon icon = QIcon::fromTheme(name); | - | ||||||||||||||||||||||||||||||||||||
2236 | if (!icon.isNull()) | - | ||||||||||||||||||||||||||||||||||||
2237 | action->setIcon(icon); | - | ||||||||||||||||||||||||||||||||||||
2238 | } | - | ||||||||||||||||||||||||||||||||||||
2239 | - | |||||||||||||||||||||||||||||||||||||
2240 | QMenu *QWidgetTextControl::createStandardContextMenu(const QPointF &pos, QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||
2241 | { | - | ||||||||||||||||||||||||||||||||||||
2242 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2243 | - | |||||||||||||||||||||||||||||||||||||
2244 | const bool showTextSelectionActions = d->interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse); | - | ||||||||||||||||||||||||||||||||||||
2245 | - | |||||||||||||||||||||||||||||||||||||
2246 | d->linkToCopy = QString(); | - | ||||||||||||||||||||||||||||||||||||
2247 | if (!pos.isNull()) | - | ||||||||||||||||||||||||||||||||||||
2248 | d->linkToCopy = anchorAt(pos); | - | ||||||||||||||||||||||||||||||||||||
2249 | - | |||||||||||||||||||||||||||||||||||||
2250 | if (d->linkToCopy.isEmpty() && !showTextSelectionActions) | - | ||||||||||||||||||||||||||||||||||||
2251 | return 0; | - | ||||||||||||||||||||||||||||||||||||
2252 | - | |||||||||||||||||||||||||||||||||||||
2253 | QMenu *menu = new QMenu(parent); | - | ||||||||||||||||||||||||||||||||||||
2254 | QAction *a; | - | ||||||||||||||||||||||||||||||||||||
2255 | - | |||||||||||||||||||||||||||||||||||||
2256 | if (d->interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
2257 | a = menu->addAction(tr("&Undo") + ACCEL_KEY(QKeySequence::Undo), this, SLOT(undo())); | - | ||||||||||||||||||||||||||||||||||||
2258 | a->setEnabled(d->doc->isUndoAvailable()); | - | ||||||||||||||||||||||||||||||||||||
2259 | a->setObjectName(QStringLiteral("edit-undo")); | - | ||||||||||||||||||||||||||||||||||||
2260 | setActionIcon(a, QStringLiteral("edit-undo")); | - | ||||||||||||||||||||||||||||||||||||
2261 | a = menu->addAction(tr("&Redo") + ACCEL_KEY(QKeySequence::Redo), this, SLOT(redo())); | - | ||||||||||||||||||||||||||||||||||||
2262 | a->setEnabled(d->doc->isRedoAvailable()); | - | ||||||||||||||||||||||||||||||||||||
2263 | a->setObjectName(QStringLiteral("edit-redo")); | - | ||||||||||||||||||||||||||||||||||||
2264 | setActionIcon(a, QStringLiteral("edit-redo")); | - | ||||||||||||||||||||||||||||||||||||
2265 | menu->addSeparator(); | - | ||||||||||||||||||||||||||||||||||||
2266 | - | |||||||||||||||||||||||||||||||||||||
2267 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
2268 | a = menu->addAction(tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut), this, SLOT(cut())); | - | ||||||||||||||||||||||||||||||||||||
2269 | a->setEnabled(d->cursor.hasSelection()); | - | ||||||||||||||||||||||||||||||||||||
2270 | a->setObjectName(QStringLiteral("edit-cut")); | - | ||||||||||||||||||||||||||||||||||||
2271 | setActionIcon(a, QStringLiteral("edit-cut")); | - | ||||||||||||||||||||||||||||||||||||
2272 | #endif | - | ||||||||||||||||||||||||||||||||||||
2273 | } | - | ||||||||||||||||||||||||||||||||||||
2274 | - | |||||||||||||||||||||||||||||||||||||
2275 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
2276 | if (showTextSelectionActions) { | - | ||||||||||||||||||||||||||||||||||||
2277 | a = menu->addAction(tr("&Copy") + ACCEL_KEY(QKeySequence::Copy), this, SLOT(copy())); | - | ||||||||||||||||||||||||||||||||||||
2278 | a->setEnabled(d->cursor.hasSelection()); | - | ||||||||||||||||||||||||||||||||||||
2279 | a->setObjectName(QStringLiteral("edit-copy")); | - | ||||||||||||||||||||||||||||||||||||
2280 | setActionIcon(a, QStringLiteral("edit-copy")); | - | ||||||||||||||||||||||||||||||||||||
2281 | } | - | ||||||||||||||||||||||||||||||||||||
2282 | - | |||||||||||||||||||||||||||||||||||||
2283 | if ((d->interactionFlags & Qt::LinksAccessibleByKeyboard) | - | ||||||||||||||||||||||||||||||||||||
2284 | || (d->interactionFlags & Qt::LinksAccessibleByMouse)) { | - | ||||||||||||||||||||||||||||||||||||
2285 | - | |||||||||||||||||||||||||||||||||||||
2286 | a = menu->addAction(tr("Copy &Link Location"), this, SLOT(_q_copyLink())); | - | ||||||||||||||||||||||||||||||||||||
2287 | a->setEnabled(!d->linkToCopy.isEmpty()); | - | ||||||||||||||||||||||||||||||||||||
2288 | a->setObjectName(QStringLiteral("link-copy")); | - | ||||||||||||||||||||||||||||||||||||
2289 | } | - | ||||||||||||||||||||||||||||||||||||
2290 | #endif // QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||||||||||||||
2292 | if (d->interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
2293 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
2294 | a = menu->addAction(tr("&Paste") + ACCEL_KEY(QKeySequence::Paste), this, SLOT(paste())); | - | ||||||||||||||||||||||||||||||||||||
2295 | a->setEnabled(canPaste()); | - | ||||||||||||||||||||||||||||||||||||
2296 | a->setObjectName(QStringLiteral("edit-paste")); | - | ||||||||||||||||||||||||||||||||||||
2297 | setActionIcon(a, QStringLiteral("edit-paste")); | - | ||||||||||||||||||||||||||||||||||||
2298 | #endif | - | ||||||||||||||||||||||||||||||||||||
2299 | a = menu->addAction(tr("Delete"), this, SLOT(_q_deleteSelected())); | - | ||||||||||||||||||||||||||||||||||||
2300 | a->setEnabled(d->cursor.hasSelection()); | - | ||||||||||||||||||||||||||||||||||||
2301 | a->setObjectName(QStringLiteral("edit-delete")); | - | ||||||||||||||||||||||||||||||||||||
2302 | setActionIcon(a, QStringLiteral("edit-delete")); | - | ||||||||||||||||||||||||||||||||||||
2303 | } | - | ||||||||||||||||||||||||||||||||||||
2304 | - | |||||||||||||||||||||||||||||||||||||
2305 | - | |||||||||||||||||||||||||||||||||||||
2306 | if (showTextSelectionActions) { | - | ||||||||||||||||||||||||||||||||||||
2307 | menu->addSeparator(); | - | ||||||||||||||||||||||||||||||||||||
2308 | a = menu->addAction(tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll), this, SLOT(selectAll())); | - | ||||||||||||||||||||||||||||||||||||
2309 | a->setEnabled(!d->doc->isEmpty()); | - | ||||||||||||||||||||||||||||||||||||
2310 | a->setObjectName(QStringLiteral("select-all")); | - | ||||||||||||||||||||||||||||||||||||
2311 | } | - | ||||||||||||||||||||||||||||||||||||
2312 | - | |||||||||||||||||||||||||||||||||||||
2313 | if ((d->interactionFlags & Qt::TextEditable) && QGuiApplication::styleHints()->useRtlExtensions()) { | - | ||||||||||||||||||||||||||||||||||||
2314 | menu->addSeparator(); | - | ||||||||||||||||||||||||||||||||||||
2315 | QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, menu); | - | ||||||||||||||||||||||||||||||||||||
2316 | menu->addMenu(ctrlCharacterMenu); | - | ||||||||||||||||||||||||||||||||||||
2317 | } | - | ||||||||||||||||||||||||||||||||||||
2318 | - | |||||||||||||||||||||||||||||||||||||
2319 | return menu; | - | ||||||||||||||||||||||||||||||||||||
2320 | } | - | ||||||||||||||||||||||||||||||||||||
2321 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
2322 | - | |||||||||||||||||||||||||||||||||||||
2323 | QTextCursor QWidgetTextControl::cursorForPosition(const QPointF &pos) const | - | ||||||||||||||||||||||||||||||||||||
2324 | { | - | ||||||||||||||||||||||||||||||||||||
2325 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2326 | int cursorPos = hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||||||||||||||
2327 | if (cursorPos == -1) | - | ||||||||||||||||||||||||||||||||||||
2328 | cursorPos = 0; | - | ||||||||||||||||||||||||||||||||||||
2329 | QTextCursor c(d->doc); | - | ||||||||||||||||||||||||||||||||||||
2330 | c.setPosition(cursorPos); | - | ||||||||||||||||||||||||||||||||||||
2331 | return c; | - | ||||||||||||||||||||||||||||||||||||
2332 | } | - | ||||||||||||||||||||||||||||||||||||
2333 | - | |||||||||||||||||||||||||||||||||||||
2334 | QRectF QWidgetTextControl::cursorRect(const QTextCursor &cursor) const | - | ||||||||||||||||||||||||||||||||||||
2335 | { | - | ||||||||||||||||||||||||||||||||||||
2336 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2337 | if (cursor.isNull()) | - | ||||||||||||||||||||||||||||||||||||
2338 | return QRectF(); | - | ||||||||||||||||||||||||||||||||||||
2339 | - | |||||||||||||||||||||||||||||||||||||
2340 | return d->rectForPosition(cursor.position()); | - | ||||||||||||||||||||||||||||||||||||
2341 | } | - | ||||||||||||||||||||||||||||||||||||
2342 | - | |||||||||||||||||||||||||||||||||||||
2343 | QRectF QWidgetTextControl::cursorRect() const | - | ||||||||||||||||||||||||||||||||||||
2344 | { | - | ||||||||||||||||||||||||||||||||||||
2345 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2346 | return cursorRect(d->cursor); | - | ||||||||||||||||||||||||||||||||||||
2347 | } | - | ||||||||||||||||||||||||||||||||||||
2348 | - | |||||||||||||||||||||||||||||||||||||
2349 | QRectF QWidgetTextControlPrivate::cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const | - | ||||||||||||||||||||||||||||||||||||
2350 | { | - | ||||||||||||||||||||||||||||||||||||
2351 | if (cursor.isNull()) | - | ||||||||||||||||||||||||||||||||||||
2352 | return QRectF(); | - | ||||||||||||||||||||||||||||||||||||
2353 | - | |||||||||||||||||||||||||||||||||||||
2354 | return rectForPosition(cursor.position()).adjusted(-4, 0, 4, 0); | - | ||||||||||||||||||||||||||||||||||||
2355 | } | - | ||||||||||||||||||||||||||||||||||||
2356 | - | |||||||||||||||||||||||||||||||||||||
2357 | QString QWidgetTextControl::anchorAt(const QPointF &pos) const | - | ||||||||||||||||||||||||||||||||||||
2358 | { | - | ||||||||||||||||||||||||||||||||||||
2359 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2360 | return d->doc->documentLayout()->anchorAt(pos); | - | ||||||||||||||||||||||||||||||||||||
2361 | } | - | ||||||||||||||||||||||||||||||||||||
2362 | - | |||||||||||||||||||||||||||||||||||||
2363 | QString QWidgetTextControl::anchorAtCursor() const | - | ||||||||||||||||||||||||||||||||||||
2364 | { | - | ||||||||||||||||||||||||||||||||||||
2365 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2366 | - | |||||||||||||||||||||||||||||||||||||
2367 | return d->anchorForCursor(d->cursor); | - | ||||||||||||||||||||||||||||||||||||
2368 | } | - | ||||||||||||||||||||||||||||||||||||
2369 | - | |||||||||||||||||||||||||||||||||||||
2370 | bool QWidgetTextControl::overwriteMode() const | - | ||||||||||||||||||||||||||||||||||||
2371 | { | - | ||||||||||||||||||||||||||||||||||||
2372 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2373 | return d->overwriteMode; | - | ||||||||||||||||||||||||||||||||||||
2374 | } | - | ||||||||||||||||||||||||||||||||||||
2375 | - | |||||||||||||||||||||||||||||||||||||
2376 | void QWidgetTextControl::setOverwriteMode(bool overwrite) | - | ||||||||||||||||||||||||||||||||||||
2377 | { | - | ||||||||||||||||||||||||||||||||||||
2378 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2379 | d->overwriteMode = overwrite; | - | ||||||||||||||||||||||||||||||||||||
2380 | } | - | ||||||||||||||||||||||||||||||||||||
2381 | - | |||||||||||||||||||||||||||||||||||||
2382 | int QWidgetTextControl::cursorWidth() const | - | ||||||||||||||||||||||||||||||||||||
2383 | { | - | ||||||||||||||||||||||||||||||||||||
2384 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||||||||||||||||||||
2385 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2386 | return d->doc->documentLayout()->property("cursorWidth").toInt(); | - | ||||||||||||||||||||||||||||||||||||
2387 | #else | - | ||||||||||||||||||||||||||||||||||||
2388 | return 1; | - | ||||||||||||||||||||||||||||||||||||
2389 | #endif | - | ||||||||||||||||||||||||||||||||||||
2390 | } | - | ||||||||||||||||||||||||||||||||||||
2391 | - | |||||||||||||||||||||||||||||||||||||
2392 | void QWidgetTextControl::setCursorWidth(int width) | - | ||||||||||||||||||||||||||||||||||||
2393 | { | - | ||||||||||||||||||||||||||||||||||||
2394 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2395 | #ifdef QT_NO_PROPERTIES | - | ||||||||||||||||||||||||||||||||||||
2396 | Q_UNUSED(width); | - | ||||||||||||||||||||||||||||||||||||
2397 | #else | - | ||||||||||||||||||||||||||||||||||||
2398 | if (width == -1) | - | ||||||||||||||||||||||||||||||||||||
2399 | width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth); | - | ||||||||||||||||||||||||||||||||||||
2400 | d->doc->documentLayout()->setProperty("cursorWidth", width); | - | ||||||||||||||||||||||||||||||||||||
2401 | #endif | - | ||||||||||||||||||||||||||||||||||||
2402 | d->repaintCursor(); | - | ||||||||||||||||||||||||||||||||||||
2403 | } | - | ||||||||||||||||||||||||||||||||||||
2404 | - | |||||||||||||||||||||||||||||||||||||
2405 | bool QWidgetTextControl::acceptRichText() const | - | ||||||||||||||||||||||||||||||||||||
2406 | { | - | ||||||||||||||||||||||||||||||||||||
2407 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2408 | return d->acceptRichText; | - | ||||||||||||||||||||||||||||||||||||
2409 | } | - | ||||||||||||||||||||||||||||||||||||
2410 | - | |||||||||||||||||||||||||||||||||||||
2411 | void QWidgetTextControl::setAcceptRichText(bool accept) | - | ||||||||||||||||||||||||||||||||||||
2412 | { | - | ||||||||||||||||||||||||||||||||||||
2413 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2414 | d->acceptRichText = accept; | - | ||||||||||||||||||||||||||||||||||||
2415 | } | - | ||||||||||||||||||||||||||||||||||||
2416 | - | |||||||||||||||||||||||||||||||||||||
2417 | #ifndef QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||||||||||||||
2418 | - | |||||||||||||||||||||||||||||||||||||
2419 | void QWidgetTextControl::setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections) | - | ||||||||||||||||||||||||||||||||||||
2420 | { | - | ||||||||||||||||||||||||||||||||||||
2421 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2422 | - | |||||||||||||||||||||||||||||||||||||
2423 | QHash<int, int> hash; | - | ||||||||||||||||||||||||||||||||||||
2424 | for (int i = 0; i < d->extraSelections.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||
2425 | const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(i); | - | ||||||||||||||||||||||||||||||||||||
2426 | hash.insertMulti(esel.cursor.anchor(), i); | - | ||||||||||||||||||||||||||||||||||||
2427 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2428 | - | |||||||||||||||||||||||||||||||||||||
2429 | for (int i = 0; i < selections.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||
2430 | const QTextEdit::ExtraSelection &sel = selections.at(i); | - | ||||||||||||||||||||||||||||||||||||
2431 | QHash<int, int>::iteratorconst auto it = hash.findconstFind(sel.cursor.anchor()); | - | ||||||||||||||||||||||||||||||||||||
2432 | if (it != hash.endcend()) {
| 0 | ||||||||||||||||||||||||||||||||||||
2433 | const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value()); | - | ||||||||||||||||||||||||||||||||||||
2434 | if (esel.cursor.position() == sel.cursor.position()
| 0 | ||||||||||||||||||||||||||||||||||||
2435 | && esel.format == sel.format) {
| 0 | ||||||||||||||||||||||||||||||||||||
2436 | hash.erase(it); | - | ||||||||||||||||||||||||||||||||||||
2437 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||
2438 | } | - | ||||||||||||||||||||||||||||||||||||
2439 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2440 | QRectF r = selectionRect(sel.cursor); | - | ||||||||||||||||||||||||||||||||||||
2441 | if (sel.format.boolProperty(QTextFormat::FullWidthSelection)) {
| 0 | ||||||||||||||||||||||||||||||||||||
2442 | r.setLeft(0); | - | ||||||||||||||||||||||||||||||||||||
2443 | r.setWidth(qreal(INT_MAX)); | - | ||||||||||||||||||||||||||||||||||||
2444 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2445 | emit updateRequest(r); | - | ||||||||||||||||||||||||||||||||||||
2446 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2447 | - | |||||||||||||||||||||||||||||||||||||
2448 | for (QHash<int, int>::iterator it = hash.begin(); it != hash.end(); ++it) {
| 0 | ||||||||||||||||||||||||||||||||||||
2449 | const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value()); | - | ||||||||||||||||||||||||||||||||||||
2450 | QRectF r = selectionRect(esel.cursor); | - | ||||||||||||||||||||||||||||||||||||
2451 | if (esel.format.boolProperty(QTextFormat::FullWidthSelection)) {
| 0 | ||||||||||||||||||||||||||||||||||||
2452 | r.setLeft(0); | - | ||||||||||||||||||||||||||||||||||||
2453 | r.setWidth(qreal(INT_MAX)); | - | ||||||||||||||||||||||||||||||||||||
2454 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2455 | emit updateRequest(r); | - | ||||||||||||||||||||||||||||||||||||
2456 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2457 | - | |||||||||||||||||||||||||||||||||||||
2458 | d->extraSelections.resize(selections.count()); | - | ||||||||||||||||||||||||||||||||||||
2459 | for (int i = 0; i < selections.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||
2460 | d->extraSelections[i].cursor = selections.at(i).cursor; | - | ||||||||||||||||||||||||||||||||||||
2461 | d->extraSelections[i].format = selections.at(i).format; | - | ||||||||||||||||||||||||||||||||||||
2462 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2463 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2464 | - | |||||||||||||||||||||||||||||||||||||
2465 | QList<QTextEdit::ExtraSelection> QWidgetTextControl::extraSelections() const | - | ||||||||||||||||||||||||||||||||||||
2466 | { | - | ||||||||||||||||||||||||||||||||||||
2467 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2468 | QList<QTextEdit::ExtraSelection> selections; | - | ||||||||||||||||||||||||||||||||||||
2469 | const int numExtraSelections = d->extraSelections.count(); | - | ||||||||||||||||||||||||||||||||||||
2470 | selections.reserve(numExtraSelections); | - | ||||||||||||||||||||||||||||||||||||
2471 | for (int i = 0; i < numExtraSelections; ++i) { | - | ||||||||||||||||||||||||||||||||||||
2472 | QTextEdit::ExtraSelection sel; | - | ||||||||||||||||||||||||||||||||||||
2473 | const QAbstractTextDocumentLayout::Selection &sel2 = d->extraSelections.at(i); | - | ||||||||||||||||||||||||||||||||||||
2474 | sel.cursor = sel2.cursor; | - | ||||||||||||||||||||||||||||||||||||
2475 | sel.format = sel2.format; | - | ||||||||||||||||||||||||||||||||||||
2476 | selections.append(sel); | - | ||||||||||||||||||||||||||||||||||||
2477 | } | - | ||||||||||||||||||||||||||||||||||||
2478 | return selections; | - | ||||||||||||||||||||||||||||||||||||
2479 | } | - | ||||||||||||||||||||||||||||||||||||
2480 | - | |||||||||||||||||||||||||||||||||||||
2481 | #endif // QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||||||||||||||
2482 | - | |||||||||||||||||||||||||||||||||||||
2483 | void QWidgetTextControl::setTextWidth(qreal width) | - | ||||||||||||||||||||||||||||||||||||
2484 | { | - | ||||||||||||||||||||||||||||||||||||
2485 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2486 | d->doc->setTextWidth(width); | - | ||||||||||||||||||||||||||||||||||||
2487 | } | - | ||||||||||||||||||||||||||||||||||||
2488 | - | |||||||||||||||||||||||||||||||||||||
2489 | qreal QWidgetTextControl::textWidth() const | - | ||||||||||||||||||||||||||||||||||||
2490 | { | - | ||||||||||||||||||||||||||||||||||||
2491 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2492 | return d->doc->textWidth(); | - | ||||||||||||||||||||||||||||||||||||
2493 | } | - | ||||||||||||||||||||||||||||||||||||
2494 | - | |||||||||||||||||||||||||||||||||||||
2495 | QSizeF QWidgetTextControl::size() const | - | ||||||||||||||||||||||||||||||||||||
2496 | { | - | ||||||||||||||||||||||||||||||||||||
2497 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2498 | return d->doc->size(); | - | ||||||||||||||||||||||||||||||||||||
2499 | } | - | ||||||||||||||||||||||||||||||||||||
2500 | - | |||||||||||||||||||||||||||||||||||||
2501 | void QWidgetTextControl::setOpenExternalLinks(bool open) | - | ||||||||||||||||||||||||||||||||||||
2502 | { | - | ||||||||||||||||||||||||||||||||||||
2503 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2504 | d->openExternalLinks = open; | - | ||||||||||||||||||||||||||||||||||||
2505 | } | - | ||||||||||||||||||||||||||||||||||||
2506 | - | |||||||||||||||||||||||||||||||||||||
2507 | bool QWidgetTextControl::openExternalLinks() const | - | ||||||||||||||||||||||||||||||||||||
2508 | { | - | ||||||||||||||||||||||||||||||||||||
2509 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2510 | return d->openExternalLinks; | - | ||||||||||||||||||||||||||||||||||||
2511 | } | - | ||||||||||||||||||||||||||||||||||||
2512 | - | |||||||||||||||||||||||||||||||||||||
2513 | bool QWidgetTextControl::ignoreUnusedNavigationEvents() const | - | ||||||||||||||||||||||||||||||||||||
2514 | { | - | ||||||||||||||||||||||||||||||||||||
2515 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2516 | return d->ignoreUnusedNavigationEvents; | - | ||||||||||||||||||||||||||||||||||||
2517 | } | - | ||||||||||||||||||||||||||||||||||||
2518 | - | |||||||||||||||||||||||||||||||||||||
2519 | void QWidgetTextControl::setIgnoreUnusedNavigationEvents(bool ignore) | - | ||||||||||||||||||||||||||||||||||||
2520 | { | - | ||||||||||||||||||||||||||||||||||||
2521 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2522 | d->ignoreUnusedNavigationEvents = ignore; | - | ||||||||||||||||||||||||||||||||||||
2523 | } | - | ||||||||||||||||||||||||||||||||||||
2524 | - | |||||||||||||||||||||||||||||||||||||
2525 | void QWidgetTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode) | - | ||||||||||||||||||||||||||||||||||||
2526 | { | - | ||||||||||||||||||||||||||||||||||||
2527 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2528 | const QTextCursor oldSelection = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
2529 | const bool moved = d->cursor.movePosition(op, mode); | - | ||||||||||||||||||||||||||||||||||||
2530 | d->_q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||||||||||||||
2531 | ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
2532 | d->repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||||||||||||||
2533 | if (moved) | - | ||||||||||||||||||||||||||||||||||||
2534 | emit cursorPositionChanged(); | - | ||||||||||||||||||||||||||||||||||||
2535 | } | - | ||||||||||||||||||||||||||||||||||||
2536 | - | |||||||||||||||||||||||||||||||||||||
2537 | bool QWidgetTextControl::canPaste() const | - | ||||||||||||||||||||||||||||||||||||
2538 | { | - | ||||||||||||||||||||||||||||||||||||
2539 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
2540 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2541 | if (d->interactionFlags & Qt::TextEditable) { | - | ||||||||||||||||||||||||||||||||||||
2542 | const QMimeData *md = QApplication::clipboard()->mimeData(); | - | ||||||||||||||||||||||||||||||||||||
2543 | return md && canInsertFromMimeData(md); | - | ||||||||||||||||||||||||||||||||||||
2544 | } | - | ||||||||||||||||||||||||||||||||||||
2545 | #endif | - | ||||||||||||||||||||||||||||||||||||
2546 | return false; | - | ||||||||||||||||||||||||||||||||||||
2547 | } | - | ||||||||||||||||||||||||||||||||||||
2548 | - | |||||||||||||||||||||||||||||||||||||
2549 | void QWidgetTextControl::setCursorIsFocusIndicator(bool b) | - | ||||||||||||||||||||||||||||||||||||
2550 | { | - | ||||||||||||||||||||||||||||||||||||
2551 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2552 | d->cursorIsFocusIndicator = b; | - | ||||||||||||||||||||||||||||||||||||
2553 | d->repaintCursor(); | - | ||||||||||||||||||||||||||||||||||||
2554 | } | - | ||||||||||||||||||||||||||||||||||||
2555 | - | |||||||||||||||||||||||||||||||||||||
2556 | bool QWidgetTextControl::cursorIsFocusIndicator() const | - | ||||||||||||||||||||||||||||||||||||
2557 | { | - | ||||||||||||||||||||||||||||||||||||
2558 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2559 | return d->cursorIsFocusIndicator; | - | ||||||||||||||||||||||||||||||||||||
2560 | } | - | ||||||||||||||||||||||||||||||||||||
2561 | - | |||||||||||||||||||||||||||||||||||||
2562 | - | |||||||||||||||||||||||||||||||||||||
2563 | void QWidgetTextControl::setDragEnabled(bool enabled) | - | ||||||||||||||||||||||||||||||||||||
2564 | { | - | ||||||||||||||||||||||||||||||||||||
2565 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2566 | d->dragEnabled = enabled; | - | ||||||||||||||||||||||||||||||||||||
2567 | } | - | ||||||||||||||||||||||||||||||||||||
2568 | - | |||||||||||||||||||||||||||||||||||||
2569 | bool QWidgetTextControl::isDragEnabled() const | - | ||||||||||||||||||||||||||||||||||||
2570 | { | - | ||||||||||||||||||||||||||||||||||||
2571 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2572 | return d->dragEnabled; | - | ||||||||||||||||||||||||||||||||||||
2573 | } | - | ||||||||||||||||||||||||||||||||||||
2574 | - | |||||||||||||||||||||||||||||||||||||
2575 | void QWidgetTextControl::setWordSelectionEnabled(bool enabled) | - | ||||||||||||||||||||||||||||||||||||
2576 | { | - | ||||||||||||||||||||||||||||||||||||
2577 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2578 | d->wordSelectionEnabled = enabled; | - | ||||||||||||||||||||||||||||||||||||
2579 | } | - | ||||||||||||||||||||||||||||||||||||
2580 | - | |||||||||||||||||||||||||||||||||||||
2581 | bool QWidgetTextControl::isWordSelectionEnabled() const | - | ||||||||||||||||||||||||||||||||||||
2582 | { | - | ||||||||||||||||||||||||||||||||||||
2583 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2584 | return d->wordSelectionEnabled; | - | ||||||||||||||||||||||||||||||||||||
2585 | } | - | ||||||||||||||||||||||||||||||||||||
2586 | - | |||||||||||||||||||||||||||||||||||||
2587 | bool QWidgetTextControl::isPreediting() | - | ||||||||||||||||||||||||||||||||||||
2588 | { | - | ||||||||||||||||||||||||||||||||||||
2589 | return d_func()->isPreediting(); | - | ||||||||||||||||||||||||||||||||||||
2590 | } | - | ||||||||||||||||||||||||||||||||||||
2591 | - | |||||||||||||||||||||||||||||||||||||
2592 | #ifndef QT_NO_PRINTER | - | ||||||||||||||||||||||||||||||||||||
2593 | void QWidgetTextControl::print(QPagedPaintDevice *printer) const | - | ||||||||||||||||||||||||||||||||||||
2594 | { | - | ||||||||||||||||||||||||||||||||||||
2595 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2596 | if (!printer) | - | ||||||||||||||||||||||||||||||||||||
2597 | return; | - | ||||||||||||||||||||||||||||||||||||
2598 | QTextDocument *tempDoc = 0; | - | ||||||||||||||||||||||||||||||||||||
2599 | const QTextDocument *doc = d->doc; | - | ||||||||||||||||||||||||||||||||||||
2600 | if (QPagedPaintDevicePrivate::get(printer)->printSelectionOnly) { | - | ||||||||||||||||||||||||||||||||||||
2601 | if (!d->cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
2602 | return; | - | ||||||||||||||||||||||||||||||||||||
2603 | tempDoc = new QTextDocument(const_cast<QTextDocument *>(doc)); | - | ||||||||||||||||||||||||||||||||||||
2604 | tempDoc->setMetaInformation(QTextDocument::DocumentTitle, doc->metaInformation(QTextDocument::DocumentTitle)); | - | ||||||||||||||||||||||||||||||||||||
2605 | tempDoc->setPageSize(doc->pageSize()); | - | ||||||||||||||||||||||||||||||||||||
2606 | tempDoc->setDefaultFont(doc->defaultFont()); | - | ||||||||||||||||||||||||||||||||||||
2607 | tempDoc->setUseDesignMetrics(doc->useDesignMetrics()); | - | ||||||||||||||||||||||||||||||||||||
2608 | QTextCursor(tempDoc).insertFragment(d->cursor.selection()); | - | ||||||||||||||||||||||||||||||||||||
2609 | doc = tempDoc; | - | ||||||||||||||||||||||||||||||||||||
2610 | - | |||||||||||||||||||||||||||||||||||||
2611 | // copy the custom object handlers | - | ||||||||||||||||||||||||||||||||||||
2612 | doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers; | - | ||||||||||||||||||||||||||||||||||||
2613 | } | - | ||||||||||||||||||||||||||||||||||||
2614 | doc->print(printer); | - | ||||||||||||||||||||||||||||||||||||
2615 | delete tempDoc; | - | ||||||||||||||||||||||||||||||||||||
2616 | } | - | ||||||||||||||||||||||||||||||||||||
2617 | #endif | - | ||||||||||||||||||||||||||||||||||||
2618 | - | |||||||||||||||||||||||||||||||||||||
2619 | QMimeData *QWidgetTextControl::createMimeDataFromSelection() const | - | ||||||||||||||||||||||||||||||||||||
2620 | { | - | ||||||||||||||||||||||||||||||||||||
2621 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2622 | const QTextDocumentFragment fragment(d->cursor); | - | ||||||||||||||||||||||||||||||||||||
2623 | return new QTextEditMimeData(fragment); | - | ||||||||||||||||||||||||||||||||||||
2624 | } | - | ||||||||||||||||||||||||||||||||||||
2625 | - | |||||||||||||||||||||||||||||||||||||
2626 | bool QWidgetTextControl::canInsertFromMimeData(const QMimeData *source) const | - | ||||||||||||||||||||||||||||||||||||
2627 | { | - | ||||||||||||||||||||||||||||||||||||
2628 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2629 | if (d->acceptRichText) | - | ||||||||||||||||||||||||||||||||||||
2630 | return (source->hasText() && !source->text().isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
2631 | || source->hasHtml() | - | ||||||||||||||||||||||||||||||||||||
2632 | || source->hasFormat(QLatin1String("application/x-qrichtext")) | - | ||||||||||||||||||||||||||||||||||||
2633 | || source->hasFormat(QLatin1String("application/x-qt-richtext")); | - | ||||||||||||||||||||||||||||||||||||
2634 | else | - | ||||||||||||||||||||||||||||||||||||
2635 | return source->hasText() && !source->text().isEmpty(); | - | ||||||||||||||||||||||||||||||||||||
2636 | } | - | ||||||||||||||||||||||||||||||||||||
2637 | - | |||||||||||||||||||||||||||||||||||||
2638 | void QWidgetTextControl::insertFromMimeData(const QMimeData *source) | - | ||||||||||||||||||||||||||||||||||||
2639 | { | - | ||||||||||||||||||||||||||||||||||||
2640 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2641 | if (!(d->interactionFlags & Qt::TextEditable) || !source)
| 0 | ||||||||||||||||||||||||||||||||||||
2642 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
2643 | - | |||||||||||||||||||||||||||||||||||||
2644 | bool hasData = false; | - | ||||||||||||||||||||||||||||||||||||
2645 | QTextDocumentFragment fragment; | - | ||||||||||||||||||||||||||||||||||||
2646 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
2647 | if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) {
| 0 | ||||||||||||||||||||||||||||||||||||
2648 | // x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore). | - | ||||||||||||||||||||||||||||||||||||
2649 | const QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext"))); | - | ||||||||||||||||||||||||||||||||||||
richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));) | ||||||||||||||||||||||||||||||||||||||
2650 | + QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext"))); | - | ||||||||||||||||||||||||||||||||||||
2651 | fragment = QTextDocumentFragment::fromHtml(richtext, d->doc); | - | ||||||||||||||||||||||||||||||||||||
2652 | hasData = true; | - | ||||||||||||||||||||||||||||||||||||
2653 | } else if (source->hasHtml() && d->acceptRichText) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
2654 | fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc); | - | ||||||||||||||||||||||||||||||||||||
2655 | hasData = true; | - | ||||||||||||||||||||||||||||||||||||
2656 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2657 | QString text = source->text(); | - | ||||||||||||||||||||||||||||||||||||
2658 | if (!text.isNull()) {
| 0 | ||||||||||||||||||||||||||||||||||||
2659 | fragment = QTextDocumentFragment::fromPlainText(text); | - | ||||||||||||||||||||||||||||||||||||
2660 | hasData = true; | - | ||||||||||||||||||||||||||||||||||||
2661 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2662 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2663 | #else | - | ||||||||||||||||||||||||||||||||||||
2664 | fragment = QTextDocumentFragment::fromPlainText(source->text()); | - | ||||||||||||||||||||||||||||||||||||
2665 | #endif // QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
2666 | - | |||||||||||||||||||||||||||||||||||||
2667 | if (hasData)
| 0 | ||||||||||||||||||||||||||||||||||||
2668 | d->cursor.insertFragment(fragment); never executed: d->cursor.insertFragment(fragment); | 0 | ||||||||||||||||||||||||||||||||||||
2669 | ensureCursorVisible(); | - | ||||||||||||||||||||||||||||||||||||
2670 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2671 | - | |||||||||||||||||||||||||||||||||||||
2672 | bool QWidgetTextControl::findNextPrevAnchor(const QTextCursor &startCursor, bool next, QTextCursor &newAnchor) | - | ||||||||||||||||||||||||||||||||||||
2673 | { | - | ||||||||||||||||||||||||||||||||||||
2674 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2675 | - | |||||||||||||||||||||||||||||||||||||
2676 | int anchorStart = -1; | - | ||||||||||||||||||||||||||||||||||||
2677 | QString anchorHref; | - | ||||||||||||||||||||||||||||||||||||
2678 | int anchorEnd = -1; | - | ||||||||||||||||||||||||||||||||||||
2679 | - | |||||||||||||||||||||||||||||||||||||
2680 | if (next) { | - | ||||||||||||||||||||||||||||||||||||
2681 | const int startPos = startCursor.selectionEnd(); | - | ||||||||||||||||||||||||||||||||||||
2682 | - | |||||||||||||||||||||||||||||||||||||
2683 | QTextBlock block = d->doc->findBlock(startPos); | - | ||||||||||||||||||||||||||||||||||||
2684 | QTextBlock::Iterator it = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2685 | - | |||||||||||||||||||||||||||||||||||||
2686 | while (!it.atEnd() && it.fragment().position() < startPos) | - | ||||||||||||||||||||||||||||||||||||
2687 | ++it; | - | ||||||||||||||||||||||||||||||||||||
2688 | - | |||||||||||||||||||||||||||||||||||||
2689 | while (block.isValid()) { | - | ||||||||||||||||||||||||||||||||||||
2690 | anchorStart = -1; | - | ||||||||||||||||||||||||||||||||||||
2691 | - | |||||||||||||||||||||||||||||||||||||
2692 | // find next anchor | - | ||||||||||||||||||||||||||||||||||||
2693 | for (; !it.atEnd(); ++it) { | - | ||||||||||||||||||||||||||||||||||||
2694 | const QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2695 | const QTextCharFormat fmt = fragment.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
2696 | - | |||||||||||||||||||||||||||||||||||||
2697 | if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) { | - | ||||||||||||||||||||||||||||||||||||
2698 | anchorStart = fragment.position(); | - | ||||||||||||||||||||||||||||||||||||
2699 | anchorHref = fmt.anchorHref(); | - | ||||||||||||||||||||||||||||||||||||
2700 | break; | - | ||||||||||||||||||||||||||||||||||||
2701 | } | - | ||||||||||||||||||||||||||||||||||||
2702 | } | - | ||||||||||||||||||||||||||||||||||||
2703 | - | |||||||||||||||||||||||||||||||||||||
2704 | if (anchorStart != -1) { | - | ||||||||||||||||||||||||||||||||||||
2705 | anchorEnd = -1; | - | ||||||||||||||||||||||||||||||||||||
2706 | - | |||||||||||||||||||||||||||||||||||||
2707 | // find next non-anchor fragment | - | ||||||||||||||||||||||||||||||||||||
2708 | for (; !it.atEnd(); ++it) { | - | ||||||||||||||||||||||||||||||||||||
2709 | const QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2710 | const QTextCharFormat fmt = fragment.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
2711 | - | |||||||||||||||||||||||||||||||||||||
2712 | if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) { | - | ||||||||||||||||||||||||||||||||||||
2713 | anchorEnd = fragment.position(); | - | ||||||||||||||||||||||||||||||||||||
2714 | break; | - | ||||||||||||||||||||||||||||||||||||
2715 | } | - | ||||||||||||||||||||||||||||||||||||
2716 | } | - | ||||||||||||||||||||||||||||||||||||
2717 | - | |||||||||||||||||||||||||||||||||||||
2718 | if (anchorEnd == -1) | - | ||||||||||||||||||||||||||||||||||||
2719 | anchorEnd = block.position() + block.length() - 1; | - | ||||||||||||||||||||||||||||||||||||
2720 | - | |||||||||||||||||||||||||||||||||||||
2721 | // make found selection | - | ||||||||||||||||||||||||||||||||||||
2722 | break; | - | ||||||||||||||||||||||||||||||||||||
2723 | } | - | ||||||||||||||||||||||||||||||||||||
2724 | - | |||||||||||||||||||||||||||||||||||||
2725 | block = block.next(); | - | ||||||||||||||||||||||||||||||||||||
2726 | it = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2727 | } | - | ||||||||||||||||||||||||||||||||||||
2728 | } else { | - | ||||||||||||||||||||||||||||||||||||
2729 | int startPos = startCursor.selectionStart(); | - | ||||||||||||||||||||||||||||||||||||
2730 | if (startPos > 0) | - | ||||||||||||||||||||||||||||||||||||
2731 | --startPos; | - | ||||||||||||||||||||||||||||||||||||
2732 | - | |||||||||||||||||||||||||||||||||||||
2733 | QTextBlock block = d->doc->findBlock(startPos); | - | ||||||||||||||||||||||||||||||||||||
2734 | QTextBlock::Iterator blockStart = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2735 | QTextBlock::Iterator it = block.end(); | - | ||||||||||||||||||||||||||||||||||||
2736 | - | |||||||||||||||||||||||||||||||||||||
2737 | if (startPos == block.position()) { | - | ||||||||||||||||||||||||||||||||||||
2738 | it = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2739 | } else { | - | ||||||||||||||||||||||||||||||||||||
2740 | do { | - | ||||||||||||||||||||||||||||||||||||
2741 | if (it == blockStart) { | - | ||||||||||||||||||||||||||||||||||||
2742 | it = QTextBlock::Iterator(); | - | ||||||||||||||||||||||||||||||||||||
2743 | block = QTextBlock(); | - | ||||||||||||||||||||||||||||||||||||
2744 | } else { | - | ||||||||||||||||||||||||||||||||||||
2745 | --it; | - | ||||||||||||||||||||||||||||||||||||
2746 | } | - | ||||||||||||||||||||||||||||||||||||
2747 | } while (!it.atEnd() && it.fragment().position() + it.fragment().length() - 1 > startPos); | - | ||||||||||||||||||||||||||||||||||||
2748 | } | - | ||||||||||||||||||||||||||||||||||||
2749 | - | |||||||||||||||||||||||||||||||||||||
2750 | while (block.isValid()) { | - | ||||||||||||||||||||||||||||||||||||
2751 | anchorStart = -1; | - | ||||||||||||||||||||||||||||||||||||
2752 | - | |||||||||||||||||||||||||||||||||||||
2753 | if (!it.atEnd()) { | - | ||||||||||||||||||||||||||||||||||||
2754 | do { | - | ||||||||||||||||||||||||||||||||||||
2755 | const QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2756 | const QTextCharFormat fmt = fragment.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
2757 | - | |||||||||||||||||||||||||||||||||||||
2758 | if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) { | - | ||||||||||||||||||||||||||||||||||||
2759 | anchorStart = fragment.position() + fragment.length(); | - | ||||||||||||||||||||||||||||||||||||
2760 | anchorHref = fmt.anchorHref(); | - | ||||||||||||||||||||||||||||||||||||
2761 | break; | - | ||||||||||||||||||||||||||||||||||||
2762 | } | - | ||||||||||||||||||||||||||||||||||||
2763 | - | |||||||||||||||||||||||||||||||||||||
2764 | if (it == blockStart) | - | ||||||||||||||||||||||||||||||||||||
2765 | it = QTextBlock::Iterator(); | - | ||||||||||||||||||||||||||||||||||||
2766 | else | - | ||||||||||||||||||||||||||||||||||||
2767 | --it; | - | ||||||||||||||||||||||||||||||||||||
2768 | } while (!it.atEnd()); | - | ||||||||||||||||||||||||||||||||||||
2769 | } | - | ||||||||||||||||||||||||||||||||||||
2770 | - | |||||||||||||||||||||||||||||||||||||
2771 | if (anchorStart != -1 && !it.atEnd()) { | - | ||||||||||||||||||||||||||||||||||||
2772 | anchorEnd = -1; | - | ||||||||||||||||||||||||||||||||||||
2773 | - | |||||||||||||||||||||||||||||||||||||
2774 | do { | - | ||||||||||||||||||||||||||||||||||||
2775 | const QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2776 | const QTextCharFormat fmt = fragment.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
2777 | - | |||||||||||||||||||||||||||||||||||||
2778 | if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) { | - | ||||||||||||||||||||||||||||||||||||
2779 | anchorEnd = fragment.position() + fragment.length(); | - | ||||||||||||||||||||||||||||||||||||
2780 | break; | - | ||||||||||||||||||||||||||||||||||||
2781 | } | - | ||||||||||||||||||||||||||||||||||||
2782 | - | |||||||||||||||||||||||||||||||||||||
2783 | if (it == blockStart) | - | ||||||||||||||||||||||||||||||||||||
2784 | it = QTextBlock::Iterator(); | - | ||||||||||||||||||||||||||||||||||||
2785 | else | - | ||||||||||||||||||||||||||||||||||||
2786 | --it; | - | ||||||||||||||||||||||||||||||||||||
2787 | } while (!it.atEnd()); | - | ||||||||||||||||||||||||||||||||||||
2788 | - | |||||||||||||||||||||||||||||||||||||
2789 | if (anchorEnd == -1) | - | ||||||||||||||||||||||||||||||||||||
2790 | anchorEnd = qMax(0, block.position()); | - | ||||||||||||||||||||||||||||||||||||
2791 | - | |||||||||||||||||||||||||||||||||||||
2792 | break; | - | ||||||||||||||||||||||||||||||||||||
2793 | } | - | ||||||||||||||||||||||||||||||||||||
2794 | - | |||||||||||||||||||||||||||||||||||||
2795 | block = block.previous(); | - | ||||||||||||||||||||||||||||||||||||
2796 | it = block.end(); | - | ||||||||||||||||||||||||||||||||||||
2797 | if (it != block.begin()) | - | ||||||||||||||||||||||||||||||||||||
2798 | --it; | - | ||||||||||||||||||||||||||||||||||||
2799 | blockStart = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2800 | } | - | ||||||||||||||||||||||||||||||||||||
2801 | - | |||||||||||||||||||||||||||||||||||||
2802 | } | - | ||||||||||||||||||||||||||||||||||||
2803 | - | |||||||||||||||||||||||||||||||||||||
2804 | if (anchorStart != -1 && anchorEnd != -1) { | - | ||||||||||||||||||||||||||||||||||||
2805 | newAnchor = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
2806 | newAnchor.setPosition(anchorStart); | - | ||||||||||||||||||||||||||||||||||||
2807 | newAnchor.setPosition(anchorEnd, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
2808 | return true; | - | ||||||||||||||||||||||||||||||||||||
2809 | } | - | ||||||||||||||||||||||||||||||||||||
2810 | - | |||||||||||||||||||||||||||||||||||||
2811 | return false; | - | ||||||||||||||||||||||||||||||||||||
2812 | } | - | ||||||||||||||||||||||||||||||||||||
2813 | - | |||||||||||||||||||||||||||||||||||||
2814 | void QWidgetTextControlPrivate::activateLinkUnderCursor(QString href) | - | ||||||||||||||||||||||||||||||||||||
2815 | { | - | ||||||||||||||||||||||||||||||||||||
2816 | QTextCursor oldCursor = cursor; | - | ||||||||||||||||||||||||||||||||||||
2817 | - | |||||||||||||||||||||||||||||||||||||
2818 | if (href.isEmpty()) { | - | ||||||||||||||||||||||||||||||||||||
2819 | QTextCursor tmp = cursor; | - | ||||||||||||||||||||||||||||||||||||
2820 | if (tmp.selectionStart() != tmp.position()) | - | ||||||||||||||||||||||||||||||||||||
2821 | tmp.setPosition(tmp.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
2822 | tmp.movePosition(QTextCursor::NextCharacter); | - | ||||||||||||||||||||||||||||||||||||
2823 | href = tmp.charFormat().anchorHref(); | - | ||||||||||||||||||||||||||||||||||||
2824 | } | - | ||||||||||||||||||||||||||||||||||||
2825 | if (href.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
2826 | return; | - | ||||||||||||||||||||||||||||||||||||
2827 | - | |||||||||||||||||||||||||||||||||||||
2828 | if (!cursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
2829 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
2830 | const int cursorPos = cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
2831 | - | |||||||||||||||||||||||||||||||||||||
2832 | QTextBlock::Iterator it = block.begin(); | - | ||||||||||||||||||||||||||||||||||||
2833 | QTextBlock::Iterator linkFragment; | - | ||||||||||||||||||||||||||||||||||||
2834 | - | |||||||||||||||||||||||||||||||||||||
2835 | for (; !it.atEnd(); ++it) { | - | ||||||||||||||||||||||||||||||||||||
2836 | QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2837 | const int fragmentPos = fragment.position(); | - | ||||||||||||||||||||||||||||||||||||
2838 | if (fragmentPos <= cursorPos && | - | ||||||||||||||||||||||||||||||||||||
2839 | fragmentPos + fragment.length() > cursorPos) { | - | ||||||||||||||||||||||||||||||||||||
2840 | linkFragment = it; | - | ||||||||||||||||||||||||||||||||||||
2841 | break; | - | ||||||||||||||||||||||||||||||||||||
2842 | } | - | ||||||||||||||||||||||||||||||||||||
2843 | } | - | ||||||||||||||||||||||||||||||||||||
2844 | - | |||||||||||||||||||||||||||||||||||||
2845 | if (!linkFragment.atEnd()) { | - | ||||||||||||||||||||||||||||||||||||
2846 | it = linkFragment; | - | ||||||||||||||||||||||||||||||||||||
2847 | cursor.setPosition(it.fragment().position()); | - | ||||||||||||||||||||||||||||||||||||
2848 | if (it != block.begin()) { | - | ||||||||||||||||||||||||||||||||||||
2849 | do { | - | ||||||||||||||||||||||||||||||||||||
2850 | --it; | - | ||||||||||||||||||||||||||||||||||||
2851 | QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2852 | if (fragment.charFormat().anchorHref() != href) | - | ||||||||||||||||||||||||||||||||||||
2853 | break; | - | ||||||||||||||||||||||||||||||||||||
2854 | cursor.setPosition(fragment.position()); | - | ||||||||||||||||||||||||||||||||||||
2855 | } while (it != block.begin()); | - | ||||||||||||||||||||||||||||||||||||
2856 | } | - | ||||||||||||||||||||||||||||||||||||
2857 | - | |||||||||||||||||||||||||||||||||||||
2858 | for (it = linkFragment; !it.atEnd(); ++it) { | - | ||||||||||||||||||||||||||||||||||||
2859 | QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
2860 | if (fragment.charFormat().anchorHref() != href) | - | ||||||||||||||||||||||||||||||||||||
2861 | break; | - | ||||||||||||||||||||||||||||||||||||
2862 | cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
2863 | } | - | ||||||||||||||||||||||||||||||||||||
2864 | } | - | ||||||||||||||||||||||||||||||||||||
2865 | } | - | ||||||||||||||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||||||||||||||
2867 | if (hasFocus) { | - | ||||||||||||||||||||||||||||||||||||
2868 | cursorIsFocusIndicator = true; | - | ||||||||||||||||||||||||||||||||||||
2869 | } else { | - | ||||||||||||||||||||||||||||||||||||
2870 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||||||||||||||
2871 | cursor.clearSelection(); | - | ||||||||||||||||||||||||||||||||||||
2872 | } | - | ||||||||||||||||||||||||||||||||||||
2873 | repaintOldAndNewSelection(oldCursor); | - | ||||||||||||||||||||||||||||||||||||
2874 | - | |||||||||||||||||||||||||||||||||||||
2875 | #ifndef QT_NO_DESKTOPSERVICES | - | ||||||||||||||||||||||||||||||||||||
2876 | if (openExternalLinks) | - | ||||||||||||||||||||||||||||||||||||
2877 | QDesktopServices::openUrl(href); | - | ||||||||||||||||||||||||||||||||||||
2878 | else | - | ||||||||||||||||||||||||||||||||||||
2879 | #endif | - | ||||||||||||||||||||||||||||||||||||
2880 | emit q_func()->linkActivated(href); | - | ||||||||||||||||||||||||||||||||||||
2881 | } | - | ||||||||||||||||||||||||||||||||||||
2882 | - | |||||||||||||||||||||||||||||||||||||
2883 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||||||||
2884 | void QWidgetTextControlPrivate::showToolTip(const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget) | - | ||||||||||||||||||||||||||||||||||||
2885 | { | - | ||||||||||||||||||||||||||||||||||||
2886 | const QString toolTip = q_func()->cursorForPosition(pos).charFormat().toolTip(); | - | ||||||||||||||||||||||||||||||||||||
2887 | if (toolTip.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
2888 | return; | - | ||||||||||||||||||||||||||||||||||||
2889 | QToolTip::showText(globalPos, toolTip, contextWidget); | - | ||||||||||||||||||||||||||||||||||||
2890 | } | - | ||||||||||||||||||||||||||||||||||||
2891 | #endif // QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||||||||
2892 | - | |||||||||||||||||||||||||||||||||||||
2893 | bool QWidgetTextControlPrivate::isPreediting() const | - | ||||||||||||||||||||||||||||||||||||
2894 | { | - | ||||||||||||||||||||||||||||||||||||
2895 | QTextLayout *layout = cursor.block().layout(); | - | ||||||||||||||||||||||||||||||||||||
2896 | if (layout && !layout->preeditAreaText().isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
2897 | return true; | - | ||||||||||||||||||||||||||||||||||||
2898 | - | |||||||||||||||||||||||||||||||||||||
2899 | return false; | - | ||||||||||||||||||||||||||||||||||||
2900 | } | - | ||||||||||||||||||||||||||||||||||||
2901 | - | |||||||||||||||||||||||||||||||||||||
2902 | void QWidgetTextControlPrivate::commitPreedit() | - | ||||||||||||||||||||||||||||||||||||
2903 | { | - | ||||||||||||||||||||||||||||||||||||
2904 | if (!isPreediting()) | - | ||||||||||||||||||||||||||||||||||||
2905 | return; | - | ||||||||||||||||||||||||||||||||||||
2906 | - | |||||||||||||||||||||||||||||||||||||
2907 | QGuiApplication::inputMethod()->commit(); | - | ||||||||||||||||||||||||||||||||||||
2908 | - | |||||||||||||||||||||||||||||||||||||
2909 | if (!isPreediting()) | - | ||||||||||||||||||||||||||||||||||||
2910 | return; | - | ||||||||||||||||||||||||||||||||||||
2911 | - | |||||||||||||||||||||||||||||||||||||
2912 | cursor.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2913 | preeditCursor = 0; | - | ||||||||||||||||||||||||||||||||||||
2914 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||||||||||||||
2915 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||||||||||||||
2916 | layout->setPreeditArea(-1, QString()); | - | ||||||||||||||||||||||||||||||||||||
2917 | layout->clearFormats(); | - | ||||||||||||||||||||||||||||||||||||
2918 | cursor.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
2919 | } | - | ||||||||||||||||||||||||||||||||||||
2920 | - | |||||||||||||||||||||||||||||||||||||
2921 | bool QWidgetTextControl::setFocusToNextOrPreviousAnchor(bool next) | - | ||||||||||||||||||||||||||||||||||||
2922 | { | - | ||||||||||||||||||||||||||||||||||||
2923 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2924 | - | |||||||||||||||||||||||||||||||||||||
2925 | if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard)) | - | ||||||||||||||||||||||||||||||||||||
2926 | return false; | - | ||||||||||||||||||||||||||||||||||||
2927 | - | |||||||||||||||||||||||||||||||||||||
2928 | QRectF crect = selectionRect(); | - | ||||||||||||||||||||||||||||||||||||
2929 | emit updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2930 | - | |||||||||||||||||||||||||||||||||||||
2931 | // If we don't have a current anchor, we start from the start/end | - | ||||||||||||||||||||||||||||||||||||
2932 | if (!d->cursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
2933 | d->cursor = QTextCursor(d->doc); | - | ||||||||||||||||||||||||||||||||||||
2934 | if (next) | - | ||||||||||||||||||||||||||||||||||||
2935 | d->cursor.movePosition(QTextCursor::Start); | - | ||||||||||||||||||||||||||||||||||||
2936 | else | - | ||||||||||||||||||||||||||||||||||||
2937 | d->cursor.movePosition(QTextCursor::End); | - | ||||||||||||||||||||||||||||||||||||
2938 | } | - | ||||||||||||||||||||||||||||||||||||
2939 | - | |||||||||||||||||||||||||||||||||||||
2940 | QTextCursor newAnchor; | - | ||||||||||||||||||||||||||||||||||||
2941 | if (findNextPrevAnchor(d->cursor, next, newAnchor)) { | - | ||||||||||||||||||||||||||||||||||||
2942 | d->cursor = newAnchor; | - | ||||||||||||||||||||||||||||||||||||
2943 | d->cursorIsFocusIndicator = true; | - | ||||||||||||||||||||||||||||||||||||
2944 | } else { | - | ||||||||||||||||||||||||||||||||||||
2945 | d->cursor.clearSelection(); | - | ||||||||||||||||||||||||||||||||||||
2946 | } | - | ||||||||||||||||||||||||||||||||||||
2947 | - | |||||||||||||||||||||||||||||||||||||
2948 | if (d->cursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
2949 | crect = selectionRect(); | - | ||||||||||||||||||||||||||||||||||||
2950 | emit updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2951 | emit visibilityRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2952 | return true; | - | ||||||||||||||||||||||||||||||||||||
2953 | } else { | - | ||||||||||||||||||||||||||||||||||||
2954 | return false; | - | ||||||||||||||||||||||||||||||||||||
2955 | } | - | ||||||||||||||||||||||||||||||||||||
2956 | } | - | ||||||||||||||||||||||||||||||||||||
2957 | - | |||||||||||||||||||||||||||||||||||||
2958 | bool QWidgetTextControl::setFocusToAnchor(const QTextCursor &newCursor) | - | ||||||||||||||||||||||||||||||||||||
2959 | { | - | ||||||||||||||||||||||||||||||||||||
2960 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2961 | - | |||||||||||||||||||||||||||||||||||||
2962 | if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard)) | - | ||||||||||||||||||||||||||||||||||||
2963 | return false; | - | ||||||||||||||||||||||||||||||||||||
2964 | - | |||||||||||||||||||||||||||||||||||||
2965 | // Verify that this is an anchor. | - | ||||||||||||||||||||||||||||||||||||
2966 | const QString anchorHref = d->anchorForCursor(newCursor); | - | ||||||||||||||||||||||||||||||||||||
2967 | if (anchorHref.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
2968 | return false; | - | ||||||||||||||||||||||||||||||||||||
2969 | - | |||||||||||||||||||||||||||||||||||||
2970 | // and process it | - | ||||||||||||||||||||||||||||||||||||
2971 | QRectF crect = selectionRect(); | - | ||||||||||||||||||||||||||||||||||||
2972 | emit updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2973 | - | |||||||||||||||||||||||||||||||||||||
2974 | d->cursor.setPosition(newCursor.selectionStart()); | - | ||||||||||||||||||||||||||||||||||||
2975 | d->cursor.setPosition(newCursor.selectionEnd(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||||||||||||||
2976 | d->cursorIsFocusIndicator = true; | - | ||||||||||||||||||||||||||||||||||||
2977 | - | |||||||||||||||||||||||||||||||||||||
2978 | crect = selectionRect(); | - | ||||||||||||||||||||||||||||||||||||
2979 | emit updateRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2980 | emit visibilityRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
2981 | return true; | - | ||||||||||||||||||||||||||||||||||||
2982 | } | - | ||||||||||||||||||||||||||||||||||||
2983 | - | |||||||||||||||||||||||||||||||||||||
2984 | void QWidgetTextControl::setTextInteractionFlags(Qt::TextInteractionFlags flags) | - | ||||||||||||||||||||||||||||||||||||
2985 | { | - | ||||||||||||||||||||||||||||||||||||
2986 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2987 | if (flags == d->interactionFlags)
| 0 | ||||||||||||||||||||||||||||||||||||
2988 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
2989 | d->interactionFlags = flags; | - | ||||||||||||||||||||||||||||||||||||
2990 | - | |||||||||||||||||||||||||||||||||||||
2991 | if (d->hasFocus)
| 0 | ||||||||||||||||||||||||||||||||||||
2992 | d->setBlinkingCursorEnabledsetCursorVisible(flags & Qt::TextEditable); never executed: d->setCursorVisible(flags & Qt::TextEditable); | 0 | ||||||||||||||||||||||||||||||||||||
2993 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
2994 | - | |||||||||||||||||||||||||||||||||||||
2995 | Qt::TextInteractionFlags QWidgetTextControl::textInteractionFlags() const | - | ||||||||||||||||||||||||||||||||||||
2996 | { | - | ||||||||||||||||||||||||||||||||||||
2997 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
2998 | return d->interactionFlags; | - | ||||||||||||||||||||||||||||||||||||
2999 | } | - | ||||||||||||||||||||||||||||||||||||
3000 | - | |||||||||||||||||||||||||||||||||||||
3001 | void QWidgetTextControl::mergeCurrentCharFormat(const QTextCharFormat &modifier) | - | ||||||||||||||||||||||||||||||||||||
3002 | { | - | ||||||||||||||||||||||||||||||||||||
3003 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3004 | d->cursor.mergeCharFormat(modifier); | - | ||||||||||||||||||||||||||||||||||||
3005 | d->updateCurrentCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
3006 | } | - | ||||||||||||||||||||||||||||||||||||
3007 | - | |||||||||||||||||||||||||||||||||||||
3008 | void QWidgetTextControl::setCurrentCharFormat(const QTextCharFormat &format) | - | ||||||||||||||||||||||||||||||||||||
3009 | { | - | ||||||||||||||||||||||||||||||||||||
3010 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3011 | d->cursor.setCharFormat(format); | - | ||||||||||||||||||||||||||||||||||||
3012 | d->updateCurrentCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
3013 | } | - | ||||||||||||||||||||||||||||||||||||
3014 | - | |||||||||||||||||||||||||||||||||||||
3015 | QTextCharFormat QWidgetTextControl::currentCharFormat() const | - | ||||||||||||||||||||||||||||||||||||
3016 | { | - | ||||||||||||||||||||||||||||||||||||
3017 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3018 | return d->cursor.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
3019 | } | - | ||||||||||||||||||||||||||||||||||||
3020 | - | |||||||||||||||||||||||||||||||||||||
3021 | void QWidgetTextControl::insertPlainText(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
3022 | { | - | ||||||||||||||||||||||||||||||||||||
3023 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3024 | d->cursor.insertText(text); | - | ||||||||||||||||||||||||||||||||||||
3025 | } | - | ||||||||||||||||||||||||||||||||||||
3026 | - | |||||||||||||||||||||||||||||||||||||
3027 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3028 | void QWidgetTextControl::insertHtml(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
3029 | { | - | ||||||||||||||||||||||||||||||||||||
3030 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3031 | d->cursor.insertHtml(text); | - | ||||||||||||||||||||||||||||||||||||
3032 | } | - | ||||||||||||||||||||||||||||||||||||
3033 | #endif // QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3034 | - | |||||||||||||||||||||||||||||||||||||
3035 | QPointF QWidgetTextControl::anchorPosition(const QString &name) const | - | ||||||||||||||||||||||||||||||||||||
3036 | { | - | ||||||||||||||||||||||||||||||||||||
3037 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3038 | if (name.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
3039 | return QPointF(); | - | ||||||||||||||||||||||||||||||||||||
3040 | - | |||||||||||||||||||||||||||||||||||||
3041 | QRectF r; | - | ||||||||||||||||||||||||||||||||||||
3042 | for (QTextBlock block = d->doc->begin(); block.isValid(); block = block.next()) { | - | ||||||||||||||||||||||||||||||||||||
3043 | QTextCharFormat format = block.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
3044 | if (format.isAnchor() && format.anchorNames().contains(name)) { | - | ||||||||||||||||||||||||||||||||||||
3045 | r = d->rectForPosition(block.position()); | - | ||||||||||||||||||||||||||||||||||||
3046 | break; | - | ||||||||||||||||||||||||||||||||||||
3047 | } | - | ||||||||||||||||||||||||||||||||||||
3048 | - | |||||||||||||||||||||||||||||||||||||
3049 | for (QTextBlock::Iterator it = block.begin(); !it.atEnd(); ++it) { | - | ||||||||||||||||||||||||||||||||||||
3050 | QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||||||||||||||
3051 | format = fragment.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
3052 | if (format.isAnchor() && format.anchorNames().contains(name)) { | - | ||||||||||||||||||||||||||||||||||||
3053 | r = d->rectForPosition(fragment.position()); | - | ||||||||||||||||||||||||||||||||||||
3054 | block = QTextBlock(); | - | ||||||||||||||||||||||||||||||||||||
3055 | break; | - | ||||||||||||||||||||||||||||||||||||
3056 | } | - | ||||||||||||||||||||||||||||||||||||
3057 | } | - | ||||||||||||||||||||||||||||||||||||
3058 | } | - | ||||||||||||||||||||||||||||||||||||
3059 | if (!r.isValid()) | - | ||||||||||||||||||||||||||||||||||||
3060 | return QPointF(); | - | ||||||||||||||||||||||||||||||||||||
3061 | return QPointF(0, r.top()); | - | ||||||||||||||||||||||||||||||||||||
3062 | } | - | ||||||||||||||||||||||||||||||||||||
3063 | - | |||||||||||||||||||||||||||||||||||||
3064 | void QWidgetTextControl::adjustSize() | - | ||||||||||||||||||||||||||||||||||||
3065 | { | - | ||||||||||||||||||||||||||||||||||||
3066 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3067 | d->doc->adjustSize(); | - | ||||||||||||||||||||||||||||||||||||
3068 | } | - | ||||||||||||||||||||||||||||||||||||
3069 | - | |||||||||||||||||||||||||||||||||||||
3070 | bool QWidgetTextControl::find(const QString &exp, QTextDocument::FindFlags options) | - | ||||||||||||||||||||||||||||||||||||
3071 | { | - | ||||||||||||||||||||||||||||||||||||
3072 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3073 | QTextCursor search = d->doc->find(exp, d->cursor, options); | - | ||||||||||||||||||||||||||||||||||||
3074 | if (search.isNull()) | - | ||||||||||||||||||||||||||||||||||||
3075 | return false; | - | ||||||||||||||||||||||||||||||||||||
3076 | - | |||||||||||||||||||||||||||||||||||||
3077 | setTextCursor(search); | - | ||||||||||||||||||||||||||||||||||||
3078 | return true; | - | ||||||||||||||||||||||||||||||||||||
3079 | } | - | ||||||||||||||||||||||||||||||||||||
3080 | - | |||||||||||||||||||||||||||||||||||||
3081 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||||||||||||||
3082 | bool QWidgetTextControl::find(const QRegExp &exp, QTextDocument::FindFlags options) | - | ||||||||||||||||||||||||||||||||||||
3083 | { | - | ||||||||||||||||||||||||||||||||||||
3084 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3085 | QTextCursor search = d->doc->find(exp, d->cursor, options); | - | ||||||||||||||||||||||||||||||||||||
3086 | if (search.isNull()) | - | ||||||||||||||||||||||||||||||||||||
3087 | return false; | - | ||||||||||||||||||||||||||||||||||||
3088 | - | |||||||||||||||||||||||||||||||||||||
3089 | setTextCursor(search); | - | ||||||||||||||||||||||||||||||||||||
3090 | return true; | - | ||||||||||||||||||||||||||||||||||||
3091 | } | - | ||||||||||||||||||||||||||||||||||||
3092 | #endif | - | ||||||||||||||||||||||||||||||||||||
3093 | - | |||||||||||||||||||||||||||||||||||||
3094 | QString QWidgetTextControl::toPlainText() const | - | ||||||||||||||||||||||||||||||||||||
3095 | { | - | ||||||||||||||||||||||||||||||||||||
3096 | return document()->toPlainText(); | - | ||||||||||||||||||||||||||||||||||||
3097 | } | - | ||||||||||||||||||||||||||||||||||||
3098 | - | |||||||||||||||||||||||||||||||||||||
3099 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3100 | QString QWidgetTextControl::toHtml() const | - | ||||||||||||||||||||||||||||||||||||
3101 | { | - | ||||||||||||||||||||||||||||||||||||
3102 | return document()->toHtml(); | - | ||||||||||||||||||||||||||||||||||||
3103 | } | - | ||||||||||||||||||||||||||||||||||||
3104 | #endif | - | ||||||||||||||||||||||||||||||||||||
3105 | - | |||||||||||||||||||||||||||||||||||||
3106 | void QWidgetTextControlPrivate::append(const QString &text, Qt::TextFormat format) | - | ||||||||||||||||||||||||||||||||||||
3107 | { | - | ||||||||||||||||||||||||||||||||||||
3108 | QTextCursor tmp(doc); | - | ||||||||||||||||||||||||||||||||||||
3109 | tmp.beginEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
3110 | tmp.movePosition(QTextCursor::End); | - | ||||||||||||||||||||||||||||||||||||
3111 | - | |||||||||||||||||||||||||||||||||||||
3112 | if (!doc->isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
3113 | tmp.insertBlock(cursor.blockFormat(), cursor.charFormat()); | - | ||||||||||||||||||||||||||||||||||||
3114 | else | - | ||||||||||||||||||||||||||||||||||||
3115 | tmp.setCharFormat(cursor.charFormat()); | - | ||||||||||||||||||||||||||||||||||||
3116 | - | |||||||||||||||||||||||||||||||||||||
3117 | // preserve the char format | - | ||||||||||||||||||||||||||||||||||||
3118 | QTextCharFormat oldCharFormat = cursor.charFormat(); | - | ||||||||||||||||||||||||||||||||||||
3119 | - | |||||||||||||||||||||||||||||||||||||
3120 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3121 | if (format == Qt::RichText || (format == Qt::AutoText && Qt::mightBeRichText(text))) { | - | ||||||||||||||||||||||||||||||||||||
3122 | tmp.insertHtml(text); | - | ||||||||||||||||||||||||||||||||||||
3123 | } else { | - | ||||||||||||||||||||||||||||||||||||
3124 | tmp.insertText(text); | - | ||||||||||||||||||||||||||||||||||||
3125 | } | - | ||||||||||||||||||||||||||||||||||||
3126 | #else | - | ||||||||||||||||||||||||||||||||||||
3127 | tmp.insertText(text); | - | ||||||||||||||||||||||||||||||||||||
3128 | #endif // QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3129 | if (!cursor.hasSelection()) | - | ||||||||||||||||||||||||||||||||||||
3130 | cursor.setCharFormat(oldCharFormat); | - | ||||||||||||||||||||||||||||||||||||
3131 | - | |||||||||||||||||||||||||||||||||||||
3132 | tmp.endEditBlock(); | - | ||||||||||||||||||||||||||||||||||||
3133 | } | - | ||||||||||||||||||||||||||||||||||||
3134 | - | |||||||||||||||||||||||||||||||||||||
3135 | void QWidgetTextControl::append(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
3136 | { | - | ||||||||||||||||||||||||||||||||||||
3137 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3138 | d->append(text, Qt::AutoText); | - | ||||||||||||||||||||||||||||||||||||
3139 | } | - | ||||||||||||||||||||||||||||||||||||
3140 | - | |||||||||||||||||||||||||||||||||||||
3141 | void QWidgetTextControl::appendHtml(const QString &html) | - | ||||||||||||||||||||||||||||||||||||
3142 | { | - | ||||||||||||||||||||||||||||||||||||
3143 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3144 | d->append(html, Qt::RichText); | - | ||||||||||||||||||||||||||||||||||||
3145 | } | - | ||||||||||||||||||||||||||||||||||||
3146 | - | |||||||||||||||||||||||||||||||||||||
3147 | void QWidgetTextControl::appendPlainText(const QString &text) | - | ||||||||||||||||||||||||||||||||||||
3148 | { | - | ||||||||||||||||||||||||||||||||||||
3149 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3150 | d->append(text, Qt::PlainText); | - | ||||||||||||||||||||||||||||||||||||
3151 | } | - | ||||||||||||||||||||||||||||||||||||
3152 | - | |||||||||||||||||||||||||||||||||||||
3153 | - | |||||||||||||||||||||||||||||||||||||
3154 | void QWidgetTextControl::ensureCursorVisible() | - | ||||||||||||||||||||||||||||||||||||
3155 | { | - | ||||||||||||||||||||||||||||||||||||
3156 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3157 | QRectF crect = d->rectForPosition(d->cursor.position()).adjusted(-5, 0, 5, 0); | - | ||||||||||||||||||||||||||||||||||||
3158 | emit visibilityRequest(crect); | - | ||||||||||||||||||||||||||||||||||||
3159 | emit microFocusChanged(); | - | ||||||||||||||||||||||||||||||||||||
3160 | } | - | ||||||||||||||||||||||||||||||||||||
3161 | - | |||||||||||||||||||||||||||||||||||||
3162 | QPalette QWidgetTextControl::palette() const | - | ||||||||||||||||||||||||||||||||||||
3163 | { | - | ||||||||||||||||||||||||||||||||||||
3164 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3165 | return d->palette; | - | ||||||||||||||||||||||||||||||||||||
3166 | } | - | ||||||||||||||||||||||||||||||||||||
3167 | - | |||||||||||||||||||||||||||||||||||||
3168 | void QWidgetTextControl::setPalette(const QPalette &pal) | - | ||||||||||||||||||||||||||||||||||||
3169 | { | - | ||||||||||||||||||||||||||||||||||||
3170 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3171 | d->palette = pal; | - | ||||||||||||||||||||||||||||||||||||
3172 | } | - | ||||||||||||||||||||||||||||||||||||
3173 | - | |||||||||||||||||||||||||||||||||||||
3174 | QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QWidget *widget) const | - | ||||||||||||||||||||||||||||||||||||
3175 | { | - | ||||||||||||||||||||||||||||||||||||
3176 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3177 | - | |||||||||||||||||||||||||||||||||||||
3178 | QAbstractTextDocumentLayout::PaintContext ctx; | - | ||||||||||||||||||||||||||||||||||||
3179 | - | |||||||||||||||||||||||||||||||||||||
3180 | ctx.selections = d->extraSelections; | - | ||||||||||||||||||||||||||||||||||||
3181 | ctx.palette = d->palette; | - | ||||||||||||||||||||||||||||||||||||
3182 | if (d->cursorOn && d->isEnabled) { | - | ||||||||||||||||||||||||||||||||||||
3183 | if (d->hideCursor) | - | ||||||||||||||||||||||||||||||||||||
3184 | ctx.cursorPosition = -1; | - | ||||||||||||||||||||||||||||||||||||
3185 | else if (d->preeditCursor != 0) | - | ||||||||||||||||||||||||||||||||||||
3186 | ctx.cursorPosition = - (d->preeditCursor + 2); | - | ||||||||||||||||||||||||||||||||||||
3187 | else | - | ||||||||||||||||||||||||||||||||||||
3188 | ctx.cursorPosition = d->cursor.position(); | - | ||||||||||||||||||||||||||||||||||||
3189 | } | - | ||||||||||||||||||||||||||||||||||||
3190 | - | |||||||||||||||||||||||||||||||||||||
3191 | if (!d->dndFeedbackCursor.isNull()) | - | ||||||||||||||||||||||||||||||||||||
3192 | ctx.cursorPosition = d->dndFeedbackCursor.position(); | - | ||||||||||||||||||||||||||||||||||||
3193 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||||||||
3194 | if (!QApplication::keypadNavigationEnabled() || d->hasEditFocus) | - | ||||||||||||||||||||||||||||||||||||
3195 | #endif | - | ||||||||||||||||||||||||||||||||||||
3196 | if (d->cursor.hasSelection()) { | - | ||||||||||||||||||||||||||||||||||||
3197 | QAbstractTextDocumentLayout::Selection selection; | - | ||||||||||||||||||||||||||||||||||||
3198 | selection.cursor = d->cursor; | - | ||||||||||||||||||||||||||||||||||||
3199 | if (d->cursorIsFocusIndicator) { | - | ||||||||||||||||||||||||||||||||||||
3200 | QStyleOption opt; | - | ||||||||||||||||||||||||||||||||||||
3201 | opt.palette = ctx.palette; | - | ||||||||||||||||||||||||||||||||||||
3202 | QStyleHintReturnVariant ret; | - | ||||||||||||||||||||||||||||||||||||
3203 | QStyle *style = QApplication::style(); | - | ||||||||||||||||||||||||||||||||||||
3204 | if (widget) | - | ||||||||||||||||||||||||||||||||||||
3205 | style = widget->style(); | - | ||||||||||||||||||||||||||||||||||||
3206 | style->styleHint(QStyle::SH_TextControl_FocusIndicatorTextCharFormat, &opt, widget, &ret); | - | ||||||||||||||||||||||||||||||||||||
3207 | selection.format = qvariant_cast<QTextFormat>(ret.variant).toCharFormat(); | - | ||||||||||||||||||||||||||||||||||||
3208 | } else { | - | ||||||||||||||||||||||||||||||||||||
3209 | QPalette::ColorGroup cg = d->hasFocus ? QPalette::Active : QPalette::Inactive; | - | ||||||||||||||||||||||||||||||||||||
3210 | selection.format.setBackground(ctx.palette.brush(cg, QPalette::Highlight)); | - | ||||||||||||||||||||||||||||||||||||
3211 | selection.format.setForeground(ctx.palette.brush(cg, QPalette::HighlightedText)); | - | ||||||||||||||||||||||||||||||||||||
3212 | QStyleOption opt; | - | ||||||||||||||||||||||||||||||||||||
3213 | QStyle *style = QApplication::style(); | - | ||||||||||||||||||||||||||||||||||||
3214 | if (widget) { | - | ||||||||||||||||||||||||||||||||||||
3215 | opt.initFrom(widget); | - | ||||||||||||||||||||||||||||||||||||
3216 | style = widget->style(); | - | ||||||||||||||||||||||||||||||||||||
3217 | } | - | ||||||||||||||||||||||||||||||||||||
3218 | if (style->styleHint(QStyle::SH_RichText_FullWidthSelection, &opt, widget)) | - | ||||||||||||||||||||||||||||||||||||
3219 | selection.format.setProperty(QTextFormat::FullWidthSelection, true); | - | ||||||||||||||||||||||||||||||||||||
3220 | } | - | ||||||||||||||||||||||||||||||||||||
3221 | ctx.selections.append(selection); | - | ||||||||||||||||||||||||||||||||||||
3222 | } | - | ||||||||||||||||||||||||||||||||||||
3223 | - | |||||||||||||||||||||||||||||||||||||
3224 | return ctx; | - | ||||||||||||||||||||||||||||||||||||
3225 | } | - | ||||||||||||||||||||||||||||||||||||
3226 | - | |||||||||||||||||||||||||||||||||||||
3227 | void QWidgetTextControl::drawContents(QPainter *p, const QRectF &rect, QWidget *widget) | - | ||||||||||||||||||||||||||||||||||||
3228 | { | - | ||||||||||||||||||||||||||||||||||||
3229 | Q_D(QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3230 | p->save(); | - | ||||||||||||||||||||||||||||||||||||
3231 | QAbstractTextDocumentLayout::PaintContext ctx = getPaintContext(widget); | - | ||||||||||||||||||||||||||||||||||||
3232 | if (rect.isValid()) | - | ||||||||||||||||||||||||||||||||||||
3233 | p->setClipRect(rect, Qt::IntersectClip); | - | ||||||||||||||||||||||||||||||||||||
3234 | ctx.clip = rect; | - | ||||||||||||||||||||||||||||||||||||
3235 | - | |||||||||||||||||||||||||||||||||||||
3236 | d->doc->documentLayout()->draw(p, ctx); | - | ||||||||||||||||||||||||||||||||||||
3237 | p->restore(); | - | ||||||||||||||||||||||||||||||||||||
3238 | } | - | ||||||||||||||||||||||||||||||||||||
3239 | - | |||||||||||||||||||||||||||||||||||||
3240 | void QWidgetTextControlPrivate::_q_copyLink() | - | ||||||||||||||||||||||||||||||||||||
3241 | { | - | ||||||||||||||||||||||||||||||||||||
3242 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||||||||||||||
3243 | QMimeData *md = new QMimeData; | - | ||||||||||||||||||||||||||||||||||||
3244 | md->setText(linkToCopy); | - | ||||||||||||||||||||||||||||||||||||
3245 | QApplication::clipboard()->setMimeData(md); | - | ||||||||||||||||||||||||||||||||||||
3246 | #endif | - | ||||||||||||||||||||||||||||||||||||
3247 | } | - | ||||||||||||||||||||||||||||||||||||
3248 | - | |||||||||||||||||||||||||||||||||||||
3249 | int QWidgetTextControl::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const | - | ||||||||||||||||||||||||||||||||||||
3250 | { | - | ||||||||||||||||||||||||||||||||||||
3251 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3252 | return d->doc->documentLayout()->hitTest(point, accuracy); | - | ||||||||||||||||||||||||||||||||||||
3253 | } | - | ||||||||||||||||||||||||||||||||||||
3254 | - | |||||||||||||||||||||||||||||||||||||
3255 | QRectF QWidgetTextControl::blockBoundingRect(const QTextBlock &block) const | - | ||||||||||||||||||||||||||||||||||||
3256 | { | - | ||||||||||||||||||||||||||||||||||||
3257 | Q_D(const QWidgetTextControl); | - | ||||||||||||||||||||||||||||||||||||
3258 | return d->doc->documentLayout()->blockBoundingRect(block); | - | ||||||||||||||||||||||||||||||||||||
3259 | } | - | ||||||||||||||||||||||||||||||||||||
3260 | - | |||||||||||||||||||||||||||||||||||||
3261 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
3262 | #define NUM_CONTROL_CHARACTERS 14 | - | ||||||||||||||||||||||||||||||||||||
3263 | const struct QUnicodeControlCharacter { | - | ||||||||||||||||||||||||||||||||||||
3264 | const char *text; | - | ||||||||||||||||||||||||||||||||||||
3265 | ushort character; | - | ||||||||||||||||||||||||||||||||||||
3266 | } qt_controlCharacters[NUM_CONTROL_CHARACTERS] = { | - | ||||||||||||||||||||||||||||||||||||
3267 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRM Left-to-right mark"), 0x200e }, | - | ||||||||||||||||||||||||||||||||||||
3268 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLM Right-to-left mark"), 0x200f }, | - | ||||||||||||||||||||||||||||||||||||
3269 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWJ Zero width joiner"), 0x200d }, | - | ||||||||||||||||||||||||||||||||||||
3270 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWNJ Zero width non-joiner"), 0x200c }, | - | ||||||||||||||||||||||||||||||||||||
3271 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWSP Zero width space"), 0x200b }, | - | ||||||||||||||||||||||||||||||||||||
3272 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRE Start of left-to-right embedding"), 0x202a }, | - | ||||||||||||||||||||||||||||||||||||
3273 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLE Start of right-to-left embedding"), 0x202b }, | - | ||||||||||||||||||||||||||||||||||||
3274 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRO Start of left-to-right override"), 0x202d }, | - | ||||||||||||||||||||||||||||||||||||
3275 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLO Start of right-to-left override"), 0x202e }, | - | ||||||||||||||||||||||||||||||||||||
3276 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "PDF Pop directional formatting"), 0x202c }, | - | ||||||||||||||||||||||||||||||||||||
3277 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRI Left-to-right isolate"), 0x2066 }, | - | ||||||||||||||||||||||||||||||||||||
3278 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLI Right-to-left isolate"), 0x2067 }, | - | ||||||||||||||||||||||||||||||||||||
3279 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "FSI First strong isolate"), 0x2068 }, | - | ||||||||||||||||||||||||||||||||||||
3280 | { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "PDI Pop directional isolate"), 0x2069 } | - | ||||||||||||||||||||||||||||||||||||
3281 | }; | - | ||||||||||||||||||||||||||||||||||||
3282 | - | |||||||||||||||||||||||||||||||||||||
3283 | QUnicodeControlCharacterMenu::QUnicodeControlCharacterMenu(QObject *_editWidget, QWidget *parent) | - | ||||||||||||||||||||||||||||||||||||
3284 | : QMenu(parent), editWidget(_editWidget) | - | ||||||||||||||||||||||||||||||||||||
3285 | { | - | ||||||||||||||||||||||||||||||||||||
3286 | setTitle(tr("Insert Unicode control character")); | - | ||||||||||||||||||||||||||||||||||||
3287 | for (int i = 0; i < NUM_CONTROL_CHARACTERS; ++i) { | - | ||||||||||||||||||||||||||||||||||||
3288 | addAction(tr(qt_controlCharacters[i].text), this, SLOT(menuActionTriggered())); | - | ||||||||||||||||||||||||||||||||||||
3289 | } | - | ||||||||||||||||||||||||||||||||||||
3290 | } | - | ||||||||||||||||||||||||||||||||||||
3291 | - | |||||||||||||||||||||||||||||||||||||
3292 | void QUnicodeControlCharacterMenu::menuActionTriggered() | - | ||||||||||||||||||||||||||||||||||||
3293 | { | - | ||||||||||||||||||||||||||||||||||||
3294 | QAction *a = qobject_cast<QAction *>(sender()); | - | ||||||||||||||||||||||||||||||||||||
3295 | int idx = actions().indexOf(a); | - | ||||||||||||||||||||||||||||||||||||
3296 | if (idx < 0 || idx >= NUM_CONTROL_CHARACTERS) | - | ||||||||||||||||||||||||||||||||||||
3297 | return; | - | ||||||||||||||||||||||||||||||||||||
3298 | QChar c(qt_controlCharacters[idx].character); | - | ||||||||||||||||||||||||||||||||||||
3299 | QString str(c); | - | ||||||||||||||||||||||||||||||||||||
3300 | - | |||||||||||||||||||||||||||||||||||||
3301 | #ifndef QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||||||||||||||
3302 | if (QTextEdit *edit = qobject_cast<QTextEdit *>(editWidget)) { | - | ||||||||||||||||||||||||||||||||||||
3303 | edit->insertPlainText(str); | - | ||||||||||||||||||||||||||||||||||||
3304 | return; | - | ||||||||||||||||||||||||||||||||||||
3305 | } | - | ||||||||||||||||||||||||||||||||||||
3306 | #endif | - | ||||||||||||||||||||||||||||||||||||
3307 | if (QWidgetTextControl *control = qobject_cast<QWidgetTextControl *>(editWidget)) { | - | ||||||||||||||||||||||||||||||||||||
3308 | control->insertPlainText(str); | - | ||||||||||||||||||||||||||||||||||||
3309 | } | - | ||||||||||||||||||||||||||||||||||||
3310 | #ifndef QT_NO_LINEEDIT | - | ||||||||||||||||||||||||||||||||||||
3311 | if (QLineEdit *edit = qobject_cast<QLineEdit *>(editWidget)) { | - | ||||||||||||||||||||||||||||||||||||
3312 | edit->insert(str); | - | ||||||||||||||||||||||||||||||||||||
3313 | return; | - | ||||||||||||||||||||||||||||||||||||
3314 | } | - | ||||||||||||||||||||||||||||||||||||
3315 | #endif | - | ||||||||||||||||||||||||||||||||||||
3316 | } | - | ||||||||||||||||||||||||||||||||||||
3317 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||||||||||||||
3318 | - | |||||||||||||||||||||||||||||||||||||
3319 | QStringList QTextEditMimeData::formats() const | - | ||||||||||||||||||||||||||||||||||||
3320 | { | - | ||||||||||||||||||||||||||||||||||||
3321 | if (!fragment.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
3322 | return QStringList() << QString::fromLatin1("text/plain") << QString::fromLatin1("text/html") | - | ||||||||||||||||||||||||||||||||||||
3323 | #ifndef QT_NO_TEXTODFWRITER | - | ||||||||||||||||||||||||||||||||||||
3324 | << QString::fromLatin1("application/vnd.oasis.opendocument.text") | - | ||||||||||||||||||||||||||||||||||||
3325 | #endif | - | ||||||||||||||||||||||||||||||||||||
3326 | ; | - | ||||||||||||||||||||||||||||||||||||
3327 | else | - | ||||||||||||||||||||||||||||||||||||
3328 | return QMimeData::formats(); | - | ||||||||||||||||||||||||||||||||||||
3329 | } | - | ||||||||||||||||||||||||||||||||||||
3330 | - | |||||||||||||||||||||||||||||||||||||
3331 | QVariant QTextEditMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const | - | ||||||||||||||||||||||||||||||||||||
3332 | { | - | ||||||||||||||||||||||||||||||||||||
3333 | if (!fragment.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
3334 | setup(); | - | ||||||||||||||||||||||||||||||||||||
3335 | return QMimeData::retrieveData(mimeType, type); | - | ||||||||||||||||||||||||||||||||||||
3336 | } | - | ||||||||||||||||||||||||||||||||||||
3337 | - | |||||||||||||||||||||||||||||||||||||
3338 | void QTextEditMimeData::setup() const | - | ||||||||||||||||||||||||||||||||||||
3339 | { | - | ||||||||||||||||||||||||||||||||||||
3340 | QTextEditMimeData *that = const_cast<QTextEditMimeData *>(this); | - | ||||||||||||||||||||||||||||||||||||
3341 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||||||||||||||||||||
3342 | that->setData(QLatin1String("text/html"), fragment.toHtml("utf-8").toUtf8()); | - | ||||||||||||||||||||||||||||||||||||
3343 | #endif | - | ||||||||||||||||||||||||||||||||||||
3344 | #ifndef QT_NO_TEXTODFWRITER | - | ||||||||||||||||||||||||||||||||||||
3345 | { | - | ||||||||||||||||||||||||||||||||||||
3346 | QBuffer buffer; | - | ||||||||||||||||||||||||||||||||||||
3347 | QTextDocumentWriter writer(&buffer, "ODF"); | - | ||||||||||||||||||||||||||||||||||||
3348 | writer.write(fragment); | - | ||||||||||||||||||||||||||||||||||||
3349 | buffer.close(); | - | ||||||||||||||||||||||||||||||||||||
3350 | that->setData(QLatin1String("application/vnd.oasis.opendocument.text"), buffer.data()); | - | ||||||||||||||||||||||||||||||||||||
3351 | } | - | ||||||||||||||||||||||||||||||||||||
3352 | #endif | - | ||||||||||||||||||||||||||||||||||||
3353 | that->setText(fragment.toPlainText()); | - | ||||||||||||||||||||||||||||||||||||
3354 | fragment = QTextDocumentFragment(); | - | ||||||||||||||||||||||||||||||||||||
3355 | } | - | ||||||||||||||||||||||||||||||||||||
3356 | - | |||||||||||||||||||||||||||||||||||||
3357 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
3358 | - | |||||||||||||||||||||||||||||||||||||
3359 | #include "moc_qwidgettextcontrol_p.cpp" | - | ||||||||||||||||||||||||||||||||||||
3360 | - | |||||||||||||||||||||||||||||||||||||
3361 | #endif // QT_NO_TEXTCONTROL | - | ||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |