Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qapplication.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 "qplatformdefs.h" | - | ||||||||||||||||||
41 | #include "qabstracteventdispatcher.h" | - | ||||||||||||||||||
42 | #include "qapplication.h" | - | ||||||||||||||||||
43 | #include "qclipboard.h" | - | ||||||||||||||||||
44 | #include "qcursor.h" | - | ||||||||||||||||||
45 | #include "qdesktopwidget.h" | - | ||||||||||||||||||
46 | #include "qdir.h" | - | ||||||||||||||||||
47 | #include "qevent.h" | - | ||||||||||||||||||
48 | #include "qfile.h" | - | ||||||||||||||||||
49 | #include "qfileinfo.h" | - | ||||||||||||||||||
50 | #include "qgraphicsscene.h" | - | ||||||||||||||||||
51 | #include "qhash.h" | - | ||||||||||||||||||
52 | #include "qset.h" | - | ||||||||||||||||||
53 | #include "qlayout.h" | - | ||||||||||||||||||
54 | #include "qstyle.h" | - | ||||||||||||||||||
55 | #include "qstyleoption.h" | - | ||||||||||||||||||
56 | #include "qstylefactory.h" | - | ||||||||||||||||||
57 | #include "qtextcodec.h" | - | ||||||||||||||||||
58 | #include "qtooltip.h" | - | ||||||||||||||||||
59 | #include "qtranslator.h" | - | ||||||||||||||||||
60 | #include "qvariant.h" | - | ||||||||||||||||||
61 | #include "qwidget.h" | - | ||||||||||||||||||
62 | #include "private/qdnd_p.h" | - | ||||||||||||||||||
63 | #include "private/qguiapplication_p.h" | - | ||||||||||||||||||
64 | #include "qcolormap.h" | - | ||||||||||||||||||
65 | #include "qdebug.h" | - | ||||||||||||||||||
66 | #include "private/qstylesheetstyle_p.h" | - | ||||||||||||||||||
67 | #include "private/qstyle_p.h" | - | ||||||||||||||||||
68 | #include "qmessagebox.h" | - | ||||||||||||||||||
69 | #include "qwidgetwindow_p.h" | - | ||||||||||||||||||
70 | #include <QtWidgets/qgraphicsproxywidget.h> | - | ||||||||||||||||||
71 | #include <QtGui/qstylehints.h> | - | ||||||||||||||||||
72 | #include <QtGui/qinputmethod.h> | - | ||||||||||||||||||
73 | #include <QtGui/private/qwindow_p.h> | - | ||||||||||||||||||
74 | #include <QtGui/qtouchdevice.h> | - | ||||||||||||||||||
75 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||
76 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||
77 | #include <QtWidgets/QWhatsThis> | - | ||||||||||||||||||
78 | #endif | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | #include "private/qkeymapper_p.h" | - | ||||||||||||||||||
81 | #include "private/qaccessiblewidgetfactory_p.h" | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | #include <qthread.h> | - | ||||||||||||||||||
84 | #include <private/qthread_p.h> | - | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | #include <private/qfont_p.h> | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | #include <stdlib.h> | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | #include "qapplication_p.h" | - | ||||||||||||||||||
91 | #include "private/qevent_p.h" | - | ||||||||||||||||||
92 | #include "qwidget_p.h" | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | #include "qgesture.h" | - | ||||||||||||||||||
95 | #include "private/qgesturemanager_p.h" | - | ||||||||||||||||||
96 | #include <qpa/qplatformfontdatabase.h> | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
99 | #include <QtCore/qt_windows.h> // for qt_win_display_dc() | - | ||||||||||||||||||
100 | #endif | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | #include "qdatetime.h" | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||
105 | extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp | - | ||||||||||||||||||
106 | extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp | - | ||||||||||||||||||
107 | extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp | - | ||||||||||||||||||
108 | #endif | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | #include <qpa/qplatformwindow.h> | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | //#define ALIEN_DEBUG | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | static void initResources() | - | ||||||||||||||||||
115 | { | - | ||||||||||||||||||
116 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||
117 | Q_INIT_RESOURCE(qstyle_wince); | - | ||||||||||||||||||
118 | #else | - | ||||||||||||||||||
119 | Q_INIT_RESOURCE(qstyle); | - | ||||||||||||||||||
120 | #endif | - | ||||||||||||||||||
121 | Q_INIT_RESOURCE(qmessagebox); | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | } | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | // Helper macro for static functions to check on the existence of the application class. | - | ||||||||||||||||||
128 | #define CHECK_QAPP_INSTANCE(...) \ | - | ||||||||||||||||||
129 | if (Q_LIKELY(QCoreApplication::instance())) { \ | - | ||||||||||||||||||
130 | } else { \ | - | ||||||||||||||||||
131 | qWarning("Must construct a QApplication first."); \ | - | ||||||||||||||||||
132 | return __VA_ARGS__; \ | - | ||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | Q_CORE_EXPORT void qt_call_post_routines(); | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | QApplicationPrivate *QApplicationPrivate::self = 0; | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | static void initSystemPalette() | - | ||||||||||||||||||
140 | { | - | ||||||||||||||||||
141 | if (!QApplicationPrivate::sys_pal) { | - | ||||||||||||||||||
142 | QPalette defaultPlatte; | - | ||||||||||||||||||
143 | if (QApplicationPrivate::app_style) | - | ||||||||||||||||||
144 | defaultPlatte = QApplicationPrivate::app_style->standardPalette(); | - | ||||||||||||||||||
145 | if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) { | - | ||||||||||||||||||
146 | QApplicationPrivate::setSystemPalette(themePalette->resolve(defaultPlatte)); | - | ||||||||||||||||||
147 | QApplicationPrivate::initializeWidgetPaletteHash(); | - | ||||||||||||||||||
148 | } else { | - | ||||||||||||||||||
149 | QApplicationPrivate::setSystemPalette(defaultPlatte); | - | ||||||||||||||||||
150 | } | - | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | } | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | static void clearSystemPalette() | - | ||||||||||||||||||
155 | { | - | ||||||||||||||||||
156 | delete QApplicationPrivate::sys_pal; | - | ||||||||||||||||||
157 | QApplicationPrivate::sys_pal = 0; | - | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | static QByteArray get_style_class_name() | - | ||||||||||||||||||
161 | { | - | ||||||||||||||||||
162 | QScopedPointer<QStyle> s(QStyleFactory::create(QApplicationPrivate::desktopStyleKey())); | - | ||||||||||||||||||
163 | if (!s.isNull()) | - | ||||||||||||||||||
164 | return s->metaObject()->className(); | - | ||||||||||||||||||
165 | return QByteArray(); | - | ||||||||||||||||||
166 | } | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | static QByteArray nativeStyleClassName() | - | ||||||||||||||||||
169 | { | - | ||||||||||||||||||
170 | static QByteArray name = get_style_class_name(); | - | ||||||||||||||||||
171 | return name; | - | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||
175 | int QApplicationPrivate::autoMaximizeThreshold = -1; | - | ||||||||||||||||||
176 | bool QApplicationPrivate::autoSipEnabled = false; | - | ||||||||||||||||||
177 | #else | - | ||||||||||||||||||
178 | bool QApplicationPrivate::autoSipEnabled = true; | - | ||||||||||||||||||
179 | #endif | - | ||||||||||||||||||
180 | - | |||||||||||||||||||
181 | QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, int flags) | - | ||||||||||||||||||
182 | : QApplicationPrivateBase(argc, argv, flags) | - | ||||||||||||||||||
183 | { | - | ||||||||||||||||||
184 | application_type = QApplicationPrivate::Gui; | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
187 | gestureManager = 0; | - | ||||||||||||||||||
188 | gestureWidget = 0; | - | ||||||||||||||||||
189 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | if (!self) | - | ||||||||||||||||||
192 | self = this; | - | ||||||||||||||||||
193 | } | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | QApplicationPrivate::~QApplicationPrivate() | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | if (self == this) | - | ||||||||||||||||||
198 | self = 0; | - | ||||||||||||||||||
199 | } | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | void QApplicationPrivate::createEventDispatcher() | - | ||||||||||||||||||
202 | { | - | ||||||||||||||||||
203 | QGuiApplicationPrivate::createEventDispatcher(); | - | ||||||||||||||||||
204 | } | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | /*! | - | ||||||||||||||||||
207 | \class QApplication | - | ||||||||||||||||||
208 | \brief The QApplication class manages the GUI application's control | - | ||||||||||||||||||
209 | flow and main settings. | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | \inmodule QtWidgets | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | QApplication specializes QGuiApplication with some functionality needed | - | ||||||||||||||||||
214 | for QWidget-based applications. It handles widget specific initialization, | - | ||||||||||||||||||
215 | finalization. | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | For any GUI application using Qt, there is precisely \b one QApplication | - | ||||||||||||||||||
218 | object, no matter whether the application has 0, 1, 2 or more windows at | - | ||||||||||||||||||
219 | any given time. For non-QWidget based Qt applications, use QGuiApplication instead, | - | ||||||||||||||||||
220 | as it does not depend on the \l QtWidgets library. | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | Some GUI applications provide a special batch mode ie. provide command line | - | ||||||||||||||||||
223 | arguments for executing tasks without manual intervention. In such non-GUI | - | ||||||||||||||||||
224 | mode, it is often sufficient to instantiate a plain QCoreApplication to | - | ||||||||||||||||||
225 | avoid unnecessarily initializing resources needed for a graphical user | - | ||||||||||||||||||
226 | interface. The following example shows how to dynamically create an | - | ||||||||||||||||||
227 | appropriate type of application instance: | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | \snippet code/src_gui_kernel_qapplication.cpp 0 | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | The QApplication object is accessible through the instance() function that | - | ||||||||||||||||||
232 | returns a pointer equivalent to the global qApp pointer. | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | QApplication's main areas of responsibility are: | - | ||||||||||||||||||
235 | \list | - | ||||||||||||||||||
236 | \li It initializes the application with the user's desktop settings | - | ||||||||||||||||||
237 | such as palette(), font() and doubleClickInterval(). It keeps | - | ||||||||||||||||||
238 | track of these properties in case the user changes the desktop | - | ||||||||||||||||||
239 | globally, for example through some kind of control panel. | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | \li It performs event handling, meaning that it receives events | - | ||||||||||||||||||
242 | from the underlying window system and dispatches them to the | - | ||||||||||||||||||
243 | relevant widgets. By using sendEvent() and postEvent() you can | - | ||||||||||||||||||
244 | send your own events to widgets. | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | \li It parses common command line arguments and sets its internal | - | ||||||||||||||||||
247 | state accordingly. See the \l{QApplication::QApplication()} | - | ||||||||||||||||||
248 | {constructor documentation} below for more details. | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | \li It defines the application's look and feel, which is | - | ||||||||||||||||||
251 | encapsulated in a QStyle object. This can be changed at runtime | - | ||||||||||||||||||
252 | with setStyle(). | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | \li It specifies how the application is to allocate colors. See | - | ||||||||||||||||||
255 | setColorSpec() for details. | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | \li It provides localization of strings that are visible to the | - | ||||||||||||||||||
258 | user via translate(). | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | \li It provides some magical objects like the desktop() and the | - | ||||||||||||||||||
261 | clipboard(). | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | \li It knows about the application's windows. You can ask which | - | ||||||||||||||||||
264 | widget is at a certain position using widgetAt(), get a list of | - | ||||||||||||||||||
265 | topLevelWidgets() and closeAllWindows(), etc. | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | \li It manages the application's mouse cursor handling, see | - | ||||||||||||||||||
268 | setOverrideCursor() | - | ||||||||||||||||||
269 | \endlist | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | Since the QApplication object does so much initialization, it \e{must} be | - | ||||||||||||||||||
272 | created before any other objects related to the user interface are created. | - | ||||||||||||||||||
273 | QApplication also deals with common command line arguments. Hence, it is | - | ||||||||||||||||||
274 | usually a good idea to create it \e before any interpretation or | - | ||||||||||||||||||
275 | modification of \c argv is done in the application itself. | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | \table | - | ||||||||||||||||||
278 | \header | - | ||||||||||||||||||
279 | \li{2,1} Groups of functions | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | \row | - | ||||||||||||||||||
282 | \li System settings | - | ||||||||||||||||||
283 | \li desktopSettingsAware(), | - | ||||||||||||||||||
284 | setDesktopSettingsAware(), | - | ||||||||||||||||||
285 | cursorFlashTime(), | - | ||||||||||||||||||
286 | setCursorFlashTime(), | - | ||||||||||||||||||
287 | doubleClickInterval(), | - | ||||||||||||||||||
288 | setDoubleClickInterval(), | - | ||||||||||||||||||
289 | setKeyboardInputInterval(), | - | ||||||||||||||||||
290 | wheelScrollLines(), | - | ||||||||||||||||||
291 | setWheelScrollLines(), | - | ||||||||||||||||||
292 | palette(), | - | ||||||||||||||||||
293 | setPalette(), | - | ||||||||||||||||||
294 | font(), | - | ||||||||||||||||||
295 | setFont(), | - | ||||||||||||||||||
296 | fontMetrics(). | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | \row | - | ||||||||||||||||||
299 | \li Event handling | - | ||||||||||||||||||
300 | \li exec(), | - | ||||||||||||||||||
301 | processEvents(), | - | ||||||||||||||||||
302 | exit(), | - | ||||||||||||||||||
303 | quit(). | - | ||||||||||||||||||
304 | sendEvent(), | - | ||||||||||||||||||
305 | postEvent(), | - | ||||||||||||||||||
306 | sendPostedEvents(), | - | ||||||||||||||||||
307 | removePostedEvents(), | - | ||||||||||||||||||
308 | hasPendingEvents(), | - | ||||||||||||||||||
309 | notify(). | - | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | \row | - | ||||||||||||||||||
312 | \li GUI Styles | - | ||||||||||||||||||
313 | \li style(), | - | ||||||||||||||||||
314 | setStyle(). | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | \row | - | ||||||||||||||||||
317 | \li Color usage | - | ||||||||||||||||||
318 | \li colorSpec(), | - | ||||||||||||||||||
319 | setColorSpec(). | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | \row | - | ||||||||||||||||||
322 | \li Text handling | - | ||||||||||||||||||
323 | \li installTranslator(), | - | ||||||||||||||||||
324 | removeTranslator() | - | ||||||||||||||||||
325 | translate(). | - | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | \row | - | ||||||||||||||||||
328 | \li Widgets | - | ||||||||||||||||||
329 | \li allWidgets(), | - | ||||||||||||||||||
330 | topLevelWidgets(), | - | ||||||||||||||||||
331 | desktop(), | - | ||||||||||||||||||
332 | activePopupWidget(), | - | ||||||||||||||||||
333 | activeModalWidget(), | - | ||||||||||||||||||
334 | clipboard(), | - | ||||||||||||||||||
335 | focusWidget(), | - | ||||||||||||||||||
336 | activeWindow(), | - | ||||||||||||||||||
337 | widgetAt(). | - | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | \row | - | ||||||||||||||||||
340 | \li Advanced cursor handling | - | ||||||||||||||||||
341 | \li overrideCursor(), | - | ||||||||||||||||||
342 | setOverrideCursor(), | - | ||||||||||||||||||
343 | restoreOverrideCursor(). | - | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | \row | - | ||||||||||||||||||
346 | \li Miscellaneous | - | ||||||||||||||||||
347 | \li closeAllWindows(), | - | ||||||||||||||||||
348 | startingUp(), | - | ||||||||||||||||||
349 | closingDown(). | - | ||||||||||||||||||
350 | \endtable | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | \sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings | - | ||||||||||||||||||
353 | */ | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | /*! | - | ||||||||||||||||||
356 | \enum QApplication::ColorSpec | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | \value NormalColor the default color allocation policy | - | ||||||||||||||||||
359 | \value CustomColor the same as NormalColor for X11; allocates colors | - | ||||||||||||||||||
360 | to a palette on demand under Windows | - | ||||||||||||||||||
361 | \value ManyColor the right choice for applications that use thousands of | - | ||||||||||||||||||
362 | colors | - | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | See setColorSpec() for full details. | - | ||||||||||||||||||
365 | */ | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | /*! | - | ||||||||||||||||||
368 | \fn QApplication::setGraphicsSystem(const QString &) | - | ||||||||||||||||||
369 | \obsolete | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | This call has no effect. | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | Use the QPA framework instead. | - | ||||||||||||||||||
374 | */ | - | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | /*! | - | ||||||||||||||||||
377 | \fn QWidget *QApplication::topLevelAt(const QPoint &point) | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | Returns the top-level widget at the given \a point; returns 0 if | - | ||||||||||||||||||
380 | there is no such widget. | - | ||||||||||||||||||
381 | */ | - | ||||||||||||||||||
382 | QWidget *QApplication::topLevelAt(const QPoint &pos) | - | ||||||||||||||||||
383 | { | - | ||||||||||||||||||
384 | if (const QWindow *window = QGuiApplication::topLevelAt(pos)) { | - | ||||||||||||||||||
385 | if (const QWidgetWindow *widgetWindow = qobject_cast<const QWidgetWindow *>(window)) | - | ||||||||||||||||||
386 | return widgetWindow->widget(); | - | ||||||||||||||||||
387 | } | - | ||||||||||||||||||
388 | return 0; | - | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | /*! | - | ||||||||||||||||||
392 | \fn QWidget *QApplication::topLevelAt(int x, int y) | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | \overload | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | Returns the top-level widget at the point (\a{x}, \a{y}); returns | - | ||||||||||||||||||
397 | 0 if there is no such widget. | - | ||||||||||||||||||
398 | */ | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | void qt_init(QApplicationPrivate *priv, int type | - | ||||||||||||||||||
401 | ); | - | ||||||||||||||||||
402 | void qt_init_tooltip_palette(); | - | ||||||||||||||||||
403 | void qt_cleanup(); | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | QStyle *QApplicationPrivate::app_style = 0; // default application style | - | ||||||||||||||||||
406 | bool QApplicationPrivate::overrides_native_style = false; // whether native QApplication style is | - | ||||||||||||||||||
407 | // overridden, i.e. not native | - | ||||||||||||||||||
408 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
409 | QString QApplicationPrivate::styleSheet; // default application stylesheet | - | ||||||||||||||||||
410 | #endif | - | ||||||||||||||||||
411 | QPointer<QWidget> QApplicationPrivate::leaveAfterRelease = 0; | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | int QApplicationPrivate::app_cspec = QApplication::NormalColor; | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | QPalette *QApplicationPrivate::sys_pal = 0; // default system palette | - | ||||||||||||||||||
416 | QPalette *QApplicationPrivate::set_pal = 0; // default palette set by programmer | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | QFont *QApplicationPrivate::sys_font = 0; // default system font | - | ||||||||||||||||||
419 | QFont *QApplicationPrivate::set_font = 0; // default font set by programmer | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | QWidget *QApplicationPrivate::main_widget = 0; // main application widget | - | ||||||||||||||||||
422 | QWidget *QApplicationPrivate::focus_widget = 0; // has keyboard input focus | - | ||||||||||||||||||
423 | QWidget *QApplicationPrivate::hidden_focus_widget = 0; // will get keyboard input focus after show() | - | ||||||||||||||||||
424 | QWidget *QApplicationPrivate::active_window = 0; // toplevel with keyboard focus | - | ||||||||||||||||||
425 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
426 | int QApplicationPrivate::wheel_scroll_lines; // number of lines to scroll | - | ||||||||||||||||||
427 | QPointer<QWidget> QApplicationPrivate::wheel_widget; | - | ||||||||||||||||||
428 | #endif | - | ||||||||||||||||||
429 | bool qt_in_tab_key_event = false; | - | ||||||||||||||||||
430 | int qt_antialiasing_threshold = -1; | - | ||||||||||||||||||
431 | QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut | - | ||||||||||||||||||
432 | int QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect; | - | ||||||||||||||||||
433 | bool QApplicationPrivate::widgetCount = false; | - | ||||||||||||||||||
434 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
435 | Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadTabOrder; | - | ||||||||||||||||||
436 | QWidget *QApplicationPrivate::oldEditFocus = 0; | - | ||||||||||||||||||
437 | #endif | - | ||||||||||||||||||
438 | - | |||||||||||||||||||
bool qt_tabletChokeMouse = false;inline bool QApplicationPrivate::isAlien(QWidget *widget) | ||||||||||||||||||||
440 | { | - | ||||||||||||||||||
441 | return widget && !widget->isWindow(); | - | ||||||||||||||||||
442 | } | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | bool Q_WIDGETS_EXPORT qt_tab_all_widgets() | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | return QGuiApplication::styleHints()->tabFocusBehavior() == Qt::TabFocusAllControls; | - | ||||||||||||||||||
447 | } | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | // ######## move to QApplicationPrivate | - | ||||||||||||||||||
450 | // Default application palettes and fonts (per widget type) | - | ||||||||||||||||||
451 | Q_GLOBAL_STATIC(PaletteHash, app_palettes) | - | ||||||||||||||||||
452 | PaletteHash *qt_app_palettes_hash() | - | ||||||||||||||||||
453 | { | - | ||||||||||||||||||
454 | return app_palettes(); | - | ||||||||||||||||||
455 | } | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | Q_GLOBAL_STATIC(FontHash, app_fonts) | - | ||||||||||||||||||
458 | FontHash *qt_app_fonts_hash() | - | ||||||||||||||||||
459 | { | - | ||||||||||||||||||
460 | return app_fonts(); | - | ||||||||||||||||||
461 | } | - | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | QWidgetList *QApplicationPrivate::popupWidgets = 0; // has keyboard input focus | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | QDesktopWidget *qt_desktopWidget = 0; // root window widgets | - | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | /*! | - | ||||||||||||||||||
468 | \internal | - | ||||||||||||||||||
469 | */ | - | ||||||||||||||||||
470 | void QApplicationPrivate::process_cmdline() | - | ||||||||||||||||||
471 | { | - | ||||||||||||||||||
472 | if (styleOverride.isEmpty() && qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE")) | - | ||||||||||||||||||
473 | styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | if (!styleOverride.isEmpty()) { | - | ||||||||||||||||||
476 | if (app_style) { | - | ||||||||||||||||||
477 | delete app_style; | - | ||||||||||||||||||
478 | app_style = 0; | - | ||||||||||||||||||
479 | } | - | ||||||||||||||||||
480 | } | - | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | // process platform-indep command line | - | ||||||||||||||||||
483 | if (!qt_is_gui_used || !argc) | - | ||||||||||||||||||
484 | return; | - | ||||||||||||||||||
485 | - | |||||||||||||||||||
486 | int i, j; | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | j = 1; | - | ||||||||||||||||||
489 | for (i=1; i<argc; i++) { // if you add anything here, modify QCoreApplication::arguments() | - | ||||||||||||||||||
490 | if (!argv[i]) | - | ||||||||||||||||||
491 | continue; | - | ||||||||||||||||||
492 | if (*argv[i] != '-') { | - | ||||||||||||||||||
493 | argv[j++] = argv[i]; | - | ||||||||||||||||||
494 | continue; | - | ||||||||||||||||||
495 | } | - | ||||||||||||||||||
496 | const char *arg = argv[i]; | - | ||||||||||||||||||
497 | if (arg[1] == '-') // startsWith("--") | - | ||||||||||||||||||
498 | ++arg; | - | ||||||||||||||||||
499 | if (strcmp(arg, "-qdevel") == 0 || strcmp(arg, "-qdebug") == 0) { | - | ||||||||||||||||||
500 | // obsolete argument | - | ||||||||||||||||||
501 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
502 | } else if (strcmp(arg, "-stylesheet") == 0 && i < argc -1) { | - | ||||||||||||||||||
503 | styleSheet = QLatin1String("file:///"); | - | ||||||||||||||||||
504 | styleSheet.append(QString::fromLocal8Bit(argv[++i])); | - | ||||||||||||||||||
505 | } else if (strncmp(arg, "-stylesheet=", 12) == 0) { | - | ||||||||||||||||||
506 | styleSheet = QLatin1String("file:///"); | - | ||||||||||||||||||
507 | styleSheet.append(QString::fromLocal8Bit(arg + 12)); | - | ||||||||||||||||||
508 | #endif | - | ||||||||||||||||||
509 | } else if (qstrcmp(arg, "-widgetcount") == 0) { | - | ||||||||||||||||||
510 | widgetCount = true; | - | ||||||||||||||||||
511 | } else { | - | ||||||||||||||||||
512 | argv[j++] = argv[i]; | - | ||||||||||||||||||
513 | } | - | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | if(j < argc) { | - | ||||||||||||||||||
517 | argv[j] = 0; | - | ||||||||||||||||||
518 | argc = j; | - | ||||||||||||||||||
519 | } | - | ||||||||||||||||||
520 | } | - | ||||||||||||||||||
521 | - | |||||||||||||||||||
522 | /*! | - | ||||||||||||||||||
523 | Initializes the window system and constructs an application object with | - | ||||||||||||||||||
524 | \a argc command line arguments in \a argv. | - | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | \warning The data referred to by \a argc and \a argv must stay valid for | - | ||||||||||||||||||
527 | the entire lifetime of the QApplication object. In addition, \a argc must | - | ||||||||||||||||||
528 | be greater than zero and \a argv must contain at least one valid character | - | ||||||||||||||||||
529 | string. | - | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | The global \c qApp pointer refers to this application object. Only one | - | ||||||||||||||||||
532 | application object should be created. | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | This application object must be constructed before any \l{QPaintDevice} | - | ||||||||||||||||||
535 | {paint devices} (including widgets, pixmaps, bitmaps etc.). | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | \note \a argc and \a argv might be changed as Qt removes command line | - | ||||||||||||||||||
538 | arguments that it recognizes. | - | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | All Qt programs automatically support the following command line options: | - | ||||||||||||||||||
541 | \list | - | ||||||||||||||||||
542 | \li -style= \e style, sets the application GUI style. Possible values | - | ||||||||||||||||||
543 | depend on your system configuration. If you compiled Qt with | - | ||||||||||||||||||
544 | additional styles or have additional styles as plugins these will | - | ||||||||||||||||||
545 | be available to the \c -style command line option. You can also | - | ||||||||||||||||||
546 | set the style for all Qt applications by setting the | - | ||||||||||||||||||
547 | \c QT_STYLE_OVERRIDE environment variable. | - | ||||||||||||||||||
548 | \li -style \e style, is the same as listed above. | - | ||||||||||||||||||
549 | \li -stylesheet= \e stylesheet, sets the application \l styleSheet. The | - | ||||||||||||||||||
550 | value must be a path to a file that contains the Style Sheet. | - | ||||||||||||||||||
551 | \note Relative URLs in the Style Sheet file are relative to the | - | ||||||||||||||||||
552 | Style Sheet file's path. | - | ||||||||||||||||||
553 | \li -stylesheet \e stylesheet, is the same as listed above. | - | ||||||||||||||||||
554 | \li -widgetcount, prints debug message at the end about number of | - | ||||||||||||||||||
555 | widgets left undestroyed and maximum number of widgets existed at | - | ||||||||||||||||||
556 | the same time | - | ||||||||||||||||||
557 | \li -reverse, sets the application's layout direction to | - | ||||||||||||||||||
558 | Qt::RightToLeft | - | ||||||||||||||||||
559 | \li -qmljsdebugger=, activates the QML/JS debugger with a specified port. | - | ||||||||||||||||||
560 | The value must be of format port:1234[,block], where block is optional | - | ||||||||||||||||||
561 | and will make the application wait until a debugger connects to it. | - | ||||||||||||||||||
562 | \endlist | - | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | \sa QCoreApplication::arguments() | - | ||||||||||||||||||
565 | */ | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | #ifdef Q_QDOC | - | ||||||||||||||||||
568 | QApplication::QApplication(int &argc, char **argv) | - | ||||||||||||||||||
569 | #else | - | ||||||||||||||||||
570 | QApplication::QApplication(int &argc, char **argv, int _internal) | - | ||||||||||||||||||
571 | #endif | - | ||||||||||||||||||
572 | : QGuiApplication(*new QApplicationPrivate(argc, argv, _internal)) | - | ||||||||||||||||||
573 | { | - | ||||||||||||||||||
574 | Q_D(QApplication); | - | ||||||||||||||||||
575 | d->init(); | - | ||||||||||||||||||
576 | } | - | ||||||||||||||||||
577 | - | |||||||||||||||||||
578 | /*! | - | ||||||||||||||||||
579 | \internal | - | ||||||||||||||||||
580 | */ | - | ||||||||||||||||||
581 | void QApplicationPrivate::init() | - | ||||||||||||||||||
582 | { | - | ||||||||||||||||||
583 | QGuiApplicationPrivate::init(); | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | initResources(); | - | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | qt_is_gui_used = (application_type != QApplicationPrivate::Tty); | - | ||||||||||||||||||
588 | process_cmdline(); | - | ||||||||||||||||||
589 | - | |||||||||||||||||||
590 | // Must be called before initialize() | - | ||||||||||||||||||
591 | qt_init(this, application_type); | - | ||||||||||||||||||
592 | initialize(); | - | ||||||||||||||||||
593 | eventDispatcher->startingUp(); | - | ||||||||||||||||||
594 | - | |||||||||||||||||||
595 | #ifdef QT_EVAL | - | ||||||||||||||||||
596 | extern void qt_gui_eval_init(QCoreApplicationPrivate::Type); | - | ||||||||||||||||||
597 | qt_gui_eval_init(application_type); | - | ||||||||||||||||||
598 | #endif | - | ||||||||||||||||||
599 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
600 | // factory for accessible interfaces for widgets shipped with Qt | - | ||||||||||||||||||
601 | QAccessible::installFactory(&qAccessibleFactory); | - | ||||||||||||||||||
602 | #endif | - | ||||||||||||||||||
603 | - | |||||||||||||||||||
604 | } | - | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | void qt_init(QApplicationPrivate *priv, int type) | - | ||||||||||||||||||
607 | { | - | ||||||||||||||||||
608 | Q_UNUSED(priv); | - | ||||||||||||||||||
609 | Q_UNUSED(type); | - | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | QColormap::initialize(); | - | ||||||||||||||||||
612 | - | |||||||||||||||||||
613 | qt_init_tooltip_palette(); | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | QApplicationPrivate::initializeWidgetFontHash(); | - | ||||||||||||||||||
616 | } | - | ||||||||||||||||||
617 | - | |||||||||||||||||||
618 | void qt_init_tooltip_palette() | - | ||||||||||||||||||
619 | { | - | ||||||||||||||||||
620 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||
621 | if (const QPalette *toolTipPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::ToolTipPalette)) | - | ||||||||||||||||||
622 | QToolTip::setPalette(*toolTipPalette); | - | ||||||||||||||||||
623 | #endif | - | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | #ifndef QT_NO_STATEMACHINE | - | ||||||||||||||||||
627 | void qRegisterGuiStateMachine(); | - | ||||||||||||||||||
628 | void qUnregisterGuiStateMachine(); | - | ||||||||||||||||||
629 | #endif | - | ||||||||||||||||||
630 | extern void qRegisterWidgetsVariant(); | - | ||||||||||||||||||
631 | - | |||||||||||||||||||
632 | /*! | - | ||||||||||||||||||
633 | \fn void QApplicationPrivate::initialize() | - | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | Initializes the QApplication object, called from the constructors. | - | ||||||||||||||||||
636 | */ | - | ||||||||||||||||||
637 | void QApplicationPrivate::initialize() | - | ||||||||||||||||||
638 | { | - | ||||||||||||||||||
639 | is_app_running = false; // Starting up. | - | ||||||||||||||||||
640 | - | |||||||||||||||||||
641 | QWidgetPrivate::mapper = new QWidgetMapper; | - | ||||||||||||||||||
642 | QWidgetPrivate::allWidgets = new QWidgetSet; | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | // needed for a static build. | - | ||||||||||||||||||
645 | qRegisterWidgetsVariant(); | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | // needed for widgets in QML | - | ||||||||||||||||||
648 | QAbstractDeclarativeData::setWidgetParent = QWidgetPrivate::setWidgetParentHelper; | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | if (application_type != QApplicationPrivate::Tty) | - | ||||||||||||||||||
651 | (void) QApplication::style(); // trigger creation of application style | - | ||||||||||||||||||
652 | #ifndef QT_NO_STATEMACHINE | - | ||||||||||||||||||
653 | // trigger registering of QStateMachine's GUI types | - | ||||||||||||||||||
654 | qRegisterGuiStateMachine(); | - | ||||||||||||||||||
655 | #endif | - | ||||||||||||||||||
656 | - | |||||||||||||||||||
657 | if (qEnvironmentVariableIntValue("QT_USE_NATIVE_WINDOWS") > 0) | - | ||||||||||||||||||
658 | QCoreApplication::setAttribute(Qt::AA_NativeWindows); | - | ||||||||||||||||||
659 | - | |||||||||||||||||||
660 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||
661 | #ifdef QT_AUTO_MAXIMIZE_THRESHOLD | - | ||||||||||||||||||
662 | autoMaximizeThreshold = QT_AUTO_MAXIMIZE_THRESHOLD; | - | ||||||||||||||||||
663 | #else | - | ||||||||||||||||||
664 | if (qt_wince_is_mobile()) | - | ||||||||||||||||||
665 | autoMaximizeThreshold = 50; | - | ||||||||||||||||||
666 | else | - | ||||||||||||||||||
667 | autoMaximizeThreshold = -1; | - | ||||||||||||||||||
668 | #endif //QT_AUTO_MAXIMIZE_THRESHOLD | - | ||||||||||||||||||
669 | #endif //Q_OS_WINCE | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
672 | QApplicationPrivate::wheel_scroll_lines = 3; | - | ||||||||||||||||||
673 | #endif | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | if (qt_is_gui_used) | - | ||||||||||||||||||
676 | initializeMultitouch(); | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | if (QApplication::desktopSettingsAware()) | - | ||||||||||||||||||
679 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { | - | ||||||||||||||||||
680 | QApplicationPrivate::enabledAnimations = theme->themeHint(QPlatformTheme::UiEffects).toInt(); | - | ||||||||||||||||||
681 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
682 | QApplicationPrivate::wheel_scroll_lines = theme->themeHint(QPlatformTheme::WheelScrollLines).toInt(); | - | ||||||||||||||||||
683 | #endif | - | ||||||||||||||||||
684 | } | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | is_app_running = true; // no longer starting up | - | ||||||||||||||||||
687 | } | - | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | static void setPossiblePalette(const QPalette *palette, const char *className) | - | ||||||||||||||||||
690 | { | - | ||||||||||||||||||
691 | if (palette == 0) | - | ||||||||||||||||||
692 | return; | - | ||||||||||||||||||
693 | QApplicationPrivate::setPalette_helper(*palette, className, false); | - | ||||||||||||||||||
694 | } | - | ||||||||||||||||||
695 | - | |||||||||||||||||||
696 | void QApplicationPrivate::initializeWidgetPaletteHash() | - | ||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||
699 | if (!platformTheme) | - | ||||||||||||||||||
700 | return; | - | ||||||||||||||||||
701 | qt_app_palettes_hash()->clear(); | - | ||||||||||||||||||
702 | - | |||||||||||||||||||
703 | setPossiblePalette(platformTheme->palette(QPlatformTheme::ToolButtonPalette), "QToolButton"); | - | ||||||||||||||||||
704 | setPossiblePalette(platformTheme->palette(QPlatformTheme::ButtonPalette), "QAbstractButton"); | - | ||||||||||||||||||
705 | setPossiblePalette(platformTheme->palette(QPlatformTheme::CheckBoxPalette), "QCheckBox"); | - | ||||||||||||||||||
706 | setPossiblePalette(platformTheme->palette(QPlatformTheme::RadioButtonPalette), "QRadioButton"); | - | ||||||||||||||||||
707 | setPossiblePalette(platformTheme->palette(QPlatformTheme::HeaderPalette), "QHeaderView"); | - | ||||||||||||||||||
708 | setPossiblePalette(platformTheme->palette(QPlatformTheme::ItemViewPalette), "QAbstractItemView"); | - | ||||||||||||||||||
709 | setPossiblePalette(platformTheme->palette(QPlatformTheme::MessageBoxLabelPalette), "QMessageBoxLabel"); | - | ||||||||||||||||||
710 | setPossiblePalette(platformTheme->palette(QPlatformTheme::TabBarPalette), "QTabBar"); | - | ||||||||||||||||||
711 | setPossiblePalette(platformTheme->palette(QPlatformTheme::LabelPalette), "QLabel"); | - | ||||||||||||||||||
712 | setPossiblePalette(platformTheme->palette(QPlatformTheme::GroupBoxPalette), "QGroupBox"); | - | ||||||||||||||||||
713 | setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuPalette), "QMenu"); | - | ||||||||||||||||||
714 | setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuBarPalette), "QMenuBar"); | - | ||||||||||||||||||
715 | setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextEdit"); | - | ||||||||||||||||||
716 | setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextControl"); | - | ||||||||||||||||||
717 | setPossiblePalette(platformTheme->palette(QPlatformTheme::TextLineEditPalette), "QLineEdit"); | - | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | void QApplicationPrivate::initializeWidgetFontHash() | - | ||||||||||||||||||
721 | { | - | ||||||||||||||||||
722 | const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||
723 | if (!theme) | - | ||||||||||||||||||
724 | return; | - | ||||||||||||||||||
725 | FontHash *fontHash = qt_app_fonts_hash(); | - | ||||||||||||||||||
726 | fontHash->clear(); | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | if (const QFont *font = theme->font(QPlatformTheme::MenuFont)) | - | ||||||||||||||||||
729 | fontHash->insert(QByteArrayLiteral("QMenu"), *font); | - | ||||||||||||||||||
730 | if (const QFont *font = theme->font(QPlatformTheme::MenuBarFont)) | - | ||||||||||||||||||
731 | fontHash->insert(QByteArrayLiteral("QMenuBar"), *font); | - | ||||||||||||||||||
732 | if (const QFont *font = theme->font(QPlatformTheme::MenuItemFont)) | - | ||||||||||||||||||
733 | fontHash->insert(QByteArrayLiteral("QMenuItem"), *font); | - | ||||||||||||||||||
734 | if (const QFont *font = theme->font(QPlatformTheme::MessageBoxFont)) | - | ||||||||||||||||||
735 | fontHash->insert(QByteArrayLiteral("QMessageBox"), *font); | - | ||||||||||||||||||
736 | if (const QFont *font = theme->font(QPlatformTheme::LabelFont)) | - | ||||||||||||||||||
737 | fontHash->insert(QByteArrayLiteral("QLabel"), *font); | - | ||||||||||||||||||
738 | if (const QFont *font = theme->font(QPlatformTheme::TipLabelFont)) | - | ||||||||||||||||||
739 | fontHash->insert(QByteArrayLiteral("QTipLabel"), *font); | - | ||||||||||||||||||
740 | if (const QFont *font = theme->font(QPlatformTheme::TitleBarFont)) | - | ||||||||||||||||||
741 | fontHash->insert(QByteArrayLiteral("QTitleBar"), *font); | - | ||||||||||||||||||
742 | if (const QFont *font = theme->font(QPlatformTheme::StatusBarFont)) | - | ||||||||||||||||||
743 | fontHash->insert(QByteArrayLiteral("QStatusBar"), *font); | - | ||||||||||||||||||
744 | if (const QFont *font = theme->font(QPlatformTheme::MdiSubWindowTitleFont)) | - | ||||||||||||||||||
745 | fontHash->insert(QByteArrayLiteral("QMdiSubWindowTitleBar"), *font); | - | ||||||||||||||||||
746 | if (const QFont *font = theme->font(QPlatformTheme::DockWidgetTitleFont)) | - | ||||||||||||||||||
747 | fontHash->insert(QByteArrayLiteral("QDockWidgetTitle"), *font); | - | ||||||||||||||||||
748 | if (const QFont *font = theme->font(QPlatformTheme::PushButtonFont)) | - | ||||||||||||||||||
749 | fontHash->insert(QByteArrayLiteral("QPushButton"), *font); | - | ||||||||||||||||||
750 | if (const QFont *font = theme->font(QPlatformTheme::CheckBoxFont)) | - | ||||||||||||||||||
751 | fontHash->insert(QByteArrayLiteral("QCheckBox"), *font); | - | ||||||||||||||||||
752 | if (const QFont *font = theme->font(QPlatformTheme::RadioButtonFont)) | - | ||||||||||||||||||
753 | fontHash->insert(QByteArrayLiteral("QRadioButton"), *font); | - | ||||||||||||||||||
754 | if (const QFont *font = theme->font(QPlatformTheme::ToolButtonFont)) | - | ||||||||||||||||||
755 | fontHash->insert(QByteArrayLiteral("QToolButton"), *font); | - | ||||||||||||||||||
756 | if (const QFont *font = theme->font(QPlatformTheme::ItemViewFont)) | - | ||||||||||||||||||
757 | fontHash->insert(QByteArrayLiteral("QAbstractItemView"), *font); | - | ||||||||||||||||||
758 | if (const QFont *font = theme->font(QPlatformTheme::ListViewFont)) | - | ||||||||||||||||||
759 | fontHash->insert(QByteArrayLiteral("QListView"), *font); | - | ||||||||||||||||||
760 | if (const QFont *font = theme->font(QPlatformTheme::HeaderViewFont)) | - | ||||||||||||||||||
761 | fontHash->insert(QByteArrayLiteral("QHeaderView"), *font); | - | ||||||||||||||||||
762 | if (const QFont *font = theme->font(QPlatformTheme::ListBoxFont)) | - | ||||||||||||||||||
763 | fontHash->insert(QByteArrayLiteral("QListBox"), *font); | - | ||||||||||||||||||
764 | if (const QFont *font = theme->font(QPlatformTheme::ComboMenuItemFont)) | - | ||||||||||||||||||
765 | fontHash->insert(QByteArrayLiteral("QComboMenuItem"), *font); | - | ||||||||||||||||||
766 | if (const QFont *font = theme->font(QPlatformTheme::ComboLineEditFont)) | - | ||||||||||||||||||
767 | fontHash->insert(QByteArrayLiteral("QComboLineEdit"), *font); | - | ||||||||||||||||||
768 | if (const QFont *font = theme->font(QPlatformTheme::SmallFont)) | - | ||||||||||||||||||
769 | fontHash->insert(QByteArrayLiteral("QSmallFont"), *font); | - | ||||||||||||||||||
770 | if (const QFont *font = theme->font(QPlatformTheme::MiniFont)) | - | ||||||||||||||||||
771 | fontHash->insert(QByteArrayLiteral("QMiniFont"), *font); | - | ||||||||||||||||||
772 | } | - | ||||||||||||||||||
773 | - | |||||||||||||||||||
774 | /***************************************************************************** | - | ||||||||||||||||||
775 | Functions returning the active popup and modal widgets. | - | ||||||||||||||||||
776 | *****************************************************************************/ | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | /*! | - | ||||||||||||||||||
779 | Returns the active popup widget. | - | ||||||||||||||||||
780 | - | |||||||||||||||||||
781 | A popup widget is a special top-level widget that sets the \c | - | ||||||||||||||||||
782 | Qt::WType_Popup widget flag, e.g. the QMenu widget. When the application | - | ||||||||||||||||||
783 | opens a popup widget, all events are sent to the popup. Normal widgets and | - | ||||||||||||||||||
784 | modal widgets cannot be accessed before the popup widget is closed. | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | Only other popup widgets may be opened when a popup widget is shown. The | - | ||||||||||||||||||
787 | popup widgets are organized in a stack. This function returns the active | - | ||||||||||||||||||
788 | popup widget at the top of the stack. | - | ||||||||||||||||||
789 | - | |||||||||||||||||||
790 | \sa activeModalWidget(), topLevelWidgets() | - | ||||||||||||||||||
791 | */ | - | ||||||||||||||||||
792 | - | |||||||||||||||||||
793 | QWidget *QApplication::activePopupWidget() | - | ||||||||||||||||||
794 | { | - | ||||||||||||||||||
795 | return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? never executed: return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? QApplicationPrivate::popupWidgets->constLast() : nullptr; | 0 | ||||||||||||||||||
796 | QApplicationPrivate::popupWidgets->lastconstLast() : 0nullptr; never executed: return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? QApplicationPrivate::popupWidgets->constLast() : nullptr; | 0 | ||||||||||||||||||
797 | } | - | ||||||||||||||||||
798 | - | |||||||||||||||||||
799 | - | |||||||||||||||||||
800 | /*! | - | ||||||||||||||||||
801 | Returns the active modal widget. | - | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | A modal widget is a special top-level widget which is a subclass of QDialog | - | ||||||||||||||||||
804 | that specifies the modal parameter of the constructor as true. A modal | - | ||||||||||||||||||
805 | widget must be closed before the user can continue with other parts of the | - | ||||||||||||||||||
806 | program. | - | ||||||||||||||||||
807 | - | |||||||||||||||||||
808 | Modal widgets are organized in a stack. This function returns the active | - | ||||||||||||||||||
809 | modal widget at the top of the stack. | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | \sa activePopupWidget(), topLevelWidgets() | - | ||||||||||||||||||
812 | */ | - | ||||||||||||||||||
813 | - | |||||||||||||||||||
814 | QWidget *QApplication::activeModalWidget() | - | ||||||||||||||||||
815 | { | - | ||||||||||||||||||
816 | QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(modalWindow()); | - | ||||||||||||||||||
817 | return widgetWindow ? widgetWindow->widget() : 0; | - | ||||||||||||||||||
818 | } | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | /*! | - | ||||||||||||||||||
821 | Cleans up any window system resources that were allocated by this | - | ||||||||||||||||||
822 | application. Sets the global variable \c qApp to 0. | - | ||||||||||||||||||
823 | */ | - | ||||||||||||||||||
824 | - | |||||||||||||||||||
825 | QApplication::~QApplication() | - | ||||||||||||||||||
826 | { | - | ||||||||||||||||||
827 | Q_D(QApplication); | - | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | //### this should probable be done even later | - | ||||||||||||||||||
830 | qt_call_post_routines(); | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | // kill timers before closing down the dispatcher | - | ||||||||||||||||||
833 | d->toolTipWakeUp.stop(); | - | ||||||||||||||||||
834 | d->toolTipFallAsleep.stop(); | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | QApplicationPrivate::is_app_closing = true; | - | ||||||||||||||||||
837 | QApplicationPrivate::is_app_running = false; | - | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | delete QWidgetPrivate::mapper; | - | ||||||||||||||||||
840 | QWidgetPrivate::mapper = 0; | - | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | // delete all widgets | - | ||||||||||||||||||
843 | if (QWidgetPrivate::allWidgets) { | - | ||||||||||||||||||
844 | QWidgetSet *mySet = QWidgetPrivate::allWidgets; | - | ||||||||||||||||||
845 | QWidgetPrivate::allWidgets = 0; | - | ||||||||||||||||||
846 | for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
847 | QWidget *w = *it; | - | ||||||||||||||||||
848 | if (!w->parent()) // window | - | ||||||||||||||||||
849 | w->destroy(true, true); | - | ||||||||||||||||||
850 | } | - | ||||||||||||||||||
851 | delete mySet; | - | ||||||||||||||||||
852 | } | - | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | delete qt_desktopWidget; | - | ||||||||||||||||||
855 | qt_desktopWidget = 0; | - | ||||||||||||||||||
856 | - | |||||||||||||||||||
857 | delete QApplicationPrivate::app_pal; | - | ||||||||||||||||||
858 | QApplicationPrivate::app_pal = 0; | - | ||||||||||||||||||
859 | clearSystemPalette(); | - | ||||||||||||||||||
860 | delete QApplicationPrivate::set_pal; | - | ||||||||||||||||||
861 | QApplicationPrivate::set_pal = 0; | - | ||||||||||||||||||
862 | app_palettes()->clear(); | - | ||||||||||||||||||
863 | - | |||||||||||||||||||
864 | delete QApplicationPrivate::sys_font; | - | ||||||||||||||||||
865 | QApplicationPrivate::sys_font = 0; | - | ||||||||||||||||||
866 | delete QApplicationPrivate::set_font; | - | ||||||||||||||||||
867 | QApplicationPrivate::set_font = 0; | - | ||||||||||||||||||
868 | app_fonts()->clear(); | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | delete QApplicationPrivate::app_style; | - | ||||||||||||||||||
871 | QApplicationPrivate::app_style = 0; | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
874 | if (qt_is_gui_used) | - | ||||||||||||||||||
875 | delete QDragManager::self(); | - | ||||||||||||||||||
876 | #endif | - | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | d->cleanupMultitouch(); | - | ||||||||||||||||||
879 | - | |||||||||||||||||||
880 | qt_cleanup(); | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | if (QApplicationPrivate::widgetCount) | - | ||||||||||||||||||
883 | qDebug("Widgets left: %i Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances); | - | ||||||||||||||||||
884 | - | |||||||||||||||||||
885 | QApplicationPrivate::obey_desktop_settings = true; | - | ||||||||||||||||||
886 | - | |||||||||||||||||||
887 | QApplicationPrivate::app_strut = QSize(0, 0); | - | ||||||||||||||||||
888 | QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect; | - | ||||||||||||||||||
889 | QApplicationPrivate::widgetCount = false; | - | ||||||||||||||||||
890 | - | |||||||||||||||||||
891 | #ifndef QT_NO_STATEMACHINE | - | ||||||||||||||||||
892 | // trigger unregistering of QStateMachine's GUI types | - | ||||||||||||||||||
893 | qUnregisterGuiStateMachine(); | - | ||||||||||||||||||
894 | #endif | - | ||||||||||||||||||
895 | } | - | ||||||||||||||||||
896 | - | |||||||||||||||||||
897 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||
898 | // #fixme: Remove. | - | ||||||||||||||||||
899 | static HDC displayDC = 0; // display device context | - | ||||||||||||||||||
900 | - | |||||||||||||||||||
901 | Q_WIDGETS_EXPORT HDC qt_win_display_dc() // get display DC | - | ||||||||||||||||||
902 | { | - | ||||||||||||||||||
903 | Q_ASSERT(qApp && qApp->thread() == QThread::currentThread()); | - | ||||||||||||||||||
904 | if (!displayDC) | - | ||||||||||||||||||
905 | displayDC = GetDC(0); | - | ||||||||||||||||||
906 | return displayDC; | - | ||||||||||||||||||
907 | } | - | ||||||||||||||||||
908 | #endif | - | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | void qt_cleanup() | - | ||||||||||||||||||
911 | { | - | ||||||||||||||||||
912 | QPixmapCache::clear(); | - | ||||||||||||||||||
913 | QColormap::cleanup(); | - | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | QApplicationPrivate::active_window = 0; //### this should not be necessary | - | ||||||||||||||||||
916 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||
917 | if (displayDC) { | - | ||||||||||||||||||
918 | ReleaseDC(0, displayDC); | - | ||||||||||||||||||
919 | displayDC = 0; | - | ||||||||||||||||||
920 | } | - | ||||||||||||||||||
921 | #endif | - | ||||||||||||||||||
922 | } | - | ||||||||||||||||||
923 | - | |||||||||||||||||||
924 | /*! | - | ||||||||||||||||||
925 | \fn QWidget *QApplication::widgetAt(const QPoint &point) | - | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | Returns the widget at global screen position \a point, or 0 if there is no | - | ||||||||||||||||||
928 | Qt widget there. | - | ||||||||||||||||||
929 | - | |||||||||||||||||||
930 | This function can be slow. | - | ||||||||||||||||||
931 | - | |||||||||||||||||||
932 | \sa QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard() | - | ||||||||||||||||||
933 | */ | - | ||||||||||||||||||
934 | QWidget *QApplication::widgetAt(const QPoint &p) | - | ||||||||||||||||||
935 | { | - | ||||||||||||||||||
936 | QWidget *window = QApplication::topLevelAt(p); | - | ||||||||||||||||||
937 | if (!window) | - | ||||||||||||||||||
938 | return 0; | - | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | QWidget *child = 0; | - | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | if (!window->testAttribute(Qt::WA_TransparentForMouseEvents)) | - | ||||||||||||||||||
943 | child = window->childAt(window->mapFromGlobal(p)); | - | ||||||||||||||||||
944 | - | |||||||||||||||||||
945 | if (child) | - | ||||||||||||||||||
946 | return child; | - | ||||||||||||||||||
947 | - | |||||||||||||||||||
948 | if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) { | - | ||||||||||||||||||
949 | //shoot a hole in the widget and try once again, | - | ||||||||||||||||||
950 | //suboptimal on Qt for Embedded Linux where we do | - | ||||||||||||||||||
951 | //know the stacking order of the toplevels. | - | ||||||||||||||||||
952 | int x = p.x(); | - | ||||||||||||||||||
953 | int y = p.y(); | - | ||||||||||||||||||
954 | QRegion oldmask = window->mask(); | - | ||||||||||||||||||
955 | QPoint wpoint = window->mapFromGlobal(QPoint(x, y)); | - | ||||||||||||||||||
956 | QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask) | - | ||||||||||||||||||
957 | - QRegion(wpoint.x(), wpoint.y(), 1, 1); | - | ||||||||||||||||||
958 | window->setMask(newmask); | - | ||||||||||||||||||
959 | QWidget *recurse = 0; | - | ||||||||||||||||||
960 | if (QApplication::topLevelAt(p) != window) // verify recursion will terminate | - | ||||||||||||||||||
961 | recurse = widgetAt(x, y); | - | ||||||||||||||||||
962 | if (oldmask.isEmpty()) | - | ||||||||||||||||||
963 | window->clearMask(); | - | ||||||||||||||||||
964 | else | - | ||||||||||||||||||
965 | window->setMask(oldmask); | - | ||||||||||||||||||
966 | return recurse; | - | ||||||||||||||||||
967 | } | - | ||||||||||||||||||
968 | return window; | - | ||||||||||||||||||
969 | } | - | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | /*! | - | ||||||||||||||||||
972 | \fn QWidget *QApplication::widgetAt(int x, int y) | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | \overload | - | ||||||||||||||||||
975 | - | |||||||||||||||||||
976 | Returns the widget at global screen position (\a x, \a y), or 0 if there is | - | ||||||||||||||||||
977 | no Qt widget there. | - | ||||||||||||||||||
978 | */ | - | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | /*! | - | ||||||||||||||||||
981 | \internal | - | ||||||||||||||||||
982 | */ | - | ||||||||||||||||||
983 | bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) | - | ||||||||||||||||||
984 | { | - | ||||||||||||||||||
985 | if ((event->type() == QEvent::UpdateRequest | - | ||||||||||||||||||
986 | || event->type() == QEvent::LayoutRequest | - | ||||||||||||||||||
987 | || event->type() == QEvent::Resize | - | ||||||||||||||||||
988 | || event->type() == QEvent::Move | - | ||||||||||||||||||
989 | || event->type() == QEvent::LanguageChange)) { | - | ||||||||||||||||||
990 | for (QPostEventList::const_iterator it = postedEvents->constBegin(); it != postedEvents->constEnd(); ++it) { | - | ||||||||||||||||||
991 | const QPostEvent &cur = *it; | - | ||||||||||||||||||
992 | if (cur.receiver != receiver || cur.event == 0 || cur.event->type() != event->type()) | - | ||||||||||||||||||
993 | continue; | - | ||||||||||||||||||
994 | if (cur.event->type() == QEvent::LayoutRequest | - | ||||||||||||||||||
995 | || cur.event->type() == QEvent::UpdateRequest) { | - | ||||||||||||||||||
996 | ; | - | ||||||||||||||||||
997 | } else if (cur.event->type() == QEvent::Resize) { | - | ||||||||||||||||||
998 | ((QResizeEvent *)(cur.event))->s = ((QResizeEvent *)event)->s; | - | ||||||||||||||||||
999 | } else if (cur.event->type() == QEvent::Move) { | - | ||||||||||||||||||
1000 | ((QMoveEvent *)(cur.event))->p = ((QMoveEvent *)event)->p; | - | ||||||||||||||||||
1001 | } else if (cur.event->type() == QEvent::LanguageChange) { | - | ||||||||||||||||||
1002 | ; | - | ||||||||||||||||||
1003 | } else { | - | ||||||||||||||||||
1004 | continue; | - | ||||||||||||||||||
1005 | } | - | ||||||||||||||||||
1006 | delete event; | - | ||||||||||||||||||
1007 | return true; | - | ||||||||||||||||||
1008 | } | - | ||||||||||||||||||
1009 | return false; | - | ||||||||||||||||||
1010 | } | - | ||||||||||||||||||
1011 | return QGuiApplication::compressEvent(event, receiver, postedEvents); | - | ||||||||||||||||||
1012 | } | - | ||||||||||||||||||
1013 | - | |||||||||||||||||||
1014 | /*! | - | ||||||||||||||||||
1015 | \property QApplication::styleSheet | - | ||||||||||||||||||
1016 | \brief the application style sheet | - | ||||||||||||||||||
1017 | \since 4.2 | - | ||||||||||||||||||
1018 | - | |||||||||||||||||||
1019 | By default, this property returns an empty string unless the user specifies | - | ||||||||||||||||||
1020 | the \c{-stylesheet} option on the command line when running the application. | - | ||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | \sa QWidget::setStyle(), {Qt Style Sheets} | - | ||||||||||||||||||
1023 | */ | - | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | /*! | - | ||||||||||||||||||
1026 | \property QApplication::autoMaximizeThreshold | - | ||||||||||||||||||
1027 | \since 4.4 | - | ||||||||||||||||||
1028 | \brief defines a threshold for auto maximizing widgets | - | ||||||||||||||||||
1029 | \deprecated | - | ||||||||||||||||||
1030 | \b{The auto maximize threshold is only available as part of Qt for | - | ||||||||||||||||||
1031 | Windows CE.} | - | ||||||||||||||||||
1032 | - | |||||||||||||||||||
1033 | This property defines a threshold for the size of a window as a percentage | - | ||||||||||||||||||
1034 | of the screen size. If the minimum size hint of a window exceeds the | - | ||||||||||||||||||
1035 | threshold, calling show() will cause the window to be maximized | - | ||||||||||||||||||
1036 | automatically. | - | ||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | Setting the threshold to 100 or greater means that the widget will always | - | ||||||||||||||||||
1039 | be maximized. Alternatively, setting the threshold to 50 means that the | - | ||||||||||||||||||
1040 | widget will be maximized only if the vertical minimum size hint is at least | - | ||||||||||||||||||
1041 | 50% of the vertical screen size. | - | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | Setting the threshold to -1 disables the feature. | - | ||||||||||||||||||
1044 | - | |||||||||||||||||||
1045 | On Windows CE the default is -1 (i.e., it is disabled). | - | ||||||||||||||||||
1046 | On Windows Mobile the default is 40. | - | ||||||||||||||||||
1047 | */ | - | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | /*! | - | ||||||||||||||||||
1050 | \property QApplication::autoSipEnabled | - | ||||||||||||||||||
1051 | \since 4.5 | - | ||||||||||||||||||
1052 | \brief toggles automatic SIP (software input panel) visibility | - | ||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | Set this property to \c true to automatically display the SIP when entering | - | ||||||||||||||||||
1055 | widgets that accept keyboard input. This property only affects widgets with | - | ||||||||||||||||||
1056 | the WA_InputMethodEnabled attribute set, and is typically used to launch | - | ||||||||||||||||||
1057 | a virtual keyboard on devices which have very few or no keys. | - | ||||||||||||||||||
1058 | - | |||||||||||||||||||
1059 | \b{ The property only has an effect on platforms that use software input | - | ||||||||||||||||||
1060 | panels.} | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | The default is platform dependent. | - | ||||||||||||||||||
1063 | */ | - | ||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||
1066 | void QApplication::setAutoMaximizeThreshold(const int threshold) | - | ||||||||||||||||||
1067 | { | - | ||||||||||||||||||
1068 | QApplicationPrivate::autoMaximizeThreshold = threshold; | - | ||||||||||||||||||
1069 | } | - | ||||||||||||||||||
1070 | - | |||||||||||||||||||
1071 | int QApplication::autoMaximizeThreshold() const | - | ||||||||||||||||||
1072 | { | - | ||||||||||||||||||
1073 | return QApplicationPrivate::autoMaximizeThreshold; | - | ||||||||||||||||||
1074 | } | - | ||||||||||||||||||
1075 | #endif | - | ||||||||||||||||||
1076 | - | |||||||||||||||||||
1077 | void QApplication::setAutoSipEnabled(const bool enabled) | - | ||||||||||||||||||
1078 | { | - | ||||||||||||||||||
1079 | QApplicationPrivate::autoSipEnabled = enabled; | - | ||||||||||||||||||
1080 | } | - | ||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | bool QApplication::autoSipEnabled() const | - | ||||||||||||||||||
1083 | { | - | ||||||||||||||||||
1084 | return QApplicationPrivate::autoSipEnabled; | - | ||||||||||||||||||
1085 | } | - | ||||||||||||||||||
1086 | - | |||||||||||||||||||
1087 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1088 | - | |||||||||||||||||||
1089 | QString QApplication::styleSheet() const | - | ||||||||||||||||||
1090 | { | - | ||||||||||||||||||
1091 | return QApplicationPrivate::styleSheet; | - | ||||||||||||||||||
1092 | } | - | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | void QApplication::setStyleSheet(const QString& styleSheet) | - | ||||||||||||||||||
1095 | { | - | ||||||||||||||||||
1096 | QApplicationPrivate::styleSheet = styleSheet; | - | ||||||||||||||||||
1097 | QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle*>(QApplicationPrivate::app_style); | - | ||||||||||||||||||
1098 | if (styleSheet.isEmpty()) { // application style sheet removed | - | ||||||||||||||||||
1099 | if (!proxy) | - | ||||||||||||||||||
1100 | return; // there was no stylesheet before | - | ||||||||||||||||||
1101 | setStyle(proxy->base); | - | ||||||||||||||||||
1102 | } else if (proxy) { // style sheet update, just repolish | - | ||||||||||||||||||
1103 | proxy->repolish(qApp); | - | ||||||||||||||||||
1104 | } else { // stylesheet set the first time | - | ||||||||||||||||||
1105 | QStyleSheetStyle *newProxy = new QStyleSheetStyle(QApplicationPrivate::app_style); | - | ||||||||||||||||||
1106 | QApplicationPrivate::app_style->setParent(newProxy); | - | ||||||||||||||||||
1107 | setStyle(newProxy); | - | ||||||||||||||||||
1108 | } | - | ||||||||||||||||||
1109 | } | - | ||||||||||||||||||
1110 | - | |||||||||||||||||||
1111 | #endif // QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1112 | - | |||||||||||||||||||
1113 | /*! | - | ||||||||||||||||||
1114 | Returns the application's style object. | - | ||||||||||||||||||
1115 | - | |||||||||||||||||||
1116 | \sa setStyle(), QStyle | - | ||||||||||||||||||
1117 | */ | - | ||||||||||||||||||
1118 | QStyle *QApplication::style() | - | ||||||||||||||||||
1119 | { | - | ||||||||||||||||||
1120 | if (QApplicationPrivate::app_style)
| 0 | ||||||||||||||||||
1121 | return QApplicationPrivate::app_style; never executed: return QApplicationPrivate::app_style; | 0 | ||||||||||||||||||
1122 | if (!qobject_cast<QApplication *>(QCoreApplication::instance())) {
| 0 | ||||||||||||||||||
1123 | Q_ASSERT(!"No style available without QApplication!"); | - | ||||||||||||||||||
1124 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1125 | } | - | ||||||||||||||||||
1126 | - | |||||||||||||||||||
1127 | if (!QApplicationPrivate::app_style) {
| 0 | ||||||||||||||||||
1128 | // Compile-time search for default style | - | ||||||||||||||||||
1129 | // | - | ||||||||||||||||||
1130 | QString style; | - | ||||||||||||||||||
1131 | if (!QApplicationPrivate::styleOverride.isEmpty()) {
| 0 | ||||||||||||||||||
1132 | style = QApplicationPrivate::styleOverride;.toLower(); | - | ||||||||||||||||||
1133 | } else { never executed: end of block | 0 | ||||||||||||||||||
1134 | style = QApplicationPrivate::desktopStyleKey(); | - | ||||||||||||||||||
1135 | } never executed: end of block | 0 | ||||||||||||||||||
1136 | - | |||||||||||||||||||
1137 | QStyle *&app_style = QApplicationPrivate::app_style; | - | ||||||||||||||||||
1138 | app_style = QStyleFactory::create(style); | - | ||||||||||||||||||
1139 | if (!app_style) {
| 0 | ||||||||||||||||||
1140 | const QStringList styles = QStyleFactory::keys(); | - | ||||||||||||||||||
1141 | for (int i = 0; i <const auto &style : styles.size(); ++i) { | - | ||||||||||||||||||
1142 | if ((app_style = QStyleFactory::create(styles.at(i))))style)))
| 0 | ||||||||||||||||||
1143 | break; never executed: break; | 0 | ||||||||||||||||||
1144 | } never executed: end of block | 0 | ||||||||||||||||||
1145 | } never executed: end of block | 0 | ||||||||||||||||||
1146 | if (!app_style) {
| 0 | ||||||||||||||||||
1147 | Q_ASSERT(!"No styles available!"); | - | ||||||||||||||||||
1148 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1149 | } | - | ||||||||||||||||||
1150 | QApplicationPrivate::overrides_native_style = | - | ||||||||||||||||||
1151 | app_style->objectName() != QApplicationPrivate::desktopStyleKey(); | - | ||||||||||||||||||
1152 | } never executed: end of block | 0 | ||||||||||||||||||
1153 | // take ownership of the style | - | ||||||||||||||||||
1154 | QApplicationPrivate::app_style->setParent(qApp); | - | ||||||||||||||||||
1155 | - | |||||||||||||||||||
1156 | initSystemPalette(); | - | ||||||||||||||||||
1157 | - | |||||||||||||||||||
1158 | if (QApplicationPrivate::set_pal) // repolish set palette with the new style
| 0 | ||||||||||||||||||
1159 | QApplication::setPalette(*QApplicationPrivate::set_pal); never executed: QApplication::setPalette(*QApplicationPrivate::set_pal); | 0 | ||||||||||||||||||
1160 | - | |||||||||||||||||||
1161 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1162 | if (!QApplicationPrivate::styleSheet.isEmpty()) {
| 0 | ||||||||||||||||||
1163 | qApp->setStyleSheet(QApplicationPrivate::styleSheet); | - | ||||||||||||||||||
1164 | } else never executed: end of block | 0 | ||||||||||||||||||
1165 | #endif | - | ||||||||||||||||||
1166 | QApplicationPrivate::app_style->polish(qApp); never executed: QApplicationPrivate::app_style->polish((static_cast<QApplication *>(QCoreApplication::instance()))); | 0 | ||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | return QApplicationPrivate::app_style; never executed: return QApplicationPrivate::app_style; | 0 | ||||||||||||||||||
1169 | } | - | ||||||||||||||||||
1170 | - | |||||||||||||||||||
1171 | /*! | - | ||||||||||||||||||
1172 | Sets the application's GUI style to \a style. Ownership of the style object | - | ||||||||||||||||||
1173 | is transferred to QApplication, so QApplication will delete the style | - | ||||||||||||||||||
1174 | object on application exit or when a new style is set and the old style is | - | ||||||||||||||||||
1175 | still the parent of the application object. | - | ||||||||||||||||||
1176 | - | |||||||||||||||||||
1177 | Example usage: | - | ||||||||||||||||||
1178 | \snippet code/src_gui_kernel_qapplication.cpp 1 | - | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | When switching application styles, the color palette is set back to the | - | ||||||||||||||||||
1181 | initial colors or the system defaults. This is necessary since certain | - | ||||||||||||||||||
1182 | styles have to adapt the color palette to be fully style-guide compliant. | - | ||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | Setting the style before a palette has been set, i.e., before creating | - | ||||||||||||||||||
1185 | QApplication, will cause the application to use QStyle::standardPalette() | - | ||||||||||||||||||
1186 | for the palette. | - | ||||||||||||||||||
1187 | - | |||||||||||||||||||
1188 | \warning Qt style sheets are currently not supported for custom QStyle | - | ||||||||||||||||||
1189 | subclasses. We plan to address this in some future release. | - | ||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | \sa style(), QStyle, setPalette(), desktopSettingsAware() | - | ||||||||||||||||||
1192 | */ | - | ||||||||||||||||||
1193 | void QApplication::setStyle(QStyle *style) | - | ||||||||||||||||||
1194 | { | - | ||||||||||||||||||
1195 | if (!style || style == QApplicationPrivate::app_style) | - | ||||||||||||||||||
1196 | return; | - | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | QWidgetList all = allWidgets(); | - | ||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | // clean up the old style | - | ||||||||||||||||||
1201 | if (QApplicationPrivate::app_style) { | - | ||||||||||||||||||
1202 | if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { | - | ||||||||||||||||||
1203 | for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1204 | QWidget *w = *it; | - | ||||||||||||||||||
1205 | if (!(w->windowType() == Qt::Desktop) && // except desktop | - | ||||||||||||||||||
1206 | w->testAttribute(Qt::WA_WState_Polished)) { // has been polished | - | ||||||||||||||||||
1207 | QApplicationPrivate::app_style->unpolish(w); | - | ||||||||||||||||||
1208 | } | - | ||||||||||||||||||
1209 | } | - | ||||||||||||||||||
1210 | } | - | ||||||||||||||||||
1211 | QApplicationPrivate::app_style->unpolish(qApp); | - | ||||||||||||||||||
1212 | } | - | ||||||||||||||||||
1213 | - | |||||||||||||||||||
1214 | QStyle *old = QApplicationPrivate::app_style; // save | - | ||||||||||||||||||
1215 | - | |||||||||||||||||||
1216 | QApplicationPrivate::overrides_native_style = | - | ||||||||||||||||||
1217 | nativeStyleClassName() == QByteArray(style->metaObject()->className()); | - | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1220 | if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast<QStyleSheetStyle *>(style)) { | - | ||||||||||||||||||
1221 | // we have a stylesheet already and a new style is being set | - | ||||||||||||||||||
1222 | QStyleSheetStyle *newProxy = new QStyleSheetStyle(style); | - | ||||||||||||||||||
1223 | style->setParent(newProxy); | - | ||||||||||||||||||
1224 | QApplicationPrivate::app_style = newProxy; | - | ||||||||||||||||||
1225 | } else | - | ||||||||||||||||||
1226 | #endif // QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1227 | QApplicationPrivate::app_style = style; | - | ||||||||||||||||||
1228 | QApplicationPrivate::app_style->setParent(qApp); // take ownership | - | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | // take care of possible palette requirements of certain gui | - | ||||||||||||||||||
1231 | // styles. Do it before polishing the application since the style | - | ||||||||||||||||||
1232 | // might call QApplication::setPalette() itself | - | ||||||||||||||||||
1233 | if (QApplicationPrivate::set_pal) { | - | ||||||||||||||||||
1234 | QApplication::setPalette(*QApplicationPrivate::set_pal); | - | ||||||||||||||||||
1235 | } else if (QApplicationPrivate::sys_pal) { | - | ||||||||||||||||||
1236 | clearSystemPalette(); | - | ||||||||||||||||||
1237 | initSystemPalette(); | - | ||||||||||||||||||
1238 | QApplicationPrivate::initializeWidgetPaletteHash(); | - | ||||||||||||||||||
1239 | QApplicationPrivate::initializeWidgetFontHash(); | - | ||||||||||||||||||
1240 | QApplicationPrivate::setPalette_helper(*QApplicationPrivate::sys_pal, /*className=*/0, /*clearWidgetPaletteHash=*/false); | - | ||||||||||||||||||
1241 | } else if (!QApplicationPrivate::sys_pal) { | - | ||||||||||||||||||
1242 | // Initialize the sys_pal if it hasn't happened yet... | - | ||||||||||||||||||
1243 | QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); | - | ||||||||||||||||||
1244 | } | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | // initialize the application with the new style | - | ||||||||||||||||||
1247 | QApplicationPrivate::app_style->polish(qApp); | - | ||||||||||||||||||
1248 | - | |||||||||||||||||||
1249 | // re-polish existing widgets if necessary | - | ||||||||||||||||||
1250 | if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { | - | ||||||||||||||||||
1251 | for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1252 | QWidget *w = *it; | - | ||||||||||||||||||
1253 | if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) { | - | ||||||||||||||||||
1254 | if (w->style() == QApplicationPrivate::app_style) | - | ||||||||||||||||||
1255 | QApplicationPrivate::app_style->polish(w); // repolish | - | ||||||||||||||||||
1256 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1257 | else | - | ||||||||||||||||||
1258 | w->setStyleSheet(w->styleSheet()); // touch | - | ||||||||||||||||||
1259 | #endif | - | ||||||||||||||||||
1260 | } | - | ||||||||||||||||||
1261 | } | - | ||||||||||||||||||
1262 | - | |||||||||||||||||||
1263 | for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1264 | QWidget *w = *it; | - | ||||||||||||||||||
1265 | if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) { | - | ||||||||||||||||||
1266 | QEvent e(QEvent::StyleChange); | - | ||||||||||||||||||
1267 | QApplication::sendEvent(w, &e); | - | ||||||||||||||||||
1268 | w->update(); | - | ||||||||||||||||||
1269 | } | - | ||||||||||||||||||
1270 | } | - | ||||||||||||||||||
1271 | } | - | ||||||||||||||||||
1272 | - | |||||||||||||||||||
1273 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1274 | if (QStyleSheetStyle *oldProxy = qobject_cast<QStyleSheetStyle *>(old)) { | - | ||||||||||||||||||
1275 | oldProxy->deref(); | - | ||||||||||||||||||
1276 | } else | - | ||||||||||||||||||
1277 | #endif | - | ||||||||||||||||||
1278 | if (old && old->parent() == qApp) { | - | ||||||||||||||||||
1279 | delete old; | - | ||||||||||||||||||
1280 | } | - | ||||||||||||||||||
1281 | - | |||||||||||||||||||
1282 | if (QApplicationPrivate::focus_widget) { | - | ||||||||||||||||||
1283 | QFocusEvent in(QEvent::FocusIn, Qt::OtherFocusReason); | - | ||||||||||||||||||
1284 | QApplication::sendEvent(QApplicationPrivate::focus_widget->style(), &in); | - | ||||||||||||||||||
1285 | QApplicationPrivate::focus_widget->update(); | - | ||||||||||||||||||
1286 | } | - | ||||||||||||||||||
1287 | } | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | /*! | - | ||||||||||||||||||
1290 | \overload | - | ||||||||||||||||||
1291 | - | |||||||||||||||||||
1292 | Requests a QStyle object for \a style from the QStyleFactory. | - | ||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | The string must be one of the QStyleFactory::keys(), typically one of | - | ||||||||||||||||||
1295 | "windows", "fusion", "windowsxp", or "macintosh". Style | - | ||||||||||||||||||
1296 | names are case insensitive. | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | Returns 0 if an unknown \a style is passed, otherwise the QStyle object | - | ||||||||||||||||||
1299 | returned is set as the application's GUI style. | - | ||||||||||||||||||
1300 | - | |||||||||||||||||||
1301 | \warning To ensure that the application's style is set correctly, it is | - | ||||||||||||||||||
1302 | best to call this function before the QApplication constructor, if | - | ||||||||||||||||||
1303 | possible. | - | ||||||||||||||||||
1304 | */ | - | ||||||||||||||||||
1305 | QStyle* QApplication::setStyle(const QString& style) | - | ||||||||||||||||||
1306 | { | - | ||||||||||||||||||
1307 | QStyle *s = QStyleFactory::create(style); | - | ||||||||||||||||||
1308 | if (!s) | - | ||||||||||||||||||
1309 | return 0; | - | ||||||||||||||||||
1310 | - | |||||||||||||||||||
1311 | setStyle(s); | - | ||||||||||||||||||
1312 | return s; | - | ||||||||||||||||||
1313 | } | - | ||||||||||||||||||
1314 | - | |||||||||||||||||||
1315 | /*! | - | ||||||||||||||||||
1316 | Returns the color specification. | - | ||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | \sa QApplication::setColorSpec() | - | ||||||||||||||||||
1319 | */ | - | ||||||||||||||||||
1320 | - | |||||||||||||||||||
1321 | int QApplication::colorSpec() | - | ||||||||||||||||||
1322 | { | - | ||||||||||||||||||
1323 | return QApplicationPrivate::app_cspec; | - | ||||||||||||||||||
1324 | } | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | /*! | - | ||||||||||||||||||
1327 | Sets the color specification for the application to \a spec. | - | ||||||||||||||||||
1328 | - | |||||||||||||||||||
1329 | The color specification controls how the application allocates colors when | - | ||||||||||||||||||
1330 | run on a display with a limited amount of colors, e.g. 8 bit / 256 color | - | ||||||||||||||||||
1331 | displays. | - | ||||||||||||||||||
1332 | - | |||||||||||||||||||
1333 | The color specification must be set before you create the QApplication | - | ||||||||||||||||||
1334 | object. | - | ||||||||||||||||||
1335 | - | |||||||||||||||||||
1336 | The options are: | - | ||||||||||||||||||
1337 | \list | - | ||||||||||||||||||
1338 | \li QApplication::NormalColor. This is the default color allocation | - | ||||||||||||||||||
1339 | strategy. Use this option if your application uses buttons, menus, | - | ||||||||||||||||||
1340 | texts and pixmaps with few colors. With this option, the | - | ||||||||||||||||||
1341 | application uses system global colors. This works fine for most | - | ||||||||||||||||||
1342 | applications under X11, but on the Windows platform, it may cause | - | ||||||||||||||||||
1343 | dithering of non-standard colors. | - | ||||||||||||||||||
1344 | \li QApplication::CustomColor. Use this option if your application | - | ||||||||||||||||||
1345 | needs a small number of custom colors. On X11, this option is the | - | ||||||||||||||||||
1346 | same as NormalColor. On Windows, Qt creates a Windows palette, and | - | ||||||||||||||||||
1347 | allocates colors to it on demand. | - | ||||||||||||||||||
1348 | \li QApplication::ManyColor. Use this option if your application is | - | ||||||||||||||||||
1349 | very color hungry, e.g., it requires thousands of colors. \br | - | ||||||||||||||||||
1350 | Under X11 the effect is: | - | ||||||||||||||||||
1351 | \list | - | ||||||||||||||||||
1352 | \li For 256-color displays which have at best a 256 color true | - | ||||||||||||||||||
1353 | color visual, the default visual is used, and colors are | - | ||||||||||||||||||
1354 | allocated from a color cube. The color cube is the 6x6x6 | - | ||||||||||||||||||
1355 | (216 color) "Web palette" (the red, green, and blue | - | ||||||||||||||||||
1356 | components always have one of the following values: 0x00, | - | ||||||||||||||||||
1357 | 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors | - | ||||||||||||||||||
1358 | can be changed by the \e -ncols option. The user can force | - | ||||||||||||||||||
1359 | the application to use the true color visual with the | - | ||||||||||||||||||
1360 | \l{QApplication::QApplication()}{-visual} option. | - | ||||||||||||||||||
1361 | \li For 256-color displays which have a true color visual with | - | ||||||||||||||||||
1362 | more than 256 colors, use that visual. Silicon Graphics X | - | ||||||||||||||||||
1363 | servers this feature, for example. They provide an 8 bit | - | ||||||||||||||||||
1364 | visual by default but can deliver true color when asked. | - | ||||||||||||||||||
1365 | \endlist | - | ||||||||||||||||||
1366 | On Windows, Qt creates a Windows palette, and fills it with a color | - | ||||||||||||||||||
1367 | cube. | - | ||||||||||||||||||
1368 | \endlist | - | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | Be aware that the CustomColor and ManyColor choices may lead to colormap | - | ||||||||||||||||||
1371 | flashing: The foreground application gets (most) of the available colors, | - | ||||||||||||||||||
1372 | while the background windows will look less attractive. | - | ||||||||||||||||||
1373 | - | |||||||||||||||||||
1374 | Example: | - | ||||||||||||||||||
1375 | - | |||||||||||||||||||
1376 | \snippet code/src_gui_kernel_qapplication.cpp 2 | - | ||||||||||||||||||
1377 | - | |||||||||||||||||||
1378 | \sa colorSpec() | - | ||||||||||||||||||
1379 | */ | - | ||||||||||||||||||
1380 | - | |||||||||||||||||||
1381 | void QApplication::setColorSpec(int spec) | - | ||||||||||||||||||
1382 | { | - | ||||||||||||||||||
1383 | if (Q_UNLIKELY(qApp)))
| 0 | ||||||||||||||||||
1384 | qWarning("QApplication::setColorSpec: This function must be " never executed: QMessageLogger(__FILE__, 1384, __PRETTY_FUNCTION__).warning("QApplication::setColorSpec: This function must be " "called before the QApplication object is created"); | 0 | ||||||||||||||||||
1385 | "called before the QApplication object is created"); never executed: QMessageLogger(__FILE__, 1384, __PRETTY_FUNCTION__).warning("QApplication::setColorSpec: This function must be " "called before the QApplication object is created"); | 0 | ||||||||||||||||||
1386 | QApplicationPrivate::app_cspec = spec; | - | ||||||||||||||||||
1387 | } never executed: end of block | 0 | ||||||||||||||||||
1388 | - | |||||||||||||||||||
1389 | /*! | - | ||||||||||||||||||
1390 | \property QApplication::globalStrut | - | ||||||||||||||||||
1391 | \brief the minimum size that any GUI element that the user can interact | - | ||||||||||||||||||
1392 | with should have | - | ||||||||||||||||||
1393 | - | |||||||||||||||||||
1394 | For example, no button should be resized to be smaller than the global | - | ||||||||||||||||||
1395 | strut size. The strut size should be considered when reimplementing GUI | - | ||||||||||||||||||
1396 | controls that may be used on touch-screens or similar I/O devices. | - | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | Example: | - | ||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | \snippet code/src_gui_kernel_qapplication.cpp 3 | - | ||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | By default, this property contains a QSize object with zero width and height. | - | ||||||||||||||||||
1403 | */ | - | ||||||||||||||||||
1404 | QSize QApplication::globalStrut() | - | ||||||||||||||||||
1405 | { | - | ||||||||||||||||||
1406 | return QApplicationPrivate::app_strut; | - | ||||||||||||||||||
1407 | } | - | ||||||||||||||||||
1408 | - | |||||||||||||||||||
1409 | void QApplication::setGlobalStrut(const QSize& strut) | - | ||||||||||||||||||
1410 | { | - | ||||||||||||||||||
1411 | QApplicationPrivate::app_strut = strut; | - | ||||||||||||||||||
1412 | } | - | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | /*! | - | ||||||||||||||||||
1416 | \fn QPalette QApplication::palette(const QWidget* widget) | - | ||||||||||||||||||
1417 | \overload | - | ||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | If a \a widget is passed, the default palette for the widget's class is | - | ||||||||||||||||||
1420 | returned. This may or may not be the application palette. In most cases | - | ||||||||||||||||||
1421 | there is no special palette for certain types of widgets, but one notable | - | ||||||||||||||||||
1422 | exception is the popup menu under Windows, if the user has defined a | - | ||||||||||||||||||
1423 | special background color for menus in the display settings. | - | ||||||||||||||||||
1424 | - | |||||||||||||||||||
1425 | \sa setPalette(), QWidget::palette() | - | ||||||||||||||||||
1426 | */ | - | ||||||||||||||||||
1427 | QPalette QApplication::palette(const QWidget* w) | - | ||||||||||||||||||
1428 | { | - | ||||||||||||||||||
1429 | typedef PaletteHash::const_iterator PaletteHashConstIt; | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | PaletteHash *hash = app_palettes(); | - | ||||||||||||||||||
1432 | if (w && hash && hash->size()) { | - | ||||||||||||||||||
1433 | PaletteHashConstIt it = hash->constFind(w->metaObject()->className()); | - | ||||||||||||||||||
1434 | const PaletteHashConstIt cend = hash->constEnd(); | - | ||||||||||||||||||
1435 | if (it != cend) | - | ||||||||||||||||||
1436 | return *it; | - | ||||||||||||||||||
1437 | for (it = hash->constBegin(); it != cend; ++it) { | - | ||||||||||||||||||
1438 | if (w->inherits(it.key())) | - | ||||||||||||||||||
1439 | return it.value(); | - | ||||||||||||||||||
1440 | } | - | ||||||||||||||||||
1441 | } | - | ||||||||||||||||||
1442 | return palette(); | - | ||||||||||||||||||
1443 | } | - | ||||||||||||||||||
1444 | - | |||||||||||||||||||
1445 | /*! | - | ||||||||||||||||||
1446 | \overload | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | Returns the palette for widgets of the given \a className. | - | ||||||||||||||||||
1449 | - | |||||||||||||||||||
1450 | \sa setPalette(), QWidget::palette() | - | ||||||||||||||||||
1451 | */ | - | ||||||||||||||||||
1452 | QPalette QApplication::palette(const char *className) | - | ||||||||||||||||||
1453 | { | - | ||||||||||||||||||
1454 | if (!QApplicationPrivate::app_pal) | - | ||||||||||||||||||
1455 | palette(); | - | ||||||||||||||||||
1456 | PaletteHash *hash = app_palettes(); | - | ||||||||||||||||||
1457 | if (className && hash && hash->size()) { | - | ||||||||||||||||||
1458 | QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(className); | - | ||||||||||||||||||
1459 | if (it != hash->constEnd()) | - | ||||||||||||||||||
1460 | return *it; | - | ||||||||||||||||||
1461 | } | - | ||||||||||||||||||
1462 | return *QApplicationPrivate::app_pal; | - | ||||||||||||||||||
1463 | } | - | ||||||||||||||||||
1464 | - | |||||||||||||||||||
1465 | void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash) | - | ||||||||||||||||||
1466 | { | - | ||||||||||||||||||
1467 | QPalette pal = palette; | - | ||||||||||||||||||
1468 | - | |||||||||||||||||||
1469 | if (QApplicationPrivate::app_style) | - | ||||||||||||||||||
1470 | QApplicationPrivate::app_style->polish(pal); // NB: non-const reference | - | ||||||||||||||||||
1471 | - | |||||||||||||||||||
1472 | bool all = false; | - | ||||||||||||||||||
1473 | PaletteHash *hash = app_palettes(); | - | ||||||||||||||||||
1474 | if (!className) { | - | ||||||||||||||||||
1475 | if (QApplicationPrivate::app_pal && pal.isCopyOf(*QApplicationPrivate::app_pal)) | - | ||||||||||||||||||
1476 | return; | - | ||||||||||||||||||
1477 | if (!QApplicationPrivate::app_pal) | - | ||||||||||||||||||
1478 | QApplicationPrivate::app_pal = new QPalette(pal); | - | ||||||||||||||||||
1479 | else | - | ||||||||||||||||||
1480 | *QApplicationPrivate::app_pal = pal; | - | ||||||||||||||||||
1481 | if (hash && hash->size()) { | - | ||||||||||||||||||
1482 | all = true; | - | ||||||||||||||||||
1483 | if (clearWidgetPaletteHash) | - | ||||||||||||||||||
1484 | hash->clear(); | - | ||||||||||||||||||
1485 | } | - | ||||||||||||||||||
1486 | } else if (hash) { | - | ||||||||||||||||||
1487 | hash->insert(className, pal); | - | ||||||||||||||||||
1488 | } | - | ||||||||||||||||||
1489 | - | |||||||||||||||||||
1490 | if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { | - | ||||||||||||||||||
1491 | // Send ApplicationPaletteChange to qApp itself, and to the widgets. | - | ||||||||||||||||||
1492 | QEvent e(QEvent::ApplicationPaletteChange); | - | ||||||||||||||||||
1493 | QApplication::sendEvent(QApplication::instance(), &e); | - | ||||||||||||||||||
1494 | - | |||||||||||||||||||
1495 | QWidgetList wids = QApplication::allWidgets(); | - | ||||||||||||||||||
1496 | for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1497 | QWidget *w = *it; | - | ||||||||||||||||||
1498 | if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class | - | ||||||||||||||||||
1499 | QApplication::sendEvent(w, &e); | - | ||||||||||||||||||
1500 | } | - | ||||||||||||||||||
1501 | - | |||||||||||||||||||
1502 | // Send to all scenes as well. | - | ||||||||||||||||||
1503 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1504 | QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list; | - | ||||||||||||||||||
1505 | for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin(); | - | ||||||||||||||||||
1506 | it != scenes.constEnd(); ++it) { | - | ||||||||||||||||||
1507 | QApplication::sendEvent(*it, &e); | - | ||||||||||||||||||
1508 | } | - | ||||||||||||||||||
1509 | #endif //QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1510 | } | - | ||||||||||||||||||
1511 | if (!className && (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal))) { | - | ||||||||||||||||||
1512 | if (!QApplicationPrivate::set_pal) | - | ||||||||||||||||||
1513 | QApplicationPrivate::set_pal = new QPalette(palette); | - | ||||||||||||||||||
1514 | else | - | ||||||||||||||||||
1515 | *QApplicationPrivate::set_pal = palette; | - | ||||||||||||||||||
1516 | QCoreApplication::setAttribute(Qt::AA_SetPalette); | - | ||||||||||||||||||
1517 | } | - | ||||||||||||||||||
1518 | } | - | ||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | /*! | - | ||||||||||||||||||
1521 | Changes the default application palette to \a palette. | - | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | If \a className is passed, the change applies only to widgets that inherit | - | ||||||||||||||||||
1524 | \a className (as reported by QObject::inherits()). If \a className is left | - | ||||||||||||||||||
1525 | 0, the change affects all widgets, thus overriding any previously set class | - | ||||||||||||||||||
1526 | specific palettes. | - | ||||||||||||||||||
1527 | - | |||||||||||||||||||
1528 | The palette may be changed according to the current GUI style in | - | ||||||||||||||||||
1529 | QStyle::polish(). | - | ||||||||||||||||||
1530 | - | |||||||||||||||||||
1531 | \warning Do not use this function in conjunction with \l{Qt Style Sheets}. | - | ||||||||||||||||||
1532 | When using style sheets, the palette of a widget can be customized using | - | ||||||||||||||||||
1533 | the "color", "background-color", "selection-color", | - | ||||||||||||||||||
1534 | "selection-background-color" and "alternate-background-color". | - | ||||||||||||||||||
1535 | - | |||||||||||||||||||
1536 | \note Some styles do not use the palette for all drawing, for instance, if | - | ||||||||||||||||||
1537 | they make use of native theme engines. This is the case for the Windows XP, | - | ||||||||||||||||||
1538 | Windows Vista, and \macos styles. | - | ||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | \sa QWidget::setPalette(), palette(), QStyle::polish() | - | ||||||||||||||||||
1541 | */ | - | ||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | void QApplication::setPalette(const QPalette &palette, const char* className) | - | ||||||||||||||||||
1544 | { | - | ||||||||||||||||||
1545 | QApplicationPrivate::setPalette_helper(palette, className, /*clearWidgetPaletteHash=*/ true); | - | ||||||||||||||||||
1546 | } | - | ||||||||||||||||||
1547 | - | |||||||||||||||||||
1548 | - | |||||||||||||||||||
1549 | - | |||||||||||||||||||
1550 | void QApplicationPrivate::setSystemPalette(const QPalette &pal) | - | ||||||||||||||||||
1551 | { | - | ||||||||||||||||||
1552 | QPalette adjusted; | - | ||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | #if 0 | - | ||||||||||||||||||
1555 | // adjust the system palette to avoid dithering | - | ||||||||||||||||||
1556 | QColormap cmap = QColormap::instance(); | - | ||||||||||||||||||
1557 | if (cmap.depths() > 4 && cmap.depths() < 24) { | - | ||||||||||||||||||
1558 | for (int g = 0; g < QPalette::NColorGroups; g++) | - | ||||||||||||||||||
1559 | for (int i = 0; i < QPalette::NColorRoles; i++) { | - | ||||||||||||||||||
1560 | QColor color = pal.color((QPalette::ColorGroup)g, (QPalette::ColorRole)i); | - | ||||||||||||||||||
1561 | color = cmap.colorAt(cmap.pixel(color)); | - | ||||||||||||||||||
1562 | adjusted.setColor((QPalette::ColorGroup)g, (QPalette::ColorRole) i, color); | - | ||||||||||||||||||
1563 | } | - | ||||||||||||||||||
1564 | } | - | ||||||||||||||||||
1565 | #else | - | ||||||||||||||||||
1566 | adjusted = pal; | - | ||||||||||||||||||
1567 | #endif | - | ||||||||||||||||||
1568 | - | |||||||||||||||||||
1569 | if (!sys_pal) | - | ||||||||||||||||||
1570 | sys_pal = new QPalette(adjusted); | - | ||||||||||||||||||
1571 | else | - | ||||||||||||||||||
1572 | *sys_pal = adjusted; | - | ||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | if (!QApplicationPrivate::set_pal) | - | ||||||||||||||||||
1576 | QApplication::setPalette(*sys_pal); | - | ||||||||||||||||||
1577 | } | - | ||||||||||||||||||
1578 | - | |||||||||||||||||||
1579 | /*! | - | ||||||||||||||||||
1580 | Returns the default application font. | - | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | \sa fontMetrics(), QWidget::font() | - | ||||||||||||||||||
1583 | */ | - | ||||||||||||||||||
1584 | QFont QApplication::font() | - | ||||||||||||||||||
1585 | { | - | ||||||||||||||||||
1586 | return QGuiApplication::font(); | - | ||||||||||||||||||
1587 | } | - | ||||||||||||||||||
1588 | - | |||||||||||||||||||
1589 | /*! | - | ||||||||||||||||||
1590 | \overload | - | ||||||||||||||||||
1591 | - | |||||||||||||||||||
1592 | Returns the default font for the \a widget. | - | ||||||||||||||||||
1593 | - | |||||||||||||||||||
1594 | \sa fontMetrics(), QWidget::setFont() | - | ||||||||||||||||||
1595 | */ | - | ||||||||||||||||||
1596 | - | |||||||||||||||||||
1597 | QFont QApplication::font(const QWidget *widget) | - | ||||||||||||||||||
1598 | { | - | ||||||||||||||||||
1599 | typedef FontHash::const_iterator FontHashConstIt; | - | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | FontHash *hash = app_fonts(); | - | ||||||||||||||||||
1602 | - | |||||||||||||||||||
1603 | if (widget && hash && hash->size()) { | - | ||||||||||||||||||
1604 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
1605 | // short circuit for small and mini controls | - | ||||||||||||||||||
1606 | if (widget->testAttribute(Qt::WA_MacSmallSize)) { | - | ||||||||||||||||||
1607 | return hash->value(QByteArrayLiteral("QSmallFont")); | - | ||||||||||||||||||
1608 | } else if (widget->testAttribute(Qt::WA_MacMiniSize)) { | - | ||||||||||||||||||
1609 | return hash->value(QByteArrayLiteral("QMiniFont")); | - | ||||||||||||||||||
1610 | } | - | ||||||||||||||||||
1611 | #endif | - | ||||||||||||||||||
1612 | FontHashConstIt it = hash->constFind(widget->metaObject()->className()); | - | ||||||||||||||||||
1613 | const FontHashConstIt cend = hash->constEnd(); | - | ||||||||||||||||||
1614 | if (it != cend) | - | ||||||||||||||||||
1615 | return it.value(); | - | ||||||||||||||||||
1616 | for (it = hash->constBegin(); it != cend; ++it) { | - | ||||||||||||||||||
1617 | if (widget->inherits(it.key())) | - | ||||||||||||||||||
1618 | return it.value(); | - | ||||||||||||||||||
1619 | } | - | ||||||||||||||||||
1620 | } | - | ||||||||||||||||||
1621 | return font(); | - | ||||||||||||||||||
1622 | } | - | ||||||||||||||||||
1623 | - | |||||||||||||||||||
1624 | /*! | - | ||||||||||||||||||
1625 | \overload | - | ||||||||||||||||||
1626 | - | |||||||||||||||||||
1627 | Returns the font for widgets of the given \a className. | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | \sa setFont(), QWidget::font() | - | ||||||||||||||||||
1630 | */ | - | ||||||||||||||||||
1631 | QFont QApplication::font(const char *className) | - | ||||||||||||||||||
1632 | { | - | ||||||||||||||||||
1633 | FontHash *hash = app_fonts(); | - | ||||||||||||||||||
1634 | if (className && hash && hash->size()) { | - | ||||||||||||||||||
1635 | QHash<QByteArray, QFont>::ConstIterator it = hash->constFind(className); | - | ||||||||||||||||||
1636 | if (it != hash->constEnd()) | - | ||||||||||||||||||
1637 | return *it; | - | ||||||||||||||||||
1638 | } | - | ||||||||||||||||||
1639 | return font(); | - | ||||||||||||||||||
1640 | } | - | ||||||||||||||||||
1641 | - | |||||||||||||||||||
1642 | - | |||||||||||||||||||
1643 | /*! | - | ||||||||||||||||||
1644 | Changes the default application font to \a font. If \a className is passed, | - | ||||||||||||||||||
1645 | the change applies only to classes that inherit \a className (as reported | - | ||||||||||||||||||
1646 | by QObject::inherits()). | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | On application start-up, the default font depends on the window system. It | - | ||||||||||||||||||
1649 | can vary depending on both the window system version and the locale. This | - | ||||||||||||||||||
1650 | function lets you override the default font; but overriding may be a bad | - | ||||||||||||||||||
1651 | idea because, for example, some locales need extra large fonts to support | - | ||||||||||||||||||
1652 | their special characters. | - | ||||||||||||||||||
1653 | - | |||||||||||||||||||
1654 | \warning Do not use this function in conjunction with \l{Qt Style Sheets}. | - | ||||||||||||||||||
1655 | The font of an application can be customized using the "font" style sheet | - | ||||||||||||||||||
1656 | property. To set a bold font for all QPushButtons, set the application | - | ||||||||||||||||||
1657 | styleSheet() as "QPushButton { font: bold }" | - | ||||||||||||||||||
1658 | - | |||||||||||||||||||
1659 | \sa font(), fontMetrics(), QWidget::setFont() | - | ||||||||||||||||||
1660 | */ | - | ||||||||||||||||||
1661 | - | |||||||||||||||||||
1662 | void QApplication::setFont(const QFont &font, const char *className) | - | ||||||||||||||||||
1663 | { | - | ||||||||||||||||||
1664 | bool all = false; | - | ||||||||||||||||||
1665 | FontHash *hash = app_fonts(); | - | ||||||||||||||||||
1666 | if (!className) { | - | ||||||||||||||||||
1667 | QGuiApplication::setFont(font); | - | ||||||||||||||||||
1668 | if (hash && hash->size()) { | - | ||||||||||||||||||
1669 | all = true; | - | ||||||||||||||||||
1670 | hash->clear(); | - | ||||||||||||||||||
1671 | } | - | ||||||||||||||||||
1672 | } else if (hash) { | - | ||||||||||||||||||
1673 | hash->insert(className, font); | - | ||||||||||||||||||
1674 | } | - | ||||||||||||||||||
1675 | if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { | - | ||||||||||||||||||
1676 | // Send ApplicationFontChange to qApp itself, and to the widgets. | - | ||||||||||||||||||
1677 | QEvent e(QEvent::ApplicationFontChange); | - | ||||||||||||||||||
1678 | QApplication::sendEvent(QApplication::instance(), &e); | - | ||||||||||||||||||
1679 | - | |||||||||||||||||||
1680 | QWidgetList wids = QApplication::allWidgets(); | - | ||||||||||||||||||
1681 | for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1682 | QWidget *w = *it; | - | ||||||||||||||||||
1683 | if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class | - | ||||||||||||||||||
1684 | sendEvent(w, &e); | - | ||||||||||||||||||
1685 | } | - | ||||||||||||||||||
1686 | - | |||||||||||||||||||
1687 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1688 | // Send to all scenes as well. | - | ||||||||||||||||||
1689 | QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list; | - | ||||||||||||||||||
1690 | for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin(); | - | ||||||||||||||||||
1691 | it != scenes.constEnd(); ++it) { | - | ||||||||||||||||||
1692 | QApplication::sendEvent(*it, &e); | - | ||||||||||||||||||
1693 | } | - | ||||||||||||||||||
1694 | #endif //QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1695 | } | - | ||||||||||||||||||
1696 | if (!className && (!QApplicationPrivate::sys_font || !font.isCopyOf(*QApplicationPrivate::sys_font))) { | - | ||||||||||||||||||
1697 | if (!QApplicationPrivate::set_font) | - | ||||||||||||||||||
1698 | QApplicationPrivate::set_font = new QFont(font); | - | ||||||||||||||||||
1699 | else | - | ||||||||||||||||||
1700 | *QApplicationPrivate::set_font = font; | - | ||||||||||||||||||
1701 | } | - | ||||||||||||||||||
1702 | } | - | ||||||||||||||||||
1703 | - | |||||||||||||||||||
1704 | /*! \internal | - | ||||||||||||||||||
1705 | */ | - | ||||||||||||||||||
1706 | void QApplicationPrivate::setSystemFont(const QFont &font) | - | ||||||||||||||||||
1707 | { | - | ||||||||||||||||||
1708 | if (!sys_font) | - | ||||||||||||||||||
1709 | sys_font = new QFont(font); | - | ||||||||||||||||||
1710 | else | - | ||||||||||||||||||
1711 | *sys_font = font; | - | ||||||||||||||||||
1712 | - | |||||||||||||||||||
1713 | if (!QApplicationPrivate::set_font) | - | ||||||||||||||||||
1714 | QApplication::setFont(*sys_font); | - | ||||||||||||||||||
1715 | } | - | ||||||||||||||||||
1716 | - | |||||||||||||||||||
1717 | /*! \internal | - | ||||||||||||||||||
1718 | */ | - | ||||||||||||||||||
1719 | QString QApplicationPrivate::desktopStyleKey() | - | ||||||||||||||||||
1720 | { | - | ||||||||||||||||||
1721 | // The platform theme might return a style that is not available, find | - | ||||||||||||||||||
1722 | // first valid one. | - | ||||||||||||||||||
1723 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
| 0 | ||||||||||||||||||
1724 | const QStringList availableKeys = QStyleFactory::keys(); | - | ||||||||||||||||||
1725 | foreach (const QString &style,auto styles = theme->themeHint(QPlatformTheme::StyleNames).toStringList())(); | - | ||||||||||||||||||
1726 | for (const QString &style : styles) { | - | ||||||||||||||||||
1727 | if (availableKeys.contains(style, Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
1728 | return style; never executed: return style; | 0 | ||||||||||||||||||
1729 | } never executed: end of block | 0 | ||||||||||||||||||
1730 | } never executed: end of block | 0 | ||||||||||||||||||
1731 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
1732 | } | - | ||||||||||||||||||
1733 | - | |||||||||||||||||||
1734 | #if QT_VERSION < 0x060000 // remove these forwarders in Qt 6 | - | ||||||||||||||||||
1735 | /*! | - | ||||||||||||||||||
1736 | \property QApplication::windowIcon | - | ||||||||||||||||||
1737 | \brief the default window icon | - | ||||||||||||||||||
1738 | - | |||||||||||||||||||
1739 | \sa QWidget::setWindowIcon(), {Setting the Application Icon} | - | ||||||||||||||||||
1740 | */ | - | ||||||||||||||||||
1741 | QIcon QApplication::windowIcon() | - | ||||||||||||||||||
1742 | { | - | ||||||||||||||||||
1743 | return QGuiApplication::windowIcon(); | - | ||||||||||||||||||
1744 | } | - | ||||||||||||||||||
1745 | - | |||||||||||||||||||
1746 | void QApplication::setWindowIcon(const QIcon &icon) | - | ||||||||||||||||||
1747 | { | - | ||||||||||||||||||
1748 | QGuiApplication::setWindowIcon(icon); | - | ||||||||||||||||||
1749 | } | - | ||||||||||||||||||
1750 | #endif | - | ||||||||||||||||||
1751 | - | |||||||||||||||||||
1752 | void QApplicationPrivate::notifyWindowIconChanged() | - | ||||||||||||||||||
1753 | { | - | ||||||||||||||||||
1754 | QEvent ev(QEvent::ApplicationWindowIconChange); | - | ||||||||||||||||||
1755 | const QWidgetList list = QApplication::topLevelWidgets(); | - | ||||||||||||||||||
1756 | QWindowList windowList = QGuiApplication::topLevelWindows(); | - | ||||||||||||||||||
1757 | - | |||||||||||||||||||
1758 | // send to all top-level QWidgets | - | ||||||||||||||||||
1759 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
1760 | windowList.removeOne(w->windowHandle()); | - | ||||||||||||||||||
1761 | QCoreApplication::sendEvent(w, &ev); | - | ||||||||||||||||||
1762 | } never executed: end of block | 0 | ||||||||||||||||||
1763 | - | |||||||||||||||||||
1764 | // in case there are any plain QWindows in this QApplication-using | - | ||||||||||||||||||
1765 | // application, also send the notification to them | - | ||||||||||||||||||
1766 | for (int i = 0; i < windowList.size(); ++i)
| 0 | ||||||||||||||||||
1767 | QCoreApplication::sendEvent(windowList.at(i), &ev); never executed: QCoreApplication::sendEvent(windowList.at(i), &ev); | 0 | ||||||||||||||||||
1768 | } never executed: end of block | 0 | ||||||||||||||||||
1769 | - | |||||||||||||||||||
1770 | /*! | - | ||||||||||||||||||
1771 | Returns a list of the top-level widgets (windows) in the application. | - | ||||||||||||||||||
1772 | - | |||||||||||||||||||
1773 | \note Some of the top-level widgets may be hidden, for example a tooltip if | - | ||||||||||||||||||
1774 | no tooltip is currently shown. | - | ||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | Example: | - | ||||||||||||||||||
1777 | - | |||||||||||||||||||
1778 | \snippet code/src_gui_kernel_qapplication.cpp 4 | - | ||||||||||||||||||
1779 | - | |||||||||||||||||||
1780 | \sa allWidgets(), QWidget::isWindow(), QWidget::isHidden() | - | ||||||||||||||||||
1781 | */ | - | ||||||||||||||||||
1782 | QWidgetList QApplication::topLevelWidgets() | - | ||||||||||||||||||
1783 | { | - | ||||||||||||||||||
1784 | QWidgetList list; | - | ||||||||||||||||||
1785 | QWidgetList all = allWidgets(); | - | ||||||||||||||||||
1786 | - | |||||||||||||||||||
1787 | for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { | - | ||||||||||||||||||
1788 | QWidget *w = *it; | - | ||||||||||||||||||
1789 | if (w->isWindow() && w->windowType() != Qt::Desktop) | - | ||||||||||||||||||
1790 | list.append(w); | - | ||||||||||||||||||
1791 | } | - | ||||||||||||||||||
1792 | return list; | - | ||||||||||||||||||
1793 | } | - | ||||||||||||||||||
1794 | - | |||||||||||||||||||
1795 | /*! | - | ||||||||||||||||||
1796 | Returns a list of all the widgets in the application. | - | ||||||||||||||||||
1797 | - | |||||||||||||||||||
1798 | The list is empty (QList::isEmpty()) if there are no widgets. | - | ||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | \note Some of the widgets may be hidden. | - | ||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | Example: | - | ||||||||||||||||||
1803 | \snippet code/src_gui_kernel_qapplication.cpp 5 | - | ||||||||||||||||||
1804 | - | |||||||||||||||||||
1805 | \sa topLevelWidgets(), QWidget::isVisible() | - | ||||||||||||||||||
1806 | */ | - | ||||||||||||||||||
1807 | - | |||||||||||||||||||
1808 | QWidgetList QApplication::allWidgets() | - | ||||||||||||||||||
1809 | { | - | ||||||||||||||||||
1810 | if (QWidgetPrivate::allWidgets) | - | ||||||||||||||||||
1811 | return QWidgetPrivate::allWidgets->toList(); | - | ||||||||||||||||||
1812 | return QWidgetList(); | - | ||||||||||||||||||
1813 | } | - | ||||||||||||||||||
1814 | - | |||||||||||||||||||
1815 | /*! | - | ||||||||||||||||||
1816 | Returns the application widget that has the keyboard input focus, or 0 if | - | ||||||||||||||||||
1817 | no widget in this application has the focus. | - | ||||||||||||||||||
1818 | - | |||||||||||||||||||
1819 | \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged() | - | ||||||||||||||||||
1820 | */ | - | ||||||||||||||||||
1821 | - | |||||||||||||||||||
1822 | QWidget *QApplication::focusWidget() | - | ||||||||||||||||||
1823 | { | - | ||||||||||||||||||
1824 | return QApplicationPrivate::focus_widget; | - | ||||||||||||||||||
1825 | } | - | ||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) | - | ||||||||||||||||||
1828 | { | - | ||||||||||||||||||
1829 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1830 | if (focus && focus->window()->graphicsProxyWidget()) | - | ||||||||||||||||||
1831 | return; | - | ||||||||||||||||||
1832 | #endif | - | ||||||||||||||||||
1833 | - | |||||||||||||||||||
1834 | hidden_focus_widget = 0; | - | ||||||||||||||||||
1835 | - | |||||||||||||||||||
1836 | if (focus != focus_widget) { | - | ||||||||||||||||||
1837 | if (focus && focus->isHidden()) { | - | ||||||||||||||||||
1838 | hidden_focus_widget = focus; | - | ||||||||||||||||||
1839 | return; | - | ||||||||||||||||||
1840 | } | - | ||||||||||||||||||
1841 | - | |||||||||||||||||||
1842 | if (focus && (reason == Qt::BacktabFocusReason || reason == Qt::TabFocusReason) | - | ||||||||||||||||||
1843 | && qt_in_tab_key_event) | - | ||||||||||||||||||
1844 | focus->window()->setAttribute(Qt::WA_KeyboardFocusChange); | - | ||||||||||||||||||
1845 | else if (focus && reason == Qt::ShortcutFocusReason) { | - | ||||||||||||||||||
1846 | focus->window()->setAttribute(Qt::WA_KeyboardFocusChange); | - | ||||||||||||||||||
1847 | } | - | ||||||||||||||||||
1848 | QWidget *prev = focus_widget; | - | ||||||||||||||||||
1849 | focus_widget = focus; | - | ||||||||||||||||||
1850 | - | |||||||||||||||||||
1851 | if(focus_widget) | - | ||||||||||||||||||
1852 | focus_widget->d_func()->setFocus_sys(); | - | ||||||||||||||||||
1853 | - | |||||||||||||||||||
1854 | if (reason != Qt::NoFocusReason) { | - | ||||||||||||||||||
1855 | - | |||||||||||||||||||
1856 | //send events | - | ||||||||||||||||||
1857 | if (prev) { | - | ||||||||||||||||||
1858 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
1859 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||
1860 | if (prev->hasEditFocus() && reason != Qt::PopupFocusReason) | - | ||||||||||||||||||
1861 | prev->setEditFocus(false); | - | ||||||||||||||||||
1862 | } | - | ||||||||||||||||||
1863 | #endif | - | ||||||||||||||||||
1864 | QFocusEvent out(QEvent::FocusOut, reason); | - | ||||||||||||||||||
1865 | QPointer<QWidget> that = prev; | - | ||||||||||||||||||
1866 | QApplication::sendEvent(prev, &out); | - | ||||||||||||||||||
1867 | if (that) | - | ||||||||||||||||||
1868 | QApplication::sendEvent(that->style(), &out); | - | ||||||||||||||||||
1869 | } | - | ||||||||||||||||||
1870 | if(focus && QApplicationPrivate::focus_widget == focus) { | - | ||||||||||||||||||
1871 | QFocusEvent in(QEvent::FocusIn, reason); | - | ||||||||||||||||||
1872 | QPointer<QWidget> that = focus; | - | ||||||||||||||||||
1873 | QApplication::sendEvent(focus, &in); | - | ||||||||||||||||||
1874 | if (that) | - | ||||||||||||||||||
1875 | QApplication::sendEvent(that->style(), &in); | - | ||||||||||||||||||
1876 | } | - | ||||||||||||||||||
1877 | emit qApp->focusChanged(prev, focus_widget); | - | ||||||||||||||||||
1878 | } | - | ||||||||||||||||||
1879 | } | - | ||||||||||||||||||
1880 | } | - | ||||||||||||||||||
1881 | - | |||||||||||||||||||
1882 | - | |||||||||||||||||||
1883 | /*! | - | ||||||||||||||||||
1884 | Returns the application top-level window that has the keyboard input focus, | - | ||||||||||||||||||
1885 | or 0 if no application window has the focus. There might be an | - | ||||||||||||||||||
1886 | activeWindow() even if there is no focusWidget(), for example if no widget | - | ||||||||||||||||||
1887 | in that window accepts key events. | - | ||||||||||||||||||
1888 | - | |||||||||||||||||||
1889 | \sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget() | - | ||||||||||||||||||
1890 | */ | - | ||||||||||||||||||
1891 | - | |||||||||||||||||||
1892 | QWidget *QApplication::activeWindow() | - | ||||||||||||||||||
1893 | { | - | ||||||||||||||||||
1894 | return QApplicationPrivate::active_window; | - | ||||||||||||||||||
1895 | } | - | ||||||||||||||||||
1896 | - | |||||||||||||||||||
1897 | /*! | - | ||||||||||||||||||
1898 | Returns display (screen) font metrics for the application font. | - | ||||||||||||||||||
1899 | - | |||||||||||||||||||
1900 | \sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics() | - | ||||||||||||||||||
1901 | */ | - | ||||||||||||||||||
1902 | - | |||||||||||||||||||
1903 | QFontMetrics QApplication::fontMetrics() | - | ||||||||||||||||||
1904 | { | - | ||||||||||||||||||
1905 | return desktop()->fontMetrics(); | - | ||||||||||||||||||
1906 | } | - | ||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows) | - | ||||||||||||||||||
1909 | { | - | ||||||||||||||||||
1910 | Q_ASSERT(processedWindows); | - | ||||||||||||||||||
1911 | while (QWidget *w = QApplication::activeModalWidget()) {
| 0 | ||||||||||||||||||
1912 | if (!w->isVisible() || w->data->is_closing)
| 0 | ||||||||||||||||||
1913 | break; never executed: break; | 0 | ||||||||||||||||||
1914 | QWindow *window = w->windowHandle(); | - | ||||||||||||||||||
1915 | if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
| 0 | ||||||||||||||||||
1916 | return false; never executed: return false; | 0 | ||||||||||||||||||
1917 | if (window)
| 0 | ||||||||||||||||||
1918 | processedWindows->append(window); never executed: processedWindows->append(window); | 0 | ||||||||||||||||||
1919 | } never executed: end of block | 0 | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | retry: code before this statement never executed: retry: | 0 | ||||||||||||||||||
1922 | const QWidgetList list = QApplication::topLevelWidgets(); | - | ||||||||||||||||||
1923 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
1924 | if (w->isVisible() && w->windowType() != Qt::Desktop &&
| 0 | ||||||||||||||||||
1925 | !w->testAttribute(Qt::WA_DontShowOnScreen) && !w->data->is_closing) {
| 0 | ||||||||||||||||||
1926 | QWindow *window = w->windowHandle(); | - | ||||||||||||||||||
1927 | if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
| 0 | ||||||||||||||||||
1928 | return false; never executed: return false; | 0 | ||||||||||||||||||
1929 | if (window)
| 0 | ||||||||||||||||||
1930 | processedWindows->append(window); never executed: processedWindows->append(window); | 0 | ||||||||||||||||||
1931 | list = QApplication::topLevelWidgets(); never executed: goto retry; | 0 | ||||||||||||||||||
i = -1 never executed: goto retry;goto retry; never executed: goto retry; | ||||||||||||||||||||
1932 | } | - | ||||||||||||||||||
1933 | } never executed: end of block | 0 | ||||||||||||||||||
1934 | return true; never executed: return true; | 0 | ||||||||||||||||||
1935 | } | - | ||||||||||||||||||
1936 | - | |||||||||||||||||||
1937 | bool QApplicationPrivate::tryCloseAllWindows() | - | ||||||||||||||||||
1938 | { | - | ||||||||||||||||||
1939 | QWindowList processedWindows; | - | ||||||||||||||||||
1940 | return QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows) | - | ||||||||||||||||||
1941 | && QGuiApplicationPrivate::tryCloseRemainingWindows(processedWindows); | - | ||||||||||||||||||
1942 | } | - | ||||||||||||||||||
1943 | - | |||||||||||||||||||
1944 | /*! | - | ||||||||||||||||||
1945 | Closes all top-level windows. | - | ||||||||||||||||||
1946 | - | |||||||||||||||||||
1947 | This function is particularly useful for applications with many top-level | - | ||||||||||||||||||
1948 | windows. It could, for example, be connected to a \uicontrol{Exit} entry in the | - | ||||||||||||||||||
1949 | \uicontrol{File} menu: | - | ||||||||||||||||||
1950 | - | |||||||||||||||||||
1951 | \snippet mainwindows/mdi/mainwindow.cpp 0 | - | ||||||||||||||||||
1952 | - | |||||||||||||||||||
1953 | The windows are closed in random order, until one window does not accept | - | ||||||||||||||||||
1954 | the close event. The application quits when the last window was | - | ||||||||||||||||||
1955 | successfully closed; this can be turned off by setting | - | ||||||||||||||||||
1956 | \l quitOnLastWindowClosed to false. | - | ||||||||||||||||||
1957 | - | |||||||||||||||||||
1958 | \sa quitOnLastWindowClosed, lastWindowClosed(), QWidget::close(), | - | ||||||||||||||||||
1959 | QWidget::closeEvent(), lastWindowClosed(), QCoreApplication::quit(), topLevelWidgets(), | - | ||||||||||||||||||
1960 | QWidget::isWindow() | - | ||||||||||||||||||
1961 | */ | - | ||||||||||||||||||
1962 | void QApplication::closeAllWindows() | - | ||||||||||||||||||
1963 | { | - | ||||||||||||||||||
1964 | QWindowList processedWindows; | - | ||||||||||||||||||
1965 | QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows); | - | ||||||||||||||||||
1966 | } | - | ||||||||||||||||||
1967 | - | |||||||||||||||||||
1968 | /*! | - | ||||||||||||||||||
1969 | Displays a simple message box about Qt. The message includes the version | - | ||||||||||||||||||
1970 | number of Qt being used by the application. | - | ||||||||||||||||||
1971 | - | |||||||||||||||||||
1972 | This is useful for inclusion in the \uicontrol Help menu of an application, as | - | ||||||||||||||||||
1973 | shown in the \l{mainwindows/menus}{Menus} example. | - | ||||||||||||||||||
1974 | - | |||||||||||||||||||
1975 | This function is a convenience slot for QMessageBox::aboutQt(). | - | ||||||||||||||||||
1976 | */ | - | ||||||||||||||||||
1977 | void QApplication::aboutQt() | - | ||||||||||||||||||
1978 | { | - | ||||||||||||||||||
1979 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
1980 | QMessageBox::aboutQt(activeWindow()); | - | ||||||||||||||||||
1981 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
1982 | } | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | /*! | - | ||||||||||||||||||
1985 | \since 4.1 | - | ||||||||||||||||||
1986 | \fn void QApplication::focusChanged(QWidget *old, QWidget *now) | - | ||||||||||||||||||
1987 | - | |||||||||||||||||||
1988 | This signal is emitted when the widget that has keyboard focus changed from | - | ||||||||||||||||||
1989 | \a old to \a now, i.e., because the user pressed the tab-key, clicked into | - | ||||||||||||||||||
1990 | a widget or changed the active window. Both \a old and \a now can be the | - | ||||||||||||||||||
1991 | null-pointer. | - | ||||||||||||||||||
1992 | - | |||||||||||||||||||
1993 | The signal is emitted after both widget have been notified about the change | - | ||||||||||||||||||
1994 | through QFocusEvent. | - | ||||||||||||||||||
1995 | - | |||||||||||||||||||
1996 | \sa QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason | - | ||||||||||||||||||
1997 | */ | - | ||||||||||||||||||
1998 | - | |||||||||||||||||||
1999 | /*!\reimp | - | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | */ | - | ||||||||||||||||||
2002 | bool QApplication::event(QEvent *e) | - | ||||||||||||||||||
2003 | { | - | ||||||||||||||||||
2004 | Q_D(QApplication); | - | ||||||||||||||||||
2005 | if(e->type() == QEvent::Close) {
| 0 | ||||||||||||||||||
2006 | QCloseEvent *ce = static_cast<QCloseEvent*>(e); | - | ||||||||||||||||||
2007 | ce->accept(); | - | ||||||||||||||||||
2008 | closeAllWindows(); | - | ||||||||||||||||||
2009 | - | |||||||||||||||||||
2010 | const QWidgetList list = topLevelWidgets(); | - | ||||||||||||||||||
2011 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2012 | if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) &&
| 0 | ||||||||||||||||||
2013 | (!(w->windowType() == Qt::Dialog) || !w->parentWidget())) {
| 0 | ||||||||||||||||||
2014 | ce->ignore(); | - | ||||||||||||||||||
2015 | break; never executed: break; | 0 | ||||||||||||||||||
2016 | } | - | ||||||||||||||||||
2017 | } never executed: end of block | 0 | ||||||||||||||||||
2018 | if (ce->isAccepted()) {
| 0 | ||||||||||||||||||
2019 | return true; never executed: return true; | 0 | ||||||||||||||||||
2020 | } | - | ||||||||||||||||||
2021 | #ifndef Q_OS_WIN | - | ||||||||||||||||||
2022 | } else if (e->type() == QEvent::LocaleChange) { never executed: end of block
| 0 | ||||||||||||||||||
2023 | // on Windows the event propagation is taken care by the | - | ||||||||||||||||||
2024 | // WM_SETTINGCHANGE event handler. | - | ||||||||||||||||||
2025 | const QWidgetList list = topLevelWidgets(); | - | ||||||||||||||||||
2026 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2027 | if (!(w->windowType() == Qt::Desktop)) {
| 0 | ||||||||||||||||||
2028 | if (!w->testAttribute(Qt::WA_SetLocale))
| 0 | ||||||||||||||||||
2029 | w->d_func()->setLocale_helper(QLocale(), true); never executed: w->d_func()->setLocale_helper(QLocale(), true); | 0 | ||||||||||||||||||
2030 | } never executed: end of block | 0 | ||||||||||||||||||
2031 | } never executed: end of block | 0 | ||||||||||||||||||
2032 | #endif | - | ||||||||||||||||||
2033 | } else if (e->type() == QEvent::Timer) { never executed: end of block
| 0 | ||||||||||||||||||
2034 | QTimerEvent *te = static_cast<QTimerEvent*>(e); | - | ||||||||||||||||||
2035 | Q_ASSERT(te != 0); | - | ||||||||||||||||||
2036 | if (te->timerId() == d->toolTipWakeUp.timerId()) {
| 0 | ||||||||||||||||||
2037 | d->toolTipWakeUp.stop(); | - | ||||||||||||||||||
2038 | if (d->toolTipWidget) {
| 0 | ||||||||||||||||||
2039 | QWidget *w = d->toolTipWidget->window(); | - | ||||||||||||||||||
2040 | // show tooltip if WA_AlwaysShowToolTips is set, or if | - | ||||||||||||||||||
2041 | // any ancestor of d->toolTipWidget is the active | - | ||||||||||||||||||
2042 | // window | - | ||||||||||||||||||
2043 | bool showToolTip = w->testAttribute(Qt::WA_AlwaysShowToolTips); | - | ||||||||||||||||||
2044 | while (w && !showToolTip) {
| 0 | ||||||||||||||||||
2045 | showToolTip = w->isActiveWindow(); | - | ||||||||||||||||||
2046 | w = w->parentWidget(); | - | ||||||||||||||||||
2047 | w = w ? w->window() : 0;
| 0 | ||||||||||||||||||
2048 | } never executed: end of block | 0 | ||||||||||||||||||
2049 | if (showToolTip) {
| 0 | ||||||||||||||||||
2050 | QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos); | - | ||||||||||||||||||
2051 | QApplication::sendEvent(d->toolTipWidget, &e); | - | ||||||||||||||||||
2052 | if (e.isAccepted()) {
| 0 | ||||||||||||||||||
2053 | QStyle *s = d->toolTipWidget->style(); | - | ||||||||||||||||||
2054 | int sleepDelay = s->styleHint(QStyle::SH_ToolTip_FallAsleepDelay, 0, d->toolTipWidget, 0); | - | ||||||||||||||||||
2055 | d->toolTipFallAsleep.start(sleepDelay, this); | - | ||||||||||||||||||
2056 | } never executed: end of block | 0 | ||||||||||||||||||
2057 | } never executed: end of block | 0 | ||||||||||||||||||
2058 | } never executed: end of block | 0 | ||||||||||||||||||
2059 | } else if (te->timerId() == d->toolTipFallAsleep.timerId()) { never executed: end of block
| 0 | ||||||||||||||||||
2060 | d->toolTipFallAsleep.stop(); | - | ||||||||||||||||||
2061 | } never executed: end of block | 0 | ||||||||||||||||||
2062 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||
2063 | } else if (e->type() == QEvent::EnterWhatsThisMode) { never executed: end of block
| 0 | ||||||||||||||||||
2064 | QWhatsThis::enterWhatsThisMode(); | - | ||||||||||||||||||
2065 | return true; never executed: return true; | 0 | ||||||||||||||||||
2066 | #endif | - | ||||||||||||||||||
2067 | } | - | ||||||||||||||||||
2068 | - | |||||||||||||||||||
2069 | if(e->type() == QEvent::LanguageChange) {
| 0 | ||||||||||||||||||
2070 | const QWidgetList list = topLevelWidgets(); | - | ||||||||||||||||||
2071 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2072 | if (!(w->windowType() == Qt::Desktop))
| 0 | ||||||||||||||||||
2073 | postEvent(w, new QEvent(QEvent::LanguageChange)); never executed: postEvent(w, new QEvent(QEvent::LanguageChange)); | 0 | ||||||||||||||||||
2074 | } never executed: end of block | 0 | ||||||||||||||||||
2075 | } never executed: end of block | 0 | ||||||||||||||||||
2076 | - | |||||||||||||||||||
2077 | return QGuiApplication::event(e); never executed: return QGuiApplication::event(e); | 0 | ||||||||||||||||||
2078 | } | - | ||||||||||||||||||
2079 | - | |||||||||||||||||||
2080 | /*! | - | ||||||||||||||||||
2081 | \fn void QApplication::syncX() | - | ||||||||||||||||||
2082 | Was used to synchronize with the X server in 4.x, here for source compatibility. | - | ||||||||||||||||||
2083 | \internal | - | ||||||||||||||||||
2084 | \obsolete | - | ||||||||||||||||||
2085 | */ | - | ||||||||||||||||||
2086 | - | |||||||||||||||||||
2087 | // ### FIXME: topLevelWindows does not contain QWidgets without a parent | - | ||||||||||||||||||
2088 | // until create_sys is called. So we have to override the | - | ||||||||||||||||||
2089 | // QGuiApplication::notifyLayoutDirectionChange | - | ||||||||||||||||||
2090 | // to do the right thing. | - | ||||||||||||||||||
2091 | void QApplicationPrivate::notifyLayoutDirectionChange() | - | ||||||||||||||||||
2092 | { | - | ||||||||||||||||||
2093 | const QWidgetList list = QApplication::topLevelWidgets(); | - | ||||||||||||||||||
2094 | QWindowList windowList = QGuiApplication::topLevelWindows(); | - | ||||||||||||||||||
2095 | - | |||||||||||||||||||
2096 | // send to all top-level QWidgets | - | ||||||||||||||||||
2097 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2098 | windowList.removeAll(w->windowHandle()); | - | ||||||||||||||||||
2099 | QEvent ev(QEvent::ApplicationLayoutDirectionChange); | - | ||||||||||||||||||
2100 | QCoreApplication::sendEvent(w, &ev); | - | ||||||||||||||||||
2101 | } never executed: end of block | 0 | ||||||||||||||||||
2102 | - | |||||||||||||||||||
2103 | // in case there are any plain QWindows in this QApplication-using | - | ||||||||||||||||||
2104 | // application, also send the notification to them | - | ||||||||||||||||||
2105 | for (int i = 0; i < windowList.size(); ++i) {
| 0 | ||||||||||||||||||
2106 | QEvent ev(QEvent::ApplicationLayoutDirectionChange); | - | ||||||||||||||||||
2107 | QCoreApplication::sendEvent(windowList.at(i), &ev); | - | ||||||||||||||||||
2108 | } never executed: end of block | 0 | ||||||||||||||||||
2109 | } never executed: end of block | 0 | ||||||||||||||||||
2110 | - | |||||||||||||||||||
2111 | /*! | - | ||||||||||||||||||
2112 | \fn void QApplication::setActiveWindow(QWidget* active) | - | ||||||||||||||||||
2113 | - | |||||||||||||||||||
2114 | Sets the active window to the \a active widget in response to a system | - | ||||||||||||||||||
2115 | event. The function is called from the platform specific event handlers. | - | ||||||||||||||||||
2116 | - | |||||||||||||||||||
2117 | \warning This function does \e not set the keyboard focus to the active | - | ||||||||||||||||||
2118 | widget. Call QWidget::activateWindow() instead. | - | ||||||||||||||||||
2119 | - | |||||||||||||||||||
2120 | It sets the activeWindow() and focusWidget() attributes and sends proper | - | ||||||||||||||||||
2121 | \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate} | - | ||||||||||||||||||
2122 | {WindowDeactivate} and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut} | - | ||||||||||||||||||
2123 | {FocusOut} events to all appropriate widgets. The window will then be | - | ||||||||||||||||||
2124 | painted in active state (e.g. cursors in line edits will blink), and it | - | ||||||||||||||||||
2125 | will have tool tips enabled. | - | ||||||||||||||||||
2126 | - | |||||||||||||||||||
2127 | \sa activeWindow(), QWidget::activateWindow() | - | ||||||||||||||||||
2128 | */ | - | ||||||||||||||||||
2129 | void QApplication::setActiveWindow(QWidget* act) | - | ||||||||||||||||||
2130 | { | - | ||||||||||||||||||
2131 | QWidget* window = act?act->window():0;
| 0 | ||||||||||||||||||
2132 | - | |||||||||||||||||||
2133 | if (QApplicationPrivate::active_window == window)
| 0 | ||||||||||||||||||
2134 | return; never executed: return; | 0 | ||||||||||||||||||
2135 | - | |||||||||||||||||||
2136 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
2137 | if (window && window->graphicsProxyWidget()) {
| 0 | ||||||||||||||||||
2138 | // Activate the proxy's view->viewport() ? | - | ||||||||||||||||||
2139 | return; never executed: return; | 0 | ||||||||||||||||||
2140 | } | - | ||||||||||||||||||
2141 | #endif | - | ||||||||||||||||||
2142 | - | |||||||||||||||||||
2143 | QWidgetList toBeActivated; | - | ||||||||||||||||||
2144 | QWidgetList toBeDeactivated; | - | ||||||||||||||||||
2145 | - | |||||||||||||||||||
2146 | if (QApplicationPrivate::active_window) {
| 0 | ||||||||||||||||||
2147 | if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) {
| 0 | ||||||||||||||||||
2148 | const QWidgetList list = topLevelWidgets(); | - | ||||||||||||||||||
2149 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2150 | if (w->isVisible() && w->isActiveWindow())
| 0 | ||||||||||||||||||
2151 | toBeDeactivated.append(w); never executed: toBeDeactivated.append(w); | 0 | ||||||||||||||||||
2152 | } never executed: end of block | 0 | ||||||||||||||||||
2153 | } else { never executed: end of block | 0 | ||||||||||||||||||
2154 | toBeDeactivated.append(QApplicationPrivate::active_window); | - | ||||||||||||||||||
2155 | } never executed: end of block | 0 | ||||||||||||||||||
2156 | } | - | ||||||||||||||||||
2157 | - | |||||||||||||||||||
2158 | if (QApplicationPrivate::focus_widget) {
| 0 | ||||||||||||||||||
2159 | if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled))
| 0 | ||||||||||||||||||
2160 | QGuiApplication::inputMethod()->commit(); never executed: QGuiApplication::inputMethod()->commit(); | 0 | ||||||||||||||||||
2161 | - | |||||||||||||||||||
2162 | QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||
2163 | QApplication::sendEvent(QApplicationPrivate::focus_widget, &focusAboutToChange); | - | ||||||||||||||||||
2164 | } never executed: end of block | 0 | ||||||||||||||||||
2165 | - | |||||||||||||||||||
2166 | QApplicationPrivate::active_window = window; | - | ||||||||||||||||||
2167 | - | |||||||||||||||||||
2168 | if (QApplicationPrivate::active_window) {
| 0 | ||||||||||||||||||
2169 | if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) {
| 0 | ||||||||||||||||||
2170 | const QWidgetList list = topLevelWidgets(); | - | ||||||||||||||||||
2171 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
QWidgetauto *w =: list.at(i);) { | ||||||||||||||||||||
2172 | if (w->isVisible() && w->isActiveWindow())
| 0 | ||||||||||||||||||
2173 | toBeActivated.append(w); never executed: toBeActivated.append(w); | 0 | ||||||||||||||||||
2174 | } never executed: end of block | 0 | ||||||||||||||||||
2175 | } else { never executed: end of block | 0 | ||||||||||||||||||
2176 | toBeActivated.append(QApplicationPrivate::active_window); | - | ||||||||||||||||||
2177 | } never executed: end of block | 0 | ||||||||||||||||||
2178 | - | |||||||||||||||||||
2179 | } | - | ||||||||||||||||||
2180 | - | |||||||||||||||||||
2181 | // first the activation/deactivation events | - | ||||||||||||||||||
2182 | QEvent activationChange(QEvent::ActivationChange); | - | ||||||||||||||||||
2183 | QEvent windowActivate(QEvent::WindowActivate); | - | ||||||||||||||||||
2184 | QEvent windowDeactivate(QEvent::WindowDeactivate); | - | ||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | for (int i = 0; i < toBeActivated.size(); ++i) {
| 0 | ||||||||||||||||||
2187 | QWidget *w = toBeActivated.at(i); | - | ||||||||||||||||||
2188 | sendSpontaneousEvent(w, &windowActivate); | - | ||||||||||||||||||
2189 | sendSpontaneousEvent(w, &activationChange); | - | ||||||||||||||||||
2190 | } never executed: end of block | 0 | ||||||||||||||||||
2191 | - | |||||||||||||||||||
2192 | for(int i = 0; i < toBeDeactivated.size(); ++i) {
| 0 | ||||||||||||||||||
2193 | QWidget *w = toBeDeactivated.at(i); | - | ||||||||||||||||||
2194 | sendSpontaneousEvent(w, &windowDeactivate); | - | ||||||||||||||||||
2195 | sendSpontaneousEvent(w, &activationChange); | - | ||||||||||||||||||
2196 | } never executed: end of block | 0 | ||||||||||||||||||
2197 | - | |||||||||||||||||||
2198 | if (QApplicationPrivate::popupWidgets == 0) { // !inPopupMode()
| 0 | ||||||||||||||||||
2199 | // then focus events | - | ||||||||||||||||||
2200 | if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) {
| 0 | ||||||||||||||||||
2201 | QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||
2202 | } else if (QApplicationPrivate::active_window) { never executed: end of block
| 0 | ||||||||||||||||||
2203 | QWidget *w = QApplicationPrivate::active_window->focusWidget(); | - | ||||||||||||||||||
2204 | if (w && w->isVisible() /*&& w->focusPolicy() != QWidget::NoFocus*/)
| 0 | ||||||||||||||||||
2205 | w->setFocus(Qt::ActiveWindowFocusReason); never executed: w->setFocus(Qt::ActiveWindowFocusReason); | 0 | ||||||||||||||||||
2206 | else { | - | ||||||||||||||||||
2207 | w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window, true); | - | ||||||||||||||||||
2208 | if (w) {
| 0 | ||||||||||||||||||
2209 | w->setFocus(Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||
2210 | } else { never executed: end of block | 0 | ||||||||||||||||||
2211 | // If the focus widget is not in the activate_window, clear the focus | - | ||||||||||||||||||
2212 | w = QApplicationPrivate::focus_widget; | - | ||||||||||||||||||
2213 | if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus)
| 0 | ||||||||||||||||||
2214 | QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason); never executed: QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason); | 0 | ||||||||||||||||||
2215 | else if (!QApplicationPrivate::active_window->isAncestorOf(w))
| 0 | ||||||||||||||||||
2216 | QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); never executed: QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); | 0 | ||||||||||||||||||
2217 | } never executed: end of block | 0 | ||||||||||||||||||
2218 | } | - | ||||||||||||||||||
2219 | } | - | ||||||||||||||||||
2220 | } never executed: end of block | 0 | ||||||||||||||||||
2221 | } never executed: end of block | 0 | ||||||||||||||||||
2222 | - | |||||||||||||||||||
2223 | QWidget *qt_tlw_for_window(QWindow *wnd) | - | ||||||||||||||||||
2224 | { | - | ||||||||||||||||||
2225 | // QTBUG-32177, wnd might be a QQuickView embedded via window container. | - | ||||||||||||||||||
2226 | while (wnd && !wnd->isTopLevel()) {
| 0 | ||||||||||||||||||
2227 | QWindow *parent = wnd->parent(); | - | ||||||||||||||||||
2228 | // Don't end up in windows not belonging to this application | - | ||||||||||||||||||
2229 | if (parent && parent->type() != Qt::ForeignWindow)
| 0 | ||||||||||||||||||
2230 | wnd = wnd->parent(); never executed: wnd = wnd->parent(); | 0 | ||||||||||||||||||
2231 | else | - | ||||||||||||||||||
2232 | break; never executed: break; | 0 | ||||||||||||||||||
2233 | } | - | ||||||||||||||||||
2234 | if (wnd) foreach{
| 0 | ||||||||||||||||||
2235 | const auto tlws = qApp->topLevelWidgets(); | - | ||||||||||||||||||
2236 | for (QWidget *tlw , qApp->topLevelWidgets()): tlws) { | - | ||||||||||||||||||
2237 | if (tlw->windowHandle() == wnd)
| 0 | ||||||||||||||||||
2238 | return tlw; never executed: return tlw; | 0 | ||||||||||||||||||
2239 | } never executed: end of block | 0 | ||||||||||||||||||
2240 | } never executed: end of block | 0 | ||||||||||||||||||
2241 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2242 | } | - | ||||||||||||||||||
2243 | - | |||||||||||||||||||
2244 | void QApplicationPrivate::notifyActiveWindowChange(QWindow *previous) | - | ||||||||||||||||||
2245 | { | - | ||||||||||||||||||
2246 | Q_UNUSED(previous); | - | ||||||||||||||||||
2247 | QWindow *wnd = QGuiApplicationPrivate::focus_window; | - | ||||||||||||||||||
2248 | if (inPopupMode()) // some delayed focus event to ignore | - | ||||||||||||||||||
2249 | return; | - | ||||||||||||||||||
2250 | QWidget *tlw = qt_tlw_for_window(wnd); | - | ||||||||||||||||||
2251 | QApplication::setActiveWindow(tlw); | - | ||||||||||||||||||
2252 | // QTBUG-37126, Active X controls may set the focus on native child widgets. | - | ||||||||||||||||||
2253 | if (wnd && tlw && wnd != tlw->windowHandle()) { | - | ||||||||||||||||||
2254 | if (QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(wnd)) | - | ||||||||||||||||||
2255 | if (QWidget *widget = widgetWindow->widget()) | - | ||||||||||||||||||
2256 | if (widget->inherits("QAxHostWidget")) | - | ||||||||||||||||||
2257 | widget->setFocus(Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||
2258 | } | - | ||||||||||||||||||
2259 | } | - | ||||||||||||||||||
2260 | - | |||||||||||||||||||
2261 | /*!internal | - | ||||||||||||||||||
2262 | * Helper function that returns the new focus widget, but does not set the focus reason. | - | ||||||||||||||||||
2263 | * Returns 0 if a new focus widget could not be found. | - | ||||||||||||||||||
2264 | * Shared with QGraphicsProxyWidgetPrivate::findFocusChild() | - | ||||||||||||||||||
2265 | */ | - | ||||||||||||||||||
2266 | QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool next, | - | ||||||||||||||||||
2267 | bool *wrappingOccurred) | - | ||||||||||||||||||
2268 | { | - | ||||||||||||||||||
2269 | uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus; | - | ||||||||||||||||||
2270 | - | |||||||||||||||||||
2271 | QWidget *f = toplevel->focusWidget(); | - | ||||||||||||||||||
2272 | if (!f) | - | ||||||||||||||||||
2273 | f = toplevel; | - | ||||||||||||||||||
2274 | - | |||||||||||||||||||
2275 | QWidget *w = f; | - | ||||||||||||||||||
2276 | QWidget *test = f->d_func()->focus_next; | - | ||||||||||||||||||
2277 | bool seenWindow = false; | - | ||||||||||||||||||
2278 | bool focusWidgetAfterWindow = false; | - | ||||||||||||||||||
2279 | while (test && test != f) { | - | ||||||||||||||||||
2280 | if (test->isWindow()) | - | ||||||||||||||||||
2281 | seenWindow = true; | - | ||||||||||||||||||
2282 | - | |||||||||||||||||||
2283 | if ((test->focusPolicy() & focus_flag) == focus_flag | - | ||||||||||||||||||
2284 | && !(test->d_func()->extra && test->d_func()->extra->focus_proxy) | - | ||||||||||||||||||
2285 | && test->isVisibleTo(toplevel) && test->isEnabled() | - | ||||||||||||||||||
2286 | && !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test)) | - | ||||||||||||||||||
2287 | && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))) { | - | ||||||||||||||||||
2288 | w = test; | - | ||||||||||||||||||
2289 | if (seenWindow) | - | ||||||||||||||||||
2290 | focusWidgetAfterWindow = true; | - | ||||||||||||||||||
2291 | if (next) | - | ||||||||||||||||||
2292 | break; | - | ||||||||||||||||||
2293 | } | - | ||||||||||||||||||
2294 | test = test->d_func()->focus_next; | - | ||||||||||||||||||
2295 | } | - | ||||||||||||||||||
2296 | - | |||||||||||||||||||
2297 | if (wrappingOccurred != 0) | - | ||||||||||||||||||
2298 | *wrappingOccurred = next ? focusWidgetAfterWindow : !focusWidgetAfterWindow; | - | ||||||||||||||||||
2299 | - | |||||||||||||||||||
2300 | if (w == f) { | - | ||||||||||||||||||
2301 | if (qt_in_tab_key_event) { | - | ||||||||||||||||||
2302 | w->window()->setAttribute(Qt::WA_KeyboardFocusChange); | - | ||||||||||||||||||
2303 | w->update(); | - | ||||||||||||||||||
2304 | } | - | ||||||||||||||||||
2305 | return 0; | - | ||||||||||||||||||
2306 | } | - | ||||||||||||||||||
2307 | return w; | - | ||||||||||||||||||
2308 | } | - | ||||||||||||||||||
2309 | - | |||||||||||||||||||
2310 | /*! | - | ||||||||||||||||||
2311 | \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF) | - | ||||||||||||||||||
2312 | \internal | - | ||||||||||||||||||
2313 | - | |||||||||||||||||||
2314 | Creates the proper Enter/Leave event when widget \a enter is entered and | - | ||||||||||||||||||
2315 | widget \a leave is left. | - | ||||||||||||||||||
2316 | */ | - | ||||||||||||||||||
2317 | void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF) | - | ||||||||||||||||||
2318 | { | - | ||||||||||||||||||
2319 | #if 0 | - | ||||||||||||||||||
2320 | if (leave) { | - | ||||||||||||||||||
2321 | QEvent e(QEvent::Leave); | - | ||||||||||||||||||
2322 | QApplication::sendEvent(leave, & e); | - | ||||||||||||||||||
2323 | } | - | ||||||||||||||||||
2324 | if (enter) { | - | ||||||||||||||||||
2325 | const QPoint windowPos = enter->window()->mapFromGlobal(globalPos); | - | ||||||||||||||||||
2326 | QEnterEvent e(enter->mapFromGlobal(globalPos), windowPos, globalPos); | - | ||||||||||||||||||
2327 | QApplication::sendEvent(enter, & e); | - | ||||||||||||||||||
2328 | } | - | ||||||||||||||||||
2329 | return; | - | ||||||||||||||||||
2330 | #endif | - | ||||||||||||||||||
2331 | - | |||||||||||||||||||
2332 | QWidget* w ;if ((!enter && !leave) || (enter == leave))
| 0 | ||||||||||||||||||
2333 | return; never executed: return; | 0 | ||||||||||||||||||
2334 | #ifdef ALIEN_DEBUG | - | ||||||||||||||||||
2335 | qDebug() << "QApplicationPrivate::dispatchEnterLeave, ENTER:" << enter << "LEAVE:" << leave; | - | ||||||||||||||||||
2336 | #endif | - | ||||||||||||||||||
2337 | QWidgetList leaveList; | - | ||||||||||||||||||
2338 | QWidgetList enterList; | - | ||||||||||||||||||
2339 | - | |||||||||||||||||||
2340 | bool sameWindow = leave && enter && leave->window() == enter->window();
| 0 | ||||||||||||||||||
2341 | if (leave && !sameWindow) {
| 0 | ||||||||||||||||||
2342 | auto *w = leave; | - | ||||||||||||||||||
2343 | do { | - | ||||||||||||||||||
2344 | leaveList.append(w); | - | ||||||||||||||||||
2345 | } while (!w->isWindow() && (w = w->parentWidget())); never executed: end of block
| 0 | ||||||||||||||||||
2346 | } never executed: end of block | 0 | ||||||||||||||||||
2347 | if (enter && !sameWindow) {
| 0 | ||||||||||||||||||
2348 | auto *w = enter; | - | ||||||||||||||||||
2349 | do { | - | ||||||||||||||||||
2350 | enterList.prependappend(w); | - | ||||||||||||||||||
2351 | } while (!w->isWindow() && (w = w->parentWidget())); never executed: end of block
| 0 | ||||||||||||||||||
2352 | } never executed: end of block | 0 | ||||||||||||||||||
2353 | if (sameWindow) {
| 0 | ||||||||||||||||||
2354 | int enterDepth = 0; | - | ||||||||||||||||||
2355 | int leaveDepth = 0; | - | ||||||||||||||||||
2356 | wauto *e = enter; | - | ||||||||||||||||||
2357 | while (!we->isWindow() && (we = we->parentWidget()))
| 0 | ||||||||||||||||||
2358 | enterDepth++; never executed: enterDepth++; | 0 | ||||||||||||||||||
2359 | wauto *l = leave; | - | ||||||||||||||||||
2360 | while (!wl->isWindow() && (wl = wl->parentWidget()))
| 0 | ||||||||||||||||||
2361 | leaveDepth++; never executed: leaveDepth++; | 0 | ||||||||||||||||||
2362 | QWidget* wenter = enter; | - | ||||||||||||||||||
2363 | QWidget* wleave = leave; | - | ||||||||||||||||||
2364 | while (enterDepth > leaveDepth) {
| 0 | ||||||||||||||||||
2365 | wenter = wenter->parentWidget(); | - | ||||||||||||||||||
2366 | enterDepth--; | - | ||||||||||||||||||
2367 | } never executed: end of block | 0 | ||||||||||||||||||
2368 | while (leaveDepth > enterDepth) {
| 0 | ||||||||||||||||||
2369 | wleave = wleave->parentWidget(); | - | ||||||||||||||||||
2370 | leaveDepth--; | - | ||||||||||||||||||
2371 | } never executed: end of block | 0 | ||||||||||||||||||
2372 | while (!wenter->isWindow() && wenter != wleave) {
| 0 | ||||||||||||||||||
2373 | wenter = wenter->parentWidget(); | - | ||||||||||||||||||
2374 | wleave = wleave->parentWidget(); | - | ||||||||||||||||||
2375 | } never executed: end of block | 0 | ||||||||||||||||||
2376 | - | |||||||||||||||||||
2377 | for (auto *w = leave; while (w != wleave) {; w = w->parentWidget())
| 0 | ||||||||||||||||||
2378 | leaveList.append(w); never executed: leaveList.append(w); | 0 | ||||||||||||||||||
2379 | - | |||||||||||||||||||
2380 | w = w->parentWidget();
| 0 | ||||||||||||||||||
}
| ||||||||||||||||||||
enterList.prepend(w);
| ||||||||||||||||||||
}
| ||||||||||||||||||||
2381 | enterList.append(w); never executed: enterList.append(w); | 0 | ||||||||||||||||||
2382 | } never executed: end of block | 0 | ||||||||||||||||||
2383 | - | |||||||||||||||||||
2384 | QEvent leaveEvent(QEvent::Leave); | - | ||||||||||||||||||
2385 | for (int i = 0; i < leaveList.size(); ++i) {
| 0 | ||||||||||||||||||
2386 | auto *w = leaveList.at(i); | - | ||||||||||||||||||
2387 | if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
| 0 | ||||||||||||||||||
2388 | QApplication::sendEvent(w, &leaveEvent); | - | ||||||||||||||||||
2389 | if (w->testAttribute(Qt::WA_Hover) &&
| 0 | ||||||||||||||||||
2390 | (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
| 0 | ||||||||||||||||||
2391 | Q_ASSERT(instance()); | - | ||||||||||||||||||
2392 | QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), w->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos), | - | ||||||||||||||||||
2393 | QApplication::keyboardModifiers()); | - | ||||||||||||||||||
2394 | qApp->d_func()->notify_helper(w, &he); | - | ||||||||||||||||||
2395 | } never executed: end of block | 0 | ||||||||||||||||||
2396 | } never executed: end of block | 0 | ||||||||||||||||||
2397 | } never executed: end of block | 0 | ||||||||||||||||||
2398 | if (!enterList.isEmpty()) {
| 0 | ||||||||||||||||||
2399 | // Guard against QGuiApplicationPrivate::lastCursorPosition initialized to qInf(), qInf(). | - | ||||||||||||||||||
2400 | const QPoint globalPos = qIsInf(globalPosF.x())
| 0 | ||||||||||||||||||
2401 | ? QPoint(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) | - | ||||||||||||||||||
2402 | : globalPosF.toPoint(); | - | ||||||||||||||||||
2403 | const QPoint windowPos = qAsConst(enterList.front).back()->window()->mapFromGlobal(globalPos); | - | ||||||||||||||||||
2404 | for (int iauto it = 0; i <enterList.sizecrbegin(), end = enterList.crend(); it != end; ++iit) {
| 0 | ||||||||||||||||||
2405 | auto *w = enterList.at(i);*it; | - | ||||||||||||||||||
2406 | if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
| 0 | ||||||||||||||||||
2407 | const QPointF localPos = w->mapFromGlobal(globalPos); | - | ||||||||||||||||||
2408 | QEnterEvent enterEvent(localPos, windowPos, globalPosF); | - | ||||||||||||||||||
2409 | QApplication::sendEvent(w, &enterEvent); | - | ||||||||||||||||||
2410 | if (w->testAttribute(Qt::WA_Hover) &&
| 0 | ||||||||||||||||||
2411 | (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
| 0 | ||||||||||||||||||
2412 | QHoverEvent he(QEvent::HoverEnter, localPos, QPoint(-1, -1), | - | ||||||||||||||||||
2413 | QApplication::keyboardModifiers()); | - | ||||||||||||||||||
2414 | qApp->d_func()->notify_helper(w, &he); | - | ||||||||||||||||||
2415 | } never executed: end of block | 0 | ||||||||||||||||||
2416 | } never executed: end of block | 0 | ||||||||||||||||||
2417 | } never executed: end of block | 0 | ||||||||||||||||||
2418 | } never executed: end of block | 0 | ||||||||||||||||||
2419 | - | |||||||||||||||||||
2420 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
2421 | // Update cursor for alien/graphics widgets. | - | ||||||||||||||||||
2422 | - | |||||||||||||||||||
2423 | const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
| 0 | ||||||||||||||||||
2424 | // Whenever we leave an alien widget on X11/QPA, we need to reset its nativeParentWidget()'s cursor. | - | ||||||||||||||||||
2425 | // This is not required on Windows as the cursor is reset on every single mouse move. | - | ||||||||||||||||||
2426 | QWidget *parentOfLeavingCursor = 0; | - | ||||||||||||||||||
2427 | for (int i = 0; i < leaveList.size(); ++i) {
| 0 | ||||||||||||||||||
2428 | auto *w = leaveList.at(i); | - | ||||||||||||||||||
2429 | if (!isAlien(w))
| 0 | ||||||||||||||||||
2430 | break; never executed: break; | 0 | ||||||||||||||||||
2431 | if (w->testAttribute(Qt::WA_SetCursor)) {
| 0 | ||||||||||||||||||
2432 | QWidget *parent = w->parentWidget(); | - | ||||||||||||||||||
2433 | while (parent && parent->d_func()->data.in_destructor)
| 0 | ||||||||||||||||||
2434 | parent = parent->parentWidget(); never executed: parent = parent->parentWidget(); | 0 | ||||||||||||||||||
2435 | parentOfLeavingCursor = parent; | - | ||||||||||||||||||
2436 | //continue looping, we need to find the downest alien widget with a cursor. | - | ||||||||||||||||||
2437 | // (downest on the screen) | - | ||||||||||||||||||
2438 | } never executed: end of block | 0 | ||||||||||||||||||
2439 | } never executed: end of block | 0 | ||||||||||||||||||
2440 | //check that we will not call qt_x11_enforce_cursor twice with the same native widget | - | ||||||||||||||||||
2441 | if (parentOfLeavingCursor && (!enterOnAlien
| 0 | ||||||||||||||||||
2442 | || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
| 0 | ||||||||||||||||||
2443 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
2444 | if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
| 0 | ||||||||||||||||||
2445 | #endif | - | ||||||||||||||||||
2446 | { | - | ||||||||||||||||||
2447 | if (enter == QApplication::desktop()) {
| 0 | ||||||||||||||||||
2448 | qt_qpa_set_cursor(enter, true); | - | ||||||||||||||||||
2449 | } else { never executed: end of block | 0 | ||||||||||||||||||
2450 | qt_qpa_set_cursor(parentOfLeavingCursor, true); | - | ||||||||||||||||||
2451 | } never executed: end of block | 0 | ||||||||||||||||||
2452 | } | - | ||||||||||||||||||
2453 | } never executed: end of block | 0 | ||||||||||||||||||
2454 | if (enterOnAlien) {
| 0 | ||||||||||||||||||
2455 | QWidget *cursorWidget = enter; | - | ||||||||||||||||||
2456 | while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
| 0 | ||||||||||||||||||
2457 | cursorWidget = cursorWidget->parentWidget(); never executed: cursorWidget = cursorWidget->parentWidget(); | 0 | ||||||||||||||||||
2458 | - | |||||||||||||||||||
2459 | if (!cursorWidget)
| 0 | ||||||||||||||||||
2460 | return; never executed: return; | 0 | ||||||||||||||||||
2461 | - | |||||||||||||||||||
2462 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
2463 | if (cursorWidget->window()->graphicsProxyWidget()) {
| 0 | ||||||||||||||||||
2464 | QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor()); | - | ||||||||||||||||||
2465 | } else never executed: end of block | 0 | ||||||||||||||||||
2466 | #endif | - | ||||||||||||||||||
2467 | { | - | ||||||||||||||||||
2468 | qt_qpa_set_cursor(cursorWidget, true); | - | ||||||||||||||||||
2469 | } never executed: end of block | 0 | ||||||||||||||||||
2470 | } | - | ||||||||||||||||||
2471 | #endif | - | ||||||||||||||||||
2472 | } never executed: end of block | 0 | ||||||||||||||||||
2473 | - | |||||||||||||||||||
2474 | /* exported for the benefit of testing tools */ | - | ||||||||||||||||||
2475 | Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop) | - | ||||||||||||||||||
2476 | { | - | ||||||||||||||||||
2477 | return QApplicationPrivate::tryModalHelper(widget, rettop); | - | ||||||||||||||||||
2478 | } | - | ||||||||||||||||||
2479 | - | |||||||||||||||||||
2480 | /*! \internal | - | ||||||||||||||||||
2481 | Returns \c true if \a widget is blocked by a modal window. | - | ||||||||||||||||||
2482 | */ | - | ||||||||||||||||||
2483 | bool QApplicationPrivate::isBlockedByModal(QWidget *widget) | - | ||||||||||||||||||
2484 | { | - | ||||||||||||||||||
2485 | widget = widget->window(); | - | ||||||||||||||||||
2486 | QWindow *window = widget->windowHandle(); | - | ||||||||||||||||||
2487 | return window && self->isWindowBlocked(window); | - | ||||||||||||||||||
2488 | } | - | ||||||||||||||||||
2489 | - | |||||||||||||||||||
2490 | bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const | - | ||||||||||||||||||
2491 | { | - | ||||||||||||||||||
2492 | QWindow *unused = 0; | - | ||||||||||||||||||
2493 | if (Q_UNLIKELY(!window))) {
| 0 | ||||||||||||||||||
2494 | qWarning().nospace() << "window == 0 passed."; | - | ||||||||||||||||||
2495 | return false; never executed: return false; | 0 | ||||||||||||||||||
2496 | } | - | ||||||||||||||||||
2497 | if (!blockingWindow)
| 0 | ||||||||||||||||||
2498 | blockingWindow = &unused; never executed: blockingWindow = &unused; | 0 | ||||||||||||||||||
2499 | - | |||||||||||||||||||
2500 | if (modalWindowList.isEmpty()) {
| 0 | ||||||||||||||||||
2501 | *blockingWindow = 0; | - | ||||||||||||||||||
2502 | return false; never executed: return false; | 0 | ||||||||||||||||||
2503 | } | - | ||||||||||||||||||
2504 | QWidget *popupWidget = QApplication::activePopupWidget(); | - | ||||||||||||||||||
2505 | QWindow *popupWindow = popupWidget ? popupWidget->windowHandle() : 0;
| 0 | ||||||||||||||||||
2506 | if (popupWindow == window || (!popupWindow && QWindowPrivate::get(window)->isPopup())) {
| 0 | ||||||||||||||||||
2507 | *blockingWindow = 0; | - | ||||||||||||||||||
2508 | return false; never executed: return false; | 0 | ||||||||||||||||||
2509 | } | - | ||||||||||||||||||
2510 | - | |||||||||||||||||||
2511 | for (int i = 0; i < modalWindowList.count(); ++i) {
| 0 | ||||||||||||||||||
2512 | QWindow *modalWindow = modalWindowList.at(i); | - | ||||||||||||||||||
2513 | - | |||||||||||||||||||
2514 | { | - | ||||||||||||||||||
2515 | // check if the modal window is our window or a (transient) parent of our window | - | ||||||||||||||||||
2516 | QWindow *w = window; | - | ||||||||||||||||||
2517 | while (w) {
| 0 | ||||||||||||||||||
2518 | if (w == modalWindow) {
| 0 | ||||||||||||||||||
2519 | *blockingWindow = 0; | - | ||||||||||||||||||
2520 | return false; never executed: return false; | 0 | ||||||||||||||||||
2521 | } | - | ||||||||||||||||||
2522 | QWindow *p = w->parent(); | - | ||||||||||||||||||
2523 | if (!p)
| 0 | ||||||||||||||||||
2524 | p = w->transientParent(); never executed: p = w->transientParent(); | 0 | ||||||||||||||||||
2525 | w = p; | - | ||||||||||||||||||
2526 | } never executed: end of block | 0 | ||||||||||||||||||
2527 | - | |||||||||||||||||||
2528 | // Embedded in-process windows are not visible in normal parent-child chain, | - | ||||||||||||||||||
2529 | // so check the native parent chain, too. | - | ||||||||||||||||||
2530 | const QPlatformWindow *platWin = window->handle(); | - | ||||||||||||||||||
2531 | const QPlatformWindow *modalPlatWin = modalWindow->handle(); | - | ||||||||||||||||||
2532 | if (platWin && modalPlatWin && platWin->isEmbedded(modalPlatWin))
| 0 | ||||||||||||||||||
2533 | return false; never executed: return false; | 0 | ||||||||||||||||||
2534 | } | - | ||||||||||||||||||
2535 | - | |||||||||||||||||||
2536 | Qt::WindowModality windowModality = modalWindow->modality(); | - | ||||||||||||||||||
2537 | QWidgetWindow *modalWidgetWindow = qobject_cast<QWidgetWindow *>(modalWindow); | - | ||||||||||||||||||
2538 | if (windowModality == Qt::NonModal) {
| 0 | ||||||||||||||||||
2539 | // determine the modality type if it hasn't been set on the | - | ||||||||||||||||||
2540 | // modalWindow's widget, this normally happens when waiting for a | - | ||||||||||||||||||
2541 | // native dialog. use WindowModal if we are the child of a group | - | ||||||||||||||||||
2542 | // leader; otherwise use ApplicationModal. | - | ||||||||||||||||||
2543 | QWidget *m = modalWidgetWindow ? modalWidgetWindow->widget() : 0;
| 0 | ||||||||||||||||||
2544 | while (m && !m->testAttribute(Qt::WA_GroupLeader)) {
| 0 | ||||||||||||||||||
2545 | m = m->parentWidget(); | - | ||||||||||||||||||
2546 | if (m)
| 0 | ||||||||||||||||||
2547 | m = m->window(); never executed: m = m->window(); | 0 | ||||||||||||||||||
2548 | } never executed: end of block | 0 | ||||||||||||||||||
2549 | windowModality = (m && m->testAttribute(Qt::WA_GroupLeader))
| 0 | ||||||||||||||||||
2550 | ? Qt::WindowModal | - | ||||||||||||||||||
2551 | : Qt::ApplicationModal; | - | ||||||||||||||||||
2552 | } never executed: end of block | 0 | ||||||||||||||||||
2553 | - | |||||||||||||||||||
2554 | switch (windowModality) { | - | ||||||||||||||||||
2555 | case Qt::ApplicationModal: never executed: case Qt::ApplicationModal: | 0 | ||||||||||||||||||
2556 | { | - | ||||||||||||||||||
2557 | QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(window); | - | ||||||||||||||||||
2558 | QWidget *groupLeaderForWidget = widgetWindow ? widgetWindow->widget() : 0;
| 0 | ||||||||||||||||||
2559 | while (groupLeaderForWidget && !groupLeaderForWidget->testAttribute(Qt::WA_GroupLeader))
| 0 | ||||||||||||||||||
2560 | groupLeaderForWidget = groupLeaderForWidget->parentWidget(); never executed: groupLeaderForWidget = groupLeaderForWidget->parentWidget(); | 0 | ||||||||||||||||||
2561 | - | |||||||||||||||||||
2562 | if (groupLeaderForWidget) {
| 0 | ||||||||||||||||||
2563 | // if \a widget has WA_GroupLeader, it can only be blocked by ApplicationModal children | - | ||||||||||||||||||
2564 | QWidget *m = modalWidgetWindow ? modalWidgetWindow->widget() : 0;
| 0 | ||||||||||||||||||
2565 | while (m && m != groupLeaderForWidget && !m->testAttribute(Qt::WA_GroupLeader))
| 0 | ||||||||||||||||||
2566 | m = m->parentWidget(); never executed: m = m->parentWidget(); | 0 | ||||||||||||||||||
2567 | if (m == groupLeaderForWidget) {
| 0 | ||||||||||||||||||
2568 | *blockingWindow = m->windowHandle(); | - | ||||||||||||||||||
2569 | return true; never executed: return true; | 0 | ||||||||||||||||||
2570 | } | - | ||||||||||||||||||
2571 | } else if (modalWindow != window) { never executed: end of block
| 0 | ||||||||||||||||||
2572 | *blockingWindow = modalWindow; | - | ||||||||||||||||||
2573 | return true; never executed: return true; | 0 | ||||||||||||||||||
2574 | } | - | ||||||||||||||||||
2575 | break; never executed: break; | 0 | ||||||||||||||||||
2576 | } | - | ||||||||||||||||||
2577 | case Qt::WindowModal: never executed: case Qt::WindowModal: | 0 | ||||||||||||||||||
2578 | { | - | ||||||||||||||||||
2579 | QWindow *w = window; | - | ||||||||||||||||||
2580 | do { | - | ||||||||||||||||||
2581 | QWindow *m = modalWindow; | - | ||||||||||||||||||
2582 | do { | - | ||||||||||||||||||
2583 | if (m == w) {
| 0 | ||||||||||||||||||
2584 | *blockingWindow = m; | - | ||||||||||||||||||
2585 | return true; never executed: return true; | 0 | ||||||||||||||||||
2586 | } | - | ||||||||||||||||||
2587 | QWindow *p = m->parent(); | - | ||||||||||||||||||
2588 | if (!p)
| 0 | ||||||||||||||||||
2589 | p = m->transientParent(); never executed: p = m->transientParent(); | 0 | ||||||||||||||||||
2590 | m = p; | - | ||||||||||||||||||
2591 | } while (m); never executed: end of block
| 0 | ||||||||||||||||||
2592 | QWindow *p = w->parent(); | - | ||||||||||||||||||
2593 | if (!p)
| 0 | ||||||||||||||||||
2594 | p = w->transientParent(); never executed: p = w->transientParent(); | 0 | ||||||||||||||||||
2595 | w = p; | - | ||||||||||||||||||
2596 | } while (w); never executed: end of block
| 0 | ||||||||||||||||||
2597 | break; never executed: break; | 0 | ||||||||||||||||||
2598 | } | - | ||||||||||||||||||
2599 | default: never executed: default: | 0 | ||||||||||||||||||
2600 | Q_ASSERT_X(false, "QApplication", "internal error, a modal window cannot be modeless"); | - | ||||||||||||||||||
2601 | break; never executed: break; | 0 | ||||||||||||||||||
2602 | } | - | ||||||||||||||||||
2603 | } | - | ||||||||||||||||||
2604 | *blockingWindow = 0; | - | ||||||||||||||||||
2605 | return false; never executed: return false; | 0 | ||||||||||||||||||
2606 | } | - | ||||||||||||||||||
2607 | - | |||||||||||||||||||
2608 | /*!\internal | - | ||||||||||||||||||
2609 | - | |||||||||||||||||||
2610 | Called from qapplication_\e{platform}.cpp, returns \c true | - | ||||||||||||||||||
2611 | if the widget should accept the event. | - | ||||||||||||||||||
2612 | */ | - | ||||||||||||||||||
2613 | bool QApplicationPrivate::tryModalHelper(QWidget *widget, QWidget **rettop) | - | ||||||||||||||||||
2614 | { | - | ||||||||||||||||||
2615 | QWidget *top = QApplication::activeModalWidget(); | - | ||||||||||||||||||
2616 | if (rettop) | - | ||||||||||||||||||
2617 | *rettop = top; | - | ||||||||||||||||||
2618 | - | |||||||||||||||||||
2619 | // the active popup widget always gets the input event | - | ||||||||||||||||||
2620 | if (QApplication::activePopupWidget()) | - | ||||||||||||||||||
2621 | return true; | - | ||||||||||||||||||
2622 | - | |||||||||||||||||||
2623 | return !isBlockedByModal(widget->window()); | - | ||||||||||||||||||
2624 | } | - | ||||||||||||||||||
2625 | - | |||||||||||||||||||
2626 | bool qt_try_modal(QWidget *widget, QEvent::Type type) | - | ||||||||||||||||||
2627 | { | - | ||||||||||||||||||
2628 | QWidget * top = 0; | - | ||||||||||||||||||
2629 | - | |||||||||||||||||||
2630 | if (QApplicationPrivate::tryModalHelper(widget, &top)) | - | ||||||||||||||||||
2631 | return true; | - | ||||||||||||||||||
2632 | - | |||||||||||||||||||
2633 | bool block_event = false; | - | ||||||||||||||||||
2634 | - | |||||||||||||||||||
2635 | switch (type) { | - | ||||||||||||||||||
2636 | #if 0 | - | ||||||||||||||||||
2637 | case QEvent::Focus: | - | ||||||||||||||||||
2638 | if (!static_cast<QWSFocusEvent*>(event)->simpleData.get_focus) | - | ||||||||||||||||||
2639 | break; | - | ||||||||||||||||||
2640 | // drop through | - | ||||||||||||||||||
2641 | #endif | - | ||||||||||||||||||
2642 | case QEvent::MouseButtonPress: // disallow mouse/key events | - | ||||||||||||||||||
2643 | case QEvent::MouseButtonRelease: | - | ||||||||||||||||||
2644 | case QEvent::MouseMove: | - | ||||||||||||||||||
2645 | case QEvent::KeyPress: | - | ||||||||||||||||||
2646 | case QEvent::KeyRelease: | - | ||||||||||||||||||
2647 | block_event = true; | - | ||||||||||||||||||
2648 | break; | - | ||||||||||||||||||
2649 | default: | - | ||||||||||||||||||
2650 | break; | - | ||||||||||||||||||
2651 | } | - | ||||||||||||||||||
2652 | - | |||||||||||||||||||
2653 | if (block_event && top && top->parentWidget() == 0) | - | ||||||||||||||||||
2654 | top->raise(); | - | ||||||||||||||||||
2655 | - | |||||||||||||||||||
2656 | return !block_event; | - | ||||||||||||||||||
2657 | } | - | ||||||||||||||||||
2658 | - | |||||||||||||||||||
2659 | bool QApplicationPrivate::modalState() | - | ||||||||||||||||||
2660 | { | - | ||||||||||||||||||
2661 | return !self->modalWindowList.isEmpty(); | - | ||||||||||||||||||
2662 | } | - | ||||||||||||||||||
2663 | - | |||||||||||||||||||
2664 | /* | - | ||||||||||||||||||
2665 | \internal | - | ||||||||||||||||||
2666 | */ | - | ||||||||||||||||||
2667 | QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, | - | ||||||||||||||||||
2668 | QPoint *pos, QEvent::Type type, | - | ||||||||||||||||||
2669 | Qt::MouseButtons buttons, QWidget *buttonDown, | - | ||||||||||||||||||
2670 | QWidget *alienWidget) | - | ||||||||||||||||||
2671 | { | - | ||||||||||||||||||
2672 | Q_ASSERT(candidate); | - | ||||||||||||||||||
2673 | - | |||||||||||||||||||
2674 | QWidget *mouseGrabber = QWidget::mouseGrabber(); | - | ||||||||||||||||||
2675 | if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease)) | - | ||||||||||||||||||
2676 | && !buttonDown && !mouseGrabber) { | - | ||||||||||||||||||
2677 | return 0; | - | ||||||||||||||||||
2678 | } | - | ||||||||||||||||||
2679 | - | |||||||||||||||||||
2680 | if (alienWidget && alienWidget->internalWinId()) | - | ||||||||||||||||||
2681 | alienWidget = 0; | - | ||||||||||||||||||
2682 | - | |||||||||||||||||||
2683 | QWidget *receiver = candidate; | - | ||||||||||||||||||
2684 | - | |||||||||||||||||||
2685 | if (!mouseGrabber) | - | ||||||||||||||||||
2686 | mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget; | - | ||||||||||||||||||
2687 | - | |||||||||||||||||||
2688 | if (mouseGrabber && mouseGrabber != candidate) { | - | ||||||||||||||||||
2689 | receiver = mouseGrabber; | - | ||||||||||||||||||
2690 | *pos = receiver->mapFromGlobal(candidate->mapToGlobal(windowPos)); | - | ||||||||||||||||||
2691 | #ifdef ALIEN_DEBUG | - | ||||||||||||||||||
2692 | qDebug() << " ** receiver adjusted to:" << receiver << "pos:" << pos; | - | ||||||||||||||||||
2693 | #endif | - | ||||||||||||||||||
2694 | } | - | ||||||||||||||||||
2695 | - | |||||||||||||||||||
2696 | return receiver; | - | ||||||||||||||||||
2697 | - | |||||||||||||||||||
2698 | } | - | ||||||||||||||||||
2699 | - | |||||||||||||||||||
2700 | /* | - | ||||||||||||||||||
2701 | \internal | - | ||||||||||||||||||
2702 | */ | - | ||||||||||||||||||
2703 | bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event, | - | ||||||||||||||||||
2704 | QWidget *alienWidget, QWidget *nativeWidget, | - | ||||||||||||||||||
2705 | QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver, | - | ||||||||||||||||||
2706 | bool spontaneous) | - | ||||||||||||||||||
2707 | { | - | ||||||||||||||||||
2708 | Q_ASSERT(receiver); | - | ||||||||||||||||||
2709 | Q_ASSERT(event); | - | ||||||||||||||||||
2710 | Q_ASSERT(nativeWidget); | - | ||||||||||||||||||
2711 | Q_ASSERT(buttonDown); | - | ||||||||||||||||||
2712 | - | |||||||||||||||||||
2713 | if (alienWidget && !isAlien(alienWidget)) | - | ||||||||||||||||||
2714 | alienWidget = 0; | - | ||||||||||||||||||
2715 | - | |||||||||||||||||||
2716 | QPointer<QWidget> receiverGuard = receiver; | - | ||||||||||||||||||
2717 | QPointer<QWidget> nativeGuard = nativeWidget; | - | ||||||||||||||||||
2718 | QPointer<QWidget> alienGuard = alienWidget; | - | ||||||||||||||||||
2719 | QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget(); | - | ||||||||||||||||||
2720 | - | |||||||||||||||||||
2721 | const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen); | - | ||||||||||||||||||
2722 | - | |||||||||||||||||||
2723 | bool widgetUnderMouse = QRectF(receiver->rect()).contains(event->localPos()); | - | ||||||||||||||||||
2724 | - | |||||||||||||||||||
2725 | // Clear the obsolete leaveAfterRelease value, if mouse button has been released but | - | ||||||||||||||||||
2726 | // leaveAfterRelease has not been updated. | - | ||||||||||||||||||
2727 | // This happens e.g. when modal dialog or popup is shown as a response to button click. | - | ||||||||||||||||||
2728 | if (leaveAfterRelease && !*buttonDown && !event->buttons()) | - | ||||||||||||||||||
2729 | leaveAfterRelease = 0; | - | ||||||||||||||||||
2730 | - | |||||||||||||||||||
2731 | if (*buttonDown) { | - | ||||||||||||||||||
2732 | if (!graphicsWidget) { | - | ||||||||||||||||||
2733 | // Register the widget that shall receive a leave event | - | ||||||||||||||||||
2734 | // after the last button is released. | - | ||||||||||||||||||
2735 | if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber()) | - | ||||||||||||||||||
2736 | leaveAfterRelease = *buttonDown; | - | ||||||||||||||||||
2737 | if (event->type() == QEvent::MouseButtonRelease && !event->buttons()) | - | ||||||||||||||||||
2738 | *buttonDown = 0; | - | ||||||||||||||||||
2739 | } | - | ||||||||||||||||||
2740 | } else if (lastMouseReceiver && widgetUnderMouse) { | - | ||||||||||||||||||
2741 | // Dispatch enter/leave if we move: | - | ||||||||||||||||||
2742 | // 1) from an alien widget to another alien widget or | - | ||||||||||||||||||
2743 | // from a native widget to an alien widget (first OR case) | - | ||||||||||||||||||
2744 | // 2) from an alien widget to a native widget (second OR case) | - | ||||||||||||||||||
2745 | if ((alienWidget && alienWidget != lastMouseReceiver) | - | ||||||||||||||||||
2746 | || (isAlien(lastMouseReceiver) && !alienWidget)) { | - | ||||||||||||||||||
2747 | if (activePopupWidget) { | - | ||||||||||||||||||
2748 | if (!QWidget::mouseGrabber()) | - | ||||||||||||||||||
2749 | dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->screenPos()); | - | ||||||||||||||||||
2750 | } else { | - | ||||||||||||||||||
2751 | dispatchEnterLeave(receiver, lastMouseReceiver, event->screenPos()); | - | ||||||||||||||||||
2752 | } | - | ||||||||||||||||||
2753 | - | |||||||||||||||||||
2754 | } | - | ||||||||||||||||||
2755 | } | - | ||||||||||||||||||
2756 | - | |||||||||||||||||||
2757 | #ifdef ALIEN_DEBUG | - | ||||||||||||||||||
2758 | qDebug() << "QApplicationPrivate::sendMouseEvent: receiver:" << receiver | - | ||||||||||||||||||
2759 | << "pos:" << event->pos() << "alien" << alienWidget << "button down" | - | ||||||||||||||||||
2760 | << *buttonDown << "last" << lastMouseReceiver << "leave after release" | - | ||||||||||||||||||
2761 | << leaveAfterRelease; | - | ||||||||||||||||||
2762 | #endif | - | ||||||||||||||||||
2763 | - | |||||||||||||||||||
2764 | // We need this quard in case someone opens a modal dialog / popup. If that's the case | - | ||||||||||||||||||
2765 | // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver. | - | ||||||||||||||||||
2766 | const bool wasLeaveAfterRelease = leaveAfterRelease != 0; | - | ||||||||||||||||||
2767 | bool result; | - | ||||||||||||||||||
2768 | if (spontaneous) | - | ||||||||||||||||||
2769 | result = QApplication::sendSpontaneousEvent(receiver, event); | - | ||||||||||||||||||
2770 | else | - | ||||||||||||||||||
2771 | result = QApplication::sendEvent(receiver, event); | - | ||||||||||||||||||
2772 | - | |||||||||||||||||||
2773 | if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease | - | ||||||||||||||||||
2774 | && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) { | - | ||||||||||||||||||
2775 | // Dispatch enter/leave if: | - | ||||||||||||||||||
2776 | // 1) the mouse grabber is an alien widget | - | ||||||||||||||||||
2777 | // 2) the button is released on an alien widget | - | ||||||||||||||||||
2778 | QWidget *enter = 0; | - | ||||||||||||||||||
2779 | if (nativeGuard) | - | ||||||||||||||||||
2780 | enter = alienGuard ? alienWidget : nativeWidget; | - | ||||||||||||||||||
2781 | else // The receiver is typically deleted on mouse release with drag'n'drop. | - | ||||||||||||||||||
2782 | enter = QApplication::widgetAt(event->globalPos()); | - | ||||||||||||||||||
2783 | dispatchEnterLeave(enter, leaveAfterRelease, event->screenPos()); | - | ||||||||||||||||||
2784 | leaveAfterRelease = 0; | - | ||||||||||||||||||
2785 | lastMouseReceiver = enter; | - | ||||||||||||||||||
2786 | } else if (!wasLeaveAfterRelease) { | - | ||||||||||||||||||
2787 | if (activePopupWidget) { | - | ||||||||||||||||||
2788 | if (!QWidget::mouseGrabber()) | - | ||||||||||||||||||
2789 | lastMouseReceiver = alienGuard ? alienWidget : (nativeGuard ? nativeWidget : 0); | - | ||||||||||||||||||
2790 | } else { | - | ||||||||||||||||||
2791 | lastMouseReceiver = receiverGuard ? receiver : QApplication::widgetAt(event->globalPos()); | - | ||||||||||||||||||
2792 | } | - | ||||||||||||||||||
2793 | } | - | ||||||||||||||||||
2794 | - | |||||||||||||||||||
2795 | return result; | - | ||||||||||||||||||
2796 | } | - | ||||||||||||||||||
2797 | - | |||||||||||||||||||
2798 | /* | - | ||||||||||||||||||
2799 | This function should only be called when the widget changes visibility, i.e. | - | ||||||||||||||||||
2800 | when the \a widget is shown, hidden or deleted. This function does nothing | - | ||||||||||||||||||
2801 | if the widget is a top-level or native, i.e. not an alien widget. In that | - | ||||||||||||||||||
2802 | case enter/leave events are genereated by the underlying windowing system. | - | ||||||||||||||||||
2803 | */ | - | ||||||||||||||||||
2804 | extern QPointer<QWidget> qt_last_mouse_receiver; | - | ||||||||||||||||||
2805 | extern QWidget *qt_button_down; | - | ||||||||||||||||||
2806 | void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget) | - | ||||||||||||||||||
2807 | { | - | ||||||||||||||||||
2808 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
2809 | if (!widget || widget->isWindow()) | - | ||||||||||||||||||
2810 | return; | - | ||||||||||||||||||
2811 | const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor; | - | ||||||||||||||||||
2812 | if (!widgetInShow && widget != qt_last_mouse_receiver) | - | ||||||||||||||||||
2813 | return; // Widget was not under the cursor when it was hidden/deleted. | - | ||||||||||||||||||
2814 | - | |||||||||||||||||||
2815 | if (widgetInShow && widget->parentWidget()->data->in_show) | - | ||||||||||||||||||
2816 | return; // Ingore recursive show. | - | ||||||||||||||||||
2817 | - | |||||||||||||||||||
2818 | QWidget *mouseGrabber = QWidget::mouseGrabber(); | - | ||||||||||||||||||
2819 | if (mouseGrabber && mouseGrabber != widget) | - | ||||||||||||||||||
2820 | return; // Someone else has the grab; enter/leave should not occur. | - | ||||||||||||||||||
2821 | - | |||||||||||||||||||
2822 | QWidget *tlw = widget->window(); | - | ||||||||||||||||||
2823 | if (tlw->data->in_destructor || tlw->data->is_closing) | - | ||||||||||||||||||
2824 | return; // Closing down the business. | - | ||||||||||||||||||
2825 | - | |||||||||||||||||||
2826 | if (widgetInShow && (!qt_last_mouse_receiver || qt_last_mouse_receiver->window() != tlw)) | - | ||||||||||||||||||
2827 | return; // Mouse cursor not inside the widget's top-level. | - | ||||||||||||||||||
2828 | - | |||||||||||||||||||
2829 | const QPoint globalPos(QCursor::pos()); | - | ||||||||||||||||||
2830 | QPoint windowPos = tlw->mapFromGlobal(globalPos); | - | ||||||||||||||||||
2831 | - | |||||||||||||||||||
2832 | // Find the current widget under the mouse. If this function was called from | - | ||||||||||||||||||
2833 | // the widget's destructor, we have to make sure childAt() doesn't take into | - | ||||||||||||||||||
2834 | // account widgets that are about to be destructed. | - | ||||||||||||||||||
2835 | QWidget *widgetUnderCursor = tlw->d_func()->childAt_helper(windowPos, widget->data->in_destructor); | - | ||||||||||||||||||
2836 | if (!widgetUnderCursor) | - | ||||||||||||||||||
2837 | widgetUnderCursor = tlw; | - | ||||||||||||||||||
2838 | QPoint pos = widgetUnderCursor->mapFrom(tlw, windowPos); | - | ||||||||||||||||||
2839 | - | |||||||||||||||||||
2840 | if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor)) | - | ||||||||||||||||||
2841 | return; // Mouse cursor not inside the widget or any of its children. | - | ||||||||||||||||||
2842 | - | |||||||||||||||||||
2843 | if (widget->data->in_destructor && qt_button_down == widget) | - | ||||||||||||||||||
2844 | qt_button_down = 0; | - | ||||||||||||||||||
2845 | - | |||||||||||||||||||
2846 | // Send enter/leave events followed by a mouse move on the entered widget. | - | ||||||||||||||||||
2847 | QMouseEvent e(QEvent::MouseMove, pos, windowPos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier); | - | ||||||||||||||||||
2848 | sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver); | - | ||||||||||||||||||
2849 | #endif // QT_NO_CURSOR | - | ||||||||||||||||||
2850 | } | - | ||||||||||||||||||
2851 | - | |||||||||||||||||||
2852 | /*! | - | ||||||||||||||||||
2853 | Returns the desktop widget (also called the root window). | - | ||||||||||||||||||
2854 | - | |||||||||||||||||||
2855 | The desktop may be composed of multiple screens, so it would be incorrect, | - | ||||||||||||||||||
2856 | for example, to attempt to \e center some widget in the desktop's geometry. | - | ||||||||||||||||||
2857 | QDesktopWidget has various functions for obtaining useful geometries upon | - | ||||||||||||||||||
2858 | the desktop, such as QDesktopWidget::screenGeometry() and | - | ||||||||||||||||||
2859 | QDesktopWidget::availableGeometry(). | - | ||||||||||||||||||
2860 | - | |||||||||||||||||||
2861 | On X11, it is also possible to draw on the desktop. | - | ||||||||||||||||||
2862 | */ | - | ||||||||||||||||||
2863 | QDesktopWidget *QApplication::desktop() | - | ||||||||||||||||||
2864 | { | - | ||||||||||||||||||
2865 | CHECK_QAPP_INSTANCE(Q_NULLPTR) | - | ||||||||||||||||||
2866 | if (!qt_desktopWidget || // not created yet | - | ||||||||||||||||||
2867 | !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away | - | ||||||||||||||||||
2868 | qt_desktopWidget = new QDesktopWidget(); | - | ||||||||||||||||||
2869 | } | - | ||||||||||||||||||
2870 | return qt_desktopWidget; | - | ||||||||||||||||||
2871 | } | - | ||||||||||||||||||
2872 | - | |||||||||||||||||||
2873 | /* | - | ||||||||||||||||||
2874 | Sets the time after which a drag should start to \a ms ms. | - | ||||||||||||||||||
2875 | - | |||||||||||||||||||
2876 | \sa startDragTime() | - | ||||||||||||||||||
2877 | */ | - | ||||||||||||||||||
2878 | - | |||||||||||||||||||
2879 | void QApplication::setStartDragTime(int ms) | - | ||||||||||||||||||
2880 | { | - | ||||||||||||||||||
2881 | QGuiApplication::styleHints()->setStartDragTime(ms); | - | ||||||||||||||||||
2882 | } | - | ||||||||||||||||||
2883 | - | |||||||||||||||||||
2884 | /*! | - | ||||||||||||||||||
2885 | \property QApplication::startDragTime | - | ||||||||||||||||||
2886 | \brief the time in milliseconds that a mouse button must be held down | - | ||||||||||||||||||
2887 | before a drag and drop operation will begin | - | ||||||||||||||||||
2888 | - | |||||||||||||||||||
2889 | If you support drag and drop in your application, and want to start a drag | - | ||||||||||||||||||
2890 | and drop operation after the user has held down a mouse button for a | - | ||||||||||||||||||
2891 | certain amount of time, you should use this property's value as the delay. | - | ||||||||||||||||||
2892 | - | |||||||||||||||||||
2893 | Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for | - | ||||||||||||||||||
2894 | starting a drag. | - | ||||||||||||||||||
2895 | - | |||||||||||||||||||
2896 | The default value is 500 ms. | - | ||||||||||||||||||
2897 | - | |||||||||||||||||||
2898 | \sa startDragDistance(), {Drag and Drop} | - | ||||||||||||||||||
2899 | */ | - | ||||||||||||||||||
2900 | - | |||||||||||||||||||
2901 | int QApplication::startDragTime() | - | ||||||||||||||||||
2902 | { | - | ||||||||||||||||||
2903 | return QGuiApplication::styleHints()->startDragTime(); | - | ||||||||||||||||||
2904 | } | - | ||||||||||||||||||
2905 | - | |||||||||||||||||||
2906 | /* | - | ||||||||||||||||||
2907 | Sets the distance after which a drag should start to \a l pixels. | - | ||||||||||||||||||
2908 | - | |||||||||||||||||||
2909 | \sa startDragDistance() | - | ||||||||||||||||||
2910 | */ | - | ||||||||||||||||||
2911 | - | |||||||||||||||||||
2912 | void QApplication::setStartDragDistance(int l) | - | ||||||||||||||||||
2913 | { | - | ||||||||||||||||||
2914 | QGuiApplication::styleHints()->setStartDragDistance(l); | - | ||||||||||||||||||
2915 | } | - | ||||||||||||||||||
2916 | - | |||||||||||||||||||
2917 | /*! | - | ||||||||||||||||||
2918 | \property QApplication::startDragDistance | - | ||||||||||||||||||
2919 | - | |||||||||||||||||||
2920 | If you support drag and drop in your application, and want to start a drag | - | ||||||||||||||||||
2921 | and drop operation after the user has moved the cursor a certain distance | - | ||||||||||||||||||
2922 | with a button held down, you should use this property's value as the | - | ||||||||||||||||||
2923 | minimum distance required. | - | ||||||||||||||||||
2924 | - | |||||||||||||||||||
2925 | For example, if the mouse position of the click is stored in \c startPos | - | ||||||||||||||||||
2926 | and the current position (e.g. in the mouse move event) is \c currentPos, | - | ||||||||||||||||||
2927 | you can find out if a drag should be started with code like this: | - | ||||||||||||||||||
2928 | - | |||||||||||||||||||
2929 | \snippet code/src_gui_kernel_qapplication.cpp 6 | - | ||||||||||||||||||
2930 | - | |||||||||||||||||||
2931 | Qt uses this value internally, e.g. in QFileDialog. | - | ||||||||||||||||||
2932 | - | |||||||||||||||||||
2933 | The default value (if the platform doesn't provide a different default) | - | ||||||||||||||||||
2934 | is 10 pixels. | - | ||||||||||||||||||
2935 | - | |||||||||||||||||||
2936 | \sa startDragTime(), QPoint::manhattanLength(), {Drag and Drop} | - | ||||||||||||||||||
2937 | */ | - | ||||||||||||||||||
2938 | - | |||||||||||||||||||
2939 | int QApplication::startDragDistance() | - | ||||||||||||||||||
2940 | { | - | ||||||||||||||||||
2941 | return QGuiApplication::styleHints()->startDragDistance(); | - | ||||||||||||||||||
2942 | } | - | ||||||||||||||||||
2943 | - | |||||||||||||||||||
2944 | /*! | - | ||||||||||||||||||
2945 | Enters the main event loop and waits until exit() is called, then returns | - | ||||||||||||||||||
2946 | the value that was set to exit() (which is 0 if exit() is called via | - | ||||||||||||||||||
2947 | quit()). | - | ||||||||||||||||||
2948 | - | |||||||||||||||||||
2949 | It is necessary to call this function to start event handling. The main | - | ||||||||||||||||||
2950 | event loop receives events from the window system and dispatches these to | - | ||||||||||||||||||
2951 | the application widgets. | - | ||||||||||||||||||
2952 | - | |||||||||||||||||||
2953 | Generally, no user interaction can take place before calling exec(). As a | - | ||||||||||||||||||
2954 | special case, modal widgets like QMessageBox can be used before calling | - | ||||||||||||||||||
2955 | exec(), because modal widgets call exec() to start a local event loop. | - | ||||||||||||||||||
2956 | - | |||||||||||||||||||
2957 | To make your application perform idle processing, i.e., executing a special | - | ||||||||||||||||||
2958 | function whenever there are no pending events, use a QTimer with 0 timeout. | - | ||||||||||||||||||
2959 | More advanced idle processing schemes can be achieved using processEvents(). | - | ||||||||||||||||||
2960 | - | |||||||||||||||||||
2961 | We recommend that you connect clean-up code to the | - | ||||||||||||||||||
2962 | \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your | - | ||||||||||||||||||
2963 | application's \c{main()} function. This is because, on some platforms the | - | ||||||||||||||||||
2964 | QApplication::exec() call may not return. For example, on the Windows | - | ||||||||||||||||||
2965 | platform, when the user logs off, the system terminates the process after Qt | - | ||||||||||||||||||
2966 | closes all top-level windows. Hence, there is \e{no guarantee} that the | - | ||||||||||||||||||
2967 | application will have time to exit its event loop and execute code at the | - | ||||||||||||||||||
2968 | end of the \c{main()} function, after the QApplication::exec() call. | - | ||||||||||||||||||
2969 | - | |||||||||||||||||||
2970 | \sa quitOnLastWindowClosed, QCoreApplication::quit(), QCoreApplication::exit(), | - | ||||||||||||||||||
2971 | QCoreApplication::processEvents(), QCoreApplication::exec() | - | ||||||||||||||||||
2972 | */ | - | ||||||||||||||||||
2973 | int QApplication::exec() | - | ||||||||||||||||||
2974 | { | - | ||||||||||||||||||
2975 | return QGuiApplication::exec(); | - | ||||||||||||||||||
2976 | } | - | ||||||||||||||||||
2977 | - | |||||||||||||||||||
2978 | bool QApplicationPrivate::shouldQuit() | - | ||||||||||||||||||
2979 | { | - | ||||||||||||||||||
2980 | /* if there is no non-withdrawn primary window left (except | - | ||||||||||||||||||
2981 | the ones without QuitOnClose), we emit the lastWindowClosed | - | ||||||||||||||||||
2982 | signal */ | - | ||||||||||||||||||
2983 | QWidgetList list = QApplication::topLevelWidgets(); | - | ||||||||||||||||||
2984 | QWindowList processedWindows; | - | ||||||||||||||||||
2985 | for (int i = 0; i < list.size(); ++i) { | - | ||||||||||||||||||
2986 | QWidget *w = list.at(i); | - | ||||||||||||||||||
2987 | if (QWindow *window = w->windowHandle()) { // Menus, popup widgets may not have a QWindow | - | ||||||||||||||||||
2988 | processedWindows.push_back(window); | - | ||||||||||||||||||
2989 | if (w->isVisible() && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) | - | ||||||||||||||||||
2990 | return false; | - | ||||||||||||||||||
2991 | } | - | ||||||||||||||||||
2992 | } | - | ||||||||||||||||||
2993 | return QGuiApplicationPrivate::shouldQuitInternal(processedWindows); | - | ||||||||||||||||||
2994 | } | - | ||||||||||||||||||
2995 | - | |||||||||||||||||||
2996 | static inline void closeAllPopups() | - | ||||||||||||||||||
2997 | { | - | ||||||||||||||||||
2998 | // Close all popups: In case some popup refuses to close, | - | ||||||||||||||||||
2999 | // we give up after 1024 attempts (to avoid an infinite loop). | - | ||||||||||||||||||
3000 | int maxiter = 1024; | - | ||||||||||||||||||
3001 | QWidget *popup; | - | ||||||||||||||||||
3002 | while ((popup = QApplication::activePopupWidget()) && maxiter--) | - | ||||||||||||||||||
3003 | popup->close(); | - | ||||||||||||||||||
3004 | } | - | ||||||||||||||||||
3005 | - | |||||||||||||||||||
3006 | /*! \reimp | - | ||||||||||||||||||
3007 | */ | - | ||||||||||||||||||
3008 | bool QApplication::notify(QObject *receiver, QEvent *e) | - | ||||||||||||||||||
3009 | { | - | ||||||||||||||||||
3010 | Q_D(QApplication); | - | ||||||||||||||||||
3011 | // no events are delivered after ~QCoreApplication() has started | - | ||||||||||||||||||
3012 | if (QApplicationPrivate::is_app_closing)
| 0 | ||||||||||||||||||
3013 | return true; never executed: return true; | 0 | ||||||||||||||||||
3014 | - | |||||||||||||||||||
3015 | if (Q_UNLIKELY(!receiver== 0))) { // serious error
| 0 | ||||||||||||||||||
3016 | qWarning("QApplication::notify: Unexpected null receiver"); | - | ||||||||||||||||||
3017 | return true; never executed: return true; | 0 | ||||||||||||||||||
3018 | } | - | ||||||||||||||||||
3019 | - | |||||||||||||||||||
3020 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
3021 | d->checkReceiverThread(receiver); | - | ||||||||||||||||||
3022 | #endif | - | ||||||||||||||||||
3023 | - | |||||||||||||||||||
3024 | if (receiver->isWindowType())
| 0 | ||||||||||||||||||
3025 | QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e); never executed: QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e); | 0 | ||||||||||||||||||
3026 | - | |||||||||||||||||||
3027 | if(e->spontaneous()) {
| 0 | ||||||||||||||||||
3028 | // Capture the current mouse and keyboard states. Doing so here is | - | ||||||||||||||||||
3029 | // required in order to support Qt Test synthesized events. Real mouse | - | ||||||||||||||||||
3030 | // and keyboard state updates from the platform plugin are managed by | - | ||||||||||||||||||
3031 | // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event(); | - | ||||||||||||||||||
3032 | switch (e->type()) { | - | ||||||||||||||||||
3033 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||
3034 | { | - | ||||||||||||||||||
3035 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||
3036 | QApplicationPrivate::modifier_buttons = me->modifiers(); | - | ||||||||||||||||||
3037 | QApplicationPrivate::mouse_buttons |= me->button(); | - | ||||||||||||||||||
3038 | break; never executed: break; | 0 | ||||||||||||||||||
3039 | } | - | ||||||||||||||||||
3040 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||
3041 | { | - | ||||||||||||||||||
3042 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||
3043 | QApplicationPrivate::modifier_buttons = me->modifiers(); | - | ||||||||||||||||||
3044 | QApplicationPrivate::mouse_buttons |= me->button(); | - | ||||||||||||||||||
3045 | break; never executed: break; | 0 | ||||||||||||||||||
3046 | } | - | ||||||||||||||||||
3047 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
3048 | { | - | ||||||||||||||||||
3049 | QMouseEvent *me = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||
3050 | QApplicationPrivate::modifier_buttons = me->modifiers(); | - | ||||||||||||||||||
3051 | QApplicationPrivate::mouse_buttons &= ~me->button(); | - | ||||||||||||||||||
3052 | break; never executed: break; | 0 | ||||||||||||||||||
3053 | } | - | ||||||||||||||||||
3054 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||
3055 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||
3056 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||
3057 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
3058 | case QEvent::Wheel: never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
3059 | #endif | - | ||||||||||||||||||
3060 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
3061 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
3062 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
3063 | #ifndef QT_NO_TABLETEVENT | - | ||||||||||||||||||
3064 | case QEvent::TabletMove: never executed: case QEvent::TabletMove: | 0 | ||||||||||||||||||
3065 | case QEvent::TabletPress: never executed: case QEvent::TabletPress: | 0 | ||||||||||||||||||
3066 | case QEvent::TabletRelease: never executed: case QEvent::TabletRelease: | 0 | ||||||||||||||||||
3067 | #endif | - | ||||||||||||||||||
3068 | { | - | ||||||||||||||||||
3069 | QInputEvent *ie = static_cast<QInputEvent*>(e); | - | ||||||||||||||||||
3070 | QApplicationPrivate::modifier_buttons = ie->modifiers(); | - | ||||||||||||||||||
3071 | break; never executed: break; | 0 | ||||||||||||||||||
3072 | } | - | ||||||||||||||||||
3073 | default: never executed: default: | 0 | ||||||||||||||||||
3074 | break; never executed: break; | 0 | ||||||||||||||||||
3075 | } | - | ||||||||||||||||||
3076 | } | - | ||||||||||||||||||
3077 | - | |||||||||||||||||||
3078 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
3079 | // walk through parents and check for gestures | - | ||||||||||||||||||
3080 | if (d->gestureManager) {
| 0 | ||||||||||||||||||
3081 | switch (e->type()) { | - | ||||||||||||||||||
3082 | case QEvent::Paint: never executed: case QEvent::Paint: | 0 | ||||||||||||||||||
3083 | case QEvent::MetaCall: never executed: case QEvent::MetaCall: | 0 | ||||||||||||||||||
3084 | case QEvent::DeferredDelete: never executed: case QEvent::DeferredDelete: | 0 | ||||||||||||||||||
3085 | case QEvent::DragEnter: case QEvent::DragMove: case QEvent::DragLeave: never executed: case QEvent::DragEnter: never executed: case QEvent::DragMove: never executed: case QEvent::DragLeave: | 0 | ||||||||||||||||||
3086 | case QEvent::Drop: case QEvent::DragResponse: never executed: case QEvent::Drop: never executed: case QEvent::DragResponse: | 0 | ||||||||||||||||||
3087 | case QEvent::ChildAdded: case QEvent::ChildPolished: never executed: case QEvent::ChildAdded: never executed: case QEvent::ChildPolished: | 0 | ||||||||||||||||||
3088 | case QEvent::ChildRemoved: never executed: case QEvent::ChildRemoved: | 0 | ||||||||||||||||||
3089 | case QEvent::UpdateRequest: never executed: case QEvent::UpdateRequest: | 0 | ||||||||||||||||||
3090 | case QEvent::UpdateLater: never executed: case QEvent::UpdateLater: | 0 | ||||||||||||||||||
3091 | case QEvent::LocaleChange: never executed: case QEvent::LocaleChange: | 0 | ||||||||||||||||||
3092 | case QEvent::Style: never executed: case QEvent::Style: | 0 | ||||||||||||||||||
3093 | case QEvent::IconDrag: never executed: case QEvent::IconDrag: | 0 | ||||||||||||||||||
3094 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||
3095 | case QEvent::GraphicsSceneDragEnter: never executed: case QEvent::GraphicsSceneDragEnter: | 0 | ||||||||||||||||||
3096 | case QEvent::GraphicsSceneDragMove: never executed: case QEvent::GraphicsSceneDragMove: | 0 | ||||||||||||||||||
3097 | case QEvent::GraphicsSceneDragLeave: never executed: case QEvent::GraphicsSceneDragLeave: | 0 | ||||||||||||||||||
3098 | case QEvent::GraphicsSceneDrop: never executed: case QEvent::GraphicsSceneDrop: | 0 | ||||||||||||||||||
3099 | case QEvent::DynamicPropertyChange: never executed: case QEvent::DynamicPropertyChange: | 0 | ||||||||||||||||||
3100 | case QEvent::NetworkReplyUpdated: never executed: case QEvent::NetworkReplyUpdated: | 0 | ||||||||||||||||||
3101 | break; never executed: break; | 0 | ||||||||||||||||||
3102 | default: never executed: default: | 0 | ||||||||||||||||||
3103 | if (d->gestureManager->thread() == QThread::currentThread()) {
| 0 | ||||||||||||||||||
3104 | if (receiver->isWidgetType()) {
| 0 | ||||||||||||||||||
3105 | if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
| 0 | ||||||||||||||||||
3106 | return true; never executed: return true; | 0 | ||||||||||||||||||
3107 | } else { never executed: end of block | 0 | ||||||||||||||||||
3108 | // a special case for events that go to QGesture objects. | - | ||||||||||||||||||
3109 | // We pass the object to the gesture manager and it'll figure | - | ||||||||||||||||||
3110 | // out if it's QGesture or not. | - | ||||||||||||||||||
3111 | if (d->gestureManager->filterEvent(receiver, e))
| 0 | ||||||||||||||||||
3112 | return true; never executed: return true; | 0 | ||||||||||||||||||
3113 | } never executed: end of block | 0 | ||||||||||||||||||
3114 | } | - | ||||||||||||||||||
3115 | break; never executed: break; | 0 | ||||||||||||||||||
3116 | } | - | ||||||||||||||||||
3117 | } | - | ||||||||||||||||||
3118 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||
3119 | - | |||||||||||||||||||
3120 | switch (e->type()) { | - | ||||||||||||||||||
3121 | case QEvent::ApplicationDeactivate: never executed: case QEvent::ApplicationDeactivate: | 0 | ||||||||||||||||||
3122 | // Close all popups (triggers when switching applications | - | ||||||||||||||||||
3123 | // by pressing ALT-TAB on Windows, which is not receive as key event. | - | ||||||||||||||||||
3124 | closeAllPopups(); | - | ||||||||||||||||||
3125 | break; never executed: break; | 0 | ||||||||||||||||||
3126 | case QEvent::Wheel: // User input and window activation makes tooltips sleep never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
3127 | case QEvent::ActivationChange: never executed: case QEvent::ActivationChange: | 0 | ||||||||||||||||||
3128 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||
3129 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||
3130 | case QEvent::FocusOut: never executed: case QEvent::FocusOut: | 0 | ||||||||||||||||||
3131 | case QEvent::FocusIn: never executed: case QEvent::FocusIn: | 0 | ||||||||||||||||||
3132 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||
3133 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
3134 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||
3135 | d->toolTipFallAsleep.stop(); | - | ||||||||||||||||||
3136 | // fall-through | - | ||||||||||||||||||
3137 | case QEvent::Leave: code before this statement never executed: case QEvent::Leave: never executed: case QEvent::Leave: | 0 | ||||||||||||||||||
3138 | d->toolTipWakeUp.stop(); | - | ||||||||||||||||||
3139 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||
3140 | break; never executed: break; | 0 | ||||||||||||||||||
3141 | } | - | ||||||||||||||||||
3142 | - | |||||||||||||||||||
3143 | switch (e->type()) { | - | ||||||||||||||||||
3144 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||
3145 | int key = static_cast<QKeyEvent*>(e)->key(); | - | ||||||||||||||||||
3146 | qt_in_tab_key_event = (key == Qt::Key_Backtab
| 0 | ||||||||||||||||||
3147 | || key == Qt::Key_Tab
| 0 | ||||||||||||||||||
3148 | || key == Qt::Key_Left
| 0 | ||||||||||||||||||
3149 | || key == Qt::Key_Up
| 0 | ||||||||||||||||||
3150 | || key == Qt::Key_Right
| 0 | ||||||||||||||||||
3151 | || key == Qt::Key_Down);
| 0 | ||||||||||||||||||
3152 | } | - | ||||||||||||||||||
3153 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||
3154 | break; never executed: break; | 0 | ||||||||||||||||||
3155 | } | - | ||||||||||||||||||
3156 | - | |||||||||||||||||||
3157 | bool res = false; | - | ||||||||||||||||||
3158 | if (!receiver->isWidgetType()) {
| 0 | ||||||||||||||||||
3159 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3160 | } else switch (e->type()) { never executed: end of block | 0 | ||||||||||||||||||
3161 | case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
3162 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||
3163 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||
3164 | { | - | ||||||||||||||||||
3165 | bool isWidget = receiver->isWidgetType(); | - | ||||||||||||||||||
3166 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3167 | const bool isGraphicsWidget = !isWidget && qobject_cast<QGraphicsWidget *>(receiver);
| 0 | ||||||||||||||||||
3168 | #endif | - | ||||||||||||||||||
3169 | QKeyEvent* key = static_cast<QKeyEvent*>(e); | - | ||||||||||||||||||
3170 | bool def = key->isAccepted(); | - | ||||||||||||||||||
3171 | QPointer<QObject> pr = receiver; | - | ||||||||||||||||||
3172 | while (receiver) {
| 0 | ||||||||||||||||||
3173 | if (def)
| 0 | ||||||||||||||||||
3174 | key->accept(); never executed: key->accept(); | 0 | ||||||||||||||||||
3175 | else | - | ||||||||||||||||||
3176 | key->ignore(); never executed: key->ignore(); | 0 | ||||||||||||||||||
3177 | QWidget *w = isWidget ? static_cast<QWidget *>(receiver) : 0;
| 0 | ||||||||||||||||||
3178 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3179 | QGraphicsWidget *gw = isGraphicsWidget ? static_cast<QGraphicsWidget *>(receiver) : 0;
| 0 | ||||||||||||||||||
3180 | #endif | - | ||||||||||||||||||
3181 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3182 | - | |||||||||||||||||||
3183 | if ((res && key->isAccepted())
| 0 | ||||||||||||||||||
3184 | /* | - | ||||||||||||||||||
3185 | QLineEdit will emit a signal on Key_Return, but | - | ||||||||||||||||||
3186 | ignore the event, and sometimes the connected | - | ||||||||||||||||||
3187 | slot deletes the QLineEdit (common in itemview | - | ||||||||||||||||||
3188 | delegates), so we have to check if the widget | - | ||||||||||||||||||
3189 | was destroyed even if the event was ignored (to | - | ||||||||||||||||||
3190 | prevent a crash) | - | ||||||||||||||||||
3191 | - | |||||||||||||||||||
3192 | note that we don't have to reset pw while | - | ||||||||||||||||||
3193 | propagating (because the original receiver will | - | ||||||||||||||||||
3194 | be destroyed if one of its ancestors is) | - | ||||||||||||||||||
3195 | */ | - | ||||||||||||||||||
3196 | || !pr
| 0 | ||||||||||||||||||
3197 | || (isWidget && (w->isWindow() || !w->parentWidget()))
| 0 | ||||||||||||||||||
3198 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3199 | || (isGraphicsWidget && (gw->isWindow() || !gw->parentWidget()))
| 0 | ||||||||||||||||||
3200 | #endif | - | ||||||||||||||||||
3201 | ) { | - | ||||||||||||||||||
3202 | break; never executed: break; | 0 | ||||||||||||||||||
3203 | } | - | ||||||||||||||||||
3204 | - | |||||||||||||||||||
3205 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3206 | receiver = w ? (QObject *)w->parentWidget() : (QObject *)gw->parentWidget();
| 0 | ||||||||||||||||||
3207 | #else | - | ||||||||||||||||||
3208 | receiver = w->parentWidget(); | - | ||||||||||||||||||
3209 | #endif | - | ||||||||||||||||||
3210 | } never executed: end of block | 0 | ||||||||||||||||||
3211 | qt_in_tab_key_event = false; | - | ||||||||||||||||||
3212 | } | - | ||||||||||||||||||
3213 | break; never executed: break; | 0 | ||||||||||||||||||
3214 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||
3215 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
3216 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||
3217 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||
3218 | { | - | ||||||||||||||||||
3219 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3220 | - | |||||||||||||||||||
3221 | QMouseEvent* mouse = static_cast<QMouseEvent*>(e); | - | ||||||||||||||||||
3222 | QPoint relpos = mouse->pos(); | - | ||||||||||||||||||
3223 | - | |||||||||||||||||||
3224 | if (e->spontaneous()) {
| 0 | ||||||||||||||||||
3225 | if (e->type() != QEvent::MouseMove)
| 0 | ||||||||||||||||||
3226 | QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); never executed: QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); | 0 | ||||||||||||||||||
3227 | - | |||||||||||||||||||
3228 | // ### Qt 5 These dynamic tool tips should be an OPT-IN feature. Some platforms | - | ||||||||||||||||||
3229 | // like OS X (probably others too), can optimize their views by not | - | ||||||||||||||||||
3230 | // dispatching mouse move events. We have attributes to control hover, | - | ||||||||||||||||||
3231 | // and mouse tracking, but as long as we are deciding to implement this | - | ||||||||||||||||||
3232 | // feature without choice of opting-in or out, you ALWAYS have to have | - | ||||||||||||||||||
3233 | // tracking enabled. Therefore, the other properties give a false sense of | - | ||||||||||||||||||
3234 | // performance enhancement. | - | ||||||||||||||||||
3235 | if (e->type() == QEvent::MouseMove && mouse->buttons() == 0
| 0 | ||||||||||||||||||
3236 | && w->rect().contains(relpos)) { // Outside due to mouse grab?
| 0 | ||||||||||||||||||
3237 | d->toolTipWidget = w; | - | ||||||||||||||||||
3238 | d->toolTipPos = relpos; | - | ||||||||||||||||||
3239 | d->toolTipGlobalPos = mouse->globalPos(); | - | ||||||||||||||||||
3240 | QStyle *s = d->toolTipWidget->style(); | - | ||||||||||||||||||
3241 | int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay, 0, d->toolTipWidget, 0); | - | ||||||||||||||||||
3242 | d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay, this); | - | ||||||||||||||||||
3243 | } never executed: end of block | 0 | ||||||||||||||||||
3244 | } never executed: end of block | 0 | ||||||||||||||||||
3245 | - | |||||||||||||||||||
3246 | bool eventAccepted = mouse->isAccepted(); | - | ||||||||||||||||||
3247 | - | |||||||||||||||||||
3248 | QPointer<QWidget> pw = w; | - | ||||||||||||||||||
3249 | while (w) {
| 0 | ||||||||||||||||||
3250 | QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), | - | ||||||||||||||||||
3251 | mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source()); | - | ||||||||||||||||||
3252 | me.spont = mouse->spontaneous(); | - | ||||||||||||||||||
3253 | me.setTimestamp(mouse->timestamp()); | - | ||||||||||||||||||
3254 | QGuiApplicationPrivate::setMouseEventFlags(&me, mouse->flags()); | - | ||||||||||||||||||
3255 | // throw away any mouse-tracking-only mouse events | - | ||||||||||||||||||
3256 | if (!w->hasMouseTracking()
| 0 | ||||||||||||||||||
3257 | && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
| 0 | ||||||||||||||||||
3258 | // but still send them through all application event filters (normally done by notify_helper) | - | ||||||||||||||||||
3259 | for (int i = 0; d->extraData && i < d->extraData->eventFilters.size(); ++i) {
| 0 | ||||||||||||||||||
3260 | QObject *obj = d->extraData->eventFilters.at(i); | - | ||||||||||||||||||
3261 | if (!obj)
| 0 | ||||||||||||||||||
3262 | continue; never executed: continue; | 0 | ||||||||||||||||||
3263 | if (Q_UNLIKELY(obj->d_func()->threadData != w->d_func()->threadData))) {
| 0 | ||||||||||||||||||
3264 | qWarning("QApplication: Object event filter cannot be in a different thread."); | - | ||||||||||||||||||
3265 | continue; never executed: continue; | 0 | ||||||||||||||||||
3266 | } | - | ||||||||||||||||||
3267 | if (obj->eventFilter(w, w == receiver ? mouse : &me))
| 0 | ||||||||||||||||||
3268 | break; never executed: break; | 0 | ||||||||||||||||||
3269 | } never executed: end of block | 0 | ||||||||||||||||||
3270 | res = true; | - | ||||||||||||||||||
3271 | } else { never executed: end of block | 0 | ||||||||||||||||||
3272 | w->setAttribute(Qt::WA_NoMouseReplay, false); | - | ||||||||||||||||||
3273 | res = d->notify_helper(w, w == receiver ? mouse : &me); | - | ||||||||||||||||||
3274 | e->spont = false; | - | ||||||||||||||||||
3275 | } never executed: end of block | 0 | ||||||||||||||||||
3276 | eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
| 0 | ||||||||||||||||||
3277 | if (res && eventAccepted)
| 0 | ||||||||||||||||||
3278 | break; never executed: break; | 0 | ||||||||||||||||||
3279 | if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3280 | break; never executed: break; | 0 | ||||||||||||||||||
3281 | relpos += w->pos(); | - | ||||||||||||||||||
3282 | w = w->parentWidget(); | - | ||||||||||||||||||
3283 | } never executed: end of block | 0 | ||||||||||||||||||
3284 | - | |||||||||||||||||||
3285 | mouse->setAccepted(eventAccepted); | - | ||||||||||||||||||
3286 | - | |||||||||||||||||||
3287 | if (e->type() == QEvent::MouseMove) {
| 0 | ||||||||||||||||||
3288 | if (!pw)
| 0 | ||||||||||||||||||
3289 | break; never executed: break; | 0 | ||||||||||||||||||
3290 | - | |||||||||||||||||||
3291 | w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3292 | relpos = mouse->pos(); | - | ||||||||||||||||||
3293 | QPoint diff = relpos - w->mapFromGlobal(d->hoverGlobalPos); | - | ||||||||||||||||||
3294 | while (w) {
| 0 | ||||||||||||||||||
3295 | if (w->testAttribute(Qt::WA_Hover) &&
| 0 | ||||||||||||||||||
3296 | (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
| 0 | ||||||||||||||||||
3297 | QHoverEvent he(QEvent::HoverMove, relpos, relpos - diff, mouse->modifiers()); | - | ||||||||||||||||||
3298 | d->notify_helper(w, &he); | - | ||||||||||||||||||
3299 | } never executed: end of block | 0 | ||||||||||||||||||
3300 | if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3301 | break; never executed: break; | 0 | ||||||||||||||||||
3302 | relpos += w->pos(); | - | ||||||||||||||||||
3303 | w = w->parentWidget(); | - | ||||||||||||||||||
3304 | } never executed: end of block | 0 | ||||||||||||||||||
3305 | } never executed: end of block | 0 | ||||||||||||||||||
3306 | - | |||||||||||||||||||
3307 | d->hoverGlobalPos = mouse->globalPos(); | - | ||||||||||||||||||
3308 | } | - | ||||||||||||||||||
3309 | break; never executed: break; | 0 | ||||||||||||||||||
3310 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
3311 | case QEvent::Wheel: never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
3312 | { | - | ||||||||||||||||||
3313 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3314 | - | |||||||||||||||||||
3315 | // QTBUG-40656, QTBUG-42731: ignore wheel events when a popup (QComboBox) is open. | - | ||||||||||||||||||
3316 | if (const QWidget *popup = QApplication::activePopupWidget()) {
| 0 | ||||||||||||||||||
3317 | if (w->window() != popup)
| 0 | ||||||||||||||||||
3318 | return true; never executed: return true; | 0 | ||||||||||||||||||
3319 | } never executed: end of block | 0 | ||||||||||||||||||
3320 | - | |||||||||||||||||||
3321 | QWheelEvent* wheel = static_cast<QWheelEvent*>(e); | - | ||||||||||||||||||
3322 | const bool spontaneous = wheel->spontaneous(); | - | ||||||||||||||||||
3323 | const Qt::ScrollPhase phase = wheel->phase(); | - | ||||||||||||||||||
3324 | - | |||||||||||||||||||
3325 | // Ideally, we should lock on a widget when it starts receiving wheel | - | ||||||||||||||||||
3326 | // events. This avoids other widgets to start receiving those events | - | ||||||||||||||||||
3327 | // as the mouse cursor hovers them. However, given the way common | - | ||||||||||||||||||
3328 | // wheeled mice work, there's no certain way of connecting different | - | ||||||||||||||||||
3329 | // wheel events as a stream. This results in the NoScrollPhase case, | - | ||||||||||||||||||
3330 | // where we just send the event from the original receiver and up its | - | ||||||||||||||||||
3331 | // hierarchy until the event gets accepted. | - | ||||||||||||||||||
3332 | // | - | ||||||||||||||||||
3333 | // In the case of more evolved input devices, like Apple's trackpad or | - | ||||||||||||||||||
3334 | // Magic Mouse, we receive the scroll phase information. This helps us | - | ||||||||||||||||||
3335 | // connect wheel events as a stream and therefore makes it easier to | - | ||||||||||||||||||
3336 | // lock on the widget onto which the scrolling was initiated. | - | ||||||||||||||||||
3337 | // | - | ||||||||||||||||||
3338 | // We assume that, when supported, the phase cycle follows the pattern: | - | ||||||||||||||||||
3339 | // | - | ||||||||||||||||||
3340 | // ScrollBegin (ScrollUpdate* ScrollEnd)+ | - | ||||||||||||||||||
3341 | // | - | ||||||||||||||||||
3342 | // This means that we can have scrolling sequences (starting with ScrollBegin) | - | ||||||||||||||||||
3343 | // or partial sequences (after a ScrollEnd and starting with ScrollUpdate). | - | ||||||||||||||||||
3344 | // If wheel_widget is null because it was deleted, we also take the same | - | ||||||||||||||||||
3345 | // code path as an initial sequence. | - | ||||||||||||||||||
3346 | if (phase == Qt::NoScrollPhase || phase == Qt::ScrollBegin || !QApplicationPrivate::wheel_widget) {
| 0 | ||||||||||||||||||
3347 | - | |||||||||||||||||||
3348 | // A system-generated ScrollBegin event starts a new user scrolling | - | ||||||||||||||||||
3349 | // sequence, so we reset wheel_widget in case no one accepts the event | - | ||||||||||||||||||
3350 | // or if we didn't get (or missed) a ScrollEnd previously. | - | ||||||||||||||||||
3351 | if (spontaneous && phase == Qt::ScrollBegin)
| 0 | ||||||||||||||||||
3352 | QApplicationPrivate::wheel_widget = Q_NULLPTR; never executed: QApplicationPrivate::wheel_widget = nullptr; | 0 | ||||||||||||||||||
3353 | - | |||||||||||||||||||
3354 | const QPoint &relpos = wheel->pos(); | - | ||||||||||||||||||
3355 | - | |||||||||||||||||||
3356 | if (spontaneous && (phase == Qt::NoScrollPhase || phase == Qt::ScrollUpdate))
| 0 | ||||||||||||||||||
3357 | QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); never executed: QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); | 0 | ||||||||||||||||||
3358 | - | |||||||||||||||||||
3359 | QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), | - | ||||||||||||||||||
3360 | wheel->modifiers(), phase, wheel->source(), wheel->inverted()); | - | ||||||||||||||||||
3361 | bool eventAccepted; | - | ||||||||||||||||||
3362 | while (w) {
| 0 | ||||||||||||||||||
3363 | we.spont = spontaneous && w == receiver;
| 0 | ||||||||||||||||||
3364 | we.ignore(); | - | ||||||||||||||||||
3365 | res = d->notify_helper(w, &we); | - | ||||||||||||||||||
3366 | eventAccepted = we.isAccepted(); | - | ||||||||||||||||||
3367 | if (res && eventAccepted) {
| 0 | ||||||||||||||||||
3368 | // A new scrolling sequence or partial sequence starts and w has accepted | - | ||||||||||||||||||
3369 | // the event. Therefore, we can set wheel_widget, but only if it's not | - | ||||||||||||||||||
3370 | // the end of a sequence. | - | ||||||||||||||||||
3371 | if (spontaneous && (phase == Qt::ScrollBegin || phase == Qt::ScrollUpdate) && QGuiApplicationPrivate::scrollNoPhaseAllowed)))
| 0 | ||||||||||||||||||
3372 | QApplicationPrivate::wheel_widget = w; never executed: QApplicationPrivate::wheel_widget = w; | 0 | ||||||||||||||||||
3373 | break; never executed: break; | 0 | ||||||||||||||||||
3374 | } | - | ||||||||||||||||||
3375 | if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3376 | break; never executed: break; | 0 | ||||||||||||||||||
3377 | - | |||||||||||||||||||
3378 | we.p += w->pos(); | - | ||||||||||||||||||
3379 | w = w->parentWidget(); | - | ||||||||||||||||||
3380 | } never executed: end of block | 0 | ||||||||||||||||||
3381 | wheel->setAccepted(eventAccepted); | - | ||||||||||||||||||
3382 | } else if (!spontaneous) { never executed: end of block
| 0 | ||||||||||||||||||
3383 | // wheel_widget may forward the wheel event to a delegate widget, | - | ||||||||||||||||||
3384 | // either directly or indirectly (e.g. QAbstractScrollArea will | - | ||||||||||||||||||
3385 | // forward to its QScrollBars through viewportEvent()). In that | - | ||||||||||||||||||
3386 | // case, the event will not be spontaneous but synthesized, so | - | ||||||||||||||||||
3387 | // we can send it straight to the receiver. | - | ||||||||||||||||||
3388 | d->notify_helper(w, wheel); | - | ||||||||||||||||||
3389 | } else { never executed: end of block | 0 | ||||||||||||||||||
3390 | // The phase is either ScrollUpdate or ScrollEnd, and wheel_widget | - | ||||||||||||||||||
3391 | // is set. Since it accepted the wheel event previously, we continue | - | ||||||||||||||||||
3392 | // sending those events until we get a ScrollEnd, which signifies | - | ||||||||||||||||||
3393 | // the end of the natural scrolling sequence. | - | ||||||||||||||||||
3394 | const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPos()); | - | ||||||||||||||||||
3395 | QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), | - | ||||||||||||||||||
3396 | wheel->modifiers(), wheel->phase(), wheel->source()); | - | ||||||||||||||||||
3397 | we.spont = true; | - | ||||||||||||||||||
3398 | we.ignore(); | - | ||||||||||||||||||
3399 | d->notify_helper(QApplicationPrivate::wheel_widget, &we); | - | ||||||||||||||||||
3400 | wheel->setAccepted(we.isAccepted()); | - | ||||||||||||||||||
3401 | if (phase == Qt::ScrollEnd)
| 0 | ||||||||||||||||||
3402 | QApplicationPrivate::wheel_widget = Q_NULLPTR; never executed: QApplicationPrivate::wheel_widget = nullptr; | 0 | ||||||||||||||||||
3403 | } never executed: end of block | 0 | ||||||||||||||||||
3404 | } | - | ||||||||||||||||||
3405 | break; never executed: break; | 0 | ||||||||||||||||||
3406 | #endif | - | ||||||||||||||||||
3407 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
3408 | case QEvent::ContextMenu: never executed: case QEvent::ContextMenu: | 0 | ||||||||||||||||||
3409 | { | - | ||||||||||||||||||
3410 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3411 | QContextMenuEvent *context = static_cast<QContextMenuEvent*>(e); | - | ||||||||||||||||||
3412 | QPoint relpos = context->pos(); | - | ||||||||||||||||||
3413 | bool eventAccepted = context->isAccepted(); | - | ||||||||||||||||||
3414 | while (w) {
| 0 | ||||||||||||||||||
3415 | QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers()); | - | ||||||||||||||||||
3416 | ce.spont = e->spontaneous(); | - | ||||||||||||||||||
3417 | res = d->notify_helper(w, w == receiver ? context : &ce); | - | ||||||||||||||||||
3418 | eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
| 0 | ||||||||||||||||||
3419 | e->spont = false; | - | ||||||||||||||||||
3420 | - | |||||||||||||||||||
3421 | if ((res && eventAccepted)
| 0 | ||||||||||||||||||
3422 | || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3423 | break; never executed: break; | 0 | ||||||||||||||||||
3424 | - | |||||||||||||||||||
3425 | relpos += w->pos(); | - | ||||||||||||||||||
3426 | w = w->parentWidget(); | - | ||||||||||||||||||
3427 | } never executed: end of block | 0 | ||||||||||||||||||
3428 | context->setAccepted(eventAccepted); | - | ||||||||||||||||||
3429 | } | - | ||||||||||||||||||
3430 | break; never executed: break; | 0 | ||||||||||||||||||
3431 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||
3432 | #ifndef QT_NO_TABLETEVENT | - | ||||||||||||||||||
3433 | case QEvent::TabletMove: never executed: case QEvent::TabletMove: | 0 | ||||||||||||||||||
3434 | case QEvent::TabletPress: never executed: case QEvent::TabletPress: | 0 | ||||||||||||||||||
3435 | case QEvent::TabletRelease: never executed: case QEvent::TabletRelease: | 0 | ||||||||||||||||||
3436 | { | - | ||||||||||||||||||
3437 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3438 | QTabletEvent *tablet = static_cast<QTabletEvent*>(e); | - | ||||||||||||||||||
3439 | QPointF relpos = tablet->posF(); | - | ||||||||||||||||||
3440 | bool eventAccepted = tablet->isAccepted(); | - | ||||||||||||||||||
3441 | while (w) {
| 0 | ||||||||||||||||||
3442 | QTabletEvent te(tablet->type(), relpos, tablet->globalPosF(), | - | ||||||||||||||||||
3443 | tablet->device(), tablet->pointerType(), | - | ||||||||||||||||||
3444 | tablet->pressure(), tablet->xTilt(), tablet->yTilt(), | - | ||||||||||||||||||
3445 | tablet->tangentialPressure(), tablet->rotation(), tablet->z(), | - | ||||||||||||||||||
3446 | tablet->modifiers(), tablet->uniqueId(), tablet->button(), tablet->buttons()); | - | ||||||||||||||||||
3447 | te.spont = e->spontaneous(); | - | ||||||||||||||||||
3448 | res = d->notify_helper(w, w == receiver ? tablet : &te); | - | ||||||||||||||||||
3449 | eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
| 0 | ||||||||||||||||||
3450 | e->spont = false; | - | ||||||||||||||||||
3451 | if ((res && eventAccepted)
| 0 | ||||||||||||||||||
3452 | || w->isWindow()
| 0 | ||||||||||||||||||
3453 | || w->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3454 | break; never executed: break; | 0 | ||||||||||||||||||
3455 | - | |||||||||||||||||||
3456 | relpos += w->pos(); | - | ||||||||||||||||||
3457 | w = w->parentWidget(); | - | ||||||||||||||||||
3458 | } never executed: end of block | 0 | ||||||||||||||||||
3459 | tablet->setAccepted(eventAccepted); | - | ||||||||||||||||||
3460 | qt_tabletChokeMouse = tablet->isAccepted();} | - | ||||||||||||||||||
3461 | break; never executed: break; | 0 | ||||||||||||||||||
3462 | #endif // QT_NO_TABLETEVENT | - | ||||||||||||||||||
3463 | - | |||||||||||||||||||
3464 | #if !defined(QT_NO_TOOLTIP) || !defined(QT_NO_WHATSTHIS) | - | ||||||||||||||||||
3465 | case QEvent::ToolTip: never executed: case QEvent::ToolTip: | 0 | ||||||||||||||||||
3466 | case QEvent::WhatsThis: never executed: case QEvent::WhatsThis: | 0 | ||||||||||||||||||
3467 | case QEvent::QueryWhatsThis: never executed: case QEvent::QueryWhatsThis: | 0 | ||||||||||||||||||
3468 | { | - | ||||||||||||||||||
3469 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3470 | QHelpEvent *help = static_cast<QHelpEvent*>(e); | - | ||||||||||||||||||
3471 | QPoint relpos = help->pos(); | - | ||||||||||||||||||
3472 | bool eventAccepted = help->isAccepted(); | - | ||||||||||||||||||
3473 | while (w) {
| 0 | ||||||||||||||||||
3474 | QHelpEvent he(help->type(), relpos, help->globalPos()); | - | ||||||||||||||||||
3475 | he.spont = e->spontaneous(); | - | ||||||||||||||||||
3476 | res = d->notify_helper(w, w == receiver ? help : &he); | - | ||||||||||||||||||
3477 | e->spont = false; | - | ||||||||||||||||||
3478 | eventAccepted = (w == receiver ? help : &he)->isAccepted();
| 0 | ||||||||||||||||||
3479 | if ((res && eventAccepted) || w->isWindow())
| 0 | ||||||||||||||||||
3480 | break; never executed: break; | 0 | ||||||||||||||||||
3481 | - | |||||||||||||||||||
3482 | relpos += w->pos(); | - | ||||||||||||||||||
3483 | w = w->parentWidget(); | - | ||||||||||||||||||
3484 | } never executed: end of block | 0 | ||||||||||||||||||
3485 | help->setAccepted(eventAccepted); | - | ||||||||||||||||||
3486 | } | - | ||||||||||||||||||
3487 | break; never executed: break; | 0 | ||||||||||||||||||
3488 | #endif | - | ||||||||||||||||||
3489 | #if !defined(QT_NO_STATUSTIP) || !defined(QT_NO_WHATSTHIS) | - | ||||||||||||||||||
3490 | case QEvent::StatusTip: never executed: case QEvent::StatusTip: | 0 | ||||||||||||||||||
3491 | case QEvent::WhatsThisClicked: never executed: case QEvent::WhatsThisClicked: | 0 | ||||||||||||||||||
3492 | { | - | ||||||||||||||||||
3493 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3494 | while (w) {
| 0 | ||||||||||||||||||
3495 | res = d->notify_helper(w, e); | - | ||||||||||||||||||
3496 | if ((res && e->isAccepted()) || w->isWindow())
| 0 | ||||||||||||||||||
3497 | break; never executed: break; | 0 | ||||||||||||||||||
3498 | w = w->parentWidget(); | - | ||||||||||||||||||
3499 | } never executed: end of block | 0 | ||||||||||||||||||
3500 | } | - | ||||||||||||||||||
3501 | break; never executed: break; | 0 | ||||||||||||||||||
3502 | #endif | - | ||||||||||||||||||
3503 | - | |||||||||||||||||||
3504 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
3505 | case QEvent::DragEnter: { never executed: case QEvent::DragEnter: | 0 | ||||||||||||||||||
3506 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3507 | QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent *>(e); | - | ||||||||||||||||||
3508 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3509 | // QGraphicsProxyWidget handles its own propagation, | - | ||||||||||||||||||
3510 | // and we must not change QDragManagers currentTarget. | - | ||||||||||||||||||
3511 | QWExtra *extra = w->window()->d_func()->extra; | - | ||||||||||||||||||
3512 | if (extra && extra->proxyWidget) {
| 0 | ||||||||||||||||||
3513 | res = d->notify_helper(w, dragEvent); | - | ||||||||||||||||||
3514 | break; never executed: break; | 0 | ||||||||||||||||||
3515 | } | - | ||||||||||||||||||
3516 | #endif | - | ||||||||||||||||||
3517 | while (w) {
| 0 | ||||||||||||||||||
3518 | if (w->isEnabled() && w->acceptDrops()) {
| 0 | ||||||||||||||||||
3519 | res = d->notify_helper(w, dragEvent); | - | ||||||||||||||||||
3520 | if (res && dragEvent->isAccepted()) {
| 0 | ||||||||||||||||||
3521 | QDragManager::self()->setCurrentTarget(w); | - | ||||||||||||||||||
3522 | break; never executed: break; | 0 | ||||||||||||||||||
3523 | } | - | ||||||||||||||||||
3524 | } never executed: end of block | 0 | ||||||||||||||||||
3525 | if (w->isWindow())
| 0 | ||||||||||||||||||
3526 | break; never executed: break; | 0 | ||||||||||||||||||
3527 | dragEvent->p = w->mapToParent(dragEvent->p.toPoint()); | - | ||||||||||||||||||
3528 | w = w->parentWidget(); | - | ||||||||||||||||||
3529 | } never executed: end of block | 0 | ||||||||||||||||||
3530 | } | - | ||||||||||||||||||
3531 | break; never executed: break; | 0 | ||||||||||||||||||
3532 | case QEvent::DragMove: never executed: case QEvent::DragMove: | 0 | ||||||||||||||||||
3533 | case QEvent::Drop: never executed: case QEvent::Drop: | 0 | ||||||||||||||||||
3534 | case QEvent::DragLeave: { never executed: case QEvent::DragLeave: | 0 | ||||||||||||||||||
3535 | QWidget* w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3536 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3537 | // QGraphicsProxyWidget handles its own propagation, | - | ||||||||||||||||||
3538 | // and we must not change QDragManagers currentTarget. | - | ||||||||||||||||||
3539 | QWExtra *extra = w->window()->d_func()->extra; | - | ||||||||||||||||||
3540 | bool isProxyWidget = extra && extra->proxyWidget;
| 0 | ||||||||||||||||||
3541 | if (!isProxyWidget)
| 0 | ||||||||||||||||||
3542 | #endif | - | ||||||||||||||||||
3543 | w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget()); never executed: w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget()); | 0 | ||||||||||||||||||
3544 | - | |||||||||||||||||||
3545 | if (!w) {
| 0 | ||||||||||||||||||
3546 | break; never executed: break; | 0 | ||||||||||||||||||
3547 | } | - | ||||||||||||||||||
3548 | if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
| 0 | ||||||||||||||||||
3549 | QDropEvent *dragEvent = static_cast<QDropEvent *>(e); | - | ||||||||||||||||||
3550 | QWidget *origReciver = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3551 | while (origReciver && w != origReciver) {
| 0 | ||||||||||||||||||
3552 | dragEvent->p = origReciver->mapToParent(dragEvent->p.toPoint()); | - | ||||||||||||||||||
3553 | origReciver = origReciver->parentWidget(); | - | ||||||||||||||||||
3554 | } never executed: end of block | 0 | ||||||||||||||||||
3555 | } never executed: end of block | 0 | ||||||||||||||||||
3556 | res = d->notify_helper(w, e); | - | ||||||||||||||||||
3557 | if (e->type() != QEvent::DragMove
| 0 | ||||||||||||||||||
3558 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
3559 | && !isProxyWidget
| 0 | ||||||||||||||||||
3560 | #endif | - | ||||||||||||||||||
3561 | ) | - | ||||||||||||||||||
3562 | QDragManager::self()->setCurrentTarget(0, e->type() == QEvent::Drop); never executed: QDragManager::self()->setCurrentTarget(0, e->type() == QEvent::Drop); | 0 | ||||||||||||||||||
3563 | } | - | ||||||||||||||||||
3564 | break; never executed: break; | 0 | ||||||||||||||||||
3565 | #endif | - | ||||||||||||||||||
3566 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
3567 | // Note: TouchUpdate and TouchEnd events are never propagated | - | ||||||||||||||||||
3568 | { | - | ||||||||||||||||||
3569 | QWidget *widget = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3570 | QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); | - | ||||||||||||||||||
3571 | bool eventAccepted = touchEvent->isAccepted(); | - | ||||||||||||||||||
3572 | bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); | - | ||||||||||||||||||
3573 | - | |||||||||||||||||||
3574 | if (acceptTouchEvents && e->spontaneous()) {
| 0 | ||||||||||||||||||
3575 | const QPoint localPos = touchEvent->touchPoints()[0].pos().toPoint(); | - | ||||||||||||||||||
3576 | QApplicationPrivate::giveFocusAccordingToFocusPolicy(widget, e, localPos); | - | ||||||||||||||||||
3577 | } never executed: end of block | 0 | ||||||||||||||||||
3578 | - | |||||||||||||||||||
3579 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
3580 | QPointer<QWidget> gesturePendingWidget; | - | ||||||||||||||||||
3581 | #endif | - | ||||||||||||||||||
3582 | - | |||||||||||||||||||
3583 | while (widget) {
| 0 | ||||||||||||||||||
3584 | // first, try to deliver the touch event | - | ||||||||||||||||||
3585 | acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); | - | ||||||||||||||||||
3586 | touchEvent->setTarget(widget); | - | ||||||||||||||||||
3587 | touchEvent->setAccepted(acceptTouchEvents); | - | ||||||||||||||||||
3588 | QPointer<QWidget> p = widget; | - | ||||||||||||||||||
3589 | res = acceptTouchEvents && d->notify_helper(widget, touchEvent);
| 0 | ||||||||||||||||||
3590 | eventAccepted = touchEvent->isAccepted(); | - | ||||||||||||||||||
3591 | if (p.isNull()) {
| 0 | ||||||||||||||||||
3592 | // widget was deleted | - | ||||||||||||||||||
3593 | widget = 0; | - | ||||||||||||||||||
3594 | } else { never executed: end of block | 0 | ||||||||||||||||||
3595 | widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted); | - | ||||||||||||||||||
3596 | } never executed: end of block | 0 | ||||||||||||||||||
3597 | touchEvent->spont = false; | - | ||||||||||||||||||
3598 | if (res && eventAccepted) {
| 0 | ||||||||||||||||||
3599 | // the first widget to accept the TouchBegin gets an implicit grab. | - | ||||||||||||||||||
3600 | d->activateImplicitTouchGrab(widget, touchEvent); | - | ||||||||||||||||||
3601 | break; never executed: break; | 0 | ||||||||||||||||||
3602 | } | - | ||||||||||||||||||
3603 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
3604 | if (gesturePendingWidget.isNull() && widget && QGestureManager::gesturePending(widget))
| 0 | ||||||||||||||||||
3605 | gesturePendingWidget = widget; never executed: gesturePendingWidget = widget; | 0 | ||||||||||||||||||
3606 | #endif | - | ||||||||||||||||||
3607 | if (p.isNull() || widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation))
| 0 | ||||||||||||||||||
3608 | break; never executed: break; | 0 | ||||||||||||||||||
3609 | - | |||||||||||||||||||
3610 | QPoint offset = widget->pos(); | - | ||||||||||||||||||
3611 | widget = widget->parentWidget(); | - | ||||||||||||||||||
3612 | touchEvent->setTarget(widget); | - | ||||||||||||||||||
3613 | for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) {
| 0 | ||||||||||||||||||
3614 | QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i]; | - | ||||||||||||||||||
3615 | QRectF rect = pt.rect(); | - | ||||||||||||||||||
3616 | rect.translate(offset); | - | ||||||||||||||||||
3617 | pt.d->rect = rect; | - | ||||||||||||||||||
3618 | pt.d->startPos = pt.startPos() + offset; | - | ||||||||||||||||||
3619 | pt.d->lastPos = pt.lastPos() + offset; | - | ||||||||||||||||||
3620 | } never executed: end of block | 0 | ||||||||||||||||||
3621 | } never executed: end of block | 0 | ||||||||||||||||||
3622 | - | |||||||||||||||||||
3623 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
3624 | if (!eventAccepted && !gesturePendingWidget.isNull()) {
| 0 | ||||||||||||||||||
3625 | // the first widget subscribed to a gesture gets an implicit grab | - | ||||||||||||||||||
3626 | d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent); | - | ||||||||||||||||||
3627 | } never executed: end of block | 0 | ||||||||||||||||||
3628 | #endif | - | ||||||||||||||||||
3629 | - | |||||||||||||||||||
3630 | touchEvent->setAccepted(eventAccepted); | - | ||||||||||||||||||
3631 | break; never executed: break; | 0 | ||||||||||||||||||
3632 | } | - | ||||||||||||||||||
3633 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
3634 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
3635 | { | - | ||||||||||||||||||
3636 | QWidget *widget = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3637 | // We may get here if the widget is subscribed to a gesture, | - | ||||||||||||||||||
3638 | // but has not accepted TouchBegin. Propagate touch events | - | ||||||||||||||||||
3639 | // only if TouchBegin has been accepted. | - | ||||||||||||||||||
3640 | if (widget && widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
| 0 | ||||||||||||||||||
3641 | res = d->notify_helper(widget, e); never executed: res = d->notify_helper(widget, e); | 0 | ||||||||||||||||||
3642 | break; never executed: break; | 0 | ||||||||||||||||||
3643 | } | - | ||||||||||||||||||
3644 | case QEvent::RequestSoftwareInputPanel: never executed: case QEvent::RequestSoftwareInputPanel: | 0 | ||||||||||||||||||
3645 | inputMethod()->show(); | - | ||||||||||||||||||
3646 | break; never executed: break; | 0 | ||||||||||||||||||
3647 | case QEvent::CloseSoftwareInputPanel: never executed: case QEvent::CloseSoftwareInputPanel: | 0 | ||||||||||||||||||
3648 | inputMethod()->hide(); | - | ||||||||||||||||||
3649 | break; never executed: break; | 0 | ||||||||||||||||||
3650 | - | |||||||||||||||||||
3651 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
3652 | case QEvent::NativeGesture: never executed: case QEvent::NativeGesture: | 0 | ||||||||||||||||||
3653 | { | - | ||||||||||||||||||
3654 | // only propagate the first gesture event (after the GID_BEGIN) | - | ||||||||||||||||||
3655 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3656 | while (w) {
| 0 | ||||||||||||||||||
3657 | e->ignore(); | - | ||||||||||||||||||
3658 | res = d->notify_helper(w, e); | - | ||||||||||||||||||
3659 | if ((res && e->isAccepted()) || w->isWindow())
| 0 | ||||||||||||||||||
3660 | break; never executed: break; | 0 | ||||||||||||||||||
3661 | w = w->parentWidget(); | - | ||||||||||||||||||
3662 | } never executed: end of block | 0 | ||||||||||||||||||
3663 | break; never executed: break; | 0 | ||||||||||||||||||
3664 | } | - | ||||||||||||||||||
3665 | case QEvent::Gesture: never executed: case QEvent::Gesture: | 0 | ||||||||||||||||||
3666 | case QEvent::GestureOverride: never executed: case QEvent::GestureOverride: | 0 | ||||||||||||||||||
3667 | { | - | ||||||||||||||||||
3668 | if (receiver->isWidgetType()) {
| 0 | ||||||||||||||||||
3669 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3670 | QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e); | - | ||||||||||||||||||
3671 | QList<QGesture *> allGestures = gestureEvent->gestures(); | - | ||||||||||||||||||
3672 | - | |||||||||||||||||||
3673 | bool eventAccepted = gestureEvent->isAccepted(); | - | ||||||||||||||||||
3674 | bool wasAccepted = eventAccepted; | - | ||||||||||||||||||
3675 | while (w) {
| 0 | ||||||||||||||||||
3676 | // send only gestures the widget expects | - | ||||||||||||||||||
3677 | QList<QGesture *> gestures; | - | ||||||||||||||||||
3678 | QWidgetPrivate *wd = w->d_func(); | - | ||||||||||||||||||
3679 | for (int i = 0; i < allGestures.size();) {
| 0 | ||||||||||||||||||
3680 | QGesture *g = allGestures.at(i); | - | ||||||||||||||||||
3681 | Qt::GestureType type = g->gestureType(); | - | ||||||||||||||||||
3682 | QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = | - | ||||||||||||||||||
3683 | wd->gestureContext.find(type); | - | ||||||||||||||||||
3684 | bool deliver = contextit != wd->gestureContext.end() &&
| 0 | ||||||||||||||||||
3685 | (g->state() == Qt::GestureStarted || w == receiver ||
| 0 | ||||||||||||||||||
3686 | (contextit.value() & Qt::ReceivePartialGestures));
| 0 | ||||||||||||||||||
3687 | if (deliver) {
| 0 | ||||||||||||||||||
3688 | allGestures.removeAt(i); | - | ||||||||||||||||||
3689 | gestures.append(g); | - | ||||||||||||||||||
3690 | } else { never executed: end of block | 0 | ||||||||||||||||||
3691 | ++i; | - | ||||||||||||||||||
3692 | } never executed: end of block | 0 | ||||||||||||||||||
3693 | } | - | ||||||||||||||||||
3694 | if (!gestures.isEmpty()) { // we have gestures for this w
| 0 | ||||||||||||||||||
3695 | QGestureEvent ge(gestures); | - | ||||||||||||||||||
3696 | ge.t = gestureEvent->t; | - | ||||||||||||||||||
3697 | ge.spont = gestureEvent->spont; | - | ||||||||||||||||||
3698 | ge.m_accept = wasAccepted; | - | ||||||||||||||||||
3699 | ge.m_accepted = gestureEvent->m_accepted; | - | ||||||||||||||||||
3700 | res = d->notify_helper(w, &ge); | - | ||||||||||||||||||
3701 | gestureEvent->spont = false; | - | ||||||||||||||||||
3702 | eventAccepted = ge.isAccepted(); | - | ||||||||||||||||||
3703 | for (int i = 0; i < gestures.size(); ++i) {
| 0 | ||||||||||||||||||
3704 | QGesture *g = gestures.at(i); | - | ||||||||||||||||||
3705 | // Ignore res [event return value] because handling of multiple gestures | - | ||||||||||||||||||
3706 | // packed into a single QEvent depends on not consuming the event | - | ||||||||||||||||||
3707 | if (eventAccepted || ge.isAccepted(g)) {
| 0 | ||||||||||||||||||
3708 | // if the gesture was accepted, mark the target widget for it | - | ||||||||||||||||||
3709 | gestureEvent->m_targetWidgets[g->gestureType()] = w; | - | ||||||||||||||||||
3710 | gestureEvent->setAccepted(g, true); | - | ||||||||||||||||||
3711 | } else { never executed: end of block | 0 | ||||||||||||||||||
3712 | // if the gesture was explicitly ignored by the application, | - | ||||||||||||||||||
3713 | // put it back so a parent can get it | - | ||||||||||||||||||
3714 | allGestures.append(g); | - | ||||||||||||||||||
3715 | } never executed: end of block | 0 | ||||||||||||||||||
3716 | } | - | ||||||||||||||||||
3717 | } never executed: end of block | 0 | ||||||||||||||||||
3718 | if (allGestures.isEmpty()) // everything delivered
| 0 | ||||||||||||||||||
3719 | break; never executed: break; | 0 | ||||||||||||||||||
3720 | if (w->isWindow())
| 0 | ||||||||||||||||||
3721 | break; never executed: break; | 0 | ||||||||||||||||||
3722 | w = w->parentWidget(); | - | ||||||||||||||||||
3723 | } never executed: end of block | 0 | ||||||||||||||||||
3724 | foreach (QGesture *g, allGestures) | - | ||||||||||||||||||
3725 | gestureEvent->setAccepted(g, false); never executed: gestureEvent->setAccepted(g, false); | 0 | ||||||||||||||||||
3726 | gestureEvent->m_accept = false; // to make sure we check individual gestures | - | ||||||||||||||||||
3727 | } else { never executed: end of block | 0 | ||||||||||||||||||
3728 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3729 | } never executed: end of block | 0 | ||||||||||||||||||
3730 | break; never executed: break; | 0 | ||||||||||||||||||
3731 | } | - | ||||||||||||||||||
3732 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||
3733 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
3734 | // Enable touch events on enter, disable on leave. | - | ||||||||||||||||||
3735 | typedef void (*RegisterTouchWindowFn)(QWindow *, bool); | - | ||||||||||||||||||
3736 | case QEvent::Enter: | - | ||||||||||||||||||
3737 | if (receiver->isWidgetType()) { | - | ||||||||||||||||||
3738 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3739 | if (w->testAttribute(Qt::WA_AcceptTouchEvents)) { | - | ||||||||||||||||||
3740 | RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn> | - | ||||||||||||||||||
3741 | (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow")); | - | ||||||||||||||||||
3742 | if (registerTouchWindow) | - | ||||||||||||||||||
3743 | registerTouchWindow(w->window()->windowHandle(), true); | - | ||||||||||||||||||
3744 | } | - | ||||||||||||||||||
3745 | } | - | ||||||||||||||||||
3746 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3747 | break; | - | ||||||||||||||||||
3748 | case QEvent::Leave: | - | ||||||||||||||||||
3749 | if (receiver->isWidgetType()) { | - | ||||||||||||||||||
3750 | QWidget *w = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3751 | if (w->testAttribute(Qt::WA_AcceptTouchEvents)) { | - | ||||||||||||||||||
3752 | RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn> | - | ||||||||||||||||||
3753 | (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow")); | - | ||||||||||||||||||
3754 | if (registerTouchWindow) | - | ||||||||||||||||||
3755 | registerTouchWindow(w->window()->windowHandle(), false); | - | ||||||||||||||||||
3756 | } | - | ||||||||||||||||||
3757 | } | - | ||||||||||||||||||
3758 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3759 | break; | - | ||||||||||||||||||
3760 | #endif | - | ||||||||||||||||||
3761 | default: never executed: default: | 0 | ||||||||||||||||||
3762 | res = d->notify_helper(receiver, e); | - | ||||||||||||||||||
3763 | break; never executed: break; | 0 | ||||||||||||||||||
3764 | } | - | ||||||||||||||||||
3765 | - | |||||||||||||||||||
3766 | return res; never executed: return res; | 0 | ||||||||||||||||||
3767 | } | - | ||||||||||||||||||
3768 | - | |||||||||||||||||||
3769 | bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) | - | ||||||||||||||||||
3770 | { | - | ||||||||||||||||||
3771 | // send to all application event filters | - | ||||||||||||||||||
3772 | if (threadRequiresCoreApplication() | - | ||||||||||||||||||
3773 | && receiver->d_func()->threadData->thread == mainThread() | - | ||||||||||||||||||
3774 | && sendThroughApplicationEventFilters(receiver, e)) | - | ||||||||||||||||||
3775 | return true; | - | ||||||||||||||||||
3776 | - | |||||||||||||||||||
3777 | if (receiver->isWidgetType()) { | - | ||||||||||||||||||
3778 | QWidget *widget = static_cast<QWidget *>(receiver); | - | ||||||||||||||||||
3779 | - | |||||||||||||||||||
3780 | #if !defined(Q_OS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR)) | - | ||||||||||||||||||
3781 | // toggle HasMouse widget state on enter and leave | - | ||||||||||||||||||
3782 | if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) && | - | ||||||||||||||||||
3783 | (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == widget->window())) | - | ||||||||||||||||||
3784 | widget->setAttribute(Qt::WA_UnderMouse, true); | - | ||||||||||||||||||
3785 | else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave) | - | ||||||||||||||||||
3786 | widget->setAttribute(Qt::WA_UnderMouse, false); | - | ||||||||||||||||||
3787 | #endif | - | ||||||||||||||||||
3788 | - | |||||||||||||||||||
3789 | if (QLayout *layout=widget->d_func()->layout) { | - | ||||||||||||||||||
3790 | layout->widgetEvent(e); | - | ||||||||||||||||||
3791 | } | - | ||||||||||||||||||
3792 | } | - | ||||||||||||||||||
3793 | - | |||||||||||||||||||
3794 | // send to all receiver event filters | - | ||||||||||||||||||
3795 | if (sendThroughObjectEventFilters(receiver, e)) | - | ||||||||||||||||||
3796 | return true; | - | ||||||||||||||||||
3797 | - | |||||||||||||||||||
3798 | // deliver the event | - | ||||||||||||||||||
3799 | bool consumed = receiver->event(e); | - | ||||||||||||||||||
3800 | QCoreApplicationPrivate::setEventSpontaneous(e, false); | - | ||||||||||||||||||
3801 | return consumed; | - | ||||||||||||||||||
3802 | } | - | ||||||||||||||||||
3803 | - | |||||||||||||||||||
3804 | bool QApplicationPrivate::inPopupMode() | - | ||||||||||||||||||
3805 | { | - | ||||||||||||||||||
3806 | return QApplicationPrivate::popupWidgets != 0; | - | ||||||||||||||||||
3807 | } | - | ||||||||||||||||||
3808 | - | |||||||||||||||||||
3809 | static void ungrabKeyboardForPopup(QWidget *popup) | - | ||||||||||||||||||
3810 | { | - | ||||||||||||||||||
3811 | if (QWidget::keyboardGrabber()) | - | ||||||||||||||||||
3812 | qt_widget_private(QWidget::keyboardGrabber())->stealKeyboardGrab(true); | - | ||||||||||||||||||
3813 | else | - | ||||||||||||||||||
3814 | qt_widget_private(popup)->stealKeyboardGrab(false); | - | ||||||||||||||||||
3815 | } | - | ||||||||||||||||||
3816 | - | |||||||||||||||||||
3817 | static void ungrabMouseForPopup(QWidget *popup) | - | ||||||||||||||||||
3818 | { | - | ||||||||||||||||||
3819 | if (QWidget::mouseGrabber()) | - | ||||||||||||||||||
3820 | qt_widget_private(QWidget::mouseGrabber())->stealMouseGrab(true); | - | ||||||||||||||||||
3821 | else | - | ||||||||||||||||||
3822 | qt_widget_private(popup)->stealMouseGrab(false); | - | ||||||||||||||||||
3823 | } | - | ||||||||||||||||||
3824 | - | |||||||||||||||||||
3825 | static bool popupGrabOk; | - | ||||||||||||||||||
3826 | - | |||||||||||||||||||
3827 | static void grabForPopup(QWidget *popup) | - | ||||||||||||||||||
3828 | { | - | ||||||||||||||||||
3829 | Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created)); | - | ||||||||||||||||||
3830 | popupGrabOk = qt_widget_private(popup)->stealKeyboardGrab(true); | - | ||||||||||||||||||
3831 | if (popupGrabOk) { | - | ||||||||||||||||||
3832 | popupGrabOk = qt_widget_private(popup)->stealMouseGrab(true); | - | ||||||||||||||||||
3833 | if (!popupGrabOk) { | - | ||||||||||||||||||
3834 | // transfer grab back to the keyboard grabber if any | - | ||||||||||||||||||
3835 | ungrabKeyboardForPopup(popup); | - | ||||||||||||||||||
3836 | } | - | ||||||||||||||||||
3837 | } | - | ||||||||||||||||||
3838 | } | - | ||||||||||||||||||
3839 | - | |||||||||||||||||||
3840 | extern QWidget *qt_button_down; | - | ||||||||||||||||||
3841 | extern QWidget *qt_popup_down; | - | ||||||||||||||||||
3842 | extern bool qt_replay_popup_mouse_event; | - | ||||||||||||||||||
3843 | - | |||||||||||||||||||
3844 | void QApplicationPrivate::closePopup(QWidget *popup) | - | ||||||||||||||||||
3845 | { | - | ||||||||||||||||||
3846 | if (!popupWidgets)
| 0 | ||||||||||||||||||
3847 | return; never executed: return; | 0 | ||||||||||||||||||
3848 | popupWidgets->removeAll(popup); | - | ||||||||||||||||||
3849 | - | |||||||||||||||||||
3850 | if (popup == qt_popup_down) {
| 0 | ||||||||||||||||||
3851 | qt_button_down = 0; | - | ||||||||||||||||||
3852 | qt_popup_down = 0; | - | ||||||||||||||||||
3853 | } never executed: end of block | 0 | ||||||||||||||||||
3854 | - | |||||||||||||||||||
3855 | if (QApplicationPrivate::popupWidgets->count() == 0) { // this was the last popup
| 0 | ||||||||||||||||||
3856 | delete QApplicationPrivate::popupWidgets; | - | ||||||||||||||||||
3857 | QApplicationPrivate::popupWidgets = 0; | - | ||||||||||||||||||
3858 | - | |||||||||||||||||||
3859 | if (popupGrabOk) {
| 0 | ||||||||||||||||||
3860 | popupGrabOk = false; | - | ||||||||||||||||||
3861 | - | |||||||||||||||||||
3862 | if (popup->geometry().contains(QPoint(QGuiApplicationPrivate::mousePressX,
| 0 | ||||||||||||||||||
3863 | QGuiApplicationPrivate::mousePressY))
| 0 | ||||||||||||||||||
3864 | || popup->testAttribute(Qt::WA_NoMouseReplay)) {
| 0 | ||||||||||||||||||
3865 | // mouse release event or inside | - | ||||||||||||||||||
3866 | qt_replay_popup_mouse_event = false; | - | ||||||||||||||||||
3867 | } else { // mouse press event never executed: end of block | 0 | ||||||||||||||||||
3868 | qt_replay_popup_mouse_event = true; | - | ||||||||||||||||||
3869 | } never executed: end of block | 0 | ||||||||||||||||||
3870 | - | |||||||||||||||||||
3871 | // transfer grab back to mouse grabber if any, otherwise release the grab | - | ||||||||||||||||||
3872 | ungrabMouseForPopup(popup); | - | ||||||||||||||||||
3873 | - | |||||||||||||||||||
3874 | // transfer grab back to keyboard grabber if any, otherwise release the grab | - | ||||||||||||||||||
3875 | ungrabKeyboardForPopup(popup); | - | ||||||||||||||||||
3876 | } never executed: end of block | 0 | ||||||||||||||||||
3877 | - | |||||||||||||||||||
3878 | if (active_window) {
| 0 | ||||||||||||||||||
3879 | if (QWidget *fw = active_window->focusWidget()) {
| 0 | ||||||||||||||||||
3880 | if (fw != QApplication::focusWidget()) {
| 0 | ||||||||||||||||||
3881 | fw->setFocus(Qt::PopupFocusReason); | - | ||||||||||||||||||
3882 | } else { never executed: end of block | 0 | ||||||||||||||||||
3883 | QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason); | - | ||||||||||||||||||
3884 | QCoreApplication::sendEvent(fw, &e); | - | ||||||||||||||||||
3885 | } never executed: end of block | 0 | ||||||||||||||||||
3886 | } | - | ||||||||||||||||||
3887 | } never executed: end of block | 0 | ||||||||||||||||||
3888 | - | |||||||||||||||||||
3889 | } else { never executed: end of block | 0 | ||||||||||||||||||
3890 | // A popup was closed, so the previous popup gets the focus. | - | ||||||||||||||||||
3891 | QWidget* aw = QApplicationPrivate::popupWidgets->lastconstLast(); | - | ||||||||||||||||||
3892 | if (QWidget *fw = aw->focusWidget())
| 0 | ||||||||||||||||||
3893 | fw->setFocus(Qt::PopupFocusReason); never executed: fw->setFocus(Qt::PopupFocusReason); | 0 | ||||||||||||||||||
3894 | - | |||||||||||||||||||
3895 | if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard
| 0 | ||||||||||||||||||
3896 | grabForPopup(aw); never executed: grabForPopup(aw); | 0 | ||||||||||||||||||
3897 | } never executed: end of block | 0 | ||||||||||||||||||
3898 | - | |||||||||||||||||||
3899 | } | - | ||||||||||||||||||
3900 | - | |||||||||||||||||||
3901 | int openPopupCount = 0; | - | ||||||||||||||||||
3902 | - | |||||||||||||||||||
3903 | void QApplicationPrivate::openPopup(QWidget *popup) | - | ||||||||||||||||||
3904 | { | - | ||||||||||||||||||
3905 | openPopupCount++; | - | ||||||||||||||||||
3906 | if (!popupWidgets) // create list | - | ||||||||||||||||||
3907 | popupWidgets = new QWidgetList; | - | ||||||||||||||||||
3908 | popupWidgets->append(popup); // add to end of list | - | ||||||||||||||||||
3909 | - | |||||||||||||||||||
3910 | if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard | - | ||||||||||||||||||
3911 | grabForPopup(popup); | - | ||||||||||||||||||
3912 | - | |||||||||||||||||||
3913 | // popups are not focus-handled by the window system (the first | - | ||||||||||||||||||
3914 | // popup grabbed the keyboard), so we have to do that manually: A | - | ||||||||||||||||||
3915 | // new popup gets the focus | - | ||||||||||||||||||
3916 | if (popup->focusWidget()) { | - | ||||||||||||||||||
3917 | popup->focusWidget()->setFocus(Qt::PopupFocusReason); | - | ||||||||||||||||||
3918 | } else if (popupWidgets->count() == 1) { // this was the first popup | - | ||||||||||||||||||
3919 | if (QWidget *fw = QApplication::focusWidget()) { | - | ||||||||||||||||||
3920 | QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason); | - | ||||||||||||||||||
3921 | QApplication::sendEvent(fw, &e); | - | ||||||||||||||||||
3922 | } | - | ||||||||||||||||||
3923 | } | - | ||||||||||||||||||
3924 | } | - | ||||||||||||||||||
3925 | - | |||||||||||||||||||
3926 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3927 | /*! | - | ||||||||||||||||||
3928 | Sets the kind of focus navigation Qt should use to \a mode. | - | ||||||||||||||||||
3929 | - | |||||||||||||||||||
3930 | This feature is available in Qt for Embedded Linux only. | - | ||||||||||||||||||
3931 | - | |||||||||||||||||||
3932 | \since 4.6 | - | ||||||||||||||||||
3933 | - | |||||||||||||||||||
3934 | \sa keypadNavigationEnabled() | - | ||||||||||||||||||
3935 | */ | - | ||||||||||||||||||
3936 | void QApplication::setNavigationMode(Qt::NavigationMode mode) | - | ||||||||||||||||||
3937 | { | - | ||||||||||||||||||
3938 | QApplicationPrivate::navigationMode = mode; | - | ||||||||||||||||||
3939 | } | - | ||||||||||||||||||
3940 | - | |||||||||||||||||||
3941 | /*! | - | ||||||||||||||||||
3942 | Returns what kind of focus navigation Qt is using. | - | ||||||||||||||||||
3943 | - | |||||||||||||||||||
3944 | This feature is available in Qt for Embedded Linux only. | - | ||||||||||||||||||
3945 | - | |||||||||||||||||||
3946 | \since 4.6 | - | ||||||||||||||||||
3947 | - | |||||||||||||||||||
3948 | \sa keypadNavigationEnabled() | - | ||||||||||||||||||
3949 | */ | - | ||||||||||||||||||
3950 | Qt::NavigationMode QApplication::navigationMode() | - | ||||||||||||||||||
3951 | { | - | ||||||||||||||||||
3952 | return QApplicationPrivate::navigationMode; | - | ||||||||||||||||||
3953 | } | - | ||||||||||||||||||
3954 | - | |||||||||||||||||||
3955 | /*! | - | ||||||||||||||||||
3956 | Sets whether Qt should use focus navigation suitable for use with a | - | ||||||||||||||||||
3957 | minimal keypad. | - | ||||||||||||||||||
3958 | - | |||||||||||||||||||
3959 | This feature is available in Qt for Embedded Linux, and Windows CE only. | - | ||||||||||||||||||
3960 | - | |||||||||||||||||||
3961 | \note On Windows CE this feature is disabled by default for touch device | - | ||||||||||||||||||
3962 | mkspecs. To enable keypad navigation, build Qt with | - | ||||||||||||||||||
3963 | QT_KEYPAD_NAVIGATION defined. | - | ||||||||||||||||||
3964 | - | |||||||||||||||||||
3965 | \deprecated | - | ||||||||||||||||||
3966 | - | |||||||||||||||||||
3967 | \sa setNavigationMode() | - | ||||||||||||||||||
3968 | */ | - | ||||||||||||||||||
3969 | void QApplication::setKeypadNavigationEnabled(bool enable) | - | ||||||||||||||||||
3970 | { | - | ||||||||||||||||||
3971 | if (enable) { | - | ||||||||||||||||||
3972 | QApplication::setNavigationMode(Qt::NavigationModeKeypadTabOrder); | - | ||||||||||||||||||
3973 | } else { | - | ||||||||||||||||||
3974 | QApplication::setNavigationMode(Qt::NavigationModeNone); | - | ||||||||||||||||||
3975 | } | - | ||||||||||||||||||
3976 | } | - | ||||||||||||||||||
3977 | - | |||||||||||||||||||
3978 | /*! | - | ||||||||||||||||||
3979 | Returns \c true if Qt is set to use keypad navigation; otherwise returns | - | ||||||||||||||||||
3980 | false. The default value is false. | - | ||||||||||||||||||
3981 | - | |||||||||||||||||||
3982 | This feature is available in Qt for Embedded Linux, and Windows CE only. | - | ||||||||||||||||||
3983 | - | |||||||||||||||||||
3984 | \note On Windows CE this feature is disabled by default for touch device | - | ||||||||||||||||||
3985 | mkspecs. To enable keypad navigation, build Qt with | - | ||||||||||||||||||
3986 | QT_KEYPAD_NAVIGATION defined. | - | ||||||||||||||||||
3987 | - | |||||||||||||||||||
3988 | \deprecated | - | ||||||||||||||||||
3989 | - | |||||||||||||||||||
3990 | \sa navigationMode() | - | ||||||||||||||||||
3991 | */ | - | ||||||||||||||||||
3992 | bool QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||
3993 | { | - | ||||||||||||||||||
3994 | return QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadTabOrder || | - | ||||||||||||||||||
3995 | QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadDirectional; | - | ||||||||||||||||||
3996 | } | - | ||||||||||||||||||
3997 | #endif | - | ||||||||||||||||||
3998 | - | |||||||||||||||||||
3999 | /*! | - | ||||||||||||||||||
4000 | \fn void QApplication::alert(QWidget *widget, int msec) | - | ||||||||||||||||||
4001 | \since 4.3 | - | ||||||||||||||||||
4002 | - | |||||||||||||||||||
4003 | Causes an alert to be shown for \a widget if the window is not the active | - | ||||||||||||||||||
4004 | window. The alert is shown for \a msec miliseconds. If \a msec is zero (the | - | ||||||||||||||||||
4005 | default), then the alert is shown indefinitely until the window becomes | - | ||||||||||||||||||
4006 | active again. | - | ||||||||||||||||||
4007 | - | |||||||||||||||||||
4008 | Currently this function does nothing on Qt for Embedded Linux. | - | ||||||||||||||||||
4009 | - | |||||||||||||||||||
4010 | On \macos, this works more at the application level and will cause the | - | ||||||||||||||||||
4011 | application icon to bounce in the dock. | - | ||||||||||||||||||
4012 | - | |||||||||||||||||||
4013 | On Windows, this causes the window's taskbar entry to flash for a time. If | - | ||||||||||||||||||
4014 | \a msec is zero, the flashing will stop and the taskbar entry will turn a | - | ||||||||||||||||||
4015 | different color (currently orange). | - | ||||||||||||||||||
4016 | - | |||||||||||||||||||
4017 | On X11, this will cause the window to be marked as "demands attention", the | - | ||||||||||||||||||
4018 | window must not be hidden (i.e. not have hide() called on it, but be | - | ||||||||||||||||||
4019 | visible in some sort of way) in order for this to work. | - | ||||||||||||||||||
4020 | */ | - | ||||||||||||||||||
4021 | void QApplication::alert(QWidget *widget, int duration) | - | ||||||||||||||||||
4022 | { | - | ||||||||||||||||||
4023 | if (widget) {
| 0 | ||||||||||||||||||
4024 | if (widget->window()->isActiveWindow() && !(widget->window()->windowState() & Qt::WindowMinimized))
| 0 | ||||||||||||||||||
4025 | return; never executed: return; | 0 | ||||||||||||||||||
4026 | if (QWindow *window= QApplicationPrivate::windowForWidget(widget))
| 0 | ||||||||||||||||||
4027 | window->alert(duration); never executed: window->alert(duration); | 0 | ||||||||||||||||||
4028 | } else { never executed: end of block | 0 | ||||||||||||||||||
4029 | foreachconst auto topLevels = topLevelWidgets(); | - | ||||||||||||||||||
4030 | for (QWidget *topLevel , topLevelWidgets()): topLevels) | - | ||||||||||||||||||
4031 | QApplication::alert(topLevel, duration); never executed: QApplication::alert(topLevel, duration); | 0 | ||||||||||||||||||
4032 | } never executed: end of block | 0 | ||||||||||||||||||
4033 | } | - | ||||||||||||||||||
4034 | - | |||||||||||||||||||
4035 | /*! | - | ||||||||||||||||||
4036 | \property QApplication::cursorFlashTime | - | ||||||||||||||||||
4037 | \brief the text cursor's flash (blink) time in milliseconds | - | ||||||||||||||||||
4038 | - | |||||||||||||||||||
4039 | The flash time is the time required to display, invert and restore the | - | ||||||||||||||||||
4040 | caret display. Usually the text cursor is displayed for half the cursor | - | ||||||||||||||||||
4041 | flash time, then hidden for the same amount of time, but this may vary. | - | ||||||||||||||||||
4042 | - | |||||||||||||||||||
4043 | The default value on X11 is 1000 milliseconds. On Windows, the | - | ||||||||||||||||||
4044 | \uicontrol{Control Panel} value is used and setting this property sets the cursor | - | ||||||||||||||||||
4045 | flash time for all applications. | - | ||||||||||||||||||
4046 | - | |||||||||||||||||||
4047 | We recommend that widgets do not cache this value as it may change at any | - | ||||||||||||||||||
4048 | time if the user changes the global desktop settings. | - | ||||||||||||||||||
4049 | - | |||||||||||||||||||
4050 | \note This property may hold a negative value, for instance if cursor | - | ||||||||||||||||||
4051 | blinking is disabled. | - | ||||||||||||||||||
4052 | */ | - | ||||||||||||||||||
4053 | void QApplication::setCursorFlashTime(int msecs) | - | ||||||||||||||||||
4054 | { | - | ||||||||||||||||||
4055 | QGuiApplication::styleHints()->setCursorFlashTime(msecs); | - | ||||||||||||||||||
4056 | } | - | ||||||||||||||||||
4057 | - | |||||||||||||||||||
4058 | int QApplication::cursorFlashTime() | - | ||||||||||||||||||
4059 | { | - | ||||||||||||||||||
4060 | return QGuiApplication::styleHints()->cursorFlashTime(); | - | ||||||||||||||||||
4061 | } | - | ||||||||||||||||||
4062 | - | |||||||||||||||||||
4063 | /*! | - | ||||||||||||||||||
4064 | \property QApplication::doubleClickInterval | - | ||||||||||||||||||
4065 | \brief the time limit in milliseconds that distinguishes a double click | - | ||||||||||||||||||
4066 | from two consecutive mouse clicks | - | ||||||||||||||||||
4067 | - | |||||||||||||||||||
4068 | The default value on X11 is 400 milliseconds. On Windows and Mac OS, the | - | ||||||||||||||||||
4069 | operating system's value is used. | - | ||||||||||||||||||
4070 | */ | - | ||||||||||||||||||
4071 | void QApplication::setDoubleClickInterval(int ms) | - | ||||||||||||||||||
4072 | { | - | ||||||||||||||||||
4073 | QGuiApplication::styleHints()->setMouseDoubleClickInterval(ms); | - | ||||||||||||||||||
4074 | } | - | ||||||||||||||||||
4075 | - | |||||||||||||||||||
4076 | int QApplication::doubleClickInterval() | - | ||||||||||||||||||
4077 | { | - | ||||||||||||||||||
4078 | return QGuiApplication::styleHints()->mouseDoubleClickInterval(); | - | ||||||||||||||||||
4079 | } | - | ||||||||||||||||||
4080 | - | |||||||||||||||||||
4081 | /*! | - | ||||||||||||||||||
4082 | \fn QApplication::keyboardInputDirection() | - | ||||||||||||||||||
4083 | \since 4.2 | - | ||||||||||||||||||
4084 | \deprecated | - | ||||||||||||||||||
4085 | - | |||||||||||||||||||
4086 | Returns the current keyboard input direction. Replaced with QInputMethod::inputDirection() | - | ||||||||||||||||||
4087 | \sa QInputMethod::inputDirection() | - | ||||||||||||||||||
4088 | */ | - | ||||||||||||||||||
4089 | - | |||||||||||||||||||
4090 | /*! | - | ||||||||||||||||||
4091 | \property QApplication::keyboardInputInterval | - | ||||||||||||||||||
4092 | \brief the time limit in milliseconds that distinguishes a key press | - | ||||||||||||||||||
4093 | from two consecutive key presses | - | ||||||||||||||||||
4094 | \since 4.2 | - | ||||||||||||||||||
4095 | - | |||||||||||||||||||
4096 | The default value on X11 is 400 milliseconds. On Windows and Mac OS, the | - | ||||||||||||||||||
4097 | operating system's value is used. | - | ||||||||||||||||||
4098 | */ | - | ||||||||||||||||||
4099 | void QApplication::setKeyboardInputInterval(int ms) | - | ||||||||||||||||||
4100 | { | - | ||||||||||||||||||
4101 | QGuiApplication::styleHints()->setKeyboardInputInterval(ms); | - | ||||||||||||||||||
4102 | } | - | ||||||||||||||||||
4103 | - | |||||||||||||||||||
4104 | int QApplication::keyboardInputInterval() | - | ||||||||||||||||||
4105 | { | - | ||||||||||||||||||
4106 | return QGuiApplication::styleHints()->keyboardInputInterval(); | - | ||||||||||||||||||
4107 | } | - | ||||||||||||||||||
4108 | - | |||||||||||||||||||
4109 | /*! | - | ||||||||||||||||||
4110 | \property QApplication::wheelScrollLines | - | ||||||||||||||||||
4111 | \brief the number of lines to scroll a widget, when the | - | ||||||||||||||||||
4112 | mouse wheel is rotated. | - | ||||||||||||||||||
4113 | - | |||||||||||||||||||
4114 | If the value exceeds the widget's number of visible lines, the widget | - | ||||||||||||||||||
4115 | should interpret the scroll operation as a single \e{page up} or | - | ||||||||||||||||||
4116 | \e{page down}. If the widget is an \l{QAbstractItemView}{item view class}, | - | ||||||||||||||||||
4117 | then the result of scrolling one \e line depends on the setting of the | - | ||||||||||||||||||
4118 | widget's \l{QAbstractItemView::verticalScrollMode()}{scroll mode}. Scroll | - | ||||||||||||||||||
4119 | one \e line can mean \l{QAbstractItemView::ScrollPerItem}{scroll one item} | - | ||||||||||||||||||
4120 | or \l{QAbstractItemView::ScrollPerPixel}{scroll one pixel}. | - | ||||||||||||||||||
4121 | - | |||||||||||||||||||
4122 | By default, this property has a value of 3. | - | ||||||||||||||||||
4123 | */ | - | ||||||||||||||||||
4124 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
4125 | int QApplication::wheelScrollLines() | - | ||||||||||||||||||
4126 | { | - | ||||||||||||||||||
4127 | return QApplicationPrivate::wheel_scroll_lines; | - | ||||||||||||||||||
4128 | } | - | ||||||||||||||||||
4129 | - | |||||||||||||||||||
4130 | void QApplication::setWheelScrollLines(int lines) | - | ||||||||||||||||||
4131 | { | - | ||||||||||||||||||
4132 | QApplicationPrivate::wheel_scroll_lines = lines; | - | ||||||||||||||||||
4133 | } | - | ||||||||||||||||||
4134 | #endif | - | ||||||||||||||||||
4135 | - | |||||||||||||||||||
4136 | static inline int uiEffectToFlag(Qt::UIEffect effect) | - | ||||||||||||||||||
4137 | { | - | ||||||||||||||||||
4138 | switch (effect) { | - | ||||||||||||||||||
4139 | case Qt::UI_General: | - | ||||||||||||||||||
4140 | return QPlatformTheme::GeneralUiEffect; | - | ||||||||||||||||||
4141 | case Qt::UI_AnimateMenu: | - | ||||||||||||||||||
4142 | return QPlatformTheme::AnimateMenuUiEffect; | - | ||||||||||||||||||
4143 | case Qt::UI_FadeMenu: | - | ||||||||||||||||||
4144 | return QPlatformTheme::FadeMenuUiEffect; | - | ||||||||||||||||||
4145 | case Qt::UI_AnimateCombo: | - | ||||||||||||||||||
4146 | return QPlatformTheme::AnimateComboUiEffect; | - | ||||||||||||||||||
4147 | case Qt::UI_AnimateTooltip: | - | ||||||||||||||||||
4148 | return QPlatformTheme::AnimateTooltipUiEffect; | - | ||||||||||||||||||
4149 | case Qt::UI_FadeTooltip: | - | ||||||||||||||||||
4150 | return QPlatformTheme::FadeTooltipUiEffect; | - | ||||||||||||||||||
4151 | case Qt::UI_AnimateToolBox: | - | ||||||||||||||||||
4152 | return QPlatformTheme::AnimateToolBoxUiEffect; | - | ||||||||||||||||||
4153 | } | - | ||||||||||||||||||
4154 | return 0; | - | ||||||||||||||||||
4155 | } | - | ||||||||||||||||||
4156 | - | |||||||||||||||||||
4157 | /*! | - | ||||||||||||||||||
4158 | \fn void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) | - | ||||||||||||||||||
4159 | - | |||||||||||||||||||
4160 | Enables the UI effect \a effect if \a enable is true, otherwise the effect | - | ||||||||||||||||||
4161 | will not be used. | - | ||||||||||||||||||
4162 | - | |||||||||||||||||||
4163 | \note All effects are disabled on screens running at less than 16-bit color | - | ||||||||||||||||||
4164 | depth. | - | ||||||||||||||||||
4165 | - | |||||||||||||||||||
4166 | \sa isEffectEnabled(), Qt::UIEffect, setDesktopSettingsAware() | - | ||||||||||||||||||
4167 | */ | - | ||||||||||||||||||
4168 | void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) | - | ||||||||||||||||||
4169 | { | - | ||||||||||||||||||
4170 | int effectFlags = uiEffectToFlag(effect); | - | ||||||||||||||||||
4171 | if (enable) { | - | ||||||||||||||||||
4172 | if (effectFlags & QPlatformTheme::FadeMenuUiEffect) | - | ||||||||||||||||||
4173 | effectFlags |= QPlatformTheme::AnimateMenuUiEffect; | - | ||||||||||||||||||
4174 | if (effectFlags & QPlatformTheme::FadeTooltipUiEffect) | - | ||||||||||||||||||
4175 | effectFlags |= QPlatformTheme::AnimateTooltipUiEffect; | - | ||||||||||||||||||
4176 | QApplicationPrivate::enabledAnimations |= effectFlags; | - | ||||||||||||||||||
4177 | } else { | - | ||||||||||||||||||
4178 | QApplicationPrivate::enabledAnimations &= ~effectFlags; | - | ||||||||||||||||||
4179 | } | - | ||||||||||||||||||
4180 | } | - | ||||||||||||||||||
4181 | - | |||||||||||||||||||
4182 | /*! | - | ||||||||||||||||||
4183 | \fn bool QApplication::isEffectEnabled(Qt::UIEffect effect) | - | ||||||||||||||||||
4184 | - | |||||||||||||||||||
4185 | Returns \c true if \a effect is enabled; otherwise returns \c false. | - | ||||||||||||||||||
4186 | - | |||||||||||||||||||
4187 | By default, Qt will try to use the desktop settings. To prevent this, call | - | ||||||||||||||||||
4188 | setDesktopSettingsAware(false). | - | ||||||||||||||||||
4189 | - | |||||||||||||||||||
4190 | \note All effects are disabled on screens running at less than 16-bit color | - | ||||||||||||||||||
4191 | depth. | - | ||||||||||||||||||
4192 | - | |||||||||||||||||||
4193 | \sa setEffectEnabled(), Qt::UIEffect | - | ||||||||||||||||||
4194 | */ | - | ||||||||||||||||||
4195 | bool QApplication::isEffectEnabled(Qt::UIEffect effect) | - | ||||||||||||||||||
4196 | { | - | ||||||||||||||||||
4197 | CHECK_QAPP_INSTANCE(false) | - | ||||||||||||||||||
4198 | return QColormap::instance().depth() >= 16 | - | ||||||||||||||||||
4199 | && (QApplicationPrivate::enabledAnimations & QPlatformTheme::GeneralUiEffect) | - | ||||||||||||||||||
4200 | && (QApplicationPrivate::enabledAnimations & uiEffectToFlag(effect)); | - | ||||||||||||||||||
4201 | } | - | ||||||||||||||||||
4202 | - | |||||||||||||||||||
4203 | /*! | - | ||||||||||||||||||
4204 | \fn void QApplication::beep() | - | ||||||||||||||||||
4205 | - | |||||||||||||||||||
4206 | Sounds the bell, using the default volume and sound. The function is \e not | - | ||||||||||||||||||
4207 | available in Qt for Embedded Linux. | - | ||||||||||||||||||
4208 | */ | - | ||||||||||||||||||
4209 | void QApplication::beep() | - | ||||||||||||||||||
4210 | { | - | ||||||||||||||||||
4211 | QMetaObject::invokeMethod(QGuiApplicationQGuiApplicationPrivate::platformNativeInterface(), "beep");platformIntegration()->beep(); | - | ||||||||||||||||||
4212 | } never executed: end of block | 0 | ||||||||||||||||||
4213 | - | |||||||||||||||||||
4214 | /*! | - | ||||||||||||||||||
4215 | \macro qApp | - | ||||||||||||||||||
4216 | \relates QApplication | - | ||||||||||||||||||
4217 | - | |||||||||||||||||||
4218 | A global pointer referring to the unique application object. It is | - | ||||||||||||||||||
4219 | equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, | - | ||||||||||||||||||
4220 | so only valid when the unique application object is a QApplication. | - | ||||||||||||||||||
4221 | - | |||||||||||||||||||
4222 | \sa QCoreApplication::instance(), qGuiApp | - | ||||||||||||||||||
4223 | */ | - | ||||||||||||||||||
4224 | - | |||||||||||||||||||
4225 | /*! | - | ||||||||||||||||||
4226 | \fn QLocale QApplication::keyboardInputLocale() | - | ||||||||||||||||||
4227 | \since 4.2 | - | ||||||||||||||||||
4228 | \obsolete | - | ||||||||||||||||||
4229 | - | |||||||||||||||||||
4230 | Returns the current keyboard input locale. Replaced with QInputMethod::locale() | - | ||||||||||||||||||
4231 | */ | - | ||||||||||||||||||
4232 | - | |||||||||||||||||||
4233 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event) | - | ||||||||||||||||||
4234 | { | - | ||||||||||||||||||
4235 | return QGuiApplication::sendSpontaneousEvent(receiver, event); | - | ||||||||||||||||||
4236 | } | - | ||||||||||||||||||
4237 | - | |||||||||||||||||||
4238 | void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEvent *event, QPoint localPos) | - | ||||||||||||||||||
4239 | { | - | ||||||||||||||||||
4240 | const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease(); | - | ||||||||||||||||||
4241 | Qt::FocusPolicy focusPolicy = Qt::ClickFocus; | - | ||||||||||||||||||
4242 | static QPointer<QWidget> focusedWidgetOnTouchBegin = 0; | - | ||||||||||||||||||
4243 | - | |||||||||||||||||||
4244 | switch (event->type()) { | - | ||||||||||||||||||
4245 | case QEvent::MouseButtonPress: | - | ||||||||||||||||||
4246 | case QEvent::MouseButtonDblClick: | - | ||||||||||||||||||
4247 | case QEvent::TouchBegin: | - | ||||||||||||||||||
4248 | focusedWidgetOnTouchBegin = QApplication::focusWidget(); | - | ||||||||||||||||||
4249 | if (setFocusOnRelease) | - | ||||||||||||||||||
4250 | return; | - | ||||||||||||||||||
4251 | break; | - | ||||||||||||||||||
4252 | case QEvent::MouseButtonRelease: | - | ||||||||||||||||||
4253 | case QEvent::TouchEnd: | - | ||||||||||||||||||
4254 | if (!setFocusOnRelease) | - | ||||||||||||||||||
4255 | return; | - | ||||||||||||||||||
4256 | if (focusedWidgetOnTouchBegin != QApplication::focusWidget()) { | - | ||||||||||||||||||
4257 | // Focus widget was changed while delivering press/move events. | - | ||||||||||||||||||
4258 | // To not interfere with application logic, we leave focus as-is | - | ||||||||||||||||||
4259 | return; | - | ||||||||||||||||||
4260 | } | - | ||||||||||||||||||
4261 | break; | - | ||||||||||||||||||
4262 | case QEvent::Wheel: | - | ||||||||||||||||||
4263 | focusPolicy = Qt::WheelFocus; | - | ||||||||||||||||||
4264 | break; | - | ||||||||||||||||||
4265 | default: | - | ||||||||||||||||||
4266 | return; | - | ||||||||||||||||||
4267 | } | - | ||||||||||||||||||
4268 | - | |||||||||||||||||||
4269 | QWidget *focusWidget = widget; | - | ||||||||||||||||||
4270 | while (focusWidget) { | - | ||||||||||||||||||
4271 | if (focusWidget->isEnabled() | - | ||||||||||||||||||
4272 | && focusWidget->rect().contains(localPos) | - | ||||||||||||||||||
4273 | && QApplicationPrivate::shouldSetFocus(focusWidget, focusPolicy)) { | - | ||||||||||||||||||
4274 | focusWidget->setFocus(Qt::MouseFocusReason); | - | ||||||||||||||||||
4275 | break; | - | ||||||||||||||||||
4276 | } | - | ||||||||||||||||||
4277 | if (focusWidget->isWindow()) | - | ||||||||||||||||||
4278 | break; | - | ||||||||||||||||||
4279 | - | |||||||||||||||||||
4280 | // find out whether this widget (or its proxy) already has focus | - | ||||||||||||||||||
4281 | QWidget *f = focusWidget; | - | ||||||||||||||||||
4282 | if (focusWidget->d_func()->extra && focusWidget->d_func()->extra->focus_proxy) | - | ||||||||||||||||||
4283 | f = focusWidget->d_func()->extra->focus_proxy; | - | ||||||||||||||||||
4284 | // if it has, stop here. | - | ||||||||||||||||||
4285 | // otherwise a click on the focused widget would remove its focus if ClickFocus isn't set | - | ||||||||||||||||||
4286 | if (f->hasFocus()) | - | ||||||||||||||||||
4287 | break; | - | ||||||||||||||||||
4288 | - | |||||||||||||||||||
4289 | localPos += focusWidget->pos(); | - | ||||||||||||||||||
4290 | focusWidget = focusWidget->parentWidget(); | - | ||||||||||||||||||
4291 | } | - | ||||||||||||||||||
4292 | } | - | ||||||||||||||||||
4293 | - | |||||||||||||||||||
4294 | bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) | - | ||||||||||||||||||
4295 | { | - | ||||||||||||||||||
4296 | QWidget *f = w; | - | ||||||||||||||||||
4297 | while (f->d_func()->extra && f->d_func()->extra->focus_proxy) | - | ||||||||||||||||||
4298 | f = f->d_func()->extra->focus_proxy; | - | ||||||||||||||||||
4299 | - | |||||||||||||||||||
4300 | if ((w->focusPolicy() & policy) != policy) | - | ||||||||||||||||||
4301 | return false; | - | ||||||||||||||||||
4302 | if (w != f && (f->focusPolicy() & policy) != policy) | - | ||||||||||||||||||
4303 | return false; | - | ||||||||||||||||||
4304 | return true; | - | ||||||||||||||||||
4305 | } | - | ||||||||||||||||||
4306 | - | |||||||||||||||||||
4307 | bool QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent) | - | ||||||||||||||||||
4308 | { | - | ||||||||||||||||||
4309 | bool containsPress = false; | - | ||||||||||||||||||
4310 | for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { | - | ||||||||||||||||||
4311 | QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i]; | - | ||||||||||||||||||
4312 | - | |||||||||||||||||||
4313 | // preserve the sub-pixel resolution | - | ||||||||||||||||||
4314 | QRectF rect = touchPoint.screenRect(); | - | ||||||||||||||||||
4315 | const QPointF screenPos = rect.center(); | - | ||||||||||||||||||
4316 | const QPointF delta = screenPos - screenPos.toPoint(); | - | ||||||||||||||||||
4317 | - | |||||||||||||||||||
4318 | rect.moveCenter(widget->mapFromGlobal(screenPos.toPoint()) + delta); | - | ||||||||||||||||||
4319 | touchPoint.d->rect = rect; | - | ||||||||||||||||||
4320 | touchPoint.d->startPos = widget->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta; | - | ||||||||||||||||||
4321 | touchPoint.d->lastPos = widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta; | - | ||||||||||||||||||
4322 | - | |||||||||||||||||||
4323 | if (touchPoint.state() == Qt::TouchPointPressed) | - | ||||||||||||||||||
4324 | containsPress = true; | - | ||||||||||||||||||
4325 | } | - | ||||||||||||||||||
4326 | return containsPress; | - | ||||||||||||||||||
4327 | } | - | ||||||||||||||||||
4328 | - | |||||||||||||||||||
4329 | void QApplicationPrivate::initializeMultitouch() | - | ||||||||||||||||||
4330 | { | - | ||||||||||||||||||
4331 | initializeMultitouch_sys(); | - | ||||||||||||||||||
4332 | } | - | ||||||||||||||||||
4333 | - | |||||||||||||||||||
4334 | void QApplicationPrivate::initializeMultitouch_sys() | - | ||||||||||||||||||
4335 | { | - | ||||||||||||||||||
4336 | } | - | ||||||||||||||||||
4337 | - | |||||||||||||||||||
4338 | void QApplicationPrivate::cleanupMultitouch() | - | ||||||||||||||||||
4339 | { | - | ||||||||||||||||||
4340 | cleanupMultitouch_sys(); | - | ||||||||||||||||||
4341 | } | - | ||||||||||||||||||
4342 | - | |||||||||||||||||||
4343 | void QApplicationPrivate::cleanupMultitouch_sys() | - | ||||||||||||||||||
4344 | { | - | ||||||||||||||||||
4345 | } | - | ||||||||||||||||||
4346 | - | |||||||||||||||||||
4347 | QWidget *QApplicationPrivate::findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint) | - | ||||||||||||||||||
4348 | { | - | ||||||||||||||||||
4349 | const QPointF screenPos = touchPoint.screenPos(); | - | ||||||||||||||||||
4350 | int closestTouchPointId = -1; | - | ||||||||||||||||||
4351 | QObject *closestTarget = 0; | - | ||||||||||||||||||
4352 | qreal closestDistance = qreal(0.); | - | ||||||||||||||||||
4353 | QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it = activeTouchPoints.constBegin(), | - | ||||||||||||||||||
4354 | ite = activeTouchPoints.constEnd(); | - | ||||||||||||||||||
4355 | while (it != ite) { | - | ||||||||||||||||||
4356 | if (it.key().device == device && it.key().touchPointId != touchPoint.id()) { | - | ||||||||||||||||||
4357 | const QTouchEvent::TouchPoint &touchPoint = it->touchPoint; | - | ||||||||||||||||||
4358 | qreal dx = screenPos.x() - touchPoint.screenPos().x(); | - | ||||||||||||||||||
4359 | qreal dy = screenPos.y() - touchPoint.screenPos().y(); | - | ||||||||||||||||||
4360 | qreal distance = dx * dx + dy * dy; | - | ||||||||||||||||||
4361 | if (closestTouchPointId == -1 || distance < closestDistance) { | - | ||||||||||||||||||
4362 | closestTouchPointId = touchPoint.id(); | - | ||||||||||||||||||
4363 | closestDistance = distance; | - | ||||||||||||||||||
4364 | closestTarget = it.value().target.data(); | - | ||||||||||||||||||
4365 | } | - | ||||||||||||||||||
4366 | } | - | ||||||||||||||||||
4367 | ++it; | - | ||||||||||||||||||
4368 | } | - | ||||||||||||||||||
4369 | return static_cast<QWidget *>(closestTarget); | - | ||||||||||||||||||
4370 | } | - | ||||||||||||||||||
4371 | - | |||||||||||||||||||
4372 | void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchEvent) | - | ||||||||||||||||||
4373 | { | - | ||||||||||||||||||
4374 | if (touchEvent->type() != QEvent::TouchBegin) | - | ||||||||||||||||||
4375 | return; | - | ||||||||||||||||||
4376 | - | |||||||||||||||||||
4377 | for (int i = 0, tc = touchEvent->touchPoints().count(); i < tc; ++i) { | - | ||||||||||||||||||
4378 | const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); | - | ||||||||||||||||||
4379 | activeTouchPoints[QGuiApplicationPrivate::ActiveTouchPointsKey(touchEvent->device(), touchPoint.id())].target = widget; | - | ||||||||||||||||||
4380 | } | - | ||||||||||||||||||
4381 | } | - | ||||||||||||||||||
4382 | - | |||||||||||||||||||
4383 | bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, | - | ||||||||||||||||||
4384 | QTouchDevice *device, | - | ||||||||||||||||||
4385 | const QList<QTouchEvent::TouchPoint> &touchPoints, | - | ||||||||||||||||||
4386 | ulong timestamp) | - | ||||||||||||||||||
4387 | { | - | ||||||||||||||||||
4388 | QApplicationPrivate *d = self; | - | ||||||||||||||||||
4389 | typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints; | - | ||||||||||||||||||
4390 | QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents; | - | ||||||||||||||||||
4391 | - | |||||||||||||||||||
4392 | for (int i = 0; i < touchPoints.count(); ++i) { | - | ||||||||||||||||||
4393 | QTouchEvent::TouchPoint touchPoint = touchPoints.at(i); | - | ||||||||||||||||||
4394 | // explicitly detach from the original touch point that we got, so even | - | ||||||||||||||||||
4395 | // if the touchpoint structs are reused, we will make a copy that we'll | - | ||||||||||||||||||
4396 | // deliver to the user (which might want to store the struct for later use). | - | ||||||||||||||||||
4397 | touchPoint.d = touchPoint.d->detach(); | - | ||||||||||||||||||
4398 | - | |||||||||||||||||||
4399 | // update state | - | ||||||||||||||||||
4400 | QPointer<QObject> target; | - | ||||||||||||||||||
4401 | ActiveTouchPointsKey touchInfoKey(device, touchPoint.id()); | - | ||||||||||||||||||
4402 | ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey]; | - | ||||||||||||||||||
4403 | if (touchPoint.state() == Qt::TouchPointPressed) { | - | ||||||||||||||||||
4404 | if (device->type() == QTouchDevice::TouchPad) { | - | ||||||||||||||||||
4405 | // on touch-pads, send all touch points to the same widget | - | ||||||||||||||||||
4406 | target = d->activeTouchPoints.isEmpty() | - | ||||||||||||||||||
4407 | ? QPointer<QObject>() | - | ||||||||||||||||||
4408 | : d->activeTouchPoints.constBegin().value().target; | - | ||||||||||||||||||
4409 | } | - | ||||||||||||||||||
4410 | - | |||||||||||||||||||
4411 | if (!target) { | - | ||||||||||||||||||
4412 | // determine which widget this event will go to | - | ||||||||||||||||||
4413 | if (!window) | - | ||||||||||||||||||
4414 | window = QApplication::topLevelAt(touchPoint.screenPos().toPoint()); | - | ||||||||||||||||||
4415 | if (!window) | - | ||||||||||||||||||
4416 | continue; | - | ||||||||||||||||||
4417 | target = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint())); | - | ||||||||||||||||||
4418 | if (!target) | - | ||||||||||||||||||
4419 | target = window; | - | ||||||||||||||||||
4420 | } | - | ||||||||||||||||||
4421 | - | |||||||||||||||||||
4422 | if (device->type() == QTouchDevice::TouchScreen) { | - | ||||||||||||||||||
4423 | QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint); | - | ||||||||||||||||||
4424 | QWidget *widget = static_cast<QWidget *>(target.data()); | - | ||||||||||||||||||
4425 | if (closestWidget | - | ||||||||||||||||||
4426 | && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) { | - | ||||||||||||||||||
4427 | target = closestWidget; | - | ||||||||||||||||||
4428 | } | - | ||||||||||||||||||
4429 | } | - | ||||||||||||||||||
4430 | - | |||||||||||||||||||
4431 | touchInfo.target = target; | - | ||||||||||||||||||
4432 | } else { | - | ||||||||||||||||||
4433 | target = touchInfo.target; | - | ||||||||||||||||||
4434 | if (!target) | - | ||||||||||||||||||
4435 | continue; | - | ||||||||||||||||||
4436 | } | - | ||||||||||||||||||
4437 | Q_ASSERT(target.data() != 0); | - | ||||||||||||||||||
4438 | - | |||||||||||||||||||
4439 | QWidget *targetWidget = static_cast<QWidget *>(target.data()); | - | ||||||||||||||||||
4440 | - | |||||||||||||||||||
4441 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
4442 | // Single-touch events are normally not sent unless WA_TouchPadAcceptSingleTouchEvents is set. | - | ||||||||||||||||||
4443 | // In Qt 4 this check was in OS X-only code. That behavior is preserved here by the #ifdef. | - | ||||||||||||||||||
4444 | if (touchPoints.count() == 1 | - | ||||||||||||||||||
4445 | && device->type() == QTouchDevice::TouchPad | - | ||||||||||||||||||
4446 | && !targetWidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents)) | - | ||||||||||||||||||
4447 | continue; | - | ||||||||||||||||||
4448 | #endif | - | ||||||||||||||||||
4449 | - | |||||||||||||||||||
4450 | StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget]; | - | ||||||||||||||||||
4451 | maskAndPoints.first |= touchPoint.state(); | - | ||||||||||||||||||
4452 | maskAndPoints.second.append(touchPoint); | - | ||||||||||||||||||
4453 | } | - | ||||||||||||||||||
4454 | - | |||||||||||||||||||
4455 | if (widgetsNeedingEvents.isEmpty()) | - | ||||||||||||||||||
4456 | return false; | - | ||||||||||||||||||
4457 | - | |||||||||||||||||||
4458 | bool accepted = false; | - | ||||||||||||||||||
4459 | QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin(); | - | ||||||||||||||||||
4460 | const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd(); | - | ||||||||||||||||||
4461 | for (; it != end; ++it) { | - | ||||||||||||||||||
4462 | const QPointer<QWidget> widget = it.key(); | - | ||||||||||||||||||
4463 | if (!QApplicationPrivate::tryModalHelper(widget, 0)) | - | ||||||||||||||||||
4464 | continue; | - | ||||||||||||||||||
4465 | - | |||||||||||||||||||
4466 | QEvent::Type eventType; | - | ||||||||||||||||||
4467 | switch (it.value().first) { | - | ||||||||||||||||||
4468 | case Qt::TouchPointPressed: | - | ||||||||||||||||||
4469 | eventType = QEvent::TouchBegin; | - | ||||||||||||||||||
4470 | break; | - | ||||||||||||||||||
4471 | case Qt::TouchPointReleased: | - | ||||||||||||||||||
4472 | eventType = QEvent::TouchEnd; | - | ||||||||||||||||||
4473 | break; | - | ||||||||||||||||||
4474 | case Qt::TouchPointStationary: | - | ||||||||||||||||||
4475 | // don't send the event if nothing changed | - | ||||||||||||||||||
4476 | continue; | - | ||||||||||||||||||
4477 | default: | - | ||||||||||||||||||
4478 | eventType = QEvent::TouchUpdate; | - | ||||||||||||||||||
4479 | break; | - | ||||||||||||||||||
4480 | } | - | ||||||||||||||||||
4481 | - | |||||||||||||||||||
4482 | QTouchEvent touchEvent(eventType, | - | ||||||||||||||||||
4483 | device, | - | ||||||||||||||||||
4484 | QApplication::keyboardModifiers(), | - | ||||||||||||||||||
4485 | it.value().first, | - | ||||||||||||||||||
4486 | it.value().second); | - | ||||||||||||||||||
4487 | bool containsPress = updateTouchPointsForWidget(widget, &touchEvent); | - | ||||||||||||||||||
4488 | touchEvent.setTimestamp(timestamp); | - | ||||||||||||||||||
4489 | touchEvent.setWindow(window->windowHandle()); | - | ||||||||||||||||||
4490 | touchEvent.setTarget(widget); | - | ||||||||||||||||||
4491 | - | |||||||||||||||||||
4492 | if (containsPress) | - | ||||||||||||||||||
4493 | widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent); | - | ||||||||||||||||||
4494 | - | |||||||||||||||||||
4495 | switch (touchEvent.type()) { | - | ||||||||||||||||||
4496 | case QEvent::TouchBegin: | - | ||||||||||||||||||
4497 | { | - | ||||||||||||||||||
4498 | // if the TouchBegin handler recurses, we assume that means the event | - | ||||||||||||||||||
4499 | // has been implicitly accepted and continue to send touch events | - | ||||||||||||||||||
4500 | if (QApplication::sendSpontaneousEvent(widget, &touchEvent) && touchEvent.isAccepted()) { | - | ||||||||||||||||||
4501 | accepted = true; | - | ||||||||||||||||||
4502 | if (!widget.isNull()) | - | ||||||||||||||||||
4503 | widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent); | - | ||||||||||||||||||
4504 | } | - | ||||||||||||||||||
4505 | break; | - | ||||||||||||||||||
4506 | } | - | ||||||||||||||||||
4507 | default: | - | ||||||||||||||||||
4508 | if (widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent) | - | ||||||||||||||||||
4509 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
4510 | || QGestureManager::gesturePending(widget) | - | ||||||||||||||||||
4511 | #endif | - | ||||||||||||||||||
4512 | ) { | - | ||||||||||||||||||
4513 | if (QApplication::sendSpontaneousEvent(widget, &touchEvent) && touchEvent.isAccepted()) | - | ||||||||||||||||||
4514 | accepted = true; | - | ||||||||||||||||||
4515 | // widget can be deleted on TouchEnd | - | ||||||||||||||||||
4516 | if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull()) | - | ||||||||||||||||||
4517 | widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, false); | - | ||||||||||||||||||
4518 | } | - | ||||||||||||||||||
4519 | break; | - | ||||||||||||||||||
4520 | } | - | ||||||||||||||||||
4521 | } | - | ||||||||||||||||||
4522 | return accepted; | - | ||||||||||||||||||
4523 | } | - | ||||||||||||||||||
4524 | - | |||||||||||||||||||
4525 | void QApplicationPrivate::translateTouchCancel(QTouchDevice *device, ulong timestamp) | - | ||||||||||||||||||
4526 | { | - | ||||||||||||||||||
4527 | QTouchEvent touchEvent(QEvent::TouchCancel, device, QApplication::keyboardModifiers()); | - | ||||||||||||||||||
4528 | touchEvent.setTimestamp(timestamp); | - | ||||||||||||||||||
4529 | QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it | - | ||||||||||||||||||
4530 | = self->activeTouchPoints.constBegin(), ite = self->activeTouchPoints.constEnd(); | - | ||||||||||||||||||
4531 | QSet<QWidget *> widgetsNeedingCancel; | - | ||||||||||||||||||
4532 | while (it != ite) { | - | ||||||||||||||||||
4533 | QWidget *widget = static_cast<QWidget *>(it->target.data()); | - | ||||||||||||||||||
4534 | if (widget) | - | ||||||||||||||||||
4535 | widgetsNeedingCancel.insert(widget); | - | ||||||||||||||||||
4536 | ++it; | - | ||||||||||||||||||
4537 | } | - | ||||||||||||||||||
4538 | for (QSet<QWidget *>::const_iterator widIt = widgetsNeedingCancel.constBegin(), | - | ||||||||||||||||||
4539 | widItEnd = widgetsNeedingCancel.constEnd(); widIt != widItEnd; ++widIt) { | - | ||||||||||||||||||
4540 | QWidget *widget = *widIt; | - | ||||||||||||||||||
4541 | touchEvent.setWindow(widget->windowHandle()); | - | ||||||||||||||||||
4542 | touchEvent.setTarget(widget); | - | ||||||||||||||||||
4543 | QApplication::sendSpontaneousEvent(widget, &touchEvent); | - | ||||||||||||||||||
4544 | } | - | ||||||||||||||||||
4545 | } | - | ||||||||||||||||||
4546 | - | |||||||||||||||||||
4547 | void QApplicationPrivate::notifyThemeChanged() | - | ||||||||||||||||||
4548 | { | - | ||||||||||||||||||
4549 | QGuiApplicationPrivate::notifyThemeChanged(); | - | ||||||||||||||||||
4550 | clearSystemPalette(); | - | ||||||||||||||||||
4551 | initSystemPalette(); | - | ||||||||||||||||||
4552 | qt_init_tooltip_palette(); | - | ||||||||||||||||||
4553 | } | - | ||||||||||||||||||
4554 | - | |||||||||||||||||||
4555 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
4556 | void QApplicationPrivate::notifyDragStarted(const QDrag *drag) | - | ||||||||||||||||||
4557 | { | - | ||||||||||||||||||
4558 | // Prevent pickMouseReceiver() from using the widget where the drag was started after a drag operation. | - | ||||||||||||||||||
4559 | QGuiApplicationPrivate::notifyDragStarted(drag); | - | ||||||||||||||||||
4560 | qt_button_down = 0; | - | ||||||||||||||||||
4561 | } | - | ||||||||||||||||||
4562 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||
4563 | - | |||||||||||||||||||
4564 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
4565 | QGestureManager* QGestureManager::instance() | - | ||||||||||||||||||
4566 | { | - | ||||||||||||||||||
4567 | QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); | - | ||||||||||||||||||
4568 | if (!qAppPriv) | - | ||||||||||||||||||
4569 | return 0; | - | ||||||||||||||||||
4570 | if (!qAppPriv->gestureManager) | - | ||||||||||||||||||
4571 | qAppPriv->gestureManager = new QGestureManager(qApp); | - | ||||||||||||||||||
4572 | return qAppPriv->gestureManager; | - | ||||||||||||||||||
4573 | } | - | ||||||||||||||||||
4574 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||
4575 | - | |||||||||||||||||||
4576 | QPixmap QApplicationPrivate::applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const | - | ||||||||||||||||||
4577 | { | - | ||||||||||||||||||
4578 | QStyleOption opt(0); | - | ||||||||||||||||||
4579 | opt.palette = QGuiApplication::palette(); | - | ||||||||||||||||||
4580 | return QApplication::style()->generatedIconPixmap(mode, base, &opt); | - | ||||||||||||||||||
4581 | } | - | ||||||||||||||||||
4582 | - | |||||||||||||||||||
4583 | QT_END_NAMESPACE | - | ||||||||||||||||||
4584 | - | |||||||||||||||||||
4585 | #include "moc_qapplication.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |