kernel/qapplication.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui 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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qplatformdefs.h" -
43#include "qabstracteventdispatcher.h" -
44#include "qapplication.h" -
45#include "qclipboard.h" -
46#include "qcursor.h" -
47#include "qdesktopwidget.h" -
48#include "qdir.h" -
49#include "qevent.h" -
50#include "qfile.h" -
51#include "qfileinfo.h" -
52#include "qgraphicsscene.h" -
53#include "qhash.h" -
54#include "qset.h" -
55#include "qlayout.h" -
56#include "qstyle.h" -
57#include "qstyleoption.h" -
58#include "qstylefactory.h" -
59#include "qtextcodec.h" -
60#include "qtranslator.h" -
61#include "qvariant.h" -
62#include "qwidget.h" -
63#include "private/qdnd_p.h" -
64#include "private/qguiapplication_p.h" -
65#include "qcolormap.h" -
66#include "qdebug.h" -
67#include "private/qstylesheetstyle_p.h" -
68#include "private/qstyle_p.h" -
69#include "qmessagebox.h" -
70#include "qwidgetwindow_qpa_p.h" -
71#include <QtWidgets/qgraphicsproxywidget.h> -
72#include <QtGui/qstylehints.h> -
73#include <QtGui/qinputmethod.h> -
74#include <qpa/qplatformtheme.h> -
75 -
76#include "private/qkeymapper_p.h" -
77 -
78#include <qthread.h> -
79#include <private/qthread_p.h> -
80 -
81#include <private/qfont_p.h> -
82 -
83#include <stdlib.h> -
84 -
85#include "qapplication_p.h" -
86#include "private/qevent_p.h" -
87#include "qwidget_p.h" -
88 -
89#include "qgesture.h" -
90#include "private/qgesturemanager_p.h" -
91#include <qpa/qplatformfontdatabase.h> -
92#ifndef QT_NO_LIBRARY -
93#include "qlibrary.h" -
94#endif -
95 -
96#include "qdatetime.h" -
97 -
98#ifdef Q_OS_WINCE -
99extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp -
100extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp -
101extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp -
102#endif -
103 -
104#include <qpa/qplatformwindow.h> -
105 -
106//#define ALIEN_DEBUG -
107 -
108static void initResources() -
109{ -
110#if defined(Q_OS_WINCE) -
111 Q_INIT_RESOURCE_EXTERN(qstyle_wince) -
112 Q_INIT_RESOURCE(qstyle_wince); -
113#else -
114 Q_INIT_RESOURCE_EXTERN(qstyle) -
115 Q_INIT_RESOURCE(qstyle); -
116#endif -
117 Q_INIT_RESOURCE_EXTERN(qmessagebox) -
118 Q_INIT_RESOURCE(qmessagebox); -
119 -
120} -
121 -
122QT_BEGIN_NAMESPACE -
123 -
124Q_CORE_EXPORT void qt_call_post_routines(); -
125 -
126QApplicationPrivate *QApplicationPrivate::self = 0; -
127 -
128static void initSystemPalette() -
129{ -
130 if (!QApplicationPrivate::sys_pal) { -
131 QPalette defaultPlatte; -
132 if (QApplicationPrivate::app_style) -
133 defaultPlatte = QApplicationPrivate::app_style->standardPalette(); -
134 if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) { -
135 QApplicationPrivate::setSystemPalette(themePalette->resolve(defaultPlatte)); -
136 QApplicationPrivate::initializeWidgetPaletteHash(); -
137 } else { -
138 QApplicationPrivate::setSystemPalette(defaultPlatte); -
139 } -
140 } -
141} -
142 -
143static void clearSystemPalette() -
144{ -
145 delete QApplicationPrivate::sys_pal; -
146 QApplicationPrivate::sys_pal = 0; -
147} -
148 -
149#ifdef Q_OS_WINCE -
150int QApplicationPrivate::autoMaximizeThreshold = -1; -
151bool QApplicationPrivate::autoSipEnabled = false; -
152#else -
153bool QApplicationPrivate::autoSipEnabled = true; -
154#endif -
155 -
156QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, int flags) -
157 : QApplicationPrivateBase(argc, argv, flags) -
158{ -
159 application_type = QApplicationPrivate::Gui; -
160 -
161#ifndef QT_NO_GESTURES -
162 gestureManager = 0; -
163 gestureWidget = 0; -
164#endif // QT_NO_GESTURES -
165 -
166 if (!self) -
167 self = this; -
168} -
169 -
170QApplicationPrivate::~QApplicationPrivate() -
171{ -
172 if (self == this) -
173 self = 0; -
174} -
175 -
176/*! -
177 \class QApplication -
178 \brief The QApplication class manages the GUI application's control -
179 flow and main settings. -
180 -
181 \inmodule QtWidgets -
182 -
183 QApplication specializes QGuiApplication with some functionality needed -
184 for QWidget-based applications. It handles widget specific initialization, -
185 finalization. -
186 -
187 For any GUI application using Qt, there is precisely \b one QApplication -
188 object, no matter whether the application has 0, 1, 2 or more windows at -
189 any given time. For non-QWidget based Qt applications, use QGuiApplication instead, -
190 as it does not depend on the \l QtWidgets library. -
191 -
192 Some GUI applications provide a special batch mode ie. provide command line -
193 arguments for executing tasks without manual intervention. In such non-GUI -
194 mode, it is often sufficient to instantiate a plain QCoreApplication to -
195 avoid unnecessarily initializing resources needed for a graphical user -
196 interface. The following example shows how to dynamically create an -
197 appropriate type of application instance: -
198 -
199 \snippet code/src_gui_kernel_qapplication.cpp 0 -
200 -
201 The QApplication object is accessible through the instance() function that -
202 returns a pointer equivalent to the global qApp pointer. -
203 -
204 QApplication's main areas of responsibility are: -
205 \list -
206 \li It initializes the application with the user's desktop settings -
207 such as palette(), font() and doubleClickInterval(). It keeps -
208 track of these properties in case the user changes the desktop -
209 globally, for example through some kind of control panel. -
210 -
211 \li It performs event handling, meaning that it receives events -
212 from the underlying window system and dispatches them to the -
213 relevant widgets. By using sendEvent() and postEvent() you can -
214 send your own events to widgets. -
215 -
216 \li It parses common command line arguments and sets its internal -
217 state accordingly. See the \l{QApplication::QApplication()} -
218 {constructor documentation} below for more details. -
219 -
220 \li It defines the application's look and feel, which is -
221 encapsulated in a QStyle object. This can be changed at runtime -
222 with setStyle(). -
223 -
224 \li It specifies how the application is to allocate colors. See -
225 setColorSpec() for details. -
226 -
227 \li It provides localization of strings that are visible to the -
228 user via translate(). -
229 -
230 \li It provides some magical objects like the desktop() and the -
231 clipboard(). -
232 -
233 \li It knows about the application's windows. You can ask which -
234 widget is at a certain position using widgetAt(), get a list of -
235 topLevelWidgets() and closeAllWindows(), etc. -
236 -
237 \li It manages the application's mouse cursor handling, see -
238 setOverrideCursor() -
239 \endlist -
240 -
241 Since the QApplication object does so much initialization, it \e{must} be -
242 created before any other objects related to the user interface are created. -
243 QApplication also deals with common command line arguments. Hence, it is -
244 usually a good idea to create it \e before any interpretation or -
245 modification of \c argv is done in the application itself. -
246 -
247 \table -
248 \header -
249 \li{2,1} Groups of functions -
250 -
251 \row -
252 \li System settings -
253 \li desktopSettingsAware(), -
254 setDesktopSettingsAware(), -
255 cursorFlashTime(), -
256 setCursorFlashTime(), -
257 doubleClickInterval(), -
258 setDoubleClickInterval(), -
259 setKeyboardInputInterval(), -
260 wheelScrollLines(), -
261 setWheelScrollLines(), -
262 palette(), -
263 setPalette(), -
264 font(), -
265 setFont(), -
266 fontMetrics(). -
267 -
268 \row -
269 \li Event handling -
270 \li exec(), -
271 processEvents(), -
272 exit(), -
273 quit(). -
274 sendEvent(), -
275 postEvent(), -
276 sendPostedEvents(), -
277 removePostedEvents(), -
278 hasPendingEvents(), -
279 notify(). -
280 -
281 \row -
282 \li GUI Styles -
283 \li style(), -
284 setStyle(). -
285 -
286 \row -
287 \li Color usage -
288 \li colorSpec(), -
289 setColorSpec(). -
290 -
291 \row -
292 \li Text handling -
293 \li installTranslator(), -
294 removeTranslator() -
295 translate(). -
296 -
297 \row -
298 \li Widgets -
299 \li allWidgets(), -
300 topLevelWidgets(), -
301 desktop(), -
302 activePopupWidget(), -
303 activeModalWidget(), -
304 clipboard(), -
305 focusWidget(), -
306 activeWindow(), -
307 widgetAt(). -
308 -
309 \row -
310 \li Advanced cursor handling -
311 \li overrideCursor(), -
312 setOverrideCursor(), -
313 restoreOverrideCursor(). -
314 -
315 \row -
316 \li Miscellaneous -
317 \li closeAllWindows(), -
318 startingUp(), -
319 closingDown(), -
320 type(). -
321 \endtable -
322 -
323 \sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings -
324*/ -
325 -
326/*! -
327 \enum QApplication::ColorSpec -
328 -
329 \value NormalColor the default color allocation policy -
330 \value CustomColor the same as NormalColor for X11; allocates colors -
331 to a palette on demand under Windows -
332 \value ManyColor the right choice for applications that use thousands of -
333 colors -
334 -
335 See setColorSpec() for full details. -
336*/ -
337 -
338/*! -
339 \fn QWidget *QApplication::topLevelAt(const QPoint &point) -
340 -
341 Returns the top-level widget at the given \a point; returns 0 if -
342 there is no such widget. -
343*/ -
344 -
345/*! -
346 \fn QWidget *QApplication::topLevelAt(int x, int y) -
347 -
348 \overload -
349 -
350 Returns the top-level widget at the point (\a{x}, \a{y}); returns -
351 0 if there is no such widget. -
352*/ -
353 -
354 -
355/* -
356 The qt_init() and qt_cleanup() functions are implemented in the -
357 qapplication_xyz.cpp file. -
358*/ -
359 -
360void qt_init(QApplicationPrivate *priv, int type -
361 ); -
362void qt_cleanup(); -
363 -
364QStyle *QApplicationPrivate::app_style = 0; // default application style -
365QString QApplicationPrivate::styleOverride; // style override -
366 -
367#ifndef QT_NO_STYLE_STYLESHEET -
368QString QApplicationPrivate::styleSheet; // default application stylesheet -
369#endif -
370QPointer<QWidget> QApplicationPrivate::leaveAfterRelease = 0; -
371 -
372int QApplicationPrivate::app_cspec = QApplication::NormalColor; -
373 -
374QPalette *QApplicationPrivate::sys_pal = 0; // default system palette -
375QPalette *QApplicationPrivate::set_pal = 0; // default palette set by programmer -
376 -
377QFont *QApplicationPrivate::sys_font = 0; // default system font -
378QFont *QApplicationPrivate::set_font = 0; // default font set by programmer -
379 -
380QIcon *QApplicationPrivate::app_icon = 0; -
381QWidget *QApplicationPrivate::main_widget = 0; // main application widget -
382QWidget *QApplicationPrivate::focus_widget = 0; // has keyboard input focus -
383QWidget *QApplicationPrivate::hidden_focus_widget = 0; // will get keyboard input focus after show() -
384QWidget *QApplicationPrivate::active_window = 0; // toplevel with keyboard focus -
385#ifndef QT_NO_WHEELEVENT -
386int QApplicationPrivate::wheel_scroll_lines; // number of lines to scroll -
387#endif -
388bool qt_in_tab_key_event = false; -
389int qt_antialiasing_threshold = -1; -
390QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut -
391int QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect; -
392bool QApplicationPrivate::widgetCount = false; -
393bool QApplicationPrivate::load_testability = false; -
394#ifdef QT_KEYPAD_NAVIGATION -
395Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadTabOrder; -
396QWidget *QApplicationPrivate::oldEditFocus = 0; -
397#endif -
398 -
399bool qt_tabletChokeMouse = false; -
400 -
401inline bool QApplicationPrivate::isAlien(QWidget *widget) -
402{ -
403 return widget && !widget->isWindow(); -
404} -
405 -
406bool Q_WIDGETS_EXPORT qt_tab_all_widgets() -
407{ -
408 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) -
409 return theme->themeHint(QPlatformTheme::TabAllWidgets).toBool(); -
410 return true; -
411} -
412 -
413// ######## move to QApplicationPrivate -
414// Default application palettes and fonts (per widget type) -
415Q_GLOBAL_STATIC(PaletteHash, app_palettes) -
416PaletteHash *qt_app_palettes_hash() -
417{ -
418 return app_palettes(); -
419} -
420 -
421Q_GLOBAL_STATIC(FontHash, app_fonts) -
422FontHash *qt_app_fonts_hash() -
423{ -
424 return app_fonts(); -
425} -
426 -
427QWidgetList *QApplicationPrivate::popupWidgets = 0; // has keyboard input focus -
428 -
429QDesktopWidget *qt_desktopWidget = 0; // root window widgets -
430 -
431/*! -
432 \internal -
433*/ -
434void QApplicationPrivate::process_cmdline() -
435{ -
436 // process platform-indep command line -
437 if (!qt_is_gui_used || !argc) -
438 return; -
439 -
440 int i, j; -
441 -
442 j = 1; -
443 for (i=1; i<argc; i++) { // if you add anything here, modify QCoreApplication::arguments() -
444 if (argv[i] && *argv[i] != '-') { -
445 argv[j++] = argv[i]; -
446 continue; -
447 } -
448 QByteArray arg = argv[i]; -
449 arg = arg; -
450 QString s; -
451 if (arg == "-qdevel" || arg == "-qdebug") { -
452 // obsolete argument -
453 } else if (arg.indexOf("-style=", 0) != -1) { -
454 s = QString::fromLocal8Bit(arg.right(arg.length() - 7).toLower()); -
455 } else if (arg == "-style" && i < argc-1) { -
456 s = QString::fromLocal8Bit(argv[++i]).toLower(); -
457#ifndef QT_NO_STYLE_STYLESHEET -
458 } else if (arg == "-stylesheet" && i < argc -1) { -
459 styleSheet = QLatin1String("file:///"); -
460 styleSheet.append(QString::fromLocal8Bit(argv[++i])); -
461 } else if (arg.indexOf("-stylesheet=") != -1) { -
462 styleSheet = QLatin1String("file:///"); -
463 styleSheet.append(QString::fromLocal8Bit(arg.right(arg.length() - 12))); -
464#endif -
465 } else if (qstrcmp(arg, "-widgetcount") == 0) { -
466 widgetCount = true; -
467 } else if (qstrcmp(arg, "-testability") == 0) { -
468 load_testability = true; -
469 } else { -
470 argv[j++] = argv[i]; -
471 } -
472 if (!s.isEmpty()) { -
473 if (app_style) { -
474 delete app_style; -
475 app_style = 0; -
476 } -
477 styleOverride = s; -
478 } -
479 } -
480 -
481 if(j < argc) { -
482 argv[j] = 0; -
483 argc = j; -
484 } -
485} -
486 -
487/*! -
488 Initializes the window system and constructs an application object with -
489 \a argc command line arguments in \a argv. -
490 -
491 \warning The data referred to by \a argc and \a argv must stay valid for -
492 the entire lifetime of the QApplication object. In addition, \a argc must -
493 be greater than zero and \a argv must contain at least one valid character -
494 string. -
495 -
496 The global \c qApp pointer refers to this application object. Only one -
497 application object should be created. -
498 -
499 This application object must be constructed before any \l{QPaintDevice} -
500 {paint devices} (including widgets, pixmaps, bitmaps etc.). -
501 -
502 \note \a argc and \a argv might be changed as Qt removes command line -
503 arguments that it recognizes. -
504 -
505 All Qt programs automatically support the following command line options: -
506 \list -
507 \li -style= \e style, sets the application GUI style. Possible values -
508 depend on your system configuration. If you compiled Qt with -
509 additional styles or have additional styles as plugins these will -
510 be available to the \c -style command line option. You can also -
511 set the style for all Qt applications by setting the -
512 \c QT_STYLE_OVERRIDE environment variable. -
513 \li -style \e style, is the same as listed above. -
514 \li -stylesheet= \e stylesheet, sets the application \l styleSheet. The -
515 value must be a path to a file that contains the Style Sheet. -
516 \note Relative URLs in the Style Sheet file are relative to the -
517 Style Sheet file's path. -
518 \li -stylesheet \e stylesheet, is the same as listed above. -
519 \li -widgetcount, prints debug message at the end about number of -
520 widgets left undestroyed and maximum number of widgets existed at -
521 the same time -
522 \li -reverse, sets the application's layout direction to -
523 Qt::RightToLeft -
524 \li -qmljsdebugger=, activates the QML/JS debugger with a specified port. -
525 The value must be of format port:1234[,block], where block is optional -
526 and will make the application wait until a debugger connects to it. -
527 \endlist -
528 -
529 \sa arguments() -
530*/ -
531 -
532#ifdef Q_QDOC -
533QApplication::QApplication(int &argc, char **argv) -
534#else -
535QApplication::QApplication(int &argc, char **argv, int _internal) -
536#endif -
537 : QGuiApplication(*new QApplicationPrivate(argc, argv, _internal)) -
538{ Q_D(QApplication); d->construct(); } -
539 -
540/*! -
541 \internal -
542*/ -
543void QApplicationPrivate::construct() -
544{ -
545 initResources(); -
546 -
547 qt_is_gui_used = (application_type != QApplicationPrivate::Tty); -
548 process_cmdline(); -
549 -
550 // Must be called before initialize() -
551 qt_init(this, application_type); -
552 initialize(); -
553 eventDispatcher->startingUp(); -
554 -
555#ifdef QT_EVAL -
556 extern void qt_gui_eval_init(uint); -
557 qt_gui_eval_init(application_type); -
558#endif -
559 -
560#ifndef QT_NO_LIBRARY -
561 if(load_testability) { -
562 QLibrary testLib(QLatin1String("qttestability")); -
563 if (testLib.load()) { -
564 typedef void (*TasInitialize)(void); -
565 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init"); -
566 if (initFunction) { -
567 initFunction(); -
568 } else { -
569 qCritical("Library qttestability resolve failed!"); -
570 } -
571 } else { -
572 qCritical("Library qttestability load failed!"); -
573 } -
574 } -
575#endif -
576} -
577 -
578#ifndef QT_NO_STATEMACHINE -
579void qRegisterGuiStateMachine(); -
580void qUnregisterGuiStateMachine(); -
581#endif -
582extern void qRegisterWidgetsVariant(); -
583 -
584/*! -
585 \fn void QApplicationPrivate::initialize() -
586 -
587 Initializes the QApplication object, called from the constructors. -
588*/ -
589void QApplicationPrivate::initialize() -
590{ -
591 QWidgetPrivate::mapper = new QWidgetMapper;
executed (the execution status of this line is deduced): QWidgetPrivate::mapper = new QWidgetMapper;
-
592 QWidgetPrivate::allWidgets = new QWidgetSet;
executed (the execution status of this line is deduced): QWidgetPrivate::allWidgets = new QWidgetSet;
-
593 -
594 // needed for a static build. -
595 qRegisterWidgetsVariant();
executed (the execution status of this line is deduced): qRegisterWidgetsVariant();
-
596 -
597 if (application_type != QApplicationPrivate::Tty)
partially evaluated: application_type != QApplicationPrivate::Tty
TRUEFALSE
yes
Evaluation Count:215
no
Evaluation Count:0
0-215
598 (void) QApplication::style(); // trigger creation of application style
executed: (void) QApplication::style();
Execution Count:215
215
599#ifndef QT_NO_STATEMACHINE -
600 // trigger registering of QStateMachine's GUI types -
601 qRegisterGuiStateMachine();
executed (the execution status of this line is deduced): qRegisterGuiStateMachine();
-
602#endif -
603 -
604 is_app_running = true; // no longer starting up
executed (the execution status of this line is deduced): is_app_running = true;
-
605 -
606 Q_Q(QApplication);
executed (the execution status of this line is deduced): QApplication * const q = q_func();
-
607 -
608 if (qgetenv("QT_USE_NATIVE_WINDOWS").toInt() > 0)
partially evaluated: qgetenv("QT_USE_NATIVE_WINDOWS").toInt() > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:215
0-215
609 q->setAttribute(Qt::AA_NativeWindows);
never executed: q->setAttribute(Qt::AA_NativeWindows);
0
610 -
611#ifdef Q_OS_WINCE -
612#ifdef QT_AUTO_MAXIMIZE_THRESHOLD -
613 autoMaximizeThreshold = QT_AUTO_MAXIMIZE_THRESHOLD; -
614#else -
615 if (qt_wince_is_mobile()) -
616 autoMaximizeThreshold = 50; -
617 else -
618 autoMaximizeThreshold = -1; -
619#endif //QT_AUTO_MAXIMIZE_THRESHOLD -
620#endif //Q_OS_WINCE -
621 -
622#ifndef QT_NO_WHEELEVENT -
623 QApplicationPrivate::wheel_scroll_lines = 3;
executed (the execution status of this line is deduced): QApplicationPrivate::wheel_scroll_lines = 3;
-
624#endif -
625 -
626 if (qt_is_gui_used)
partially evaluated: qt_is_gui_used
TRUEFALSE
yes
Evaluation Count:215
no
Evaluation Count:0
0-215
627 initializeMultitouch();
executed: initializeMultitouch();
Execution Count:215
215
628 -
629 if (QApplication::desktopSettingsAware())
partially evaluated: QApplication::desktopSettingsAware()
TRUEFALSE
yes
Evaluation Count:215
no
Evaluation Count:0
0-215
630 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
partially evaluated: const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
TRUEFALSE
yes
Evaluation Count:215
no
Evaluation Count:0
0-215
631 QApplicationPrivate::enabledAnimations = theme->themeHint(QPlatformTheme::UiEffects).toInt();
executed: QApplicationPrivate::enabledAnimations = theme->themeHint(QPlatformTheme::UiEffects).toInt();
Execution Count:215
215
632}
executed: }
Execution Count:215
215
633 -
634/***************************************************************************** -
635 Functions returning the active popup and modal widgets. -
636 *****************************************************************************/ -
637 -
638/*! -
639 Returns the active popup widget. -
640 -
641 A popup widget is a special top-level widget that sets the \c -
642 Qt::WType_Popup widget flag, e.g. the QMenu widget. When the application -
643 opens a popup widget, all events are sent to the popup. Normal widgets and -
644 modal widgets cannot be accessed before the popup widget is closed. -
645 -
646 Only other popup widgets may be opened when a popup widget is shown. The -
647 popup widgets are organized in a stack. This function returns the active -
648 popup widget at the top of the stack. -
649 -
650 \sa activeModalWidget(), topLevelWidgets() -
651*/ -
652 -
653QWidget *QApplication::activePopupWidget() -
654{ -
655 return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? -
656 QApplicationPrivate::popupWidgets->last() : 0; -
657} -
658 -
659 -
660/*! -
661 Returns the active modal widget. -
662 -
663 A modal widget is a special top-level widget which is a subclass of QDialog -
664 that specifies the modal parameter of the constructor as true. A modal -
665 widget must be closed before the user can continue with other parts of the -
666 program. -
667 -
668 Modal widgets are organized in a stack. This function returns the active -
669 modal widget at the top of the stack. -
670 -
671 \sa activePopupWidget(), topLevelWidgets() -
672*/ -
673 -
674QWidget *QApplication::activeModalWidget() -
675{ -
676 QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(modalWindow()); -
677 return widgetWindow ? widgetWindow->widget() : 0; -
678} -
679 -
680/*! -
681 Cleans up any window system resources that were allocated by this -
682 application. Sets the global variable \c qApp to 0. -
683*/ -
684 -
685QApplication::~QApplication() -
686{ -
687 Q_D(QApplication); -
688 -
689 //### this should probable be done even later -
690 qt_call_post_routines(); -
691 -
692 // kill timers before closing down the dispatcher -
693 d->toolTipWakeUp.stop(); -
694 d->toolTipFallAsleep.stop(); -
695 -
696 QApplicationPrivate::is_app_closing = true; -
697 QApplicationPrivate::is_app_running = false; -
698 -
699 delete QWidgetPrivate::mapper; -
700 QWidgetPrivate::mapper = 0; -
701 -
702 // delete all widgets -
703 if (QWidgetPrivate::allWidgets) { -
704 QWidgetSet *mySet = QWidgetPrivate::allWidgets; -
705 QWidgetPrivate::allWidgets = 0; -
706 for (QWidgetSet::ConstIterator it = mySet->constBegin(); it != mySet->constEnd(); ++it) { -
707 register QWidget *w = *it; -
708 if (!w->parent()) // window -
709 w->destroy(true, true); -
710 } -
711 delete mySet; -
712 } -
713 -
714 delete qt_desktopWidget; -
715 qt_desktopWidget = 0; -
716 -
717 delete QApplicationPrivate::app_pal; -
718 QApplicationPrivate::app_pal = 0; -
719 clearSystemPalette(); -
720 delete QApplicationPrivate::set_pal; -
721 QApplicationPrivate::set_pal = 0; -
722 app_palettes()->clear(); -
723 -
724 delete QApplicationPrivate::sys_font; -
725 QApplicationPrivate::sys_font = 0; -
726 delete QApplicationPrivate::set_font; -
727 QApplicationPrivate::set_font = 0; -
728 app_fonts()->clear(); -
729 -
730 delete QApplicationPrivate::app_style; -
731 QApplicationPrivate::app_style = 0; -
732 delete QApplicationPrivate::app_icon; -
733 QApplicationPrivate::app_icon = 0; -
734 -
735#ifndef QT_NO_DRAGANDDROP -
736 if (qt_is_gui_used) -
737 delete QDragManager::self(); -
738#endif -
739 -
740 d->cleanupMultitouch(); -
741 -
742 qt_cleanup(); -
743 -
744 if (QApplicationPrivate::widgetCount) -
745 qDebug("Widgets left: %i Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances); -
746 -
747 QApplicationPrivate::obey_desktop_settings = true; -
748 -
749 QApplicationPrivate::app_strut = QSize(0, 0); -
750 QApplicationPrivate::enabledAnimations = QPlatformTheme::GeneralUiEffect; -
751 QApplicationPrivate::widgetCount = false; -
752 -
753#ifndef QT_NO_STATEMACHINE -
754 // trigger unregistering of QStateMachine's GUI types -
755 qUnregisterGuiStateMachine(); -
756#endif -
757} -
758 -
759 -
760/*! -
761 \fn QWidget *QApplication::widgetAt(const QPoint &point) -
762 -
763 Returns the widget at global screen position \a point, or 0 if there is no -
764 Qt widget there. -
765 -
766 This function can be slow. -
767 -
768 \sa QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard() -
769*/ -
770QWidget *QApplication::widgetAt(const QPoint &p) -
771{ -
772 QWidget *window = QApplication::topLevelAt(p); -
773 if (!window) -
774 return 0; -
775 -
776 QWidget *child = 0; -
777 -
778 if (!window->testAttribute(Qt::WA_TransparentForMouseEvents)) -
779 child = window->childAt(window->mapFromGlobal(p)); -
780 -
781 if (child) -
782 return child; -
783 -
784 if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) { -
785 //shoot a hole in the widget and try once again, -
786 //suboptimal on Qt for Embedded Linux where we do -
787 //know the stacking order of the toplevels. -
788 int x = p.x(); -
789 int y = p.y(); -
790 QRegion oldmask = window->mask(); -
791 QPoint wpoint = window->mapFromGlobal(QPoint(x, y)); -
792 QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask) -
793 - QRegion(wpoint.x(), wpoint.y(), 1, 1); -
794 window->setMask(newmask); -
795 QWidget *recurse = 0; -
796 if (QApplication::topLevelAt(p) != window) // verify recursion will terminate -
797 recurse = widgetAt(x, y); -
798 if (oldmask.isEmpty()) -
799 window->clearMask(); -
800 else -
801 window->setMask(oldmask); -
802 return recurse; -
803 } -
804 return window; -
805} -
806 -
807/*! -
808 \fn QWidget *QApplication::widgetAt(int x, int y) -
809 -
810 \overload -
811 -
812 Returns the widget at global screen position (\a x, \a y), or 0 if there is -
813 no Qt widget there. -
814*/ -
815 -
816/*! -
817 \internal -
818*/ -
819bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) -
820{ -
821 if ((event->type() == QEvent::UpdateRequest -
822 || event->type() == QEvent::LayoutRequest -
823 || event->type() == QEvent::Resize -
824 || event->type() == QEvent::Move -
825 || event->type() == QEvent::LanguageChange -
826 || event->type() == QEvent::InputMethod)) { -
827 for (QPostEventList::const_iterator it = postedEvents->constBegin(); it != postedEvents->constEnd(); ++it) { -
828 const QPostEvent &cur = *it; -
829 if (cur.receiver != receiver || cur.event == 0 || cur.event->type() != event->type()) -
830 continue; -
831 if (cur.event->type() == QEvent::LayoutRequest -
832 || cur.event->type() == QEvent::UpdateRequest) { -
833 ; -
834 } else if (cur.event->type() == QEvent::Resize) { -
835 ((QResizeEvent *)(cur.event))->s = ((QResizeEvent *)event)->s; -
836 } else if (cur.event->type() == QEvent::Move) { -
837 ((QMoveEvent *)(cur.event))->p = ((QMoveEvent *)event)->p; -
838 } else if (cur.event->type() == QEvent::LanguageChange) { -
839 ; -
840 } else if ( cur.event->type() == QEvent::InputMethod ) { -
841 *(QInputMethodEvent *)(cur.event) = *(QInputMethodEvent *)event; -
842 } else { -
843 continue; -
844 } -
845 delete event; -
846 return true; -
847 } -
848 return false; -
849 } -
850 return QGuiApplication::compressEvent(event, receiver, postedEvents); -
851} -
852 -
853/*! -
854 \property QApplication::styleSheet -
855 \brief the application style sheet -
856 \since 4.2 -
857 -
858 By default, this property returns an empty string unless the user specifies -
859 the \c{-stylesheet} option on the command line when running the application. -
860 -
861 \sa QWidget::setStyle(), {Qt Style Sheets} -
862*/ -
863 -
864/*! -
865 \property QApplication::autoMaximizeThreshold -
866 \since 4.4 -
867 \brief defines a threshold for auto maximizing widgets -
868 -
869 \b{The auto maximize threshold is only available as part of Qt for -
870 Windows CE.} -
871 -
872 This property defines a threshold for the size of a window as a percentage -
873 of the screen size. If the minimum size hint of a window exceeds the -
874 threshold, calling show() will cause the window to be maximized -
875 automatically. -
876 -
877 Setting the threshold to 100 or greater means that the widget will always -
878 be maximized. Alternatively, setting the threshold to 50 means that the -
879 widget will be maximized only if the vertical minimum size hint is at least -
880 50% of the vertical screen size. -
881 -
882 Setting the threshold to -1 disables the feature. -
883 -
884 On Windows CE the default is -1 (i.e., it is disabled). -
885 On Windows Mobile the default is 40. -
886*/ -
887 -
888/*! -
889 \property QApplication::autoSipEnabled -
890 \since 4.5 -
891 \brief toggles automatic SIP (software input panel) visibility -
892 -
893 Set this property to \c true to automatically display the SIP when entering -
894 widgets that accept keyboard input. This property only affects widgets with -
895 the WA_InputMethodEnabled attribute set, and is typically used to launch -
896 a virtual keyboard on devices which have very few or no keys. -
897 -
898 \b{ The property only has an effect on platforms which use software input -
899 panels, such as Windows CE.} -
900 -
901 The default is platform dependent. -
902*/ -
903 -
904#ifdef Q_OS_WINCE -
905void QApplication::setAutoMaximizeThreshold(const int threshold) -
906{ -
907 QApplicationPrivate::autoMaximizeThreshold = threshold; -
908} -
909 -
910int QApplication::autoMaximizeThreshold() const -
911{ -
912 return QApplicationPrivate::autoMaximizeThreshold; -
913} -
914#endif -
915 -
916void QApplication::setAutoSipEnabled(const bool enabled) -
917{ -
918 QApplicationPrivate::autoSipEnabled = enabled; -
919} -
920 -
921bool QApplication::autoSipEnabled() const -
922{ -
923 return QApplicationPrivate::autoSipEnabled; -
924} -
925 -
926#ifndef QT_NO_STYLE_STYLESHEET -
927 -
928QString QApplication::styleSheet() const -
929{ -
930 return QApplicationPrivate::styleSheet; -
931} -
932 -
933void QApplication::setStyleSheet(const QString& styleSheet) -
934{ -
935 QApplicationPrivate::styleSheet = styleSheet; -
936 QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle*>(QApplicationPrivate::app_style); -
937 if (styleSheet.isEmpty()) { // application style sheet removed -
938 if (!proxy) -
939 return; // there was no stylesheet before -
940 setStyle(proxy->base); -
941 } else if (proxy) { // style sheet update, just repolish -
942 proxy->repolish(qApp); -
943 } else { // stylesheet set the first time -
944 QStyleSheetStyle *newProxy = new QStyleSheetStyle(QApplicationPrivate::app_style); -
945 QApplicationPrivate::app_style->setParent(newProxy); -
946 setStyle(newProxy); -
947 } -
948} -
949 -
950#endif // QT_NO_STYLE_STYLESHEET -
951 -
952/*! -
953 Returns the application's style object. -
954 -
955 \sa setStyle(), QStyle -
956*/ -
957QStyle *QApplication::style() -
958{ -
959 if (QApplicationPrivate::app_style) -
960 return QApplicationPrivate::app_style; -
961 if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { -
962 Q_ASSERT(!"No style available without QApplication!"); -
963 return 0; -
964 } -
965 -
966 if (!QApplicationPrivate::app_style) { -
967 // Compile-time search for default style -
968 // -
969 QString style; -
970#ifdef QT_BUILD_INTERNAL -
971 QString envStyle = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); -
972#else -
973 QString envStyle; -
974#endif -
975 if (!QApplicationPrivate::styleOverride.isEmpty()) { -
976 style = QApplicationPrivate::styleOverride; -
977 } else if (!envStyle.isEmpty()) { -
978 style = envStyle; -
979 } else { -
980 style = QApplicationPrivate::desktopStyleKey(); -
981 } -
982 -
983 QStyle *&app_style = QApplicationPrivate::app_style; -
984 app_style = QStyleFactory::create(style); -
985 if (!app_style) { -
986 QStringList styles = QStyleFactory::keys(); -
987 for (int i = 0; i < styles.size(); ++i) { -
988 if ((app_style = QStyleFactory::create(styles.at(i)))) -
989 break; -
990 } -
991 } -
992 if (!app_style) { -
993 Q_ASSERT(!"No styles available!"); -
994 return 0; -
995 } -
996 } -
997 // take ownership of the style -
998 QApplicationPrivate::app_style->setParent(qApp); -
999 -
1000 initSystemPalette(); -
1001 -
1002 if (QApplicationPrivate::set_pal) // repolish set palette with the new style -
1003 QApplication::setPalette(*QApplicationPrivate::set_pal); -
1004 -
1005#ifndef QT_NO_STYLE_STYLESHEET -
1006 if (!QApplicationPrivate::styleSheet.isEmpty()) { -
1007 qApp->setStyleSheet(QApplicationPrivate::styleSheet); -
1008 } else -
1009#endif -
1010 QApplicationPrivate::app_style->polish(qApp); -
1011 -
1012 return QApplicationPrivate::app_style; -
1013} -
1014 -
1015/*! -
1016 Sets the application's GUI style to \a style. Ownership of the style object -
1017 is transferred to QApplication, so QApplication will delete the style -
1018 object on application exit or when a new style is set and the old style is -
1019 still the parent of the application object. -
1020 -
1021 Example usage: -
1022 \snippet code/src_gui_kernel_qapplication.cpp 1 -
1023 -
1024 When switching application styles, the color palette is set back to the -
1025 initial colors or the system defaults. This is necessary since certain -
1026 styles have to adapt the color palette to be fully style-guide compliant. -
1027 -
1028 Setting the style before a palette has been set, i.e., before creating -
1029 QApplication, will cause the application to use QStyle::standardPalette() -
1030 for the palette. -
1031 -
1032 \warning Qt style sheets are currently not supported for custom QStyle -
1033 subclasses. We plan to address this in some future release. -
1034 -
1035 \sa style(), QStyle, setPalette(), desktopSettingsAware() -
1036*/ -
1037void QApplication::setStyle(QStyle *style) -
1038{ -
1039 if (!style || style == QApplicationPrivate::app_style) -
1040 return; -
1041 -
1042 QWidgetList all = allWidgets(); -
1043 -
1044 // clean up the old style -
1045 if (QApplicationPrivate::app_style) { -
1046 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -
1047 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { -
1048 register QWidget *w = *it; -
1049 if (!(w->windowType() == Qt::Desktop) && // except desktop -
1050 w->testAttribute(Qt::WA_WState_Polished)) { // has been polished -
1051 QApplicationPrivate::app_style->unpolish(w); -
1052 } -
1053 } -
1054 } -
1055 QApplicationPrivate::app_style->unpolish(qApp); -
1056 } -
1057 -
1058 QStyle *old = QApplicationPrivate::app_style; // save -
1059 -
1060#ifndef QT_NO_STYLE_STYLESHEET -
1061 if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast<QStyleSheetStyle *>(style)) { -
1062 // we have a stylesheet already and a new style is being set -
1063 QStyleSheetStyle *newProxy = new QStyleSheetStyle(style); -
1064 style->setParent(newProxy); -
1065 QApplicationPrivate::app_style = newProxy; -
1066 } else -
1067#endif // QT_NO_STYLE_STYLESHEET -
1068 QApplicationPrivate::app_style = style; -
1069 QApplicationPrivate::app_style->setParent(qApp); // take ownership -
1070 -
1071 // take care of possible palette requirements of certain gui -
1072 // styles. Do it before polishing the application since the style -
1073 // might call QApplication::setPalette() itself -
1074 if (QApplicationPrivate::set_pal) { -
1075 QApplication::setPalette(*QApplicationPrivate::set_pal); -
1076 } else if (QApplicationPrivate::sys_pal) { -
1077 QApplicationPrivate::initializeWidgetPaletteHash(); -
1078 QApplicationPrivate::setPalette_helper(*QApplicationPrivate::sys_pal, /*className=*/0, /*clearWidgetPaletteHash=*/false); -
1079 } else if (!QApplicationPrivate::sys_pal) { -
1080 // Initialize the sys_pal if it hasn't happened yet... -
1081 QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); -
1082 } -
1083 -
1084 // initialize the application with the new style -
1085 QApplicationPrivate::app_style->polish(qApp); -
1086 -
1087 // re-polish existing widgets if necessary -
1088 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -
1089 for (QWidgetList::ConstIterator it1 = all.constBegin(); it1 != all.constEnd(); ++it1) { -
1090 register QWidget *w = *it1; -
1091 if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) { -
1092 if (w->style() == QApplicationPrivate::app_style) -
1093 QApplicationPrivate::app_style->polish(w); // repolish -
1094#ifndef QT_NO_STYLE_STYLESHEET -
1095 else -
1096 w->setStyleSheet(w->styleSheet()); // touch -
1097#endif -
1098 } -
1099 } -
1100 -
1101 for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) { -
1102 register QWidget *w = *it2; -
1103 if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) { -
1104 QEvent e(QEvent::StyleChange); -
1105 QApplication::sendEvent(w, &e); -
1106 w->update(); -
1107 } -
1108 } -
1109 } -
1110 -
1111#ifndef QT_NO_STYLE_STYLESHEET -
1112 if (QStyleSheetStyle *oldProxy = qobject_cast<QStyleSheetStyle *>(old)) { -
1113 oldProxy->deref(); -
1114 } else -
1115#endif -
1116 if (old && old->parent() == qApp) { -
1117 delete old; -
1118 } -
1119 -
1120 if (QApplicationPrivate::focus_widget) { -
1121 QFocusEvent in(QEvent::FocusIn, Qt::OtherFocusReason); -
1122 QApplication::sendEvent(QApplicationPrivate::focus_widget->style(), &in); -
1123 QApplicationPrivate::focus_widget->update(); -
1124 } -
1125} -
1126 -
1127/*! -
1128 \overload -
1129 -
1130 Requests a QStyle object for \a style from the QStyleFactory. -
1131 -
1132 The string must be one of the QStyleFactory::keys(), typically one of -
1133 "windows", "fusion", "windowsxp", or "macintosh". Style -
1134 names are case insensitive. -
1135 -
1136 Returns 0 if an unknown \a style is passed, otherwise the QStyle object -
1137 returned is set as the application's GUI style. -
1138 -
1139 \warning To ensure that the application's style is set correctly, it is -
1140 best to call this function before the QApplication constructor, if -
1141 possible. -
1142*/ -
1143QStyle* QApplication::setStyle(const QString& style) -
1144{ -
1145 QStyle *s = QStyleFactory::create(style); -
1146 if (!s) -
1147 return 0; -
1148 -
1149 setStyle(s); -
1150 return s; -
1151} -
1152 -
1153/*! -
1154 Returns the color specification. -
1155 -
1156 \sa QApplication::setColorSpec() -
1157*/ -
1158 -
1159int QApplication::colorSpec() -
1160{ -
1161 return QApplicationPrivate::app_cspec; -
1162} -
1163 -
1164/*! -
1165 Sets the color specification for the application to \a spec. -
1166 -
1167 The color specification controls how the application allocates colors when -
1168 run on a display with a limited amount of colors, e.g. 8 bit / 256 color -
1169 displays. -
1170 -
1171 The color specification must be set before you create the QApplication -
1172 object. -
1173 -
1174 The options are: -
1175 \list -
1176 \li QApplication::NormalColor. This is the default color allocation -
1177 strategy. Use this option if your application uses buttons, menus, -
1178 texts and pixmaps with few colors. With this option, the -
1179 application uses system global colors. This works fine for most -
1180 applications under X11, but on the Windows platform, it may cause -
1181 dithering of non-standard colors. -
1182 \li QApplication::CustomColor. Use this option if your application -
1183 needs a small number of custom colors. On X11, this option is the -
1184 same as NormalColor. On Windows, Qt creates a Windows palette, and -
1185 allocates colors to it on demand. -
1186 \li QApplication::ManyColor. Use this option if your application is -
1187 very color hungry, e.g., it requires thousands of colors. \br -
1188 Under X11 the effect is: -
1189 \list -
1190 \li For 256-color displays which have at best a 256 color true -
1191 color visual, the default visual is used, and colors are -
1192 allocated from a color cube. The color cube is the 6x6x6 -
1193 (216 color) "Web palette" (the red, green, and blue -
1194 components always have one of the following values: 0x00, -
1195 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors -
1196 can be changed by the \e -ncols option. The user can force -
1197 the application to use the true color visual with the -
1198 \l{QApplication::QApplication()}{-visual} option. -
1199 \li For 256-color displays which have a true color visual with -
1200 more than 256 colors, use that visual. Silicon Graphics X -
1201 servers this feature, for example. They provide an 8 bit -
1202 visual by default but can deliver true color when asked. -
1203 \endlist -
1204 On Windows, Qt creates a Windows palette, and fills it with a color -
1205 cube. -
1206 \endlist -
1207 -
1208 Be aware that the CustomColor and ManyColor choices may lead to colormap -
1209 flashing: The foreground application gets (most) of the available colors, -
1210 while the background windows will look less attractive. -
1211 -
1212 Example: -
1213 -
1214 \snippet code/src_gui_kernel_qapplication.cpp 2 -
1215 -
1216 \sa colorSpec() -
1217*/ -
1218 -
1219void QApplication::setColorSpec(int spec) -
1220{ -
1221 if (qApp) -
1222 qWarning("QApplication::setColorSpec: This function must be " -
1223 "called before the QApplication object is created"); -
1224 QApplicationPrivate::app_cspec = spec; -
1225} -
1226 -
1227/*! -
1228 \property QApplication::globalStrut -
1229 \brief the minimum size that any GUI element that the user can interact -
1230 with should have -
1231 -
1232 For example, no button should be resized to be smaller than the global -
1233 strut size. The strut size should be considered when reimplementing GUI -
1234 controls that may be used on touch-screens or similar I/O devices. -
1235 -
1236 Example: -
1237 -
1238 \snippet code/src_gui_kernel_qapplication.cpp 3 -
1239 -
1240 By default, this property contains a QSize object with zero width and height. -
1241*/ -
1242QSize QApplication::globalStrut() -
1243{ -
1244 return QApplicationPrivate::app_strut; -
1245} -
1246 -
1247void QApplication::setGlobalStrut(const QSize& strut) -
1248{ -
1249 QApplicationPrivate::app_strut = strut; -
1250} -
1251 -
1252 -
1253/*! -
1254 \fn QPalette QApplication::palette(const QWidget* widget) -
1255 \overload -
1256 -
1257 If a \a widget is passed, the default palette for the widget's class is -
1258 returned. This may or may not be the application palette. In most cases -
1259 there is no special palette for certain types of widgets, but one notable -
1260 exception is the popup menu under Windows, if the user has defined a -
1261 special background color for menus in the display settings. -
1262 -
1263 \sa setPalette(), QWidget::palette() -
1264*/ -
1265QPalette QApplication::palette(const QWidget* w) -
1266{ -
1267 PaletteHash *hash = app_palettes(); -
1268 if (w && hash && hash->size()) { -
1269 QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(w->metaObject()->className()); -
1270 if (it != hash->constEnd()) -
1271 return *it; -
1272 for (it = hash->constBegin(); it != hash->constEnd(); ++it) { -
1273 if (w->inherits(it.key())) -
1274 return it.value(); -
1275 } -
1276 } -
1277 return palette(); -
1278} -
1279 -
1280/*! -
1281 \overload -
1282 -
1283 Returns the palette for widgets of the given \a className. -
1284 -
1285 \sa setPalette(), QWidget::palette() -
1286*/ -
1287QPalette QApplication::palette(const char *className) -
1288{ -
1289 if (!QApplicationPrivate::app_pal) -
1290 palette(); -
1291 PaletteHash *hash = app_palettes(); -
1292 if (className && hash && hash->size()) { -
1293 QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(className); -
1294 if (it != hash->constEnd()) -
1295 return *it; -
1296 } -
1297 return *QApplicationPrivate::app_pal; -
1298} -
1299 -
1300void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash) -
1301{ -
1302 QPalette pal = palette; -
1303 -
1304 if (QApplicationPrivate::app_style) -
1305 QApplicationPrivate::app_style->polish(pal); // NB: non-const reference -
1306 -
1307 bool all = false; -
1308 PaletteHash *hash = app_palettes(); -
1309 if (!className) { -
1310 if (QApplicationPrivate::app_pal && pal.isCopyOf(*QApplicationPrivate::app_pal)) -
1311 return; -
1312 if (!QApplicationPrivate::app_pal) -
1313 QApplicationPrivate::app_pal = new QPalette(pal); -
1314 else -
1315 *QApplicationPrivate::app_pal = pal; -
1316 if (hash && hash->size()) { -
1317 all = true; -
1318 if (clearWidgetPaletteHash) -
1319 hash->clear(); -
1320 } -
1321 } else if (hash) { -
1322 hash->insert(className, pal); -
1323 } -
1324 -
1325 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -
1326 // Send ApplicationPaletteChange to qApp itself, and to the widgets. -
1327 QEvent e(QEvent::ApplicationPaletteChange); -
1328 QApplication::sendEvent(QApplication::instance(), &e); -
1329 -
1330 QWidgetList wids = QApplication::allWidgets(); -
1331 for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { -
1332 register QWidget *w = *it; -
1333 if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class -
1334 QApplication::sendEvent(w, &e); -
1335 } -
1336 -
1337 // Send to all scenes as well. -
1338#ifndef QT_NO_GRAPHICSVIEW -
1339 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list; -
1340 for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin(); -
1341 it != scenes.constEnd(); ++it) { -
1342 QApplication::sendEvent(*it, &e); -
1343 } -
1344#endif //QT_NO_GRAPHICSVIEW -
1345 } -
1346 if (!className && (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal))) { -
1347 if (!QApplicationPrivate::set_pal) -
1348 QApplicationPrivate::set_pal = new QPalette(palette); -
1349 else -
1350 *QApplicationPrivate::set_pal = palette; -
1351 } -
1352} -
1353 -
1354/*! -
1355 Changes the default application palette to \a palette. -
1356 -
1357 If \a className is passed, the change applies only to widgets that inherit -
1358 \a className (as reported by QObject::inherits()). If \a className is left -
1359 0, the change affects all widgets, thus overriding any previously set class -
1360 specific palettes. -
1361 -
1362 The palette may be changed according to the current GUI style in -
1363 QStyle::polish(). -
1364 -
1365 \warning Do not use this function in conjunction with \l{Qt Style Sheets}. -
1366 When using style sheets, the palette of a widget can be customized using -
1367 the "color", "background-color", "selection-color", -
1368 "selection-background-color" and "alternate-background-color". -
1369 -
1370 \note Some styles do not use the palette for all drawing, for instance, if -
1371 they make use of native theme engines. This is the case for the Windows XP, -
1372 Windows Vista, and Mac OS X styles. -
1373 -
1374 \sa QWidget::setPalette(), palette(), QStyle::polish() -
1375*/ -
1376 -
1377void QApplication::setPalette(const QPalette &palette, const char* className) -
1378{ -
1379 QApplicationPrivate::setPalette_helper(palette, className, /*clearWidgetPaletteHash=*/ true); -
1380} -
1381 -
1382 -
1383 -
1384void QApplicationPrivate::setSystemPalette(const QPalette &pal) -
1385{ -
1386 QPalette adjusted; -
1387 -
1388#if 0 -
1389 // adjust the system palette to avoid dithering -
1390 QColormap cmap = QColormap::instance(); -
1391 if (cmap.depths() > 4 && cmap.depths() < 24) { -
1392 for (int g = 0; g < QPalette::NColorGroups; g++) -
1393 for (int i = 0; i < QPalette::NColorRoles; i++) { -
1394 QColor color = pal.color((QPalette::ColorGroup)g, (QPalette::ColorRole)i); -
1395 color = cmap.colorAt(cmap.pixel(color)); -
1396 adjusted.setColor((QPalette::ColorGroup)g, (QPalette::ColorRole) i, color); -
1397 } -
1398 } -
1399#else -
1400 adjusted = pal; -
1401#endif -
1402 -
1403 if (!sys_pal) -
1404 sys_pal = new QPalette(adjusted); -
1405 else -
1406 *sys_pal = adjusted; -
1407 -
1408 -
1409 if (!QApplicationPrivate::set_pal) -
1410 QApplication::setPalette(*sys_pal); -
1411} -
1412 -
1413/*! -
1414 Returns the default application font. -
1415 -
1416 \sa fontMetrics(), QWidget::font() -
1417*/ -
1418QFont QApplication::font() -
1419{ -
1420 return QGuiApplication::font(); -
1421} -
1422 -
1423/*! -
1424 \overload -
1425 -
1426 Returns the default font for the \a widget. -
1427 -
1428 \sa fontMetrics(), QWidget::setFont() -
1429*/ -
1430 -
1431QFont QApplication::font(const QWidget *widget) -
1432{ -
1433 FontHash *hash = app_fonts(); -
1434 -
1435 if (widget && hash && hash->size()) { -
1436#ifdef Q_OS_MAC -
1437 // short circuit for small and mini controls -
1438 if (widget->testAttribute(Qt::WA_MacSmallSize)) { -
1439 return hash->value(QByteArrayLiteral("QSmallFont")); -
1440 } else if (widget->testAttribute(Qt::WA_MacMiniSize)) { -
1441 return hash->value(QByteArrayLiteral("QMiniFont")); -
1442 } -
1443#endif -
1444 QHash<QByteArray, QFont>::ConstIterator it = -
1445 hash->constFind(widget->metaObject()->className()); -
1446 if (it != hash->constEnd()) -
1447 return it.value(); -
1448 for (it = hash->constBegin(); it != hash->constEnd(); ++it) { -
1449 if (widget->inherits(it.key())) -
1450 return it.value(); -
1451 } -
1452 } -
1453 return font(); -
1454} -
1455 -
1456/*! -
1457 \overload -
1458 -
1459 Returns the font for widgets of the given \a className. -
1460 -
1461 \sa setFont(), QWidget::font() -
1462*/ -
1463QFont QApplication::font(const char *className) -
1464{ -
1465 FontHash *hash = app_fonts(); -
1466 if (className && hash && hash->size()) { -
1467 QHash<QByteArray, QFont>::ConstIterator it = hash->constFind(className); -
1468 if (it != hash->constEnd()) -
1469 return *it; -
1470 } -
1471 return font(); -
1472} -
1473 -
1474 -
1475/*! -
1476 Changes the default application font to \a font. If \a className is passed, -
1477 the change applies only to classes that inherit \a className (as reported -
1478 by QObject::inherits()). -
1479 -
1480 On application start-up, the default font depends on the window system. It -
1481 can vary depending on both the window system version and the locale. This -
1482 function lets you override the default font; but overriding may be a bad -
1483 idea because, for example, some locales need extra large fonts to support -
1484 their special characters. -
1485 -
1486 \warning Do not use this function in conjunction with \l{Qt Style Sheets}. -
1487 The font of an application can be customized using the "font" style sheet -
1488 property. To set a bold font for all QPushButtons, set the application -
1489 styleSheet() as "QPushButton { font: bold }" -
1490 -
1491 \sa font(), fontMetrics(), QWidget::setFont() -
1492*/ -
1493 -
1494void QApplication::setFont(const QFont &font, const char *className) -
1495{ -
1496 bool all = false; -
1497 FontHash *hash = app_fonts(); -
1498 if (!className) { -
1499 QGuiApplication::setFont(font); -
1500 if (hash && hash->size()) { -
1501 all = true; -
1502 hash->clear(); -
1503 } -
1504 } else if (hash) { -
1505 hash->insert(className, font); -
1506 } -
1507 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -
1508 // Send ApplicationFontChange to qApp itself, and to the widgets. -
1509 QEvent e(QEvent::ApplicationFontChange); -
1510 QApplication::sendEvent(QApplication::instance(), &e); -
1511 -
1512 QWidgetList wids = QApplication::allWidgets(); -
1513 for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { -
1514 register QWidget *w = *it; -
1515 if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class -
1516 sendEvent(w, &e); -
1517 } -
1518 -
1519#ifndef QT_NO_GRAPHICSVIEW -
1520 // Send to all scenes as well. -
1521 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list; -
1522 for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin(); -
1523 it != scenes.constEnd(); ++it) { -
1524 QApplication::sendEvent(*it, &e); -
1525 } -
1526#endif //QT_NO_GRAPHICSVIEW -
1527 } -
1528 if (!className && (!QApplicationPrivate::sys_font || !font.isCopyOf(*QApplicationPrivate::sys_font))) { -
1529 if (!QApplicationPrivate::set_font) -
1530 QApplicationPrivate::set_font = new QFont(font); -
1531 else -
1532 *QApplicationPrivate::set_font = font; -
1533 } -
1534} -
1535 -
1536/*! \internal -
1537*/ -
1538void QApplicationPrivate::setSystemFont(const QFont &font) -
1539{ -
1540 if (!sys_font) -
1541 sys_font = new QFont(font); -
1542 else -
1543 *sys_font = font; -
1544 -
1545 if (!QApplicationPrivate::set_font) -
1546 QApplication::setFont(*sys_font); -
1547} -
1548 -
1549/*! \internal -
1550*/ -
1551QString QApplicationPrivate::desktopStyleKey() -
1552{ -
1553 // The platform theme might return a style that is not available, find -
1554 // first valid one. -
1555 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { -
1556 const QStringList availableKeys = QStyleFactory::keys(); -
1557 foreach (const QString &style, theme->themeHint(QPlatformTheme::StyleNames).toStringList()) -
1558 if (availableKeys.contains(style, Qt::CaseInsensitive)) -
1559 return style; -
1560 } -
1561 return QString(); -
1562} -
1563 -
1564/*! -
1565 \property QApplication::windowIcon -
1566 \brief the default window icon -
1567 -
1568 \sa QWidget::setWindowIcon(), {Setting the Application Icon} -
1569*/ -
1570QIcon QApplication::windowIcon() -
1571{ -
1572 return QApplicationPrivate::app_icon ? *QApplicationPrivate::app_icon : QIcon(); -
1573} -
1574 -
1575void QApplication::setWindowIcon(const QIcon &icon) -
1576{ -
1577 if (!QApplicationPrivate::app_icon) -
1578 QApplicationPrivate::app_icon = new QIcon(); -
1579 *QApplicationPrivate::app_icon = icon; -
1580 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -
1581 QEvent e(QEvent::ApplicationWindowIconChange); -
1582 QWidgetList all = QApplication::allWidgets(); -
1583 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { -
1584 register QWidget *w = *it; -
1585 if (w->isWindow()) -
1586 sendEvent(w, &e); -
1587 } -
1588 } -
1589} -
1590 -
1591/*! -
1592 Returns a list of the top-level widgets (windows) in the application. -
1593 -
1594 \note Some of the top-level widgets may be hidden, for example a tooltip if -
1595 no tooltip is currently shown. -
1596 -
1597 Example: -
1598 -
1599 \snippet code/src_gui_kernel_qapplication.cpp 4 -
1600 -
1601 \sa allWidgets(), QWidget::isWindow(), QWidget::isHidden() -
1602*/ -
1603QWidgetList QApplication::topLevelWidgets() -
1604{ -
1605 QWidgetList list; -
1606 QWidgetList all = allWidgets(); -
1607 -
1608 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { -
1609 QWidget *w = *it; -
1610 if (w->isWindow() && w->windowType() != Qt::Desktop) -
1611 list.append(w); -
1612 } -
1613 return list; -
1614} -
1615 -
1616/*! -
1617 Returns a list of all the widgets in the application. -
1618 -
1619 The list is empty (QList::isEmpty()) if there are no widgets. -
1620 -
1621 \note Some of the widgets may be hidden. -
1622 -
1623 Example: -
1624 \snippet code/src_gui_kernel_qapplication.cpp 5 -
1625 -
1626 \sa topLevelWidgets(), QWidget::isVisible() -
1627*/ -
1628 -
1629QWidgetList QApplication::allWidgets() -
1630{ -
1631 if (QWidgetPrivate::allWidgets) -
1632 return QWidgetPrivate::allWidgets->toList(); -
1633 return QWidgetList(); -
1634} -
1635 -
1636/*! -
1637 Returns the application widget that has the keyboard input focus, or 0 if -
1638 no widget in this application has the focus. -
1639 -
1640 \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged() -
1641*/ -
1642 -
1643QWidget *QApplication::focusWidget() -
1644{ -
1645 return QApplicationPrivate::focus_widget; -
1646} -
1647 -
1648void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) -
1649{ -
1650#ifndef QT_NO_GRAPHICSVIEW -
1651 if (focus && focus->window()->graphicsProxyWidget()) -
1652 return; -
1653#endif -
1654 -
1655 hidden_focus_widget = 0; -
1656 -
1657 if (focus != focus_widget) { -
1658 if (focus && focus->isHidden()) { -
1659 hidden_focus_widget = focus; -
1660 return; -
1661 } -
1662 -
1663 if (focus && (reason == Qt::BacktabFocusReason || reason == Qt::TabFocusReason) -
1664 && qt_in_tab_key_event) -
1665 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange); -
1666 else if (focus && reason == Qt::ShortcutFocusReason) { -
1667 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange); -
1668 } -
1669 QWidget *prev = focus_widget; -
1670 focus_widget = focus; -
1671 -
1672 if(focus_widget) -
1673 focus_widget->d_func()->setFocus_sys(); -
1674 -
1675 if (reason != Qt::NoFocusReason) { -
1676 -
1677 //send events -
1678 if (prev) { -
1679#ifdef QT_KEYPAD_NAVIGATION -
1680 if (QApplication::keypadNavigationEnabled()) { -
1681 if (prev->hasEditFocus() && reason != Qt::PopupFocusReason) -
1682 prev->setEditFocus(false); -
1683 } -
1684#endif -
1685 QFocusEvent out(QEvent::FocusOut, reason); -
1686 QPointer<QWidget> that = prev; -
1687 QApplication::sendEvent(prev, &out); -
1688 if (that) -
1689 QApplication::sendEvent(that->style(), &out); -
1690 } -
1691 if(focus && QApplicationPrivate::focus_widget == focus) { -
1692 QFocusEvent in(QEvent::FocusIn, reason); -
1693 QPointer<QWidget> that = focus; -
1694 QApplication::sendEvent(focus, &in); -
1695 if (that) -
1696 QApplication::sendEvent(that->style(), &in); -
1697 } -
1698 emit qApp->focusChanged(prev, focus_widget); -
1699 } -
1700 } -
1701} -
1702 -
1703 -
1704/*! -
1705 Returns the application top-level window that has the keyboard input focus, -
1706 or 0 if no application window has the focus. There might be an -
1707 activeWindow() even if there is no focusWidget(), for example if no widget -
1708 in that window accepts key events. -
1709 -
1710 \sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget() -
1711*/ -
1712 -
1713QWidget *QApplication::activeWindow() -
1714{ -
1715 return QApplicationPrivate::active_window; -
1716} -
1717 -
1718/*! -
1719 Returns display (screen) font metrics for the application font. -
1720 -
1721 \sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics() -
1722*/ -
1723 -
1724QFontMetrics QApplication::fontMetrics() -
1725{ -
1726 return desktop()->fontMetrics(); -
1727} -
1728 -
1729 -
1730/*! -
1731 Closes all top-level windows. -
1732 -
1733 This function is particularly useful for applications with many top-level -
1734 windows. It could, for example, be connected to a \uicontrol{Exit} entry in the -
1735 \uicontrol{File} menu: -
1736 -
1737 \snippet mainwindows/mdi/mainwindow.cpp 0 -
1738 -
1739 The windows are closed in random order, until one window does not accept -
1740 the close event. The application quits when the last window was -
1741 successfully closed; this can be turned off by setting -
1742 \l quitOnLastWindowClosed to false. -
1743 -
1744 \sa quitOnLastWindowClosed, lastWindowClosed(), QWidget::close(), -
1745 QWidget::closeEvent(), lastWindowClosed(), quit(), topLevelWidgets(), -
1746 QWidget::isWindow() -
1747*/ -
1748void QApplication::closeAllWindows() -
1749{ -
1750 bool did_close = true; -
1751 QWidget *w; -
1752 while ((w = activeModalWidget()) && did_close) { -
1753 if (!w->isVisible() || w->data->is_closing) -
1754 break; -
1755 did_close = w->close(); -
1756 } -
1757 QWidgetList list = QApplication::topLevelWidgets(); -
1758 for (int i = 0; did_close && i < list.size(); ++i) { -
1759 w = list.at(i); -
1760 if (w->isVisible() -
1761 && w->windowType() != Qt::Desktop -
1762 && !w->data->is_closing) { -
1763 did_close = w->close(); -
1764 list = QApplication::topLevelWidgets(); -
1765 i = -1; -
1766 } -
1767 } -
1768} -
1769 -
1770/*! -
1771 Displays a simple message box about Qt. The message includes the version -
1772 number of Qt being used by the application. -
1773 -
1774 This is useful for inclusion in the \uicontrol Help menu of an application, as -
1775 shown in the \l{mainwindows/menus}{Menus} example. -
1776 -
1777 This function is a convenience slot for QMessageBox::aboutQt(). -
1778*/ -
1779void QApplication::aboutQt() -
1780{ -
1781#ifndef QT_NO_MESSAGEBOX -
1782 QMessageBox::aboutQt(activeWindow()); -
1783#endif // QT_NO_MESSAGEBOX -
1784} -
1785 -
1786/*! -
1787 \since 4.1 -
1788 \fn void QApplication::focusChanged(QWidget *old, QWidget *now) -
1789 -
1790 This signal is emitted when the widget that has keyboard focus changed from -
1791 \a old to \a now, i.e., because the user pressed the tab-key, clicked into -
1792 a widget or changed the active window. Both \a old and \a now can be the -
1793 null-pointer. -
1794 -
1795 The signal is emitted after both widget have been notified about the change -
1796 through QFocusEvent. -
1797 -
1798 \sa QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason -
1799*/ -
1800 -
1801/*!\reimp -
1802 -
1803*/ -
1804bool QApplication::event(QEvent *e) -
1805{ -
1806 Q_D(QApplication); -
1807 if(e->type() == QEvent::Close) { -
1808 QCloseEvent *ce = static_cast<QCloseEvent*>(e); -
1809 ce->accept(); -
1810 closeAllWindows(); -
1811 -
1812 QWidgetList list = topLevelWidgets(); -
1813 for (int i = 0; i < list.size(); ++i) { -
1814 QWidget *w = list.at(i); -
1815 if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) && -
1816 (!(w->windowType() == Qt::Dialog) || !w->parentWidget())) { -
1817 ce->ignore(); -
1818 break; -
1819 } -
1820 } -
1821 if (ce->isAccepted()) { -
1822 return true; -
1823 } -
1824#ifndef Q_OS_WIN -
1825 } else if (e->type() == QEvent::LocaleChange) { -
1826 // on Windows the event propagation is taken care by the -
1827 // WM_SETTINGCHANGE event handler. -
1828 QWidgetList list = topLevelWidgets(); -
1829 for (int i = 0; i < list.size(); ++i) { -
1830 QWidget *w = list.at(i); -
1831 if (!(w->windowType() == Qt::Desktop)) { -
1832 if (!w->testAttribute(Qt::WA_SetLocale)) -
1833 w->d_func()->setLocale_helper(QLocale(), true); -
1834 } -
1835 } -
1836#endif -
1837 } else if (e->type() == QEvent::Timer) { -
1838 QTimerEvent *te = static_cast<QTimerEvent*>(e); -
1839 Q_ASSERT(te != 0); -
1840 if (te->timerId() == d->toolTipWakeUp.timerId()) { -
1841 d->toolTipWakeUp.stop(); -
1842 if (d->toolTipWidget) { -
1843 QWidget *w = d->toolTipWidget->window(); -
1844 // show tooltip if WA_AlwaysShowToolTips is set, or if -
1845 // any ancestor of d->toolTipWidget is the active -
1846 // window -
1847 bool showToolTip = w->testAttribute(Qt::WA_AlwaysShowToolTips); -
1848 while (w && !showToolTip) { -
1849 showToolTip = w->isActiveWindow(); -
1850 w = w->parentWidget(); -
1851 w = w ? w->window() : 0; -
1852 } -
1853 if (showToolTip) { -
1854 QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos); -
1855 QApplication::sendEvent(d->toolTipWidget, &e); -
1856 if (e.isAccepted()) -
1857 d->toolTipFallAsleep.start(2000, this); -
1858 } -
1859 } -
1860 } else if (te->timerId() == d->toolTipFallAsleep.timerId()) { -
1861 d->toolTipFallAsleep.stop(); -
1862 } -
1863 } -
1864 -
1865 if(e->type() == QEvent::LanguageChange) { -
1866 QWidgetList list = topLevelWidgets(); -
1867 for (int i = 0; i < list.size(); ++i) { -
1868 QWidget *w = list.at(i); -
1869 if (!(w->windowType() == Qt::Desktop)) -
1870 postEvent(w, new QEvent(QEvent::LanguageChange)); -
1871 } -
1872 } -
1873 -
1874 return QGuiApplication::event(e); -
1875} -
1876 -
1877/*! -
1878 \fn void QApplication::syncX() -
1879 Was used to synchronize with the X server in 4.x, here for source compatibility. -
1880 \internal -
1881 \obsolete -
1882*/ -
1883 -
1884void QApplicationPrivate::notifyLayoutDirectionChange() -
1885{ -
1886 QWidgetList list = QApplication::topLevelWidgets(); -
1887 for (int i = 0; i < list.size(); ++i) { -
1888 QWidget *w = list.at(i); -
1889 QEvent ev(QEvent::ApplicationLayoutDirectionChange); -
1890 QCoreApplication::sendEvent(w, &ev); -
1891 } -
1892} -
1893 -
1894/*! -
1895 \fn void QApplication::setActiveWindow(QWidget* active) -
1896 -
1897 Sets the active window to the \a active widget in response to a system -
1898 event. The function is called from the platform specific event handlers. -
1899 -
1900 \warning This function does \e not set the keyboard focus to the active -
1901 widget. Call QWidget::activateWindow() instead. -
1902 -
1903 It sets the activeWindow() and focusWidget() attributes and sends proper -
1904 \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate} -
1905 {WindowDeactivate} and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut} -
1906 {FocusOut} events to all appropriate widgets. The window will then be -
1907 painted in active state (e.g. cursors in line edits will blink), and it -
1908 will have tool tips enabled. -
1909 -
1910 \sa activeWindow(), QWidget::activateWindow() -
1911*/ -
1912void QApplication::setActiveWindow(QWidget* act) -
1913{ -
1914 QWidget* window = act?act->window():0; -
1915 -
1916 if (QApplicationPrivate::active_window == window) -
1917 return; -
1918 -
1919#ifndef QT_NO_GRAPHICSVIEW -
1920 if (window && window->graphicsProxyWidget()) { -
1921 // Activate the proxy's view->viewport() ? -
1922 return; -
1923 } -
1924#endif -
1925 -
1926 QWidgetList toBeActivated; -
1927 QWidgetList toBeDeactivated; -
1928 -
1929 if (QApplicationPrivate::active_window) { -
1930 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { -
1931 QWidgetList list = topLevelWidgets(); -
1932 for (int i = 0; i < list.size(); ++i) { -
1933 QWidget *w = list.at(i); -
1934 if (w->isVisible() && w->isActiveWindow()) -
1935 toBeDeactivated.append(w); -
1936 } -
1937 } else { -
1938 toBeDeactivated.append(QApplicationPrivate::active_window); -
1939 } -
1940 } -
1941 -
1942 if (QApplicationPrivate::focus_widget) { -
1943 if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled)) -
1944 qApp->inputMethod()->commit(); -
1945 -
1946 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, Qt::ActiveWindowFocusReason); -
1947 QApplication::sendEvent(QApplicationPrivate::focus_widget, &focusAboutToChange); -
1948 } -
1949 -
1950 QApplicationPrivate::active_window = window; -
1951 -
1952 if (QApplicationPrivate::active_window) { -
1953 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { -
1954 QWidgetList list = topLevelWidgets(); -
1955 for (int i = 0; i < list.size(); ++i) { -
1956 QWidget *w = list.at(i); -
1957 if (w->isVisible() && w->isActiveWindow()) -
1958 toBeActivated.append(w); -
1959 } -
1960 } else { -
1961 toBeActivated.append(QApplicationPrivate::active_window); -
1962 } -
1963 -
1964 } -
1965 -
1966 // first the activation/deactivation events -
1967 QEvent activationChange(QEvent::ActivationChange); -
1968 QEvent windowActivate(QEvent::WindowActivate); -
1969 QEvent windowDeactivate(QEvent::WindowDeactivate); -
1970 -
1971 for (int i = 0; i < toBeActivated.size(); ++i) { -
1972 QWidget *w = toBeActivated.at(i); -
1973 sendSpontaneousEvent(w, &windowActivate); -
1974 sendSpontaneousEvent(w, &activationChange); -
1975 } -
1976 -
1977 for(int i = 0; i < toBeDeactivated.size(); ++i) { -
1978 QWidget *w = toBeDeactivated.at(i); -
1979 sendSpontaneousEvent(w, &windowDeactivate); -
1980 sendSpontaneousEvent(w, &activationChange); -
1981 } -
1982 -
1983 if (QApplicationPrivate::popupWidgets == 0) { // !inPopupMode() -
1984 // then focus events -
1985 if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) { -
1986 QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); -
1987 } else if (QApplicationPrivate::active_window) { -
1988 QWidget *w = QApplicationPrivate::active_window->focusWidget(); -
1989 if (w && w->isVisible() /*&& w->focusPolicy() != QWidget::NoFocus*/) -
1990 w->setFocus(Qt::ActiveWindowFocusReason); -
1991 else { -
1992 w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window, true); -
1993 if (w) { -
1994 w->setFocus(Qt::ActiveWindowFocusReason); -
1995 } else { -
1996 // If the focus widget is not in the activate_window, clear the focus -
1997 w = QApplicationPrivate::focus_widget; -
1998 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) -
1999 QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason); -
2000 else if (!QApplicationPrivate::active_window->isAncestorOf(w)) -
2001 QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); -
2002 } -
2003 } -
2004 } -
2005 } -
2006} -
2007 -
2008/*!internal -
2009 * Helper function that returns the new focus widget, but does not set the focus reason. -
2010 * Returns 0 if a new focus widget could not be found. -
2011 * Shared with QGraphicsProxyWidgetPrivate::findFocusChild() -
2012*/ -
2013QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool next) -
2014{ -
2015 uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus; -
2016 -
2017 QWidget *f = toplevel->focusWidget(); -
2018 if (!f) -
2019 f = toplevel; -
2020 -
2021 QWidget *w = f; -
2022 QWidget *test = f->d_func()->focus_next; -
2023 while (test && test != f) { -
2024 if ((test->focusPolicy() & focus_flag) == focus_flag -
2025 && !(test->d_func()->extra && test->d_func()->extra->focus_proxy) -
2026 && test->isVisibleTo(toplevel) && test->isEnabled() -
2027 && !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test)) -
2028 && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))) { -
2029 w = test; -
2030 if (next) -
2031 break; -
2032 } -
2033 test = test->d_func()->focus_next; -
2034 } -
2035 if (w == f) { -
2036 if (qt_in_tab_key_event) { -
2037 w->window()->setAttribute(Qt::WA_KeyboardFocusChange); -
2038 w->update(); -
2039 } -
2040 return 0; -
2041 } -
2042 return w; -
2043} -
2044 -
2045/*! -
2046 \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF) -
2047 \internal -
2048 -
2049 Creates the proper Enter/Leave event when widget \a enter is entered and -
2050 widget \a leave is left. -
2051 */ -
2052void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF) -
2053{ -
2054 const QPoint globalPos = globalPosF.toPoint(); -
2055#if 0 -
2056 if (leave) { -
2057 QEvent e(QEvent::Leave); -
2058 QApplication::sendEvent(leave, & e); -
2059 } -
2060 if (enter) { -
2061 const QPoint windowPos = enter->window()->mapFromGlobal(globalPos); -
2062 QEnterEvent e(enter->mapFromGlobal(globalPos), windowPos, globalPos); -
2063 QApplication::sendEvent(enter, & e); -
2064 } -
2065 return; -
2066#endif -
2067 -
2068 QWidget* w ; -
2069 if ((!enter && !leave) || (enter == leave)) -
2070 return; -
2071#ifdef ALIEN_DEBUG -
2072 qDebug() << "QApplicationPrivate::dispatchEnterLeave, ENTER:" << enter << "LEAVE:" << leave; -
2073#endif -
2074 QWidgetList leaveList; -
2075 QWidgetList enterList; -
2076 -
2077 bool sameWindow = leave && enter && leave->window() == enter->window(); -
2078 if (leave && !sameWindow) { -
2079 w = leave; -
2080 do { -
2081 leaveList.append(w); -
2082 } while (!w->isWindow() && (w = w->parentWidget())); -
2083 } -
2084 if (enter && !sameWindow) { -
2085 w = enter; -
2086 do { -
2087 enterList.prepend(w); -
2088 } while (!w->isWindow() && (w = w->parentWidget())); -
2089 } -
2090 if (sameWindow) { -
2091 int enterDepth = 0; -
2092 int leaveDepth = 0; -
2093 w = enter; -
2094 while (!w->isWindow() && (w = w->parentWidget())) -
2095 enterDepth++; -
2096 w = leave; -
2097 while (!w->isWindow() && (w = w->parentWidget())) -
2098 leaveDepth++; -
2099 QWidget* wenter = enter; -
2100 QWidget* wleave = leave; -
2101 while (enterDepth > leaveDepth) { -
2102 wenter = wenter->parentWidget(); -
2103 enterDepth--; -
2104 } -
2105 while (leaveDepth > enterDepth) { -
2106 wleave = wleave->parentWidget(); -
2107 leaveDepth--; -
2108 } -
2109 while (!wenter->isWindow() && wenter != wleave) { -
2110 wenter = wenter->parentWidget(); -
2111 wleave = wleave->parentWidget(); -
2112 } -
2113 -
2114 w = leave; -
2115 while (w != wleave) { -
2116 leaveList.append(w); -
2117 w = w->parentWidget(); -
2118 } -
2119 w = enter; -
2120 while (w != wenter) { -
2121 enterList.prepend(w); -
2122 w = w->parentWidget(); -
2123 } -
2124 } -
2125 -
2126 QEvent leaveEvent(QEvent::Leave); -
2127 for (int i = 0; i < leaveList.size(); ++i) { -
2128 w = leaveList.at(i); -
2129 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { -
2130 QApplication::sendEvent(w, &leaveEvent); -
2131 if (w->testAttribute(Qt::WA_Hover) && -
2132 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) { -
2133 Q_ASSERT(instance()); -
2134 QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), w->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos), -
2135 QApplication::keyboardModifiers()); -
2136 qApp->d_func()->notify_helper(w, &he); -
2137 } -
2138 } -
2139 } -
2140 if (!enterList.isEmpty()) { -
2141 const QPoint windowPos = enterList.front()->window()->mapFromGlobal(globalPos); -
2142 for (int i = 0; i < enterList.size(); ++i) { -
2143 w = enterList.at(i); -
2144 if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { -
2145 const QPointF localPos = w->mapFromGlobal(globalPos); -
2146 QEnterEvent enterEvent(localPos, windowPos, globalPosF); -
2147 QApplication::sendEvent(w, &enterEvent); -
2148 if (w->testAttribute(Qt::WA_Hover) && -
2149 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) { -
2150 QHoverEvent he(QEvent::HoverEnter, localPos, QPoint(-1, -1), -
2151 QApplication::keyboardModifiers()); -
2152 qApp->d_func()->notify_helper(w, &he); -
2153 } -
2154 } -
2155 } -
2156 } -
2157 -
2158#ifndef QT_NO_CURSOR -
2159 // Update cursor for alien/graphics widgets. -
2160 -
2161 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen))); -
2162 // Whenever we leave an alien widget on X11/QPA, we need to reset its nativeParentWidget()'s cursor. -
2163 // This is not required on Windows as the cursor is reset on every single mouse move. -
2164 QWidget *parentOfLeavingCursor = 0; -
2165 for (int i = 0; i < leaveList.size(); ++i) { -
2166 w = leaveList.at(i); -
2167 if (!isAlien(w)) -
2168 break; -
2169 if (w->testAttribute(Qt::WA_SetCursor)) { -
2170 QWidget *parent = w->parentWidget(); -
2171 while (parent && parent->d_func()->data.in_destructor) -
2172 parent = parent->parentWidget(); -
2173 parentOfLeavingCursor = parent; -
2174 //continue looping, we need to find the downest alien widget with a cursor. -
2175 // (downest on the screen) -
2176 } -
2177 } -
2178 //check that we will not call qt_x11_enforce_cursor twice with the same native widget -
2179 if (parentOfLeavingCursor && (!enterOnAlien -
2180 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) { -
2181#ifndef QT_NO_GRAPHICSVIEW -
2182 if (!parentOfLeavingCursor->window()->graphicsProxyWidget()) -
2183#endif -
2184 { -
2185 if (enter == QApplication::desktop()) { -
2186 qt_qpa_set_cursor(enter, true); -
2187 } else { -
2188 qt_qpa_set_cursor(parentOfLeavingCursor, true); -
2189 } -
2190 } -
2191 } -
2192 if (enterOnAlien) { -
2193 QWidget *cursorWidget = enter; -
2194 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled()) -
2195 cursorWidget = cursorWidget->parentWidget(); -
2196 -
2197 if (!cursorWidget) -
2198 return; -
2199 -
2200#ifndef QT_NO_GRAPHICSVIEW -
2201 if (cursorWidget->window()->graphicsProxyWidget()) { -
2202 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor()); -
2203 } else -
2204#endif -
2205 { -
2206 qt_qpa_set_cursor(cursorWidget, true); -
2207 } -
2208 } -
2209#endif -
2210} -
2211 -
2212/* exported for the benefit of testing tools */ -
2213Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop) -
2214{ -
2215 return QApplicationPrivate::tryModalHelper(widget, rettop); -
2216} -
2217 -
2218/*! \internal -
2219 Returns true if \a widget is blocked by a modal window. -
2220 */ -
2221bool QApplicationPrivate::isBlockedByModal(QWidget *widget) -
2222{ -
2223 widget = widget->window(); -
2224 QWindow *window = widget->windowHandle(); -
2225 return window && self->isWindowBlocked(window); -
2226} -
2227 -
2228bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const -
2229{ -
2230 QWindow *unused = 0; -
2231 if (!window) { -
2232 qWarning().nospace() << "window == 0 passed."; -
2233 return false; -
2234 } -
2235 if (!blockingWindow) -
2236 blockingWindow = &unused; -
2237 -
2238 if (modalWindowList.isEmpty()) { -
2239 *blockingWindow = 0; -
2240 return false; -
2241 } -
2242 QWidget *popupWidget = QApplication::activePopupWidget(); -
2243 QWindow *popupWindow = popupWidget ? popupWidget->windowHandle() : 0; -
2244 if (popupWindow == window) { -
2245 *blockingWindow = 0; -
2246 return false; -
2247 } -
2248 -
2249 for (int i = 0; i < modalWindowList.count(); ++i) { -
2250 QWindow *modalWindow = modalWindowList.at(i); -
2251 -
2252 { -
2253 // check if the modal window is our window or a (transient) parent of our window -
2254 QWindow *w = window; -
2255 while (w) { -
2256 if (w == modalWindow) { -
2257 *blockingWindow = 0; -
2258 return false; -
2259 } -
2260 QWindow *p = w->parent(); -
2261 if (!p) -
2262 p = w->transientParent(); -
2263 w = p; -
2264 } -
2265 -
2266 // Embedded in-process windows are not visible in normal parent-child chain, -
2267 // so check the native parent chain, too. -
2268 const QPlatformWindow *platWin = window->handle(); -
2269 const QPlatformWindow *modalPlatWin = modalWindow->handle(); -
2270 if (platWin && modalPlatWin && platWin->isEmbedded(modalPlatWin)) -
2271 return false; -
2272 } -
2273 -
2274 Qt::WindowModality windowModality = modalWindow->modality(); -
2275 QWidgetWindow *modalWidgetWindow = qobject_cast<QWidgetWindow *>(modalWindow); -
2276 if (windowModality == Qt::NonModal) { -
2277 // determine the modality type if it hasn't been set on the -
2278 // modalWindow's widget, this normally happens when waiting for a -
2279 // native dialog. use WindowModal if we are the child of a group -
2280 // leader; otherwise use ApplicationModal. -
2281 QWidget *m = modalWidgetWindow ? modalWidgetWindow->widget() : 0; -
2282 while (m && !m->testAttribute(Qt::WA_GroupLeader)) { -
2283 m = m->parentWidget(); -
2284 if (m) -
2285 m = m->window(); -
2286 } -
2287 windowModality = (m && m->testAttribute(Qt::WA_GroupLeader)) -
2288 ? Qt::WindowModal -
2289 : Qt::ApplicationModal; -
2290 } -
2291 -
2292 switch (windowModality) { -
2293 case Qt::ApplicationModal: -
2294 { -
2295 QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(window); -
2296 QWidget *groupLeaderForWidget = widgetWindow ? widgetWindow->widget() : 0; -
2297 while (groupLeaderForWidget && !groupLeaderForWidget->testAttribute(Qt::WA_GroupLeader)) -
2298 groupLeaderForWidget = groupLeaderForWidget->parentWidget(); -
2299 -
2300 if (groupLeaderForWidget) { -
2301 // if \a widget has WA_GroupLeader, it can only be blocked by ApplicationModal children -
2302 QWidget *m = modalWidgetWindow ? modalWidgetWindow->widget() : 0; -
2303 while (m && m != groupLeaderForWidget && !m->testAttribute(Qt::WA_GroupLeader)) -
2304 m = m->parentWidget(); -
2305 if (m == groupLeaderForWidget) { -
2306 *blockingWindow = m->windowHandle(); -
2307 return true; -
2308 } -
2309 } else if (modalWindow != window) { -
2310 *blockingWindow = modalWindow; -
2311 return true; -
2312 } -
2313 break; -
2314 } -
2315 case Qt::WindowModal: -
2316 { -
2317 QWindow *w = window; -
2318 do { -
2319 QWindow *m = modalWindow; -
2320 do { -
2321 if (m == w) { -
2322 *blockingWindow = m; -
2323 return true; -
2324 } -
2325 QWindow *p = m->parent(); -
2326 if (!p) -
2327 p = m->transientParent(); -
2328 m = p; -
2329 } while (m); -
2330 QWindow *p = w->parent(); -
2331 if (!p) -
2332 p = w->transientParent(); -
2333 w = p; -
2334 } while (w); -
2335 break; -
2336 } -
2337 default: -
2338 Q_ASSERT_X(false, "QApplication", "internal error, a modal window cannot be modeless"); -
2339 break; -
2340 } -
2341 } -
2342 *blockingWindow = 0; -
2343 return false; -
2344} -
2345 -
2346/*!\internal -
2347 -
2348 Called from qapplication_\e{platform}.cpp, returns true -
2349 if the widget should accept the event. -
2350 */ -
2351bool QApplicationPrivate::tryModalHelper(QWidget *widget, QWidget **rettop) -
2352{ -
2353 QWidget *top = QApplication::activeModalWidget(); -
2354 if (rettop) -
2355 *rettop = top; -
2356 -
2357 // the active popup widget always gets the input event -
2358 if (QApplication::activePopupWidget()) -
2359 return true; -
2360 -
2361 return !isBlockedByModal(widget->window()); -
2362} -
2363 -
2364/* -
2365 \internal -
2366*/ -
2367QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, -
2368 QPoint *pos, QEvent::Type type, -
2369 Qt::MouseButtons buttons, QWidget *buttonDown, -
2370 QWidget *alienWidget) -
2371{ -
2372 Q_ASSERT(candidate); -
2373 -
2374 QWidget *mouseGrabber = QWidget::mouseGrabber(); -
2375 if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease)) -
2376 && !buttonDown && !mouseGrabber) { -
2377 return 0; -
2378 } -
2379 -
2380 if (alienWidget && alienWidget->internalWinId()) -
2381 alienWidget = 0; -
2382 -
2383 QWidget *receiver = candidate; -
2384 -
2385 if (!mouseGrabber) -
2386 mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget; -
2387 -
2388 if (mouseGrabber && mouseGrabber != candidate) { -
2389 receiver = mouseGrabber; -
2390 *pos = receiver->mapFromGlobal(candidate->mapToGlobal(windowPos)); -
2391#ifdef ALIEN_DEBUG -
2392 qDebug() << " ** receiver adjusted to:" << receiver << "pos:" << pos; -
2393#endif -
2394 } -
2395 -
2396 return receiver; -
2397 -
2398} -
2399 -
2400/* -
2401 \internal -
2402*/ -
2403bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event, -
2404 QWidget *alienWidget, QWidget *nativeWidget, -
2405 QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver, -
2406 bool spontaneous) -
2407{ -
2408 Q_ASSERT(receiver); -
2409 Q_ASSERT(event); -
2410 Q_ASSERT(nativeWidget); -
2411 Q_ASSERT(buttonDown); -
2412 -
2413 if (alienWidget && !isAlien(alienWidget)) -
2414 alienWidget = 0; -
2415 -
2416 QPointer<QWidget> receiverGuard = receiver; -
2417 QPointer<QWidget> nativeGuard = nativeWidget; -
2418 QPointer<QWidget> alienGuard = alienWidget; -
2419 QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget(); -
2420 -
2421 const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen); -
2422 -
2423 bool widgetUnderMouse = QRectF(receiver->rect()).contains(event->localPos()); -
2424 -
2425 // Clear the obsolete leaveAfterRelease value, if mouse button has been released but -
2426 // leaveAfterRelease has not been updated. -
2427 // This happens e.g. when modal dialog or popup is shown as a response to button click. -
2428 if (leaveAfterRelease && !*buttonDown && !event->buttons()) -
2429 leaveAfterRelease = 0; -
2430 -
2431 if (*buttonDown) { -
2432 if (!graphicsWidget) { -
2433 // Register the widget that shall receive a leave event -
2434 // after the last button is released. -
2435 if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber()) -
2436 leaveAfterRelease = *buttonDown; -
2437 if (event->type() == QEvent::MouseButtonRelease && !event->buttons()) -
2438 *buttonDown = 0; -
2439 } -
2440 } else if (lastMouseReceiver && widgetUnderMouse) { -
2441 // Dispatch enter/leave if we move: -
2442 // 1) from an alien widget to another alien widget or -
2443 // from a native widget to an alien widget (first OR case) -
2444 // 2) from an alien widget to a native widget (second OR case) -
2445 if ((alienWidget && alienWidget != lastMouseReceiver) -
2446 || (isAlien(lastMouseReceiver) && !alienWidget)) { -
2447 if (activePopupWidget) { -
2448 if (!QWidget::mouseGrabber()) -
2449 dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->screenPos()); -
2450 } else { -
2451 dispatchEnterLeave(receiver, lastMouseReceiver, event->screenPos()); -
2452 } -
2453 -
2454 } -
2455 } -
2456 -
2457#ifdef ALIEN_DEBUG -
2458 qDebug() << "QApplicationPrivate::sendMouseEvent: receiver:" << receiver -
2459 << "pos:" << event->pos() << "alien" << alienWidget << "button down" -
2460 << *buttonDown << "last" << lastMouseReceiver << "leave after release" -
2461 << leaveAfterRelease; -
2462#endif -
2463 -
2464 // We need this quard in case someone opens a modal dialog / popup. If that's the case -
2465 // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver. -
2466 const bool wasLeaveAfterRelease = leaveAfterRelease != 0; -
2467 bool result; -
2468 if (spontaneous) -
2469 result = QApplication::sendSpontaneousEvent(receiver, event); -
2470 else -
2471 result = QApplication::sendEvent(receiver, event); -
2472 -
2473 if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease -
2474 && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) { -
2475 // Dispatch enter/leave if: -
2476 // 1) the mouse grabber is an alien widget -
2477 // 2) the button is released on an alien widget -
2478 QWidget *enter = 0; -
2479 if (nativeGuard) -
2480 enter = alienGuard ? alienWidget : nativeWidget; -
2481 else // The receiver is typically deleted on mouse release with drag'n'drop. -
2482 enter = QApplication::widgetAt(event->globalPos()); -
2483 dispatchEnterLeave(enter, leaveAfterRelease, event->screenPos()); -
2484 leaveAfterRelease = 0; -
2485 lastMouseReceiver = enter; -
2486 } else if (!wasLeaveAfterRelease) { -
2487 if (activePopupWidget) { -
2488 if (!QWidget::mouseGrabber()) -
2489 lastMouseReceiver = alienGuard ? alienWidget : (nativeGuard ? nativeWidget : 0); -
2490 } else { -
2491 lastMouseReceiver = receiverGuard ? receiver : QApplication::widgetAt(event->globalPos()); -
2492 } -
2493 } -
2494 -
2495 return result; -
2496} -
2497 -
2498/* -
2499 This function should only be called when the widget changes visibility, i.e. -
2500 when the \a widget is shown, hidden or deleted. This function does nothing -
2501 if the widget is a top-level or native, i.e. not an alien widget. In that -
2502 case enter/leave events are genereated by the underlying windowing system. -
2503*/ -
2504extern QPointer<QWidget> qt_last_mouse_receiver; -
2505extern QWidget *qt_button_down; -
2506void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget) -
2507{ -
2508#ifndef QT_NO_CURSOR -
2509 if (!widget || widget->isWindow()) -
2510 return; -
2511 const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor; -
2512 if (!widgetInShow && widget != qt_last_mouse_receiver) -
2513 return; // Widget was not under the cursor when it was hidden/deleted. -
2514 -
2515 if (widgetInShow && widget->parentWidget()->data->in_show) -
2516 return; // Ingore recursive show. -
2517 -
2518 QWidget *mouseGrabber = QWidget::mouseGrabber(); -
2519 if (mouseGrabber && mouseGrabber != widget) -
2520 return; // Someone else has the grab; enter/leave should not occur. -
2521 -
2522 QWidget *tlw = widget->window(); -
2523 if (tlw->data->in_destructor || tlw->data->is_closing) -
2524 return; // Closing down the business. -
2525 -
2526 if (widgetInShow && (!qt_last_mouse_receiver || qt_last_mouse_receiver->window() != tlw)) -
2527 return; // Mouse cursor not inside the widget's top-level. -
2528 -
2529 const QPoint globalPos(QCursor::pos()); -
2530 QPoint windowPos = tlw->mapFromGlobal(globalPos); -
2531 -
2532 // Find the current widget under the mouse. If this function was called from -
2533 // the widget's destructor, we have to make sure childAt() doesn't take into -
2534 // account widgets that are about to be destructed. -
2535 QWidget *widgetUnderCursor = tlw->d_func()->childAt_helper(windowPos, widget->data->in_destructor); -
2536 if (!widgetUnderCursor) -
2537 widgetUnderCursor = tlw; -
2538 QPoint pos = widgetUnderCursor->mapFrom(tlw, windowPos); -
2539 -
2540 if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor)) -
2541 return; // Mouse cursor not inside the widget or any of its children. -
2542 -
2543 if (widget->data->in_destructor && qt_button_down == widget) -
2544 qt_button_down = 0; -
2545 -
2546 // Send enter/leave events followed by a mouse move on the entered widget. -
2547 QMouseEvent e(QEvent::MouseMove, pos, windowPos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier); -
2548 sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver); -
2549#endif // QT_NO_CURSOR -
2550} -
2551 -
2552/*! -
2553 Returns the desktop widget (also called the root window). -
2554 -
2555 The desktop may be composed of multiple screens, so it would be incorrect, -
2556 for example, to attempt to \e center some widget in the desktop's geometry. -
2557 QDesktopWidget has various functions for obtaining useful geometries upon -
2558 the desktop, such as QDesktopWidget::screenGeometry() and -
2559 QDesktopWidget::availableGeometry(). -
2560 -
2561 On X11, it is also possible to draw on the desktop. -
2562*/ -
2563QDesktopWidget *QApplication::desktop() -
2564{ -
2565 if (!qt_desktopWidget || // not created yet -
2566 !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away -
2567 qt_desktopWidget = new QDesktopWidget(); -
2568 } -
2569 return qt_desktopWidget; -
2570} -
2571 -
2572/* -
2573 Sets the time after which a drag should start to \a ms ms. -
2574 -
2575 \sa startDragTime() -
2576*/ -
2577 -
2578void QApplication::setStartDragTime(int ms) -
2579{ -
2580 Q_UNUSED(ms) -
2581} -
2582 -
2583/*! -
2584 \property QApplication::startDragTime -
2585 \brief the time in milliseconds that a mouse button must be held down -
2586 before a drag and drop operation will begin -
2587 -
2588 If you support drag and drop in your application, and want to start a drag -
2589 and drop operation after the user has held down a mouse button for a -
2590 certain amount of time, you should use this property's value as the delay. -
2591 -
2592 Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for -
2593 starting a drag. -
2594 -
2595 The default value is 500 ms. -
2596 -
2597 \sa startDragDistance(), {Drag and Drop} -
2598*/ -
2599 -
2600int QApplication::startDragTime() -
2601{ -
2602 return qApp->styleHints()->startDragTime(); -
2603} -
2604 -
2605/* -
2606 Sets the distance after which a drag should start to \a l pixels. -
2607 -
2608 \sa startDragDistance() -
2609*/ -
2610 -
2611void QApplication::setStartDragDistance(int l) -
2612{ -
2613 Q_UNUSED(l); -
2614} -
2615 -
2616/*! -
2617 \property QApplication::startDragDistance -
2618 -
2619 If you support drag and drop in your application, and want to start a drag -
2620 and drop operation after the user has moved the cursor a certain distance -
2621 with a button held down, you should use this property's value as the -
2622 minimum distance required. -
2623 -
2624 For example, if the mouse position of the click is stored in \c startPos -
2625 and the current position (e.g. in the mouse move event) is \c currentPos, -
2626 you can find out if a drag should be started with code like this: -
2627 -
2628 \snippet code/src_gui_kernel_qapplication.cpp 7 -
2629 -
2630 Qt uses this value internally, e.g. in QFileDialog. -
2631 -
2632 The default value is 4 pixels. -
2633 -
2634 \sa startDragTime(), QPoint::manhattanLength(), {Drag and Drop} -
2635*/ -
2636 -
2637int QApplication::startDragDistance() -
2638{ -
2639 return qApp->styleHints()->startDragDistance(); -
2640} -
2641 -
2642/*! -
2643 Enters the main event loop and waits until exit() is called, then returns -
2644 the value that was set to exit() (which is 0 if exit() is called via -
2645 quit()). -
2646 -
2647 It is necessary to call this function to start event handling. The main -
2648 event loop receives events from the window system and dispatches these to -
2649 the application widgets. -
2650 -
2651 Generally, no user interaction can take place before calling exec(). As a -
2652 special case, modal widgets like QMessageBox can be used before calling -
2653 exec(), because modal widgets call exec() to start a local event loop. -
2654 -
2655 To make your application perform idle processing, i.e., executing a special -
2656 function whenever there are no pending events, use a QTimer with 0 timeout. -
2657 More advanced idle processing schemes can be achieved using processEvents(). -
2658 -
2659 We recommend that you connect clean-up code to the -
2660 \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your -
2661 application's \c{main()} function. This is because, on some platforms the -
2662 QApplication::exec() call may not return. For example, on the Windows -
2663 platform, when the user logs off, the system terminates the process after Qt -
2664 closes all top-level windows. Hence, there is \e{no guarantee} that the -
2665 application will have time to exit its event loop and execute code at the -
2666 end of the \c{main()} function, after the QApplication::exec() call. -
2667 -
2668 \sa quitOnLastWindowClosed, quit(), exit(), processEvents(), -
2669 QCoreApplication::exec() -
2670*/ -
2671int QApplication::exec() -
2672{ -
2673 return QGuiApplication::exec(); -
2674} -
2675 -
2676bool QApplicationPrivate::shouldQuit() -
2677{ -
2678 /* if there is no non-withdrawn primary window left (except -
2679 the ones without QuitOnClose), we emit the lastWindowClosed -
2680 signal */ -
2681 QWidgetList list = QApplication::topLevelWidgets(); -
2682 for (int i = 0; i < list.size(); ++i) { -
2683 QWidget *w = list.at(i); -
2684 if (w->isVisible() && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) -
2685 return false; -
2686 } -
2687 return QGuiApplicationPrivate::shouldQuit(); -
2688} -
2689 -
2690static inline void closeAllPopups() -
2691{ -
2692 // Close all popups: In case some popup refuses to close, -
2693 // we give up after 1024 attempts (to avoid an infinite loop). -
2694 int maxiter = 1024; -
2695 QWidget *popup; -
2696 while ((popup = QApplication::activePopupWidget()) && maxiter--) -
2697 popup->close(); -
2698} -
2699 -
2700/*! \reimp -
2701 */ -
2702bool QApplication::notify(QObject *receiver, QEvent *e) -
2703{ -
2704 Q_D(QApplication); -
2705 // no events are delivered after ~QCoreApplication() has started -
2706 if (QApplicationPrivate::is_app_closing) -
2707 return true; -
2708 -
2709 if (receiver == 0) { // serious error -
2710 qWarning("QApplication::notify: Unexpected null receiver"); -
2711 return true; -
2712 } -
2713 -
2714#ifndef QT_NO_DEBUG -
2715 d->checkReceiverThread(receiver); -
2716#endif -
2717 -
2718 if (receiver->isWindowType()) -
2719 QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e); -
2720 -
2721 if(e->spontaneous()) { -
2722 // Capture the current mouse and keyboard states. Doing so here is -
2723 // required in order to support QTestLib synthesized events. Real mouse-
/ required in order to support Qt Test synthesized events. Real mouse
2724 // and keyboard state updates from the platform plugin are managed by -
2725 // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event(); -
2726 switch (e->type()) { -
2727 case QEvent::MouseButtonPress: -
2728 { -
2729 QMouseEvent *me = static_cast<QMouseEvent*>(e); -
2730 QApplicationPrivate::modifier_buttons = me->modifiers(); -
2731 QApplicationPrivate::mouse_buttons |= me->button(); -
2732 break; -
2733 } -
2734 case QEvent::MouseButtonRelease: -
2735 { -
2736 QMouseEvent *me = static_cast<QMouseEvent*>(e); -
2737 QApplicationPrivate::modifier_buttons = me->modifiers(); -
2738 QApplicationPrivate::mouse_buttons &= ~me->button(); -
2739 break; -
2740 } -
2741 case QEvent::KeyPress: -
2742 case QEvent::KeyRelease: -
2743 case QEvent::MouseMove: -
2744#ifndef QT_NO_WHEELEVENT -
2745 case QEvent::Wheel: -
2746#endif -
2747 case QEvent::TouchBegin: -
2748 case QEvent::TouchUpdate: -
2749 case QEvent::TouchEnd: -
2750#ifndef QT_NO_TABLETEVENT -
2751 case QEvent::TabletMove: -
2752 case QEvent::TabletPress: -
2753 case QEvent::TabletRelease: -
2754#endif -
2755 { -
2756 QInputEvent *ie = static_cast<QInputEvent*>(e); -
2757 QApplicationPrivate::modifier_buttons = ie->modifiers(); -
2758 break; -
2759 } -
2760 default: -
2761 break; -
2762 } -
2763 } -
2764 -
2765#ifndef QT_NO_GESTURES -
2766 // walk through parents and check for gestures -
2767 if (d->gestureManager) { -
2768 switch (e->type()) { -
2769 case QEvent::Paint: -
2770 case QEvent::MetaCall: -
2771 case QEvent::DeferredDelete: -
2772 case QEvent::DragEnter: case QEvent::DragMove: case QEvent::DragLeave: -
2773 case QEvent::Drop: case QEvent::DragResponse: -
2774 case QEvent::ChildAdded: case QEvent::ChildPolished: -
2775 case QEvent::ChildRemoved: -
2776 case QEvent::UpdateRequest: -
2777 case QEvent::UpdateLater: -
2778 case QEvent::LocaleChange: -
2779 case QEvent::Style: -
2780 case QEvent::IconDrag: -
2781 case QEvent::StyleChange: -
2782 case QEvent::GraphicsSceneDragEnter: -
2783 case QEvent::GraphicsSceneDragMove: -
2784 case QEvent::GraphicsSceneDragLeave: -
2785 case QEvent::GraphicsSceneDrop: -
2786 case QEvent::DynamicPropertyChange: -
2787 case QEvent::NetworkReplyUpdated: -
2788 break; -
2789 default: -
2790 if (receiver->isWidgetType()) { -
2791 if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e)) -
2792 return true; -
2793 } else { -
2794 // a special case for events that go to QGesture objects. -
2795 // We pass the object to the gesture manager and it'll figure -
2796 // out if it's QGesture or not. -
2797 if (d->gestureManager->filterEvent(receiver, e)) -
2798 return true; -
2799 } -
2800 } -
2801 } -
2802#endif // QT_NO_GESTURES -
2803 -
2804 switch (e->type()) { -
2805 case QEvent::ApplicationDeactivate: -
2806 // Close all popups (triggers when switching applications -
2807 // by pressing ALT-TAB on Windows, which is not receive as key event. -
2808 closeAllPopups(); -
2809 break; -
2810 case QEvent::Wheel: // User input and window activation makes tooltips sleep -
2811 case QEvent::ActivationChange: -
2812 case QEvent::KeyPress: -
2813 case QEvent::KeyRelease: -
2814 case QEvent::FocusOut: -
2815 case QEvent::FocusIn: -
2816 case QEvent::MouseButtonPress: -
2817 case QEvent::MouseButtonRelease: -
2818 case QEvent::MouseButtonDblClick: -
2819 d->toolTipFallAsleep.stop(); -
2820 // fall-through -
2821 case QEvent::Leave: -
2822 d->toolTipWakeUp.stop(); -
2823 default: -
2824 break; -
2825 } -
2826 -
2827 bool res = false; -
2828 if (!receiver->isWidgetType()) { -
2829 res = d->notify_helper(receiver, e); -
2830 } else switch (e->type()) { -
2831 case QEvent::ShortcutOverride: -
2832 case QEvent::KeyPress: -
2833 case QEvent::KeyRelease: -
2834 { -
2835 bool isWidget = receiver->isWidgetType(); -
2836 bool isGraphicsWidget = false; -
2837#ifndef QT_NO_GRAPHICSVIEW -
2838 isGraphicsWidget = !isWidget && qobject_cast<QGraphicsWidget *>(receiver); -
2839#endif -
2840 if (!isWidget && !isGraphicsWidget) { -
2841 res = d->notify_helper(receiver, e); -
2842 break; -
2843 } -
2844 -
2845 QKeyEvent* key = static_cast<QKeyEvent*>(e); -
2846 if (key->type()==QEvent::KeyPress) { -
2847#ifndef QT_NO_SHORTCUT -
2848 // Try looking for a Shortcut before sending key events -
2849 if ((res = qApp->d_func()->shortcutMap.tryShortcutEvent(receiver, key))) -
2850 return res; -
2851#endif -
2852 qt_in_tab_key_event = (key->key() == Qt::Key_Backtab -
2853 || key->key() == Qt::Key_Tab -
2854 || key->key() == Qt::Key_Left -
2855 || key->key() == Qt::Key_Up -
2856 || key->key() == Qt::Key_Right -
2857 || key->key() == Qt::Key_Down); -
2858 } -
2859 bool def = key->isAccepted(); -
2860 QPointer<QObject> pr = receiver; -
2861 while (receiver) { -
2862 if (def) -
2863 key->accept(); -
2864 else -
2865 key->ignore(); -
2866 res = d->notify_helper(receiver, e); -
2867 QWidget *w = isWidget ? static_cast<QWidget *>(receiver) : 0; -
2868#ifndef QT_NO_GRAPHICSVIEW -
2869 QGraphicsWidget *gw = isGraphicsWidget ? static_cast<QGraphicsWidget *>(receiver) : 0; -
2870#endif -
2871 -
2872 if ((res && key->isAccepted()) -
2873 /* -
2874 QLineEdit will emit a signal on Key_Return, but -
2875 ignore the event, and sometimes the connected -
2876 slot deletes the QLineEdit (common in itemview -
2877 delegates), so we have to check if the widget -
2878 was destroyed even if the event was ignored (to -
2879 prevent a crash) -
2880 -
2881 note that we don't have to reset pw while -
2882 propagating (because the original receiver will -
2883 be destroyed if one of its ancestors is) -
2884 */ -
2885 || !pr -
2886 || (isWidget && (w->isWindow() || !w->parentWidget())) -
2887#ifndef QT_NO_GRAPHICSVIEW -
2888 || (isGraphicsWidget && (gw->isWindow() || !gw->parentWidget())) -
2889#endif -
2890 ) { -
2891 break; -
2892 } -
2893 -
2894#ifndef QT_NO_GRAPHICSVIEW -
2895 receiver = w ? (QObject *)w->parentWidget() : (QObject *)gw->parentWidget(); -
2896#else -
2897 receiver = w->parentWidget(); -
2898#endif -
2899 } -
2900 qt_in_tab_key_event = false; -
2901 } -
2902 break; -
2903 case QEvent::MouseButtonPress: -
2904 case QEvent::MouseButtonRelease: -
2905 case QEvent::MouseButtonDblClick: -
2906 case QEvent::MouseMove: -
2907 { -
2908 QWidget* w = static_cast<QWidget *>(receiver); -
2909 -
2910 QMouseEvent* mouse = static_cast<QMouseEvent*>(e); -
2911 QPoint relpos = mouse->pos(); -
2912 -
2913 if (e->spontaneous()) { -
2914 -
2915 if (e->type() == QEvent::MouseButtonPress) { -
2916 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, -
2917 Qt::ClickFocus, -
2918 Qt::MouseFocusReason); -
2919 } -
2920 -
2921 // ### Qt 5 These dynamic tool tips should be an OPT-IN feature. Some platforms -
2922 // like Mac OS X (probably others too), can optimize their views by not -
2923 // dispatching mouse move events. We have attributes to control hover, -
2924 // and mouse tracking, but as long as we are deciding to implement this -
2925 // feature without choice of opting-in or out, you ALWAYS have to have -
2926 // tracking enabled. Therefore, the other properties give a false sense of -
2927 // performance enhancement. -
2928 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0) { -
2929 d->toolTipWidget = w; -
2930 d->toolTipPos = relpos; -
2931 d->toolTipGlobalPos = mouse->globalPos(); -
2932 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive()?20:700, this); -
2933 } -
2934 } -
2935 -
2936 bool eventAccepted = mouse->isAccepted(); -
2937 -
2938 QPointer<QWidget> pw = w; -
2939 while (w) { -
2940 QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), mouse->button(), mouse->buttons(), -
2941 mouse->modifiers()); -
2942 me.spont = mouse->spontaneous(); -
2943 me.setTimestamp(mouse->timestamp()); -
2944 // throw away any mouse-tracking-only mouse events -
2945 if (!w->hasMouseTracking() -
2946 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) { -
2947 // but still send them through all application event filters (normally done by notify_helper) -
2948 for (int i = 0; d->extraData && i < d->extraData->eventFilters.size(); ++i) { -
2949 register QObject *obj = d->extraData->eventFilters.at(i); -
2950 if (!obj) -
2951 continue; -
2952 if (obj->d_func()->threadData != w->d_func()->threadData) { -
2953 qWarning("QApplication: Object event filter cannot be in a different thread."); -
2954 continue; -
2955 } -
2956 if (obj->eventFilter(w, w == receiver ? mouse : &me)) -
2957 break; -
2958 } -
2959 res = true; -
2960 } else { -
2961 w->setAttribute(Qt::WA_NoMouseReplay, false); -
2962 res = d->notify_helper(w, w == receiver ? mouse : &me); -
2963 e->spont = false; -
2964 } -
2965 eventAccepted = (w == receiver ? mouse : &me)->isAccepted(); -
2966 if (res && eventAccepted) -
2967 break; -
2968 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) -
2969 break; -
2970 relpos += w->pos(); -
2971 w = w->parentWidget(); -
2972 } -
2973 -
2974 mouse->setAccepted(eventAccepted); -
2975 -
2976 if (e->type() == QEvent::MouseMove) { -
2977 if (!pw) -
2978 break; -
2979 -
2980 w = static_cast<QWidget *>(receiver); -
2981 relpos = mouse->pos(); -
2982 QPoint diff = relpos - w->mapFromGlobal(d->hoverGlobalPos); -
2983 while (w) { -
2984 if (w->testAttribute(Qt::WA_Hover) && -
2985 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) { -
2986 QHoverEvent he(QEvent::HoverMove, relpos, relpos - diff, mouse->modifiers()); -
2987 d->notify_helper(w, &he); -
2988 } -
2989 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) -
2990 break; -
2991 relpos += w->pos(); -
2992 w = w->parentWidget(); -
2993 } -
2994 } -
2995 -
2996 d->hoverGlobalPos = mouse->globalPos(); -
2997 } -
2998 break; -
2999#ifndef QT_NO_WHEELEVENT -
3000 case QEvent::Wheel: -
3001 { -
3002 QWidget* w = static_cast<QWidget *>(receiver); -
3003 QWheelEvent* wheel = static_cast<QWheelEvent*>(e); -
3004 QPoint relpos = wheel->pos(); -
3005 bool eventAccepted = wheel->isAccepted(); -
3006 -
3007 if (e->spontaneous()) { -
3008 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, -
3009 Qt::WheelFocus, -
3010 Qt::MouseFocusReason); -
3011 } -
3012 -
3013 while (w) { -
3014 QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), -
3015 wheel->modifiers()); -
3016 we.spont = wheel->spontaneous(); -
3017 res = d->notify_helper(w, w == receiver ? wheel : &we); -
3018 eventAccepted = ((w == receiver) ? wheel : &we)->isAccepted(); -
3019 e->spont = false; -
3020 if ((res && eventAccepted) -
3021 || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) -
3022 break; -
3023 -
3024 relpos += w->pos(); -
3025 w = w->parentWidget(); -
3026 } -
3027 wheel->setAccepted(eventAccepted); -
3028 } -
3029 break; -
3030#endif -
3031#ifndef QT_NO_CONTEXTMENU -
3032 case QEvent::ContextMenu: -
3033 { -
3034 QWidget* w = static_cast<QWidget *>(receiver); -
3035 QContextMenuEvent *context = static_cast<QContextMenuEvent*>(e); -
3036 QPoint relpos = context->pos(); -
3037 bool eventAccepted = context->isAccepted(); -
3038 while (w) { -
3039 QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers()); -
3040 ce.spont = e->spontaneous(); -
3041 res = d->notify_helper(w, w == receiver ? context : &ce); -
3042 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted(); -
3043 e->spont = false; -
3044 -
3045 if ((res && eventAccepted) -
3046 || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) -
3047 break; -
3048 -
3049 relpos += w->pos(); -
3050 w = w->parentWidget(); -
3051 } -
3052 context->setAccepted(eventAccepted); -
3053 } -
3054 break; -
3055#endif // QT_NO_CONTEXTMENU -
3056#ifndef QT_NO_TABLETEVENT -
3057 case QEvent::TabletMove: -
3058 case QEvent::TabletPress: -
3059 case QEvent::TabletRelease: -
3060 { -
3061 QWidget *w = static_cast<QWidget *>(receiver); -
3062 QTabletEvent *tablet = static_cast<QTabletEvent*>(e); -
3063 QPointF relpos = tablet->posF(); -
3064 bool eventAccepted = tablet->isAccepted(); -
3065 while (w) { -
3066 QTabletEvent te(tablet->type(), relpos, tablet->globalPosF(), -
3067 tablet->device(), tablet->pointerType(), -
3068 tablet->pressure(), tablet->xTilt(), tablet->yTilt(), -
3069 tablet->tangentialPressure(), tablet->rotation(), tablet->z(), -
3070 tablet->modifiers(), tablet->uniqueId()); -
3071 te.spont = e->spontaneous(); -
3072 res = d->notify_helper(w, w == receiver ? tablet : &te); -
3073 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted(); -
3074 e->spont = false; -
3075 if ((res && eventAccepted) -
3076 || w->isWindow() -
3077 || w->testAttribute(Qt::WA_NoMousePropagation)) -
3078 break; -
3079 -
3080 relpos += w->pos(); -
3081 w = w->parentWidget(); -
3082 } -
3083 tablet->setAccepted(eventAccepted); -
3084 qt_tabletChokeMouse = tablet->isAccepted(); -
3085 } -
3086 break; -
3087#endif // QT_NO_TABLETEVENT -
3088 -
3089#if !defined(QT_NO_TOOLTIP) || !defined(QT_NO_WHATSTHIS) -
3090 case QEvent::ToolTip: -
3091 case QEvent::WhatsThis: -
3092 case QEvent::QueryWhatsThis: -
3093 { -
3094 QWidget* w = static_cast<QWidget *>(receiver); -
3095 QHelpEvent *help = static_cast<QHelpEvent*>(e); -
3096 QPoint relpos = help->pos(); -
3097 bool eventAccepted = help->isAccepted(); -
3098 while (w) { -
3099 QHelpEvent he(help->type(), relpos, help->globalPos()); -
3100 he.spont = e->spontaneous(); -
3101 res = d->notify_helper(w, w == receiver ? help : &he); -
3102 e->spont = false; -
3103 eventAccepted = (w == receiver ? help : &he)->isAccepted(); -
3104 if ((res && eventAccepted) || w->isWindow()) -
3105 break; -
3106 -
3107 relpos += w->pos(); -
3108 w = w->parentWidget(); -
3109 } -
3110 help->setAccepted(eventAccepted); -
3111 } -
3112 break; -
3113#endif -
3114#if !defined(QT_NO_STATUSTIP) || !defined(QT_NO_WHATSTHIS) -
3115 case QEvent::StatusTip: -
3116 case QEvent::WhatsThisClicked: -
3117 { -
3118 QWidget *w = static_cast<QWidget *>(receiver); -
3119 while (w) { -
3120 res = d->notify_helper(w, e); -
3121 if ((res && e->isAccepted()) || w->isWindow()) -
3122 break; -
3123 w = w->parentWidget(); -
3124 } -
3125 } -
3126 break; -
3127#endif -
3128 -
3129#ifndef QT_NO_DRAGANDDROP -
3130 case QEvent::DragEnter: { -
3131 QWidget* w = static_cast<QWidget *>(receiver); -
3132 QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent *>(e); -
3133#ifndef QT_NO_GRAPHICSVIEW -
3134 // QGraphicsProxyWidget handles its own propagation, -
3135 // and we must not change QDragManagers currentTarget. -
3136 QWExtra *extra = w->window()->d_func()->extra; -
3137 if (extra && extra->proxyWidget) { -
3138 res = d->notify_helper(w, dragEvent); -
3139 break; -
3140 } -
3141#endif -
3142 while (w) { -
3143 if (w->isEnabled() && w->acceptDrops()) { -
3144 res = d->notify_helper(w, dragEvent); -
3145 if (res && dragEvent->isAccepted()) { -
3146 QDragManager::self()->setCurrentTarget(w); -
3147 break; -
3148 } -
3149 } -
3150 if (w->isWindow()) -
3151 break; -
3152 dragEvent->p = w->mapToParent(dragEvent->p.toPoint()); -
3153 w = w->parentWidget(); -
3154 } -
3155 } -
3156 break; -
3157 case QEvent::DragMove: -
3158 case QEvent::Drop: -
3159 case QEvent::DragLeave: { -
3160 QWidget* w = static_cast<QWidget *>(receiver); -
3161#ifndef QT_NO_GRAPHICSVIEW -
3162 // QGraphicsProxyWidget handles its own propagation, -
3163 // and we must not change QDragManagers currentTarget. -
3164 QWExtra *extra = w->window()->d_func()->extra; -
3165 bool isProxyWidget = extra && extra->proxyWidget; -
3166 if (!isProxyWidget) -
3167#endif -
3168 w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget()); -
3169 -
3170 if (!w) { -
3171 break; -
3172 } -
3173 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) { -
3174 QDropEvent *dragEvent = static_cast<QDropEvent *>(e); -
3175 QWidget *origReciver = static_cast<QWidget *>(receiver); -
3176 while (origReciver && w != origReciver) { -
3177 dragEvent->p = origReciver->mapToParent(dragEvent->p.toPoint()); -
3178 origReciver = origReciver->parentWidget(); -
3179 } -
3180 } -
3181 res = d->notify_helper(w, e); -
3182 if (e->type() != QEvent::DragMove -
3183#ifndef QT_NO_GRAPHICSVIEW -
3184 && !isProxyWidget -
3185#endif -
3186 ) -
3187 QDragManager::self()->setCurrentTarget(0, e->type() == QEvent::Drop); -
3188 } -
3189 break; -
3190#endif -
3191 -
3192 case QEvent::TouchUpdate: -
3193 case QEvent::TouchEnd: -
3194 { -
3195 QWidget *widget = static_cast<QWidget *>(receiver); -
3196 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); -
3197 const bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); -
3198 -
3199 touchEvent->setTarget(widget); -
3200 touchEvent->setAccepted(acceptTouchEvents); -
3201 -
3202 res = acceptTouchEvents && d->notify_helper(widget, touchEvent); -
3203 -
3204 // If the touch event wasn't accepted, synthesize a mouse event and see if the widget wants it. -
3205 if (!touchEvent->isAccepted()) -
3206 res = d->translateTouchToMouse(widget, touchEvent); -
3207 break; -
3208 } -
3209 -
3210 case QEvent::TouchBegin: -
3211 // Note: TouchUpdate and TouchEnd events are never propagated -
3212 { -
3213 QWidget *widget = static_cast<QWidget *>(receiver); -
3214 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); -
3215 bool eventAccepted = touchEvent->isAccepted(); -
3216 if (widget->testAttribute(Qt::WA_AcceptTouchEvents) && e->spontaneous()) { -
3217 // give the widget focus if the focus policy allows it -
3218 QApplicationPrivate::giveFocusAccordingToFocusPolicy(widget, -
3219 Qt::ClickFocus, -
3220 Qt::MouseFocusReason); -
3221 } -
3222 -
3223 while (widget) { -
3224 // first, try to deliver the touch event -
3225 bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); -
3226 touchEvent->setTarget(widget); -
3227 touchEvent->setAccepted(acceptTouchEvents); -
3228 QPointer<QWidget> p = widget; -
3229 res = acceptTouchEvents && d->notify_helper(widget, touchEvent); -
3230 -
3231 // If the touch event wasn't accepted, synthesize a mouse event and see if the widget wants it. -
3232 if (!touchEvent->isAccepted()) { -
3233 res = d->translateTouchToMouse(widget, touchEvent); -
3234 eventAccepted = touchEvent->isAccepted(); -
3235 if (eventAccepted) -
3236 break; -
3237 } -
3238 -
3239 eventAccepted = touchEvent->isAccepted(); -
3240 if (p.isNull()) { -
3241 // widget was deleted -
3242 widget = 0; -
3243 } else { -
3244 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted); -
3245 } -
3246 touchEvent->spont = false; -
3247 if (res && eventAccepted) { -
3248 // the first widget to accept the TouchBegin gets an implicit grab. -
3249 for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { -
3250 const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); -
3251 d->activeTouchPoints[QGuiApplicationPrivate::ActiveTouchPointsKey(touchEvent->device(), touchPoint.id())].target = widget; -
3252 } -
3253 break; -
3254 } else if (p.isNull() || widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) { -
3255 break; -
3256 } -
3257 QPoint offset = widget->pos(); -
3258 widget = widget->parentWidget(); -
3259 touchEvent->setTarget(widget); -
3260 for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) { -
3261 QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i]; -
3262 QRectF rect = pt.rect(); -
3263 rect.moveCenter(offset); -
3264 pt.d->rect = rect; -
3265 pt.d->startPos = pt.startPos() + offset; -
3266 pt.d->lastPos = pt.lastPos() + offset; -
3267 } -
3268 } -
3269 -
3270 touchEvent->setAccepted(eventAccepted); -
3271 break; -
3272 } -
3273 case QEvent::RequestSoftwareInputPanel: -
3274 inputMethod()->show(); -
3275 break; -
3276 case QEvent::CloseSoftwareInputPanel: -
3277 inputMethod()->hide(); -
3278 break; -
3279 -
3280#ifndef QT_NO_GESTURES -
3281 case QEvent::NativeGesture: -
3282 { -
3283 // only propagate the first gesture event (after the GID_BEGIN) -
3284 QWidget *w = static_cast<QWidget *>(receiver); -
3285 while (w) { -
3286 e->ignore(); -
3287 res = d->notify_helper(w, e); -
3288 if ((res && e->isAccepted()) || w->isWindow()) -
3289 break; -
3290 w = w->parentWidget(); -
3291 } -
3292 break; -
3293 } -
3294 case QEvent::Gesture: -
3295 case QEvent::GestureOverride: -
3296 { -
3297 if (receiver->isWidgetType()) { -
3298 QWidget *w = static_cast<QWidget *>(receiver); -
3299 QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e); -
3300 QList<QGesture *> allGestures = gestureEvent->gestures(); -
3301 -
3302 bool eventAccepted = gestureEvent->isAccepted(); -
3303 bool wasAccepted = eventAccepted; -
3304 while (w) { -
3305 // send only gestures the widget expects -
3306 QList<QGesture *> gestures; -
3307 QWidgetPrivate *wd = w->d_func(); -
3308 for (int i = 0; i < allGestures.size();) { -
3309 QGesture *g = allGestures.at(i); -
3310 Qt::GestureType type = g->gestureType(); -
3311 QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = -
3312 wd->gestureContext.find(type); -
3313 bool deliver = contextit != wd->gestureContext.end() && -
3314 (g->state() == Qt::GestureStarted || w == receiver || -
3315 (contextit.value() & Qt::ReceivePartialGestures)); -
3316 if (deliver) { -
3317 allGestures.removeAt(i); -
3318 gestures.append(g); -
3319 } else { -
3320 ++i; -
3321 } -
3322 } -
3323 if (!gestures.isEmpty()) { // we have gestures for this w -
3324 QGestureEvent ge(gestures); -
3325 ge.t = gestureEvent->t; -
3326 ge.spont = gestureEvent->spont; -
3327 ge.m_accept = wasAccepted; -
3328 ge.m_accepted = gestureEvent->m_accepted; -
3329 res = d->notify_helper(w, &ge); -
3330 gestureEvent->spont = false; -
3331 eventAccepted = ge.isAccepted(); -
3332 for (int i = 0; i < gestures.size(); ++i) { -
3333 QGesture *g = gestures.at(i); -
3334 // Ignore res [event return value] because handling of multiple gestures -
3335 // packed into a single QEvent depends on not consuming the event -
3336 if (eventAccepted || ge.isAccepted(g)) { -
3337 // if the gesture was accepted, mark the target widget for it -
3338 gestureEvent->m_targetWidgets[g->gestureType()] = w; -
3339 gestureEvent->setAccepted(g, true); -
3340 } else { -
3341 // if the gesture was explicitly ignored by the application, -
3342 // put it back so a parent can get it -
3343 allGestures.append(g); -
3344 } -
3345 } -
3346 } -
3347 if (allGestures.isEmpty()) // everything delivered -
3348 break; -
3349 if (w->isWindow()) -
3350 break; -
3351 w = w->parentWidget(); -
3352 } -
3353 foreach (QGesture *g, allGestures) -
3354 gestureEvent->setAccepted(g, false); -
3355 gestureEvent->m_accept = false; // to make sure we check individual gestures -
3356 } else { -
3357 res = d->notify_helper(receiver, e); -
3358 } -
3359 break; -
3360 } -
3361#endif // QT_NO_GESTURES -
3362 default: -
3363 res = d->notify_helper(receiver, e); -
3364 break; -
3365 } -
3366 -
3367 return res; -
3368} -
3369 -
3370bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) -
3371{ -
3372 // send to all application event filters -
3373 if (sendThroughApplicationEventFilters(receiver, e)) -
3374 return true; -
3375 -
3376 if (receiver->isWidgetType()) { -
3377 QWidget *widget = static_cast<QWidget *>(receiver); -
3378 -
3379#if !defined(Q_OS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR)) -
3380 // toggle HasMouse widget state on enter and leave -
3381 if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) && -
3382 (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == widget->window())) -
3383 widget->setAttribute(Qt::WA_UnderMouse, true); -
3384 else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave) -
3385 widget->setAttribute(Qt::WA_UnderMouse, false); -
3386#endif -
3387 -
3388 if (QLayout *layout=widget->d_func()->layout) { -
3389 layout->widgetEvent(e); -
3390 } -
3391 } -
3392 -
3393 // send to all receiver event filters -
3394 if (sendThroughObjectEventFilters(receiver, e)) -
3395 return true; -
3396 -
3397 // deliver the event -
3398 bool consumed = receiver->event(e); -
3399 e->spont = false; -
3400 return consumed; -
3401} -
3402 -
3403bool QApplicationPrivate::inPopupMode() -
3404{ -
3405 return QApplicationPrivate::popupWidgets != 0; -
3406} -
3407 -
3408#ifdef QT_KEYPAD_NAVIGATION -
3409/*! -
3410 Sets the kind of focus navigation Qt should use to \a mode. -
3411 -
3412 This feature is available in Qt for Embedded Linux, and Windows CE -
3413 only. -
3414 -
3415 \note On Windows CE this feature is disabled by default for touch device -
3416 mkspecs. To enable keypad navigation, build Qt with -
3417 QT_KEYPAD_NAVIGATION defined. -
3418 -
3419 \since 4.6 -
3420 -
3421 \sa keypadNavigationEnabled() -
3422*/ -
3423void QApplication::setNavigationMode(Qt::NavigationMode mode) -
3424{ -
3425 QApplicationPrivate::navigationMode = mode; -
3426} -
3427 -
3428/*! -
3429 Returns what kind of focus navigation Qt is using. -
3430 -
3431 This feature is available in Qt for Embedded Linux, and Windows CE only. -
3432 -
3433 \note On Windows CE this feature is disabled by default for touch device -
3434 mkspecs. To enable keypad navigation, build Qt with -
3435 QT_KEYPAD_NAVIGATION defined. -
3436 -
3437 \since 4.6 -
3438 -
3439 \sa keypadNavigationEnabled() -
3440*/ -
3441Qt::NavigationMode QApplication::navigationMode() -
3442{ -
3443 return QApplicationPrivate::navigationMode; -
3444} -
3445 -
3446/*! -
3447 Sets whether Qt should use focus navigation suitable for use with a -
3448 minimal keypad. -
3449 -
3450 This feature is available in Qt for Embedded Linux, and Windows CE only. -
3451 -
3452 \note On Windows CE this feature is disabled by default for touch device -
3453 mkspecs. To enable keypad navigation, build Qt with -
3454 QT_KEYPAD_NAVIGATION defined. -
3455 -
3456 \deprecated -
3457 -
3458 \sa setNavigationMode() -
3459*/ -
3460void QApplication::setKeypadNavigationEnabled(bool enable) -
3461{ -
3462 if (enable) { -
3463 QApplication::setNavigationMode(Qt::NavigationModeKeypadTabOrder); -
3464 } else { -
3465 QApplication::setNavigationMode(Qt::NavigationModeNone); -
3466 } -
3467} -
3468 -
3469/*! -
3470 Returns true if Qt is set to use keypad navigation; otherwise returns -
3471 false. The default value is false. -
3472 -
3473 This feature is available in Qt for Embedded Linux, and Windows CE only. -
3474 -
3475 \note On Windows CE this feature is disabled by default for touch device -
3476 mkspecs. To enable keypad navigation, build Qt with -
3477 QT_KEYPAD_NAVIGATION defined. -
3478 -
3479 \deprecated -
3480 -
3481 \sa navigationMode() -
3482*/ -
3483bool QApplication::keypadNavigationEnabled() -
3484{ -
3485 return QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadTabOrder || -
3486 QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadDirectional; -
3487} -
3488#endif -
3489 -
3490/*! -
3491 \fn void QApplication::alert(QWidget *widget, int msec) -
3492 \since 4.3 -
3493 -
3494 Causes an alert to be shown for \a widget if the window is not the active -
3495 window. The alert is shown for \a msec miliseconds. If \a msec is zero (the -
3496 default), then the alert is shown indefinitely until the window becomes -
3497 active again. -
3498 -
3499 Currently this function does nothing on Qt for Embedded Linux. -
3500 -
3501 On Mac OS X, this works more at the application level and will cause the -
3502 application icon to bounce in the dock. -
3503 -
3504 On Windows, this causes the window's taskbar entry to flash for a time. If -
3505 \a msec is zero, the flashing will stop and the taskbar entry will turn a -
3506 different color (currently orange). -
3507 -
3508 On X11, this will cause the window to be marked as "demands attention", the -
3509 window must not be hidden (i.e. not have hide() called on it, but be -
3510 visible in some sort of way) in order for this to work. -
3511*/ -
3512 -
3513/*! -
3514 \property QApplication::cursorFlashTime -
3515 \brief the text cursor's flash (blink) time in milliseconds -
3516 -
3517 The flash time is the time required to display, invert and restore the -
3518 caret display. Usually the text cursor is displayed for half the cursor -
3519 flash time, then hidden for the same amount of time, but this may vary. -
3520 -
3521 The default value on X11 is 1000 milliseconds. On Windows, the -
3522 \uicontrol{Control Panel} value is used and setting this property sets the cursor -
3523 flash time for all applications. -
3524 -
3525 We recommend that widgets do not cache this value as it may change at any -
3526 time if the user changes the global desktop settings. -
3527*/ -
3528void QApplication::setCursorFlashTime(int msecs) -
3529{ -
3530 Q_UNUSED(msecs); -
3531} -
3532 -
3533int QApplication::cursorFlashTime() -
3534{ -
3535 return qApp->styleHints()->cursorFlashTime(); -
3536} -
3537 -
3538/*! -
3539 \property QApplication::doubleClickInterval -
3540 \brief the time limit in milliseconds that distinguishes a double click -
3541 from two consecutive mouse clicks -
3542 -
3543 The default value on X11 is 400 milliseconds. On Windows and Mac OS, the -
3544 operating system's value is used. -
3545 -
3546 Setting the interval is not supported anymore in Qt 5. -
3547*/ -
3548void QApplication::setDoubleClickInterval(int ms) -
3549{ -
3550 Q_UNUSED(ms); -
3551} -
3552 -
3553int QApplication::doubleClickInterval() -
3554{ -
3555 return qApp->styleHints()->mouseDoubleClickInterval(); -
3556} -
3557 -
3558/*! -
3559 \fn QApplication::keyboardInputDirection() -
3560 \since 4.2 -
3561 \deprecated -
3562 -
3563 Returns the current keyboard input direction. Replaced with QInputPanel::inputDirection() -
3564 \sa QInputPanel::inputDirection() -
3565*/ -
3566 -
3567/*! -
3568 \property QApplication::keyboardInputInterval -
3569 \brief the time limit in milliseconds that distinguishes a key press -
3570 from two consecutive key presses -
3571 \since 4.2 -
3572 -
3573 The default value on X11 is 400 milliseconds. On Windows and Mac OS, the -
3574 operating system's value is used. -
3575*/ -
3576void QApplication::setKeyboardInputInterval(int ms) -
3577{ -
3578 Q_UNUSED(ms); -
3579} -
3580 -
3581int QApplication::keyboardInputInterval() -
3582{ -
3583 return qApp->styleHints()->keyboardInputInterval(); -
3584} -
3585 -
3586/*! -
3587 \property QApplication::wheelScrollLines -
3588 \brief the number of lines to scroll a widget, when the -
3589 mouse wheel is rotated. -
3590 -
3591 If the value exceeds the widget's number of visible lines, the widget -
3592 should interpret the scroll operation as a single \e{page up} or -
3593 \e{page down}. If the widget is an \l{QAbstractItemView}{item view class}, -
3594 then the result of scrolling one \e line depends on the setting of the -
3595 widget's \l{QAbstractItemView::verticalScrollMode()}{scroll mode}. Scroll -
3596 one \e line can mean \l{QAbstractItemView::ScrollPerItem}{scroll one item} -
3597 or \l{QAbstractItemView::ScrollPerPixel}{scroll one pixel}. -
3598 -
3599 By default, this property has a value of 3. -
3600*/ -
3601 -
3602/*! -
3603 \fn void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) -
3604 -
3605 Enables the UI effect \a effect if \a enable is true, otherwise the effect -
3606 will not be used. -
3607 -
3608 \note All effects are disabled on screens running at less than 16-bit color -
3609 depth. -
3610 -
3611 \sa isEffectEnabled(), Qt::UIEffect, setDesktopSettingsAware() -
3612*/ -
3613 -
3614/*! -
3615 \fn bool QApplication::isEffectEnabled(Qt::UIEffect effect) -
3616 -
3617 Returns true if \a effect is enabled; otherwise returns false. -
3618 -
3619 By default, Qt will try to use the desktop settings. To prevent this, call -
3620 setDesktopSettingsAware(false). -
3621 -
3622 \note All effects are disabled on screens running at less than 16-bit color -
3623 depth. -
3624 -
3625 \sa setEffectEnabled(), Qt::UIEffect -
3626*/ -
3627 -
3628/*! -
3629 \fn void QApplication::beep() -
3630 -
3631 Sounds the bell, using the default volume and sound. The function is \e not -
3632 available in Qt for Embedded Linux. -
3633*/ -
3634 -
3635/*! -
3636 \macro qApp -
3637 \relates QApplication -
3638 -
3639 A global pointer referring to the unique application object. It is -
3640 equivalent to the pointer returned by the QCoreApplication::instance() -
3641 function except that, in GUI applications, it is a pointer to a -
3642 QApplication instance. -
3643 -
3644 Only one application object can be created. -
3645 -
3646 \sa QCoreApplication::instance() -
3647*/ -
3648 -
3649/*! -
3650 \fn QLocale QApplication::keyboardInputLocale() -
3651 \since 4.2 -
3652 \obsolete -
3653 -
3654 Returns the current keyboard input locale. Replaced with QInputMethod::locale() -
3655*/ -
3656 -
3657bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event) -
3658{ -
3659 return QGuiApplication::sendSpontaneousEvent(receiver, event); -
3660} -
3661 -
3662 -
3663void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, -
3664 Qt::FocusPolicy focusPolicy, -
3665 Qt::FocusReason focusReason) -
3666{ -
3667 QWidget *focusWidget = widget; -
3668 while (focusWidget) { -
3669 if (focusWidget->isEnabled() -
3670 && QApplicationPrivate::shouldSetFocus(focusWidget, focusPolicy)) { -
3671 focusWidget->setFocus(focusReason); -
3672 break; -
3673 } -
3674 if (focusWidget->isWindow()) -
3675 break; -
3676 focusWidget = focusWidget->parentWidget(); -
3677 } -
3678} -
3679 -
3680bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) -
3681{ -
3682 QWidget *f = w; -
3683 while (f->d_func()->extra && f->d_func()->extra->focus_proxy) -
3684 f = f->d_func()->extra->focus_proxy; -
3685 -
3686 if ((w->focusPolicy() & policy) != policy) -
3687 return false; -
3688 if (w != f && (f->focusPolicy() & policy) != policy) -
3689 return false; -
3690 return true; -
3691} -
3692 -
3693void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent) -
3694{ -
3695 for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { -
3696 QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i]; -
3697 -
3698 // preserve the sub-pixel resolution -
3699 QRectF rect = touchPoint.screenRect(); -
3700 const QPointF screenPos = rect.center(); -
3701 const QPointF delta = screenPos - screenPos.toPoint(); -
3702 -
3703 rect.moveCenter(widget->mapFromGlobal(screenPos.toPoint()) + delta); -
3704 touchPoint.d->rect = rect; -
3705 touchPoint.d->startPos = widget->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta; -
3706 touchPoint.d->lastPos = widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta; -
3707 } -
3708} -
3709 -
3710void QApplicationPrivate::initializeMultitouch() -
3711{ -
3712 initializeMultitouch_sys(); -
3713} -
3714 -
3715void QApplicationPrivate::cleanupMultitouch() -
3716{ -
3717 cleanupMultitouch_sys(); -
3718} -
3719 -
3720QWidget *QApplicationPrivate::findClosestTouchPointTarget(QTouchDevice *device, const QPointF &screenPos) -
3721{ -
3722 int closestTouchPointId = -1; -
3723 QObject *closestTarget = 0; -
3724 qreal closestDistance = qreal(0.); -
3725 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it = activeTouchPoints.constBegin(), -
3726 ite = activeTouchPoints.constEnd(); -
3727 while (it != ite) { -
3728 if (it.key().device == device) { -
3729 const QTouchEvent::TouchPoint &touchPoint = it->touchPoint; -
3730 qreal dx = screenPos.x() - touchPoint.screenPos().x(); -
3731 qreal dy = screenPos.y() - touchPoint.screenPos().y(); -
3732 qreal distance = dx * dx + dy * dy; -
3733 if (closestTouchPointId == -1 || distance < closestDistance) { -
3734 closestTouchPointId = touchPoint.id(); -
3735 closestDistance = distance; -
3736 closestTarget = it.value().target.data(); -
3737 } -
3738 } -
3739 ++it; -
3740 } -
3741 return static_cast<QWidget *>(closestTarget); -
3742} -
3743 -
3744class WidgetAttributeSaver -
3745{ -
3746public: -
3747 explicit WidgetAttributeSaver(QWidget *widget, Qt::WidgetAttribute attribute, bool forcedValue) -
3748 : m_widget(widget), -
3749 m_attribute(attribute), -
3750 m_savedValue(widget->testAttribute(attribute)) -
3751 { -
3752 widget->setAttribute(attribute, forcedValue); -
3753 } -
3754 -
3755 ~WidgetAttributeSaver() -
3756 { -
3757 m_widget->setAttribute(m_attribute, m_savedValue); -
3758 } -
3759 -
3760private: -
3761 QWidget * const m_widget; -
3762 const Qt::WidgetAttribute m_attribute; -
3763 const bool m_savedValue; -
3764}; -
3765 -
3766bool QApplicationPrivate::translateTouchToMouse(QWidget *widget, QTouchEvent *event) -
3767{ -
3768 Q_Q(QApplication); -
3769 -
3770 // Check if the platform wants synthesized mouse events. -
3771 if (!QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool()) -
3772 return false; -
3773 -
3774 Q_FOREACH (const QTouchEvent::TouchPoint &p, event->touchPoints()) { -
3775 const QEvent::Type eventType = (p.state() & Qt::TouchPointPressed) ? QEvent::MouseButtonPress -
3776 : (p.state() & Qt::TouchPointReleased) ? QEvent::MouseButtonRelease -
3777 : (p.state() & Qt::TouchPointMoved) ? QEvent::MouseMove -
3778 : QEvent::None; -
3779 -
3780 if (eventType == QEvent::None) -
3781 continue; -
3782 -
3783 const QPoint pos = widget->mapFromGlobal(p.screenPos().toPoint()); -
3784 -
3785 QMouseEvent mouseEvent(eventType, pos, -
3786 Qt::LeftButton, Qt::LeftButton, -
3787 event->modifiers()); -
3788 mouseEvent.setAccepted(true); -
3789 mouseEvent.setTimestamp(event->timestamp()); -
3790 -
3791 // Make sure our synthesized mouse event doesn't propagate -
3792 // we want to control the propagation ourself to get a chance to -
3793 // deliver a proper touch event higher up in the hierarchy if that -
3794 // widget doesn't pick up the mouse event either. -
3795 WidgetAttributeSaver saver(widget, Qt::WA_NoMousePropagation, true); -
3796 -
3797 // Note it has to be a spontaneous event if we want the focus management -
3798 // and input method support to behave properly. Quite some of the code -
3799 // related to those aspect check for the spontaneous flag. -
3800 const bool res = q->sendSpontaneousEvent(widget, &mouseEvent); -
3801 event->setAccepted(mouseEvent.isAccepted()); -
3802 -
3803 if (mouseEvent.isAccepted()) -
3804 return res; -
3805 } -
3806 -
3807 return false; -
3808} -
3809 -
3810void QApplicationPrivate::translateRawTouchEvent(QWidget *window, -
3811 QTouchDevice *device, -
3812 const QList<QTouchEvent::TouchPoint> &touchPoints, -
3813 ulong timestamp) -
3814{ -
3815 QApplicationPrivate *d = self; -
3816 typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints; -
3817 QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents; -
3818 -
3819 for (int i = 0; i < touchPoints.count(); ++i) { -
3820 QTouchEvent::TouchPoint touchPoint = touchPoints.at(i); -
3821 // explicitly detach from the original touch point that we got, so even -
3822 // if the touchpoint structs are reused, we will make a copy that we'll -
3823 // deliver to the user (which might want to store the struct for later use). -
3824 touchPoint.d = touchPoint.d->detach(); -
3825 -
3826 // update state -
3827 QPointer<QObject> target; -
3828 ActiveTouchPointsKey touchInfoKey(device, touchPoint.id()); -
3829 ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey]; -
3830 if (touchPoint.state() == Qt::TouchPointPressed) { -
3831 if (device->type() == QTouchDevice::TouchPad) { -
3832 // on touch-pads, send all touch points to the same widget -
3833 target = d->activeTouchPoints.isEmpty() -
3834 ? QPointer<QObject>() -
3835 : d->activeTouchPoints.constBegin().value().target; -
3836 } -
3837 -
3838 if (!target) { -
3839 // determine which widget this event will go to -
3840 if (!window) -
3841 window = QApplication::topLevelAt(touchPoint.screenPos().toPoint()); -
3842 if (!window) -
3843 continue; -
3844 target = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint())); -
3845 if (!target) -
3846 target = window; -
3847 } -
3848 -
3849 if (device->type() == QTouchDevice::TouchScreen) { -
3850 QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint.screenPos()); -
3851 QWidget *widget = static_cast<QWidget *>(target.data()); -
3852 if (closestWidget -
3853 && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) { -
3854 target = closestWidget; -
3855 } -
3856 } -
3857 -
3858 touchInfo.target = target; -
3859 } else { -
3860 target = touchInfo.target; -
3861 if (!target) -
3862 continue; -
3863 } -
3864 Q_ASSERT(target.data() != 0); -
3865 -
3866 StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[static_cast<QWidget *>(target.data())]; -
3867 maskAndPoints.first |= touchPoint.state(); -
3868 maskAndPoints.second.append(touchPoint); -
3869 } -
3870 -
3871 if (widgetsNeedingEvents.isEmpty()) -
3872 return; -
3873 -
3874 QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin(); -
3875 const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd(); -
3876 for (; it != end; ++it) { -
3877 QWidget *widget = it.key(); -
3878 if (!QApplicationPrivate::tryModalHelper(widget, 0)) -
3879 continue; -
3880 -
3881 QEvent::Type eventType; -
3882 switch (it.value().first) { -
3883 case Qt::TouchPointPressed: -
3884 eventType = QEvent::TouchBegin; -
3885 break; -
3886 case Qt::TouchPointReleased: -
3887 eventType = QEvent::TouchEnd; -
3888 break; -
3889 case Qt::TouchPointStationary: -
3890 // don't send the event if nothing changed -
3891 continue; -
3892 default: -
3893 eventType = QEvent::TouchUpdate; -
3894 break; -
3895 } -
3896 -
3897 QTouchEvent touchEvent(eventType, -
3898 device, -
3899 QApplication::keyboardModifiers(), -
3900 it.value().first, -
3901 it.value().second); -
3902 updateTouchPointsForWidget(widget, &touchEvent); -
3903 touchEvent.setTimestamp(timestamp); -
3904 touchEvent.setWindow(window->windowHandle()); -
3905 touchEvent.setTarget(widget); -
3906 -
3907 switch (touchEvent.type()) { -
3908 case QEvent::TouchBegin: -
3909 { -
3910 // if the TouchBegin handler recurses, we assume that means the event -
3911 // has been implicitly accepted and continue to send touch events -
3912 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent); -
3913 (void ) QApplication::sendSpontaneousEvent(widget, &touchEvent); -
3914 break; -
3915 } -
3916 default: -
3917 if (widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent)) { -
3918 if (touchEvent.type() == QEvent::TouchEnd) -
3919 widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, false); -
3920 (void) QApplication::sendSpontaneousEvent(widget, &touchEvent); -
3921 } -
3922 break; -
3923 } -
3924 } -
3925} -
3926 -
3927void QApplicationPrivate::translateTouchCancel(QTouchDevice *device, ulong timestamp) -
3928{ -
3929 QTouchEvent touchEvent(QEvent::TouchCancel, device, QApplication::keyboardModifiers()); -
3930 touchEvent.setTimestamp(timestamp); -
3931 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it -
3932 = self->activeTouchPoints.constBegin(), ite = self->activeTouchPoints.constEnd(); -
3933 QSet<QWidget *> widgetsNeedingCancel; -
3934 while (it != ite) { -
3935 QWidget *widget = static_cast<QWidget *>(it->target.data()); -
3936 if (widget) -
3937 widgetsNeedingCancel.insert(widget); -
3938 ++it; -
3939 } -
3940 for (QSet<QWidget *>::const_iterator widIt = widgetsNeedingCancel.constBegin(), -
3941 widItEnd = widgetsNeedingCancel.constEnd(); widIt != widItEnd; ++widIt) { -
3942 QWidget *widget = *widIt; -
3943 touchEvent.setWindow(widget->windowHandle()); -
3944 touchEvent.setTarget(widget); -
3945 QApplication::sendSpontaneousEvent(widget, &touchEvent); -
3946 } -
3947} -
3948 -
3949void QApplicationPrivate::notifyThemeChanged() -
3950{ -
3951 QGuiApplicationPrivate::notifyThemeChanged(); -
3952 clearSystemPalette(); -
3953 initSystemPalette(); -
3954} -
3955 -
3956#ifndef QT_NO_DRAGANDDROP -
3957void QApplicationPrivate::notifyDragStarted(const QDrag *drag) -
3958{ -
3959 // Prevent pickMouseReceiver() from using the widget where the drag was started after a drag operation. -
3960 QGuiApplicationPrivate::notifyDragStarted(drag); -
3961 qt_button_down = 0; -
3962} -
3963#endif // QT_NO_DRAGANDDROP -
3964 -
3965#ifndef QT_NO_GESTURES -
3966QGestureManager* QGestureManager::instance() -
3967{ -
3968 QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); -
3969 if (!qAppPriv) -
3970 return 0; -
3971 if (!qAppPriv->gestureManager) -
3972 qAppPriv->gestureManager = new QGestureManager(qApp); -
3973 return qAppPriv->gestureManager; -
3974} -
3975#endif // QT_NO_GESTURES -
3976 -
3977QPixmap QApplicationPrivate::applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const -
3978{ -
3979 QStyleOption opt(0); -
3980 opt.palette = QGuiApplication::palette(); -
3981 return QApplication::style()->generatedIconPixmap(mode, base, &opt); -
3982} -
3983 -
3984QT_END_NAMESPACE -
3985 -
3986#include "moc_qapplication.cpp" -
3987 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial