source: trunk/src/gui/kernel/qapplication.cpp@ 64

Last change on this file since 64 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 165.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information (qt-info@nokia.com)
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at qt-sales@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qabstracteventdispatcher.h"
43#include "qaccessible.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 "qsessionmanager.h"
57#include "qstyle.h"
58#include "qstylefactory.h"
59#include "qtextcodec.h"
60#include "qtranslator.h"
61#include "qvariant.h"
62#include "qwidget.h"
63#include "qdnd_p.h"
64#include "qcolormap.h"
65#include "qdebug.h"
66#include "private/qgraphicssystemfactory_p.h"
67#include "private/qstylesheetstyle_p.h"
68#include "private/qstyle_p.h"
69#include "qmessagebox.h"
70#include <QtGui/qgraphicsproxywidget.h>
71
72#include "qinputcontext.h"
73#include "qkeymapper_p.h"
74
75#ifdef Q_WS_X11
76#include <private/qt_x11_p.h>
77#include "qinputcontextfactory.h"
78#endif
79
80#include <qthread.h>
81#include <private/qthread_p.h>
82
83#include <private/qfont_p.h>
84
85#include <stdlib.h>
86
87#include "qapplication_p.h"
88#include "qwidget_p.h"
89
90#include "qapplication.h"
91
92#ifdef Q_OS_WINCE
93#include "qdatetime.h"
94#include "qguifunctions_wince.h"
95extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp
96extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp
97extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp
98#endif
99
100//#define ALIEN_DEBUG
101
102static void initResources()
103{
104#ifdef Q_OS_WINCE
105 Q_INIT_RESOURCE(qstyle_wince);
106#else
107 Q_INIT_RESOURCE(qstyle);
108#endif
109
110#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
111 Q_INIT_RESOURCE(qpaintengine_d3d);
112#endif
113 Q_INIT_RESOURCE(qmessagebox);
114#if !defined(QT_NO_PRINTDIALOG)
115 Q_INIT_RESOURCE(qprintdialog);
116#endif
117
118}
119
120QT_BEGIN_NAMESPACE
121
122extern void qt_call_post_routines();
123
124int QApplicationPrivate::app_compile_version = 0x040000; //we don't know exactly, but it's at least 4.0.0
125
126QApplication::Type qt_appType=QApplication::Tty;
127QApplicationPrivate *QApplicationPrivate::self = 0;
128
129QInputContext *QApplicationPrivate::inputContext;
130
131bool QApplicationPrivate::quitOnLastWindowClosed = true;
132
133#ifdef Q_OS_WINCE
134int QApplicationPrivate::autoMaximizeThreshold = -1;
135bool QApplicationPrivate::autoSipEnabled = false;
136#endif
137
138QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type)
139 : QCoreApplicationPrivate(argc, argv)
140{
141 application_type = type;
142 qt_appType = type;
143
144#ifndef QT_NO_SESSIONMANAGER
145 is_session_restored = false;
146#endif
147
148 quitOnLastWindowClosed = true;
149
150#ifdef QT3_SUPPORT
151 qt_compat_used = 0;
152 qt_compat_resolved = 0;
153 qt_tryAccelEvent = 0;
154 qt_tryComposeUnicode = 0;
155 qt_dispatchAccelEvent = 0;
156#endif
157#if defined(Q_WS_QWS) && !defined(QT_NO_DIRECTPAINTER)
158 directPainters = 0;
159#endif
160
161 if (!self)
162 self = this;
163}
164
165QApplicationPrivate::~QApplicationPrivate()
166{
167 if (self == this)
168 self = 0;
169}
170
171/*!
172 \class QApplication
173 \brief The QApplication class manages the GUI application's control
174 flow and main settings.
175
176 \ingroup application
177 \mainclass
178
179 QApplication contains the main event loop, where all events from the window
180 system and other sources are processed and dispatched. It also handles the
181 application's initialization and finalization, and provides session
182 management. In addition, it handles most system-wide and application-wide
183 settings.
184
185 For any GUI application using Qt, there is precisely one QApplication
186 object, no matter whether the application has 0, 1, 2 or more windows at
187 any given time. For non-GUI Qt applications, use QCoreApplication instead,
188 as it does not depend on the \l QtGui library.
189
190 The QApplication object is accessible through the instance() function that
191 returns a pointer equivalent to the global qApp pointer.
192
193 QApplication's main areas of responsibility are:
194 \list
195 \o It initializes the application with the user's desktop settings
196 such as palette(), font() and doubleClickInterval(). It keeps
197 track of these properties in case the user changes the desktop
198 globally, for example through some kind of control panel.
199
200 \o It performs event handling, meaning that it receives events
201 from the underlying window system and dispatches them to the
202 relevant widgets. By using sendEvent() and postEvent() you can
203 send your own events to widgets.
204
205 \o It parses common command line arguments and sets its internal
206 state accordingly. See the \l{QApplication::QApplication()}
207 {constructor documentation} below for more details.
208
209 \o It defines the application's look and feel, which is
210 encapsulated in a QStyle object. This can be changed at runtime
211 with setStyle().
212
213 \o It specifies how the application is to allocate colors. See
214 setColorSpec() for details.
215
216 \o It provides localization of strings that are visible to the
217 user via translate().
218
219 \o It provides some magical objects like the desktop() and the
220 clipboard().
221
222 \o It knows about the application's windows. You can ask which
223 widget is at a certain position using widgetAt(), get a list of
224 topLevelWidgets() and closeAllWindows(), etc.
225
226 \o It manages the application's mouse cursor handling, see
227 setOverrideCursor()
228
229 \o On the X window system, it provides functions to flush and sync
230 the communication stream, see flushX() and syncX().
231
232 \o It provides support for sophisticated \l{Session Management}
233 {session management}. This makes it possible for applications
234 to terminate gracefully when the user logs out, to cancel a
235 shutdown process if termination isn't possible and even to
236 preserve the entire application's state for a future session.
237 See isSessionRestored(), sessionId() and commitData() and
238 saveState() for details.
239 \endlist
240
241 The QApplication object does so much initialization. Hence, it \e{must} be
242 created before any other objects related to the user interface are created.
243 Since QApplication also deals with common command line arguments, 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 \o{2,1} Groups of functions
250
251 \row
252 \o System settings
253 \o 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 \o Event handling
270 \o exec(),
271 processEvents(),
272 exit(),
273 quit().
274 sendEvent(),
275 postEvent(),
276 sendPostedEvents(),
277 removePostedEvents(),
278 hasPendingEvents(),
279 notify(),
280 macEventFilter(),
281 qwsEventFilter(),
282 x11EventFilter(),
283 x11ProcessEvent(),
284 winEventFilter().
285
286 \row
287 \o GUI Styles
288 \o style(),
289 setStyle().
290
291 \row
292 \o Color usage
293 \o colorSpec(),
294 setColorSpec(),
295 qwsSetCustomColors().
296
297 \row
298 \o Text handling
299 \o installTranslator(),
300 removeTranslator()
301 translate().
302
303 \row
304 \o Widgets
305 \o allWidgets(),
306 topLevelWidgets(),
307 desktop(),
308 activePopupWidget(),
309 activeModalWidget(),
310 clipboard(),
311 focusWidget(),
312 activeWindow(),
313 widgetAt().
314
315 \row
316 \o Advanced cursor handling
317 \o overrideCursor(),
318 setOverrideCursor(),
319 restoreOverrideCursor().
320
321 \row
322 \o X Window System synchronization
323 \o flushX(),
324 syncX().
325
326 \row
327 \o Session management
328 \o isSessionRestored(),
329 sessionId(),
330 commitData(),
331 saveState().
332
333 \row
334 \o Miscellaneous
335 \o closeAllWindows(),
336 startingUp(),
337 closingDown(),
338 type().
339 \endtable
340
341 \sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings
342*/
343
344/*!
345 \enum QApplication::Type
346
347 \value Tty a console application
348 \value GuiClient a GUI client application
349 \value GuiServer a GUI server application (for Qt for Embedded Linux)
350*/
351
352/*!
353 \enum QApplication::ColorSpec
354
355 \value NormalColor the default color allocation policy
356 \value CustomColor the same as NormalColor for X11; allocates colors
357 to a palette on demand under Windows
358 \value ManyColor the right choice for applications that use thousands of
359 colors
360
361 See setColorSpec() for full details.
362*/
363
364/*!
365 \fn QWidget *QApplication::topLevelAt(const QPoint &point)
366
367 Returns the top-level widget at the given \a point; returns 0 if
368 there is no such widget.
369*/
370
371/*!
372 \fn QWidget *QApplication::topLevelAt(int x, int y)
373
374 \overload
375
376 Returns the top-level widget at the point (\a{x}, \a{y}); returns
377 0 if there is no such widget.
378*/
379
380
381/*
382 The qt_init() and qt_cleanup() functions are implemented in the
383 qapplication_xyz.cpp file.
384*/
385
386void qt_init(QApplicationPrivate *priv, int type
387#ifdef Q_WS_X11
388 , Display *display = 0, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0
389#endif
390 );
391void qt_cleanup();
392
393Qt::MouseButtons QApplicationPrivate::mouse_buttons = Qt::NoButton;
394Qt::KeyboardModifiers QApplicationPrivate::modifier_buttons = Qt::NoModifier;
395
396QStyle *QApplicationPrivate::app_style = 0; // default application style
397
398#ifndef QT_NO_STYLE_STYLESHEET
399QString QApplicationPrivate::styleSheet; // default application stylesheet
400#endif
401QPointer<QWidget> QApplicationPrivate::leaveAfterRelease = 0;
402
403int QApplicationPrivate::app_cspec = QApplication::NormalColor;
404QPalette *QApplicationPrivate::app_pal = 0; // default application palette
405QPalette *QApplicationPrivate::sys_pal = 0; // default system palette
406QPalette *QApplicationPrivate::set_pal = 0; // default palette set by programmer
407
408QGraphicsSystem *QApplicationPrivate::graphics_system = 0; // default graphics system
409QString QApplicationPrivate::graphics_system_name; // graphics system id - for delayed initialization
410
411Q_GLOBAL_STATIC(QMutex, applicationFontMutex);
412QFont *QApplicationPrivate::app_font = 0; // default application font
413QFont *QApplicationPrivate::sys_font = 0; // default system font
414QFont *QApplicationPrivate::set_font = 0; // default font set by programmer
415
416QIcon *QApplicationPrivate::app_icon = 0;
417QWidget *QApplicationPrivate::main_widget = 0; // main application widget
418QWidget *QApplicationPrivate::focus_widget = 0; // has keyboard input focus
419QWidget *QApplicationPrivate::hidden_focus_widget = 0; // will get keyboard input focus after show()
420QWidget *QApplicationPrivate::active_window = 0; // toplevel with keyboard focus
421bool QApplicationPrivate::obey_desktop_settings = true; // use winsys resources
422int QApplicationPrivate::cursor_flash_time = 1000; // text caret flash time
423int QApplicationPrivate::mouse_double_click_time = 400; // mouse dbl click limit
424int QApplicationPrivate::keyboard_input_time = 400; // keyboard input interval
425#ifndef QT_NO_WHEELEVENT
426int QApplicationPrivate::wheel_scroll_lines; // number of lines to scroll
427#endif
428bool qt_is_gui_used;
429bool Q_GUI_EXPORT qt_tab_all_widgets = true;
430bool qt_in_tab_key_event = false;
431int qt_antialiasing_threshold = -1;
432static int drag_time = 500;
433static int drag_distance = 4;
434static Qt::LayoutDirection layout_direction = Qt::LeftToRight;
435QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
436bool QApplicationPrivate::animate_ui = true;
437bool QApplicationPrivate::animate_menu = false;
438bool QApplicationPrivate::fade_menu = false;
439bool QApplicationPrivate::animate_combo = false;
440bool QApplicationPrivate::animate_tooltip = false;
441bool QApplicationPrivate::fade_tooltip = false;
442bool QApplicationPrivate::animate_toolbox = false;
443bool QApplicationPrivate::widgetCount = false;
444QString* QApplicationPrivate::styleOverride = 0;
445#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
446bool QApplicationPrivate::inSizeMove = false;
447#endif
448#ifdef QT_KEYPAD_NAVIGATION
449bool QApplicationPrivate::keypadNavigation = false;
450QWidget *QApplicationPrivate::oldEditFocus = 0;
451#endif
452
453bool qt_tabletChokeMouse = false;
454static bool force_reverse = false;
455
456static inline bool isAlien(QWidget *widget)
457{
458 if (!widget)
459 return false;
460#ifdef Q_WS_MAC // Fake alien behavior on the Mac :)
461 return !widget->isWindow() && widget->window()->testAttribute(Qt::WA_DontShowOnScreen);
462#else
463 return !widget->internalWinId();
464#endif
465}
466
467// ######## move to QApplicationPrivate
468// Default application palettes and fonts (per widget type)
469
470typedef QHash<QByteArray, QPalette> PaletteHash;
471Q_GLOBAL_STATIC(PaletteHash, app_palettes)
472PaletteHash *qt_app_palettes_hash()
473{
474 return app_palettes();
475}
476
477typedef QHash<QByteArray, QFont> FontHash;
478Q_GLOBAL_STATIC(FontHash, app_fonts)
479FontHash *qt_app_fonts_hash()
480{
481 return app_fonts();
482}
483
484QWidgetList *QApplicationPrivate::popupWidgets = 0; // has keyboard input focus
485
486QDesktopWidget *qt_desktopWidget = 0; // root window widgets
487#ifndef QT_NO_CLIPBOARD
488QClipboard *qt_clipboard = 0; // global clipboard object
489#endif
490QWidgetList * qt_modal_stack=0; // stack of modal widgets
491
492/*!
493 \internal
494*/
495void QApplicationPrivate::process_cmdline()
496{
497 Q_Q(QApplication);
498 Q_UNUSED(q);// only static members being used.
499 // process platform-indep command line
500 if (!qt_is_gui_used || !argc)
501 return;
502
503 int i, j;
504
505 j = 1;
506 for (i=1; i<argc; i++) { // if you add anything here, modify QCoreApplication::arguments()
507 if (argv[i] && *argv[i] != '-') {
508 argv[j++] = argv[i];
509 continue;
510 }
511 QByteArray arg = argv[i];
512 arg = arg;
513 QString s;
514 if (arg == "-qdevel" || arg == "-qdebug") {
515 // obsolete argument
516 } else if (arg.indexOf("-style=", 0) != -1) {
517 s = QString::fromLocal8Bit(arg.right(arg.length() - 7).toLower());
518 } else if (arg == "-style" && i < argc-1) {
519 s = QString::fromLocal8Bit(argv[++i]).toLower();
520#ifndef QT_NO_SESSIONMANAGER
521 } else if (arg == "-session" && i < argc-1) {
522 ++i;
523 if (argv[i] && *argv[i]) {
524 session_id = QString::fromLatin1(argv[i]);
525 int p = session_id.indexOf(QLatin1Char('_'));
526 if (p >= 0) {
527 session_key = session_id.mid(p +1);
528 session_id = session_id.left(p);
529 }
530 is_session_restored = true;
531 }
532#endif
533#ifndef QT_NO_STYLE_STYLESHEET
534 } else if (arg == "-stylesheet" && i < argc -1) {
535 styleSheet = QLatin1String("file:///");
536 styleSheet.append(QString::fromLocal8Bit(argv[++i]));
537 } else if (arg.indexOf("-stylesheet=") != -1) {
538 styleSheet = QLatin1String("file:///");
539 styleSheet.append(QString::fromLocal8Bit(arg.right(arg.length() - 12)));
540#endif
541 } else if (qstrcmp(arg, "-reverse") == 0) {
542 force_reverse = true;
543 q->setLayoutDirection(Qt::RightToLeft);
544 } else if (qstrcmp(arg, "-widgetcount") == 0) {
545 widgetCount = true;
546 } else if (arg == "-graphicssystem" && i < argc-1) {
547 graphics_system_name = QString::fromLocal8Bit(argv[++i]);
548 } else {
549 argv[j++] = argv[i];
550 }
551 if (!s.isEmpty()) {
552 if (app_style) {
553 delete app_style;
554 app_style = 0;
555 }
556 if (!styleOverride)
557 styleOverride = new QString;
558 *styleOverride = s;
559 }
560 }
561
562 if(j < argc) {
563 argv[j] = 0;
564 argc = j;
565 }
566}
567
568/*!
569 Initializes the window system and constructs an application object with
570 \a argc command line arguments in \a argv.
571
572 \warning The data referred to by \a argc and \a argv must stay valid for
573 the entire lifetime of the QApplication object. In addition, \a argc must
574 be greater than zero and \a argv must contain at least one valid character
575 string.
576
577 The global \c qApp pointer refers to this application object. Only one
578 application object should be created.
579
580 This application object must be constructed before any \l{QPaintDevice}
581 {paint devices} (including widgets, pixmaps, bitmaps etc.).
582
583 \note \a argc and \a argv might be changed as Qt removes command line
584 arguments that it recognizes.
585
586 Qt debugging options (not available if Qt was compiled without the QT_DEBUG
587 flag defined):
588 \list
589 \o -nograb, tells Qt that it must never grab the mouse or the
590 keyboard.
591 \o -dograb (only under X11), running under a debugger can cause an
592 implicit -nograb, use -dograb to override.
593 \o -sync (only under X11), switches to synchronous mode for
594 debugging.
595 \endlist
596
597 See \l{Debugging Techniques} for a more detailed explanation.
598
599 All Qt programs automatically support the following command line options:
600 \list
601 \o -style= \e style, sets the application GUI style. Possible values
602 are \c motif, \c windows, and \c platinum. If you compiled Qt with
603 additional styles or have additional styles as plugins these will
604 be available to the \c -style command line option.
605 \o -style \e style, is the same as listed above.
606 \o -stylesheet= \e stylesheet, sets the application \l styleSheet. The
607 value must be a path to a file that contains the Style Sheet.
608 \note Relative URLs in the Style Sheet file are relative to the
609 Style Sheet file's path.
610 \o -stylesheet \e stylesheet, is the same as listed above.
611 \o -session= \e session, restores the application from an earlier
612 \l{Session Management}{session}.
613 \o -session \e session, is the same as listed above.
614 \o -widgetcount, prints debug message at the end about number of
615 widgets left undestroyed and maximum number of widgets existed at
616 the same time
617 \o -reverse, sets the application's layout direction to
618 Qt::RightToLeft
619 \o -graphicssystem, sets the backend to be used for on-screen widgets
620 and QPixmaps. Available options are \c{raster} and \c{opengl}.
621 \endlist
622
623 The Windows version of Qt supports an additional command line option, if
624 Direct3D support has been compiled into Qt:
625 \list
626 \o -direct3d will make the Direct3D paint engine the default widget
627 paint engine in Qt. \bold {This functionality is experimental.}
628 \endlist
629
630 The X11 version of Qt supports some traditional X11 command line options:
631 \list
632 \o -display \e display, sets the X display (default is $DISPLAY).
633 \o -geometry \e geometry, sets the client geometry of the first window
634 that is shown.
635 \o -fn or \c -font \e font, defines the application font. The font
636 should be specified using an X logical font description.
637 \o -bg or \c -background \e color, sets the default background color
638 and an application palette (light and dark shades are calculated).
639 \o -fg or \c -foreground \e color, sets the default foreground color.
640 \o -btn or \c -button \e color, sets the default button color.
641 \o -name \e name, sets the application name.
642 \o -title \e title, sets the application title.
643 \o -visual \c TrueColor, forces the application to use a TrueColor
644 visual on an 8-bit display.
645 \o -ncols \e count, limits the number of colors allocated in the color
646 cube on an 8-bit display, if the application is using the
647 QApplication::ManyColor color specification. If \e count is 216
648 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green,
649 and 6 of blue); for other values, a cube approximately proportional
650 to a 2x3x1 cube is used.
651 \o -cmap, causes the application to install a private color map on an
652 8-bit display.
653 \o -im, sets the input method server (equivalent to setting the
654 XMODIFIERS environment variable)
655 \o -inputstyle, defines how the input is inserted into the given
656 widget, e.g., \c onTheSpot makes the input appear directly in the
657 widget, while \c overTheSpot makes the input appear in a box
658 floating over the widget and is not inserted until the editing is
659 done.
660 \endlist
661
662 \sa arguments()
663*/
664
665QApplication::QApplication(int &argc, char **argv)
666 : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient))
667{ Q_D(QApplication); d->construct(); }
668
669QApplication::QApplication(int &argc, char **argv, int _internal)
670 : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient))
671{ Q_D(QApplication); d->construct(); QApplicationPrivate::app_compile_version = _internal;}
672
673
674/*!
675 Constructs an application object with \a argc command line arguments in
676 \a argv. If \a GUIenabled is true, a GUI application is constructed,
677 otherwise a non-GUI (console) application is created.
678
679 \warning The data referred to by \a argc and \a argv must stay valid for
680 the entire lifetime of the QApplication object. In addition, \a argc must
681 be greater than zero and \a argv must contain at least one valid character
682 string.
683
684 Set \a GUIenabled to false for programs without a graphical user interface
685 that should be able to run without a window system.
686
687 On X11, the window system is initialized if \a GUIenabled is true. If
688 \a GUIenabled is false, the application does not connect to the X server.
689 On Windows and Macintosh, currently the window system is always
690 initialized, regardless of the value of GUIenabled. This may change in
691 future versions of Qt.
692
693 The following example shows how to create an application that uses a
694 graphical interface when available.
695
696 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 0
697*/
698
699QApplication::QApplication(int &argc, char **argv, bool GUIenabled )
700 : QCoreApplication(*new QApplicationPrivate(argc, argv, GUIenabled ? GuiClient : Tty))
701{ Q_D(QApplication); d->construct(); }
702
703QApplication::QApplication(int &argc, char **argv, bool GUIenabled , int _internal)
704 : QCoreApplication(*new QApplicationPrivate(argc, argv, GUIenabled ? GuiClient : Tty))
705{ Q_D(QApplication); d->construct(); QApplicationPrivate::app_compile_version = _internal;}
706
707
708
709/*!
710 Constructs an application object with \a argc command line arguments in
711 \a argv.
712
713 \warning The data referred to by \a argc and \a argv must stay valid for
714 the entire lifetime of the QApplication object. In addition, \a argc must
715 be greater than zero and \a argv must contain at least one valid character
716 string.
717
718 With Qt for Embedded Linux, passing QApplication::GuiServer for \a type
719 makes this application the server (equivalent to running with the
720 \c -qws option).
721*/
722QApplication::QApplication(int &argc, char **argv, Type type)
723 : QCoreApplication(*new QApplicationPrivate(argc, argv, type))
724{ Q_D(QApplication); d->construct(); }
725
726QApplication::QApplication(int &argc, char **argv, Type type , int _internal)
727 : QCoreApplication(*new QApplicationPrivate(argc, argv, type))
728{ Q_D(QApplication); d->construct(); QApplicationPrivate::app_compile_version = _internal;}
729
730
731/*!
732 \internal
733*/
734void QApplicationPrivate::construct(
735#ifdef Q_WS_X11
736 Display *dpy, Qt::HANDLE visual, Qt::HANDLE cmap
737#endif
738 )
739{
740 initResources();
741
742 qt_is_gui_used = (qt_appType != QApplication::Tty);
743 process_cmdline();
744 // Must be called before initialize()
745 qt_init(this, qt_appType
746#ifdef Q_WS_X11
747 , dpy, visual, cmap
748#endif
749 );
750 initialize();
751 eventDispatcher->startingUp();
752
753#ifdef QT_EVAL
754 extern void qt_gui_eval_init(uint);
755 qt_gui_eval_init(application_type);
756#endif
757}
758
759#if defined(Q_WS_X11)
760// ### a string literal is a cont char*
761// ### using it as a char* is wrong and could lead to segfaults
762// ### if aargv is modified someday
763// ########## make it work with argc == argv == 0
764static int aargc = 1;
765static char *aargv[] = { (char*)"unknown", 0 };
766
767/*!
768 \fn QApplication::QApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap)
769
770 Creates an application, given an already open display \a display. If
771 \a visual and \a colormap are non-zero, the application will use those
772 values as the default Visual and Colormap contexts.
773
774 \warning Qt only supports TrueColor visuals at depths higher than 8
775 bits-per-pixel.
776
777 This function is only available on X11.
778*/
779QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap)
780 : QCoreApplication(*new QApplicationPrivate(aargc, aargv, GuiClient))
781{
782 if (! dpy)
783 qWarning("QApplication: Invalid Display* argument");
784 Q_D(QApplication);
785 d->construct(dpy, visual, colormap);
786}
787
788QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap, int _internal)
789 : QCoreApplication(*new QApplicationPrivate(aargc, aargv, GuiClient))
790{
791 if (! dpy)
792 qWarning("QApplication: Invalid Display* argument");
793 Q_D(QApplication);
794 d->construct(dpy, visual, colormap);
795 QApplicationPrivate::app_compile_version = _internal;
796}
797
798/*!
799 \fn QApplication::QApplication(Display *display, int &argc, char **argv,
800 Qt::HANDLE visual, Qt::HANDLE colormap)
801
802 Creates an application, given an already open \a display and using \a argc
803 command line arguments in \a argv. If \a visual and \a colormap are
804 non-zero, the application will use those values as the default Visual
805 and Colormap contexts.
806
807 \warning Qt only supports TrueColor visuals at depths higher than 8
808 bits-per-pixel.
809
810 This function is only available on X11.
811*/
812QApplication::QApplication(Display *dpy, int &argc, char **argv,
813 Qt::HANDLE visual, Qt::HANDLE colormap)
814 : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient))
815{
816 if (! dpy)
817 qWarning("QApplication: Invalid Display* argument");
818 Q_D(QApplication);
819 d->construct(dpy, visual, colormap);
820}
821
822QApplication::QApplication(Display *dpy, int &argc, char **argv,
823 Qt::HANDLE visual, Qt::HANDLE colormap, int _internal)
824 : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient))
825{
826 if (! dpy)
827 qWarning("QApplication: Invalid Display* argument");
828 Q_D(QApplication);
829 d->construct(dpy, visual, colormap);
830 QApplicationPrivate::app_compile_version = _internal;
831}
832
833#endif // Q_WS_X11
834
835
836/*!
837 Initializes the QApplication object, called from the constructors.
838*/
839extern void qInitDrawhelperAsm();
840
841void QApplicationPrivate::initialize()
842{
843 QWidgetPrivate::mapper = new QWidgetMapper;
844 QWidgetPrivate::uncreatedWidgets = new QWidgetSet;
845 if (qt_appType != QApplication::Tty)
846 (void) QApplication::style(); // trigger creation of application style
847 // trigger registering of QVariant's GUI types
848 extern int qRegisterGuiVariant();
849 qRegisterGuiVariant();
850
851 is_app_running = true; // no longer starting up
852
853 Q_Q(QApplication);
854#ifndef QT_NO_SESSIONMANAGER
855 // connect to the session manager
856 session_manager = new QSessionManager(q, session_id, session_key);
857#endif
858
859 if (qgetenv("QT_USE_NATIVE_WINDOWS").toInt() > 0)
860 q->setAttribute(Qt::AA_NativeWindows);
861
862#if defined(Q_WS_WIN)
863 // Alien is not currently working on Windows 98
864 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)
865 q->setAttribute(Qt::AA_NativeWindows);
866#endif
867
868#ifdef Q_OS_WINCE
869#ifdef QT_AUTO_MAXIMIZE_THRESHOLD
870 autoMaximizeThreshold = QT_AUTO_MAXIMIZE_THRESHOLD;
871#else
872 if (qt_wince_is_mobile())
873 autoMaximizeThreshold = 50;
874 else
875 autoMaximizeThreshold = -1;
876#endif //QT_AUTO_MAXIMIZE_THRESHOLD
877#endif //Q_OS_WINCE
878
879 // Set up which span functions should be used in raster engine...
880 qInitDrawhelperAsm();
881
882#if !defined(Q_WS_X11) && !defined(Q_WS_QWS)
883 // initialize the graphics system - on X11 this is initialized inside
884 // qt_init() in qapplication_x11.cpp because of several reasons.
885 // On QWS, the graphics system is set by the QScreen plugin.
886 graphics_system = QGraphicsSystemFactory::create(graphics_system_name);
887#endif
888#ifndef QT_NO_WHEELEVENT
889#ifdef QT_MAC_USE_COCOA
890 QApplicationPrivate::wheel_scroll_lines = 1;
891#else
892 QApplicationPrivate::wheel_scroll_lines = 3;
893#endif
894#endif
895}
896
897/*!
898 Returns the type of application (\l Tty, GuiClient, or
899 GuiServer). The type is set when constructing the QApplication
900 object.
901*/
902QApplication::Type QApplication::type()
903{
904 return qt_appType;
905}
906
907/*****************************************************************************
908 Functions returning the active popup and modal widgets.
909 *****************************************************************************/
910
911/*!
912 Returns the active popup widget.
913
914 A popup widget is a special top-level widget that sets the \c
915 Qt::WType_Popup widget flag, e.g. the QMenu widget. When the application
916 opens a popup widget, all events are sent to the popup. Normal widgets and
917 modal widgets cannot be accessed before the popup widget is closed.
918
919 Only other popup widgets may be opened when a popup widget is shown. The
920 popup widgets are organized in a stack. This function returns the active
921 popup widget at the top of the stack.
922
923 \sa activeModalWidget(), topLevelWidgets()
924*/
925
926QWidget *QApplication::activePopupWidget()
927{
928 return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ?
929 QApplicationPrivate::popupWidgets->last() : 0;
930}
931
932
933/*!
934 Returns the active modal widget.
935
936 A modal widget is a special top-level widget which is a subclass of QDialog
937 that specifies the modal parameter of the constructor as true. A modal
938 widget must be closed before the user can continue with other parts of the
939 program.
940
941 Modal widgets are organized in a stack. This function returns the active
942 modal widget at the top of the stack.
943
944 \sa activePopupWidget(), topLevelWidgets()
945*/
946
947QWidget *QApplication::activeModalWidget()
948{
949 return qt_modal_stack && !qt_modal_stack->isEmpty() ? qt_modal_stack->first() : 0;
950}
951
952/*!
953 Cleans up any window system resources that were allocated by this
954 application. Sets the global variable \c qApp to 0.
955*/
956
957QApplication::~QApplication()
958{
959 Q_D(QApplication);
960
961#ifndef QT_NO_CLIPBOARD
962 // flush clipboard contents
963 if (qt_clipboard) {
964 QEvent event(QEvent::Clipboard);
965 QApplication::sendEvent(qt_clipboard, &event);
966 }
967#endif
968
969 //### this should probable be done even later
970 qt_call_post_routines();
971
972 // kill timers before closing down the dispatcher
973 d->toolTipWakeUp.stop();
974 d->toolTipFallAsleep.stop();
975
976 d->eventDispatcher->closingDown();
977 d->eventDispatcher = 0;
978
979 delete qt_desktopWidget;
980 qt_desktopWidget = 0;
981 QApplicationPrivate::is_app_closing = true;
982 QApplicationPrivate::is_app_running = false;
983
984#ifndef QT_NO_CLIPBOARD
985 delete qt_clipboard;
986 qt_clipboard = 0;
987#endif
988
989 // delete widget mapper
990 if (QWidgetPrivate::mapper) {
991 QWidgetMapper * myMapper = QWidgetPrivate::mapper;
992 QWidgetPrivate::mapper = 0;
993 for (QWidgetMapper::Iterator it = myMapper->begin(); it != myMapper->end(); ++it) {
994 register QWidget *w = *it;
995 if (!w->parent()) // window
996 w->destroy(true, true);
997 }
998 delete myMapper;
999 }
1000
1001 // delete uncreated widgets
1002 if (QWidgetPrivate::uncreatedWidgets) {
1003 QWidgetSet *mySet = QWidgetPrivate::uncreatedWidgets;
1004 QWidgetPrivate::uncreatedWidgets = 0;
1005 for (QWidgetSet::Iterator it = mySet->begin(); it != mySet->end(); ++it) {
1006 register QWidget *w = *it;
1007 if (!w->parent()) // window
1008 w->destroy(true, true);
1009 }
1010 delete mySet;
1011 }
1012
1013 delete QApplicationPrivate::app_pal;
1014 QApplicationPrivate::app_pal = 0;
1015 delete QApplicationPrivate::sys_pal;
1016 QApplicationPrivate::sys_pal = 0;
1017 delete QApplicationPrivate::set_pal;
1018 QApplicationPrivate::set_pal = 0;
1019 app_palettes()->clear();
1020
1021 {
1022 QMutexLocker locker(applicationFontMutex());
1023 delete QApplicationPrivate::app_font;
1024 QApplicationPrivate::app_font = 0;
1025 }
1026 delete QApplicationPrivate::sys_font;
1027 QApplicationPrivate::sys_font = 0;
1028 delete QApplicationPrivate::set_font;
1029 QApplicationPrivate::set_font = 0;
1030 app_fonts()->clear();
1031
1032 delete QApplicationPrivate::app_style;
1033 QApplicationPrivate::app_style = 0;
1034 delete QApplicationPrivate::app_icon;
1035 QApplicationPrivate::app_icon = 0;
1036#ifndef QT_NO_CURSOR
1037 d->cursor_list.clear();
1038#endif
1039
1040#ifndef QT_NO_DRAGANDDROP
1041 if (qt_is_gui_used)
1042 delete QDragManager::self();
1043#endif
1044
1045 qt_cleanup();
1046
1047 if (QApplicationPrivate::widgetCount)
1048 qDebug("Widgets left: %i Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances);
1049#ifndef QT_NO_SESSIONMANAGER
1050 delete d->session_manager;
1051 d->session_manager = 0;
1052#endif //QT_NO_SESSIONMANAGER
1053
1054 QApplicationPrivate::obey_desktop_settings = true;
1055 QApplicationPrivate::cursor_flash_time = 1000;
1056 QApplicationPrivate::mouse_double_click_time = 400;
1057 QApplicationPrivate::keyboard_input_time = 400;
1058
1059 drag_time = 500;
1060 drag_distance = 4;
1061 layout_direction = Qt::LeftToRight;
1062 QApplicationPrivate::app_strut = QSize(0, 0);
1063 QApplicationPrivate::animate_ui = true;
1064 QApplicationPrivate::animate_menu = false;
1065 QApplicationPrivate::fade_menu = false;
1066 QApplicationPrivate::animate_combo = false;
1067 QApplicationPrivate::animate_tooltip = false;
1068 QApplicationPrivate::fade_tooltip = false;
1069 QApplicationPrivate::widgetCount = false;
1070
1071 // trigger unregistering of QVariant's GUI types
1072 extern int qUnregisterGuiVariant();
1073 qUnregisterGuiVariant();
1074}
1075
1076
1077/*!
1078 \fn QWidget *QApplication::widgetAt(const QPoint &point)
1079
1080 Returns the widget at global screen position \a point, or 0 if there is no
1081 Qt widget there.
1082
1083 This function can be slow.
1084
1085 \sa QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard()
1086*/
1087QWidget *QApplication::widgetAt(const QPoint &p)
1088{
1089 QWidget *window = QApplication::topLevelAt(p);
1090 if (!window)
1091 return 0;
1092
1093 QWidget *child = 0;
1094
1095 if (!window->testAttribute(Qt::WA_TransparentForMouseEvents))
1096 child = window->childAt(window->mapFromGlobal(p));
1097
1098 if (child)
1099 return child;
1100
1101 if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) {
1102 //shoot a hole in the widget and try once again,
1103 //suboptimal on Qt for Embedded Linux where we do
1104 //know the stacking order of the toplevels.
1105 int x = p.x();
1106 int y = p.y();
1107 QRegion oldmask = window->mask();
1108 QPoint wpoint = window->mapFromGlobal(QPoint(x, y));
1109 QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask)
1110 - QRegion(wpoint.x(), wpoint.y(), 1, 1);
1111 window->setMask(newmask);
1112 QWidget *recurse = 0;
1113 if (QApplication::topLevelAt(p) != window) // verify recursion will terminate
1114 recurse = widgetAt(x, y);
1115 if (oldmask.isEmpty())
1116 window->clearMask();
1117 else
1118 window->setMask(oldmask);
1119 return recurse;
1120 }
1121 return window;
1122}
1123
1124/*!
1125 \fn QWidget *QApplication::widgetAt(int x, int y)
1126
1127 \overload
1128
1129 Returns the widget at global screen position (\a x, \a y), or 0 if there is
1130 no Qt widget there.
1131*/
1132
1133/*!
1134 \fn void QApplication::setArgs(int argc, char **argv)
1135 \internal
1136*/
1137
1138
1139
1140/*!
1141 \internal
1142*/
1143bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
1144{
1145 if ((event->type() == QEvent::UpdateRequest
1146#ifdef QT3_SUPPORT
1147 || event->type() == QEvent::LayoutHint
1148#endif
1149 || event->type() == QEvent::LayoutRequest
1150 || event->type() == QEvent::Resize
1151 || event->type() == QEvent::Move
1152 || event->type() == QEvent::LanguageChange
1153 || event->type() == QEvent::InputMethod)) {
1154 for (int i = 0; i < postedEvents->size(); ++i) {
1155 const QPostEvent &cur = postedEvents->at(i);
1156 if (cur.receiver != receiver || cur.event == 0 || cur.event->type() != event->type())
1157 continue;
1158 if (cur.event->type() == QEvent::LayoutRequest
1159#ifdef QT3_SUPPORT
1160 || cur.event->type() == QEvent::LayoutHint
1161#endif
1162 || cur.event->type() == QEvent::UpdateRequest) {
1163 ;
1164 } else if (cur.event->type() == QEvent::Resize) {
1165 ((QResizeEvent *)(cur.event))->s = ((QResizeEvent *)event)->s;
1166 } else if (cur.event->type() == QEvent::Move) {
1167 ((QMoveEvent *)(cur.event))->p = ((QMoveEvent *)event)->p;
1168 } else if (cur.event->type() == QEvent::LanguageChange) {
1169 ;
1170 } else if ( cur.event->type() == QEvent::InputMethod ) {
1171 *(QInputMethodEvent *)(cur.event) = *(QInputMethodEvent *)event;
1172 } else {
1173 continue;
1174 }
1175 delete event;
1176 return true;
1177 }
1178 return false;
1179 }
1180 return QCoreApplication::compressEvent(event, receiver, postedEvents);
1181}
1182
1183/*!
1184 \property QApplication::styleSheet
1185 \brief the application style sheet
1186 \since 4.2
1187
1188 By default, this property returns an empty string unless the user specifies
1189 the \c{-stylesheet} option on the command line when running the application.
1190
1191 \sa QWidget::setStyle(), {Qt Style Sheets}
1192*/
1193
1194/*!
1195 \property QApplication::autoMaximizeThreshold
1196 \since 4.4
1197 \brief defines a threshold for auto maximizing widgets
1198
1199 The auto maximize threshold is only available as part of Qt for Windows CE.
1200
1201 This property defines a threshold for the size of a window as a percentage
1202 of the screen size. If the minimum size hint of a window exceeds the
1203 threshold, calling show() will then cause the window to be maximized
1204 automatically.
1205
1206 Setting the threshold to be 100 or greater means that it will cause it to
1207 always be maximized. Setting it to be 50 means that the widget is maximized
1208 if the vertical minimum size hint is at least 50% of the vertical screen
1209 size.
1210
1211 If -1 is specified then this will disable the feature.
1212
1213 On Windows CE the default is -1 (i.e. it is disabled).
1214 On Windows Mobile the default is 40.
1215*/
1216
1217/*!
1218 \property QApplication::autoSipEnabled
1219 \since 4.5
1220 \brief toggles automatic SIP (software input panel) visibility
1221
1222 The auto SIP property is only available as part of Qt for Windows CE.
1223
1224 Set this property to true to automatically display the SIP when entering
1225 widgets that accept keyboard input. This property only affects widgets with
1226 the WA_InputMethodEnabled attribute set.
1227*/
1228
1229#ifdef Q_OS_WINCE
1230void QApplication::setAutoMaximizeThreshold(const int threshold)
1231{
1232 QApplicationPrivate::autoMaximizeThreshold = threshold;
1233}
1234
1235int QApplication::autoMaximizeThreshold() const
1236{
1237 return QApplicationPrivate::autoMaximizeThreshold;
1238}
1239
1240void QApplication::setAutoSipEnabled(const bool enabled)
1241{
1242 QApplicationPrivate::autoSipEnabled = enabled;
1243}
1244
1245bool QApplication::autoSipEnabled() const
1246{
1247 return QApplicationPrivate::autoSipEnabled;
1248}
1249#endif
1250
1251#ifndef QT_NO_STYLE_STYLESHEET
1252
1253QString QApplication::styleSheet() const
1254{
1255 return QApplicationPrivate::styleSheet;
1256}
1257
1258void QApplication::setStyleSheet(const QString& styleSheet)
1259{
1260 QApplicationPrivate::styleSheet = styleSheet;
1261 QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle*>(QApplicationPrivate::app_style);
1262 if (styleSheet.isEmpty()) { // application style sheet removed
1263 if (!proxy)
1264 return; // there was no stylesheet before
1265 setStyle(proxy->base);
1266 } else if (proxy) { // style sheet update, just repolish
1267 proxy->repolish(qApp);
1268 } else { // stylesheet set the first time
1269 QStyleSheetStyle *newProxy = new QStyleSheetStyle(QApplicationPrivate::app_style);
1270 QApplicationPrivate::app_style->setParent(newProxy);
1271 setStyle(newProxy);
1272 }
1273}
1274
1275#endif // QT_NO_STYLE_STYLESHEET
1276
1277/*!
1278 Returns the application's style object.
1279
1280 \sa setStyle(), QStyle
1281*/
1282QStyle *QApplication::style()
1283{
1284 if (QApplicationPrivate::app_style)
1285 return QApplicationPrivate::app_style;
1286 if (!qt_is_gui_used) {
1287 Q_ASSERT(!"No style available in non-gui applications!");
1288 return 0;
1289 }
1290
1291#if defined(Q_WS_X11)
1292 if(!QApplicationPrivate::styleOverride)
1293 QApplicationPrivate::x11_initialize_style(); // run-time search for default style
1294#endif
1295 if (!QApplicationPrivate::app_style) {
1296 // Compile-time search for default style
1297 //
1298 QString style;
1299 if (QApplicationPrivate::styleOverride) {
1300 style = *QApplicationPrivate::styleOverride;
1301 delete QApplicationPrivate::styleOverride;
1302 QApplicationPrivate::styleOverride = 0;
1303 } else {
1304#if defined(Q_WS_WIN) && defined(Q_OS_WINCE)
1305 if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc())
1306 style = QLatin1String("WindowsMobile");
1307 else
1308 style = QLatin1String("WindowsCE");
1309
1310#elif defined(Q_WS_WIN)
1311 if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA
1312 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
1313 style = QLatin1String("WindowsVista");
1314 else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
1315 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
1316 style = QLatin1String("WindowsXP");
1317 else
1318 style = QLatin1String("Windows"); // default styles for Windows
1319#elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS)
1320 style = QLatin1String("CDE"); // default style for X11 on Solaris
1321#elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
1322 style = QLatin1String("SGI"); // default style for X11 on IRIX
1323#elif defined(Q_WS_X11) || defined(Q_WS_QWS)
1324 style = QLatin1String("Plastique"); // default style for X11 and small devices
1325#elif defined(Q_WS_MAC)
1326 style = QLatin1String("Macintosh"); // default style for all Mac's
1327#endif
1328 }
1329
1330 QStyle *&app_style = QApplicationPrivate::app_style;
1331 app_style = QStyleFactory::create(style);
1332 if (!app_style) {
1333 QStringList styles = QStyleFactory::keys();
1334 for (int i = 0; i < styles.size(); ++i) {
1335 if ((app_style = QStyleFactory::create(styles.at(i))))
1336 break;
1337 }
1338 }
1339 if (!app_style) {
1340 Q_ASSERT(!"No styles available!");
1341 return 0;
1342 }
1343 }
1344 // take ownership of the style
1345 QApplicationPrivate::app_style->setParent(qApp);
1346
1347 if (!QApplicationPrivate::sys_pal)
1348 QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette());
1349 if (QApplicationPrivate::set_pal) // repolish set palette with the new style
1350 QApplication::setPalette(*QApplicationPrivate::set_pal);
1351
1352#ifndef QT_NO_STYLE_STYLESHEET
1353 if (!QApplicationPrivate::styleSheet.isEmpty()) {
1354 qApp->setStyleSheet(QApplicationPrivate::styleSheet);
1355 } else
1356#endif
1357 QApplicationPrivate::app_style->polish(qApp);
1358
1359 return QApplicationPrivate::app_style;
1360}
1361
1362/*!
1363 Sets the application's GUI style to \a style. Ownership of the style object
1364 is transferred to QApplication, so QApplication will delete the style
1365 object on application exit or when a new style is set and the old style is
1366 still the parent of the application object.
1367
1368 Example usage:
1369 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 1
1370
1371 When switching application styles, the color palette is set back to the
1372 initial colors or the system defaults. This is necessary since certain
1373 styles have to adapt the color palette to be fully style-guide compliant.
1374
1375 Setting the style before a palette has been se, i.e., before creating
1376 QApplication, will cause the application to use QStyle::standardPalette()
1377 for the palette.
1378
1379 \warning Qt style sheets are currently not supported for custom QStyle
1380 subclasses. We plan to address this in some future release.
1381
1382 \sa style(), QStyle, setPalette(), desktopSettingsAware()
1383*/
1384void QApplication::setStyle(QStyle *style)
1385{
1386 if (!style || style == QApplicationPrivate::app_style)
1387 return;
1388
1389 QWidgetList all = allWidgets();
1390
1391 // clean up the old style
1392 if (QApplicationPrivate::app_style) {
1393 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
1394 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {
1395 register QWidget *w = *it;
1396 if (!(w->windowType() == Qt::Desktop) && // except desktop
1397 w->testAttribute(Qt::WA_WState_Polished)) { // has been polished
1398 QApplicationPrivate::app_style->unpolish(w);
1399 }
1400 }
1401 }
1402 QApplicationPrivate::app_style->unpolish(qApp);
1403 }
1404
1405 QStyle *old = QApplicationPrivate::app_style; // save
1406
1407#ifndef QT_NO_STYLE_STYLESHEET
1408 if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast<QStyleSheetStyle *>(style)) {
1409 // we have a stylesheet already and a new style is being set
1410 QStyleSheetStyle *newProxy = new QStyleSheetStyle(style);
1411 style->setParent(newProxy);
1412 QApplicationPrivate::app_style = newProxy;
1413 } else
1414#endif // QT_NO_STYLE_STYLESHEET
1415 QApplicationPrivate::app_style = style;
1416
1417 QApplicationPrivate::app_style->setParent(qApp); // take ownership
1418
1419 // take care of possible palette requirements of certain gui
1420 // styles. Do it before polishing the application since the style
1421 // might call QApplication::setPalette() itself
1422 if (QApplicationPrivate::set_pal) {
1423 QApplication::setPalette(*QApplicationPrivate::set_pal);
1424 } else if (QApplicationPrivate::sys_pal) {
1425 QApplicationPrivate::initializeWidgetPaletteHash();
1426 QApplicationPrivate::setPalette_helper(*QApplicationPrivate::sys_pal, /*className=*/0, /*clearWidgetPaletteHash=*/false);
1427 } else if (!QApplicationPrivate::sys_pal) {
1428 // Initialize the sys_pal if it hasn't happened yet...
1429 QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette());
1430 }
1431
1432 // initialize the application with the new style
1433 QApplicationPrivate::app_style->polish(qApp);
1434
1435 // re-polish existing widgets if necessary
1436 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
1437 for (QWidgetList::ConstIterator it1 = all.constBegin(); it1 != all.constEnd(); ++it1) {
1438 register QWidget *w = *it1;
1439 if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) {
1440 if (w->style() == QApplicationPrivate::app_style)
1441 QApplicationPrivate::app_style->polish(w); // repolish
1442#ifndef QT_NO_STYLE_STYLESHEET
1443 else
1444 w->setStyleSheet(w->styleSheet()); // touch
1445#endif
1446 }
1447 }
1448
1449 for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) {
1450 register QWidget *w = *it2;
1451 if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) {
1452 QEvent e(QEvent::StyleChange);
1453 QApplication::sendEvent(w, &e);
1454#ifdef QT3_SUPPORT
1455 if (old)
1456 w->styleChange(*old);
1457#endif
1458 w->update();
1459 }
1460 }
1461 }
1462
1463#ifndef QT_NO_STYLE_STYLESHEET
1464 if (QStyleSheetStyle *oldProxy = qobject_cast<QStyleSheetStyle *>(old)) {
1465 oldProxy->deref();
1466 } else
1467#endif
1468 if (old && old->parent() == qApp) {
1469 delete old;
1470 }
1471
1472 if (QApplicationPrivate::focus_widget) {
1473 QFocusEvent in(QEvent::FocusIn, Qt::OtherFocusReason);
1474 QApplication::sendEvent(QApplicationPrivate::focus_widget->style(), &in);
1475 QApplicationPrivate::focus_widget->update();
1476 }
1477}
1478
1479/*!
1480 \overload
1481
1482 Requests a QStyle object for \a style from the QStyleFactory.
1483
1484 The string must be one of the QStyleFactory::keys(), typically one of
1485 "windows", "motif", "cde", "plastique", "windowsxp", or "macintosh". Style
1486 names are case insensitive.
1487
1488 Returns 0 if an unknown \a style is passed, otherwise the QStyle object
1489 returned is set as the application's GUI style.
1490
1491 \warning To ensure that the application's style is set correctly, it is
1492 best to call this function before the QApplication constructor, if
1493 possible.
1494*/
1495QStyle* QApplication::setStyle(const QString& style)
1496{
1497 QStyle *s = QStyleFactory::create(style);
1498 if (!s)
1499 return 0;
1500
1501 setStyle(s);
1502 return s;
1503}
1504
1505/*!
1506 \since 4.5
1507
1508 Sets the default graphics backend to \a system, which will be used for
1509 on-screen widgets and QPixmaps. The available systems are \c{"native"},
1510 \c{"raster"} and \c{"opengl"}.
1511
1512 This function call overrides both the application commandline
1513 \c{-graphicssystem} switch and the configure \c{-graphicssystem} switch.
1514
1515 \warning This function must be called before the QApplication constructor
1516 is called.
1517
1518 \note The \c{"opengl"} option is currently experimental.
1519*/
1520
1521void QApplication::setGraphicsSystem(const QString &system)
1522{
1523 QApplicationPrivate::graphics_system_name = system;
1524}
1525
1526/*!
1527 Returns the color specification.
1528
1529 \sa QApplication::setColorSpec()
1530*/
1531
1532int QApplication::colorSpec()
1533{
1534 return QApplicationPrivate::app_cspec;
1535}
1536
1537/*!
1538 Sets the color specification for the application to \a spec.
1539
1540 The color specification controls how the application allocates colors when
1541 run on a display with a limited amount of colors, e.g. 8 bit / 256 color
1542 displays.
1543
1544 The color specification must be set before you create the QApplication
1545 object.
1546
1547 The options are:
1548 \list
1549 \o QApplication::NormalColor. This is the default color allocation
1550 strategy. Use this option if your application uses buttons, menus,
1551 texts and pixmaps with few colors. With this option, the
1552 application uses system global colors. This works fine for most
1553 applications under X11, but on Windows machines it may cause
1554 dithering of non-standard colors.
1555 \o QApplication::CustomColor. Use this option if your application
1556 needs a small number of custom colors. On X11, this option is the
1557 same as NormalColor. On Windows, Qt creates a Windows palette, and
1558 allocates colors to it on demand.
1559 \o QApplication::ManyColor. Use this option if your application is
1560 very color hungry, e.g., it requires thousands of colors. \br
1561 Under X11 the effect is:
1562 \list
1563 \o For 256-color displays which have at best a 256 color true
1564 color visual, the default visual is used, and colors are
1565 allocated from a color cube. The color cube is the 6x6x6
1566 (216 color) "Web palette" (the red, green, and blue
1567 components always have one of the following values: 0x00,
1568 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors
1569 can be changed by the \e -ncols option. The user can force
1570 the application to use the true color visual with the
1571 \l{QApplication::QApplication()}{-visual} option.
1572 \o For 256-color displays which have a true color visual with
1573 more than 256 colors, use that visual. Silicon Graphics X
1574 servers this feature, for example. They provide an 8 bit
1575 visual by default but can deliver true color when asked.
1576 \endlist
1577 On Windows, Qt creates a Windows palette, and fills it with a color
1578 cube.
1579 \endlist
1580
1581 Be aware that the CustomColor and ManyColor choices may lead to colormap
1582 flashing: The foreground application gets (most) of the available colors,
1583 while the background windows will look less attractive.
1584
1585 Example:
1586
1587 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 2
1588
1589 \sa colorSpec()
1590*/
1591
1592void QApplication::setColorSpec(int spec)
1593{
1594 if (qApp)
1595 qWarning("QApplication::setColorSpec: This function must be "
1596 "called before the QApplication object is created");
1597 QApplicationPrivate::app_cspec = spec;
1598}
1599
1600/*!
1601 \property QApplication::globalStrut
1602 \brief the minimum size that any GUI element that the user can interact
1603 with should have
1604
1605 For example, no button should be resized to be smaller than the global
1606 strut size. The strut size should be considered when reimplementing GUI
1607 controls that may be used on touch-screens or similar I/O devices.
1608
1609 Example:
1610
1611 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 3
1612
1613 By default, this property contains a QSize object with zero width and height.
1614*/
1615QSize QApplication::globalStrut()
1616{
1617 return QApplicationPrivate::app_strut;
1618}
1619
1620void QApplication::setGlobalStrut(const QSize& strut)
1621{
1622 QApplicationPrivate::app_strut = strut;
1623}
1624
1625/*!
1626 Returns the application palette.
1627
1628 \sa setPalette(), QWidget::palette()
1629*/
1630QPalette QApplication::palette()
1631{
1632 if (!QApplicationPrivate::app_pal)
1633 QApplicationPrivate::app_pal = new QPalette(Qt::black);
1634 return *QApplicationPrivate::app_pal;
1635}
1636
1637/*!
1638 \fn QPalette QApplication::palette(const QWidget* widget)
1639 \overload
1640
1641 If a \a widget is passed, the default palette for the widget's class is
1642 returned. This may or may not be the application palette. In most cases
1643 there is no special palette for certain types of widgets, but one notable
1644 exception is the popup menu under Windows, if the user has defined a
1645 special background color for menus in the display settings.
1646
1647 \sa setPalette(), QWidget::palette()
1648*/
1649QPalette QApplication::palette(const QWidget* w)
1650{
1651 PaletteHash *hash = app_palettes();
1652 if (w && hash && hash->size()) {
1653 QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(w->metaObject()->className());
1654 if (it != hash->constEnd())
1655 return *it;
1656 for (it = hash->constBegin(); it != hash->constEnd(); ++it) {
1657 if (w->inherits(it.key()))
1658 return it.value();
1659 }
1660 }
1661 return palette();
1662}
1663
1664/*!
1665 \overload
1666
1667 Returns the palette for widgets of the given \a className.
1668
1669 \sa setPalette(), QWidget::palette()
1670*/
1671QPalette QApplication::palette(const char *className)
1672{
1673 if (!QApplicationPrivate::app_pal)
1674 palette();
1675 PaletteHash *hash = app_palettes();
1676 if (className && hash && hash->size()) {
1677 QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(className);
1678 if (it != hash->constEnd())
1679 return *it;
1680 }
1681 return *QApplicationPrivate::app_pal;
1682}
1683
1684void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash)
1685{
1686 QPalette pal = palette;
1687
1688 if (QApplicationPrivate::app_style)
1689 QApplicationPrivate::app_style->polish(pal); // NB: non-const reference
1690
1691 bool all = false;
1692 PaletteHash *hash = app_palettes();
1693 if (!className) {
1694 if (QApplicationPrivate::app_pal && pal.isCopyOf(*QApplicationPrivate::app_pal))
1695 return;
1696 if (!QApplicationPrivate::app_pal)
1697 QApplicationPrivate::app_pal = new QPalette(pal);
1698 else
1699 *QApplicationPrivate::app_pal = pal;
1700 if (hash && hash->size()) {
1701 all = true;
1702 if (clearWidgetPaletteHash)
1703 hash->clear();
1704 }
1705 } else if (hash) {
1706 hash->insert(className, pal);
1707 }
1708
1709 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
1710 // Send ApplicationPaletteChange to qApp itself, and to the widgets.
1711 QEvent e(QEvent::ApplicationPaletteChange);
1712 QApplication::sendEvent(QApplication::instance(), &e);
1713
1714 QWidgetList wids = QApplication::allWidgets();
1715 for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) {
1716 register QWidget *w = *it;
1717 if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
1718 QApplication::sendEvent(w, &e);
1719 }
1720
1721 // Send to all scenes as well.
1722#ifndef QT_NO_GRAPHICSVIEW
1723 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list;
1724 for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin();
1725 it != scenes.constEnd(); ++it) {
1726 QApplication::sendEvent(*it, &e);
1727 }
1728#endif //QT_NO_GRAPHICSVIEW
1729 }
1730 if (!className && (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal))) {
1731 if (!QApplicationPrivate::set_pal)
1732 QApplicationPrivate::set_pal = new QPalette(palette);
1733 else
1734 *QApplicationPrivate::set_pal = palette;
1735 }
1736}
1737
1738/*!
1739 Changes the default application palette to \a palette.
1740
1741 If \a className is passed, the change applies only to widgets that inherit
1742 \a className (as reported by QObject::inherits()). If \a className is left
1743 0, the change affects all widgets, thus overriding any previously set class
1744 specific palettes.
1745
1746 The palette may be changed according to the current GUI style in
1747 QStyle::polish().
1748
1749 \warning Do not use this function in conjunction with \l{Qt Style Sheets}.
1750 When using style sheets, the palette of a widget can be customized using
1751 the "color", "background-color", "selection-color",
1752 "selection-background-color" and "alternate-background-color".
1753
1754 \note Some styles do not use the palette for all drawing, for instance, if
1755 they make use of native theme engines. This is the case for the Windows XP,
1756 Windows Vista, and Mac OS X styles.
1757
1758 \sa QWidget::setPalette(), palette(), QStyle::polish()
1759*/
1760
1761void QApplication::setPalette(const QPalette &palette, const char* className)
1762{
1763 QApplicationPrivate::setPalette_helper(palette, className, /*clearWidgetPaletteHash=*/ true);
1764}
1765
1766
1767
1768void QApplicationPrivate::setSystemPalette(const QPalette &pal)
1769{
1770 QPalette adjusted;
1771
1772#if 0
1773 // adjust the system palette to avoid dithering
1774 QColormap cmap = QColormap::instance();
1775 if (cmap.depths() > 4 && cmap.depths() < 24) {
1776 for (int g = 0; g < QPalette::NColorGroups; g++)
1777 for (int i = 0; i < QPalette::NColorRoles; i++) {
1778 QColor color = pal.color((QPalette::ColorGroup)g, (QPalette::ColorRole)i);
1779 color = cmap.colorAt(cmap.pixel(color));
1780 adjusted.setColor((QPalette::ColorGroup)g, (QPalette::ColorRole) i, color);
1781 }
1782 }
1783#else
1784 adjusted = pal;
1785#endif
1786
1787 if (!sys_pal)
1788 sys_pal = new QPalette(adjusted);
1789 else
1790 *sys_pal = adjusted;
1791
1792
1793 if (!QApplicationPrivate::set_pal)
1794 QApplication::setPalette(*sys_pal);
1795}
1796
1797/*!
1798 Returns the default application font.
1799
1800 \sa fontMetrics(), QWidget::font()
1801*/
1802QFont QApplication::font()
1803{
1804 QMutexLocker locker(applicationFontMutex());
1805 if (!QApplicationPrivate::app_font)
1806 QApplicationPrivate::app_font = new QFont(QLatin1String("Helvetica"));
1807 return *QApplicationPrivate::app_font;
1808}
1809
1810/*!
1811 \overload
1812
1813 Returns the default font for the \a widget.
1814
1815 \sa fontMetrics(), QWidget::setFont()
1816*/
1817
1818QFont QApplication::font(const QWidget *widget)
1819{
1820 FontHash *hash = app_fonts();
1821
1822#ifdef Q_WS_MAC
1823 // short circuit for small and mini controls
1824 if (widget->testAttribute(Qt::WA_MacSmallSize)) {
1825 return hash->value("QSmallFont");
1826 } else if (widget->testAttribute(Qt::WA_MacMiniSize)) {
1827 return hash->value("QMiniFont");
1828 }
1829#endif
1830 if (widget && hash && hash->size()) {
1831 QHash<QByteArray, QFont>::ConstIterator it =
1832 hash->constFind(widget->metaObject()->className());
1833 if (it != hash->constEnd())
1834 return it.value();
1835 for (it = hash->constBegin(); it != hash->constEnd(); ++it) {
1836 if (widget->inherits(it.key()))
1837 return it.value();
1838 }
1839 }
1840 return font();
1841}
1842
1843/*!
1844 \overload
1845
1846 Returns the font for widgets of the given \a className.
1847
1848 \sa setFont(), QWidget::font()
1849*/
1850QFont QApplication::font(const char *className)
1851{
1852 FontHash *hash = app_fonts();
1853 if (className && hash && hash->size()) {
1854 QHash<QByteArray, QFont>::ConstIterator it = hash->constFind(className);
1855 if (it != hash->constEnd())
1856 return *it;
1857 }
1858 return font();
1859}
1860
1861
1862/*!
1863 Changes the default application font to \a font. If \a className is passed,
1864 the change applies only to classes that inherit \a className (as reported
1865 by QObject::inherits()).
1866
1867 On application start-up, the default font depends on the window system. It
1868 can vary depending on both the window system version and the locale. This
1869 function lets you override the default font; but overriding may be a bad
1870 idea because, for example, some locales need extra large fonts to support
1871 their special characters.
1872
1873 \warning Do not use this function in conjunction with \l{Qt Style Sheets}.
1874 The font of an application can be customized using the "font" style sheet
1875 property. To set a bold font for all QPushButtons, set the application
1876 styleSheet() as "QPushButton { font: bold }"
1877
1878 \sa font(), fontMetrics(), QWidget::setFont()
1879*/
1880
1881void QApplication::setFont(const QFont &font, const char *className)
1882{
1883 bool all = false;
1884 FontHash *hash = app_fonts();
1885 if (!className) {
1886 QMutexLocker locker(applicationFontMutex());
1887 if (!QApplicationPrivate::app_font)
1888 QApplicationPrivate::app_font = new QFont(font);
1889 else
1890 *QApplicationPrivate::app_font = font;
1891 if (hash && hash->size()) {
1892 all = true;
1893 hash->clear();
1894 }
1895 } else if (hash) {
1896 hash->insert(className, font);
1897 }
1898 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
1899 // Send ApplicationFontChange to qApp itself, and to the widgets.
1900 QEvent e(QEvent::ApplicationFontChange);
1901 QApplication::sendEvent(QApplication::instance(), &e);
1902
1903 QWidgetList wids = QApplication::allWidgets();
1904 for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) {
1905 register QWidget *w = *it;
1906 if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
1907 sendEvent(w, &e);
1908 }
1909
1910#ifndef QT_NO_GRAPHICSVIEW
1911 // Send to all scenes as well.
1912 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list;
1913 for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin();
1914 it != scenes.constEnd(); ++it) {
1915 QApplication::sendEvent(*it, &e);
1916 }
1917#endif //QT_NO_GRAPHICSVIEW
1918 }
1919 if (!className && (!QApplicationPrivate::sys_font || !font.isCopyOf(*QApplicationPrivate::sys_font))) {
1920 if (!QApplicationPrivate::set_font)
1921 QApplicationPrivate::set_font = new QFont(font);
1922 else
1923 *QApplicationPrivate::set_font = font;
1924 }
1925}
1926
1927/*! \internal
1928*/
1929void QApplicationPrivate::setSystemFont(const QFont &font)
1930{
1931 if (!sys_font)
1932 sys_font = new QFont(font);
1933 else
1934 *sys_font = font;
1935
1936 if (!QApplicationPrivate::set_font)
1937 QApplication::setFont(*sys_font);
1938}
1939
1940/*!
1941 \property QApplication::windowIcon
1942 \brief the default window icon
1943
1944 \sa QWidget::setWindowIcon(), {Setting the Application Icon}
1945*/
1946QIcon QApplication::windowIcon()
1947{
1948 return QApplicationPrivate::app_icon ? *QApplicationPrivate::app_icon : QIcon();
1949}
1950
1951void QApplication::setWindowIcon(const QIcon &icon)
1952{
1953 if (!QApplicationPrivate::app_icon)
1954 QApplicationPrivate::app_icon = new QIcon();
1955 *QApplicationPrivate::app_icon = icon;
1956 if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
1957#ifdef Q_WS_MAC
1958 void qt_mac_set_app_icon(const QPixmap &); //qapplication_mac.cpp
1959 QSize size = QApplicationPrivate::app_icon->actualSize(QSize(128, 128));
1960 qt_mac_set_app_icon(QApplicationPrivate::app_icon->pixmap(size));
1961#endif
1962 QEvent e(QEvent::ApplicationWindowIconChange);
1963 QWidgetList all = QApplication::allWidgets();
1964 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {
1965 register QWidget *w = *it;
1966 if (w->isWindow())
1967 sendEvent(w, &e);
1968 }
1969 }
1970}
1971
1972/*!
1973 Returns a list of the top-level widgets (windows) in the application.
1974
1975 \note Some of the top-level widgets may be hidden, for example a tooltip if
1976 no tooltip is currently shown.
1977
1978 Example:
1979
1980 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 4
1981
1982 \sa allWidgets(), QWidget::isWindow(), QWidget::isHidden()
1983*/
1984QWidgetList QApplication::topLevelWidgets()
1985{
1986 QWidgetList list;
1987 QWidgetList all = allWidgets();
1988
1989 for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {
1990 QWidget *w = *it;
1991 if (w->isWindow() && w->windowType() != Qt::Desktop)
1992 list.append(w);
1993 }
1994 return list;
1995}
1996
1997/*!
1998 Returns a list of all the widgets in the application.
1999
2000 The list is empty (QList::isEmpty()) if there are no widgets.
2001
2002 \note Some of the widgets may be hidden.
2003
2004 Example:
2005 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 5
2006
2007 \sa topLevelWidgets(), QWidget::isVisible()
2008*/
2009
2010QWidgetList QApplication::allWidgets()
2011{
2012 QWidgetList list;
2013 if (QWidgetPrivate::mapper)
2014 list += QWidgetPrivate::mapper->values();
2015 if (QWidgetPrivate::uncreatedWidgets)
2016 list += QWidgetPrivate::uncreatedWidgets->toList();
2017 return list;
2018}
2019
2020/*!
2021 Returns the application widget that has the keyboard input focus, or 0 if
2022 no widget in this application has the focus.
2023
2024 \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged()
2025*/
2026
2027QWidget *QApplication::focusWidget()
2028{
2029 return QApplicationPrivate::focus_widget;
2030}
2031
2032void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
2033{
2034 if (focus && focus->window()
2035#ifndef QT_NO_GRAPHICSVIEW
2036 && focus->window()->graphicsProxyWidget()
2037#endif
2038 )
2039 return;
2040
2041 hidden_focus_widget = 0;
2042
2043 if (focus != focus_widget) {
2044 if (focus && focus->isHidden()) {
2045 hidden_focus_widget = focus;
2046 return;
2047 }
2048
2049 if (focus && (reason == Qt::BacktabFocusReason || reason == Qt::TabFocusReason)
2050 && qt_in_tab_key_event)
2051 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
2052 else if (focus && reason == Qt::ShortcutFocusReason) {
2053 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
2054 }
2055 QWidget *prev = focus_widget;
2056 focus_widget = focus;
2057
2058 if (prev && ((reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
2059 && prev->testAttribute(Qt::WA_InputMethodEnabled))
2060 // Do reset the input context, in case the new focus widget won't accept keyboard input
2061 // or it is not created fully yet.
2062 || (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled)
2063 || !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
2064 QInputContext *qic = prev->inputContext();
2065 if(qic) {
2066 qic->reset();
2067 qic->setFocusWidget(0);
2068 }
2069 }
2070
2071 if(focus_widget)
2072 focus_widget->d_func()->setFocus_sys();
2073
2074 if (reason != Qt::NoFocusReason) {
2075
2076 //send events
2077 if (prev) {
2078#ifdef QT_KEYPAD_NAVIGATION
2079 if (QApplication::keypadNavigationEnabled()) {
2080 if (prev->hasEditFocus() && reason != Qt::PopupFocusReason)
2081 prev->setEditFocus(false);
2082 }
2083#endif
2084 QFocusEvent out(QEvent::FocusOut, reason);
2085 QPointer<QWidget> that = prev;
2086 QApplication::sendEvent(prev, &out);
2087 if (that)
2088 QApplication::sendEvent(that->style(), &out);
2089 }
2090 if(focus && QApplicationPrivate::focus_widget == focus) {
2091 if (focus->testAttribute(Qt::WA_InputMethodEnabled)) {
2092 QInputContext *qic = focus->inputContext();
2093 if (qic && focus_widget->testAttribute(Qt::WA_WState_Created))
2094 qic->setFocusWidget( focus_widget );
2095 }
2096 QFocusEvent in(QEvent::FocusIn, reason);
2097 QPointer<QWidget> that = focus;
2098 QApplication::sendEvent(focus, &in);
2099 if (that)
2100 QApplication::sendEvent(that->style(), &in);
2101 }
2102 }
2103 emit qApp->focusChanged(prev, focus_widget);
2104 }
2105}
2106
2107
2108/*!
2109 Returns the application top-level window that has the keyboard input focus,
2110 or 0 if no application window has the focus. There might be an
2111 activeWindow() even if there is no focusWidget(), for example if no widget
2112 in that window accepts key events.
2113
2114 \sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget()
2115*/
2116
2117QWidget *QApplication::activeWindow()
2118{
2119 return QApplicationPrivate::active_window;
2120}
2121
2122/*!
2123 Returns display (screen) font metrics for the application font.
2124
2125 \sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics()
2126*/
2127
2128QFontMetrics QApplication::fontMetrics()
2129{
2130 return desktop()->fontMetrics();
2131}
2132
2133
2134/*!
2135 Closes all top-level windows.
2136
2137 This function is particularly useful for applications with many top-level
2138 windows. It could, for example, be connected to a \gui{Exit} entry in the
2139 \gui{File} menu:
2140
2141 \snippet examples/mainwindows/mdi/mainwindow.cpp 0
2142
2143 The windows are closed in random order, until one window does not accept
2144 the close event. The application quits when the last window was
2145 successfully closed; this can be turned off by setting
2146 \l quitOnLastWindowClosed to false.
2147
2148 \sa quitOnLastWindowClosed, lastWindowClosed(), QWidget::close(),
2149 QWidget::closeEvent(), lastWindowClosed(), quit(), topLevelWidgets(),
2150 QWidget::isWindow()
2151*/
2152void QApplication::closeAllWindows()
2153{
2154 bool did_close = true;
2155 QWidget *w;
2156 while((w = activeModalWidget()) && did_close) {
2157 if(!w->isVisible())
2158 break;
2159 did_close = w->close();
2160 }
2161 QWidgetList list = QApplication::topLevelWidgets();
2162 for (int i = 0; did_close && i < list.size(); ++i) {
2163 w = list.at(i);
2164 if (w->isVisible() && w->windowType() != Qt::Desktop) {
2165 did_close = w->close();
2166 list = QApplication::topLevelWidgets();
2167 i = -1;
2168 }
2169 }
2170}
2171
2172/*!
2173 Displays a simple message box about Qt. The message includes the version
2174 number of Qt being used by the application.
2175
2176 This is useful for inclusion in the \gui Help menu of an application, as
2177 shown in the \l{mainwindows/menus}{Menus} example.
2178
2179 This function is a convenience slot for QMessageBox::aboutQt().
2180*/
2181void QApplication::aboutQt()
2182{
2183#ifndef QT_NO_MESSAGEBOX
2184 QMessageBox::aboutQt(
2185#ifdef Q_WS_MAC
2186 0
2187#else
2188 activeWindow()
2189#endif // Q_WS_MAC
2190 );
2191#endif // QT_NO_MESSAGEBOX
2192}
2193
2194
2195/*!
2196 \fn void QApplication::lastWindowClosed()
2197
2198 This signal is emitted from QApplication::exec() when the last visible
2199 primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose
2200 attribute set is closed.
2201
2202 By default,
2203
2204 \list
2205 \o this attribute is set for all widgets except transient windows such
2206 as splash screens, tool windows, and popup menus
2207
2208 \o QApplication implicitly quits when this signal is emitted.
2209 \endlist
2210
2211 This feature can be turned off by setting \l quitOnLastWindowClosed to
2212 false.
2213
2214 \sa QWidget::close()
2215*/
2216
2217/*!
2218 \since 4.1
2219 \fn void QApplication::focusChanged(QWidget *old, QWidget *now)
2220
2221 This signal is emitted when the widget that has keyboard focus changed from
2222 \a old to \a now, i.e., because the user pressed the tab-key, clicked into
2223 a widget or changed the active window. Both \a old and \a now can be the
2224 null-pointer.
2225
2226 The signal is emitted after both widget have been notified about the change
2227 through QFocusEvent.
2228
2229 \sa QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason
2230*/
2231
2232/*!
2233 \since 4.5
2234 \fn void QApplication::fontDatabaseChanged()
2235
2236 This signal is emitted when application fonts are loaded or removed.
2237
2238 \sa QFontDatabase::addApplicationFont(),
2239 QFontDatabase::addApplicationFontFromData(),
2240 QFontDatabase::removeAllApplicationFonts(),
2241 QFontDatabase::removeApplicationFont()
2242*/
2243
2244#ifndef QT_NO_TRANSLATION
2245static bool qt_detectRTLLanguage()
2246{
2247 return force_reverse ^
2248 (QApplication::tr("QT_LAYOUT_DIRECTION",
2249 "Translate this string to the string 'LTR' in left-to-right"
2250 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
2251 " and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
2252}
2253#endif
2254
2255/*!\reimp
2256
2257*/
2258bool QApplication::event(QEvent *e)
2259{
2260 Q_D(QApplication);
2261 if(e->type() == QEvent::Close) {
2262 QCloseEvent *ce = static_cast<QCloseEvent*>(e);
2263 ce->accept();
2264 closeAllWindows();
2265
2266 QWidgetList list = topLevelWidgets();
2267 for (int i = 0; i < list.size(); ++i) {
2268 QWidget *w = list.at(i);
2269 if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) &&
2270 (!(w->windowType() == Qt::Dialog) || !w->parentWidget())) {
2271 ce->ignore();
2272 break;
2273 }
2274 }
2275 if(ce->isAccepted())
2276 return true;
2277 } else if(e->type() == QEvent::LanguageChange) {
2278#ifndef QT_NO_TRANSLATION
2279 setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight);
2280#endif
2281 QWidgetList list = topLevelWidgets();
2282 for (int i = 0; i < list.size(); ++i) {
2283 QWidget *w = list.at(i);
2284 if (!(w->windowType() == Qt::Desktop))
2285 postEvent(w, new QEvent(QEvent::LanguageChange));
2286 }
2287 } else if (e->type() == QEvent::Timer) {
2288 QTimerEvent *te = static_cast<QTimerEvent*>(e);
2289 Q_ASSERT(te != 0);
2290 if (te->timerId() == d->toolTipWakeUp.timerId()) {
2291 d->toolTipWakeUp.stop();
2292 if (d->toolTipWidget) {
2293 QWidget *w = d->toolTipWidget->window();
2294 // show tooltip if WA_AlwaysShowToolTips is set, or if
2295 // any ancestor of d->toolTipWidget is the active
2296 // window
2297 bool showToolTip = w->testAttribute(Qt::WA_AlwaysShowToolTips);
2298 while (w && !showToolTip) {
2299 showToolTip = w->isActiveWindow();
2300 w = w->parentWidget();
2301 w = w ? w->window() : 0;
2302 }
2303 if (showToolTip) {
2304 QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos);
2305 QApplication::sendEvent(d->toolTipWidget, &e);
2306 if (e.isAccepted())
2307 d->toolTipFallAsleep.start(2000, this);
2308 }
2309 }
2310 } else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
2311 d->toolTipFallAsleep.stop();
2312 }
2313#ifdef QT_MAC_USE_COCOA
2314 } else if (e->type() == QEvent::CocoaRequestModal) {
2315 d->_q_runAppModalWindow();
2316#endif
2317 }
2318 return QCoreApplication::event(e);
2319}
2320#if !defined(Q_WS_X11)
2321
2322// The doc and X implementation of this function is in qapplication_x11.cpp
2323
2324void QApplication::syncX() {} // do nothing
2325
2326#endif
2327
2328/*!
2329 \fn Qt::WindowsVersion QApplication::winVersion()
2330
2331 Use \l QSysInfo::WindowsVersion instead.
2332*/
2333
2334/*!
2335 \fn void QApplication::setActiveWindow(QWidget* active)
2336
2337 Sets the active window to the \a active widget in response to a system
2338 event. The function is called from the platform specific event handlers.
2339
2340 \warning This function does \e not set the keyboard focus to the active
2341 widget. Call QWidget::activateWindow() instead.
2342
2343 It sets the activeWindow() and focusWidget() attributes and sends proper
2344 \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate}
2345 {WindowDeactivate} and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut}
2346 {FocusOut} events to all appropriate widgets. The window will then be
2347 painted in active state (e.g. cursors in line edits will blink), and it
2348 will have tool tips enabled.
2349
2350 \sa activeWindow(), QWidget::activateWindow()
2351*/
2352void QApplication::setActiveWindow(QWidget* act)
2353{
2354 QWidget* window = act?act->window():0;
2355
2356 if (QApplicationPrivate::active_window == window)
2357 return;
2358
2359#ifndef QT_NO_GRAPHICSVIEW
2360 if (window && window->graphicsProxyWidget()) {
2361 // Activate the proxy's view->viewport() ?
2362 return;
2363 }
2364#endif
2365
2366 QWidgetList toBeActivated;
2367 QWidgetList toBeDeactivated;
2368
2369 if (QApplicationPrivate::active_window) {
2370 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) {
2371 QWidgetList list = topLevelWidgets();
2372 for (int i = 0; i < list.size(); ++i) {
2373 QWidget *w = list.at(i);
2374 if (w->isVisible() && w->isActiveWindow())
2375 toBeDeactivated.append(w);
2376 }
2377 } else {
2378 toBeDeactivated.append(QApplicationPrivate::active_window);
2379 }
2380 }
2381
2382#if !defined(Q_WS_MAC)
2383 QWidget *previousActiveWindow = QApplicationPrivate::active_window;
2384#endif
2385 QApplicationPrivate::active_window = window;
2386
2387 if (QApplicationPrivate::active_window) {
2388 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) {
2389 QWidgetList list = topLevelWidgets();
2390 for (int i = 0; i < list.size(); ++i) {
2391 QWidget *w = list.at(i);
2392 if (w->isVisible() && w->isActiveWindow())
2393 toBeActivated.append(w);
2394 }
2395 } else {
2396 toBeActivated.append(QApplicationPrivate::active_window);
2397 }
2398
2399 }
2400
2401 // first the activation/deactivation events
2402 QEvent activationChange(QEvent::ActivationChange);
2403 QEvent windowActivate(QEvent::WindowActivate);
2404 QEvent windowDeactivate(QEvent::WindowDeactivate);
2405
2406#if !defined(Q_WS_MAC)
2407 if (!previousActiveWindow) {
2408 QEvent appActivate(QEvent::ApplicationActivate);
2409 sendSpontaneousEvent(qApp, &appActivate);
2410 }
2411#endif
2412
2413 for (int i = 0; i < toBeActivated.size(); ++i) {
2414 QWidget *w = toBeActivated.at(i);
2415 sendSpontaneousEvent(w, &windowActivate);
2416 sendSpontaneousEvent(w, &activationChange);
2417 }
2418
2419 for(int i = 0; i < toBeDeactivated.size(); ++i) {
2420 QWidget *w = toBeDeactivated.at(i);
2421 sendSpontaneousEvent(w, &windowDeactivate);
2422 sendSpontaneousEvent(w, &activationChange);
2423 }
2424
2425#if !defined(Q_WS_MAC)
2426 if (!QApplicationPrivate::active_window) {
2427 QEvent appDeactivate(QEvent::ApplicationDeactivate);
2428 sendSpontaneousEvent(qApp, &appDeactivate);
2429 }
2430#endif
2431
2432 if (QApplicationPrivate::popupWidgets == 0) { // !inPopupMode()
2433 // then focus events
2434 if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) {
2435 QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason);
2436 } else if (QApplicationPrivate::active_window) {
2437 QWidget *w = QApplicationPrivate::active_window->focusWidget();
2438 if (w && w->isVisible() /*&& w->focusPolicy() != QWidget::NoFocus*/)
2439 w->setFocus(Qt::ActiveWindowFocusReason);
2440 else {
2441 w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window, true);
2442 if (w) {
2443 w->setFocus(Qt::ActiveWindowFocusReason);
2444 } else {
2445 // If the focus widget is not in the activate_window, clear the focus
2446 w = QApplicationPrivate::focus_widget;
2447 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus)
2448 QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason);
2449 else if (!QApplicationPrivate::active_window->isAncestorOf(w))
2450 QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason);
2451 }
2452 }
2453 }
2454 }
2455}
2456
2457/*!internal
2458 * Helper function that returns the new focus widget, but does not set the focus reason.
2459 * Returns 0 if a new focus widget could not be found.
2460*/
2461QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool next)
2462{
2463 uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
2464
2465 QWidget *f = toplevel->focusWidget();
2466 if (!f)
2467 f = toplevel;
2468
2469 QWidget *w = f;
2470 QWidget *test = f->d_func()->focus_next;
2471 while (test && test != f) {
2472 if ((test->focusPolicy() & focus_flag) == focus_flag
2473 && !(test->d_func()->extra && test->d_func()->extra->focus_proxy)
2474 && test->isVisibleTo(toplevel) && test->isEnabled()
2475 && !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test))
2476 && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))) {
2477 w = test;
2478 if (next)
2479 break;
2480 }
2481 test = test->d_func()->focus_next;
2482 }
2483 if (w == f) {
2484 if (qt_in_tab_key_event) {
2485 w->window()->setAttribute(Qt::WA_KeyboardFocusChange);
2486 w->update();
2487 }
2488 return 0;
2489 }
2490 return w;
2491}
2492
2493/*!
2494 \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave)
2495 \internal
2496
2497 Creates the proper Enter/Leave event when widget \a enter is entered and
2498 widget \a leave is left.
2499 */
2500#if defined(Q_WS_WIN)
2501 extern void qt_win_set_cursor(QWidget *, bool);
2502#elif defined(Q_WS_X11)
2503 extern void qt_x11_enforce_cursor(QWidget *, bool);
2504#endif
2505
2506void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) {
2507#if 0
2508 if (leave) {
2509 QEvent e(QEvent::Leave);
2510 QApplication::sendEvent(leave, & e);
2511 }
2512 if (enter) {
2513 QEvent e(QEvent::Enter);
2514 QApplication::sendEvent(enter, & e);
2515 }
2516 return;
2517#endif
2518
2519 QWidget* w ;
2520 if ((!enter && !leave) || (enter == leave))
2521 return;
2522#ifdef ALIEN_DEBUG
2523 qDebug() << "QApplicationPrivate::dispatchEnterLeave, ENTER:" << enter << "LEAVE:" << leave;
2524#endif
2525 QWidgetList leaveList;
2526 QWidgetList enterList;
2527
2528 bool sameWindow = leave && enter && leave->window() == enter->window();
2529 if (leave && !sameWindow) {
2530 w = leave;
2531 do {
2532 leaveList.append(w);
2533 } while (!w->isWindow() && (w = w->parentWidget()));
2534 }
2535 if (enter && !sameWindow) {
2536 w = enter;
2537 do {
2538 enterList.prepend(w);
2539 } while (!w->isWindow() && (w = w->parentWidget()));
2540 }
2541 if (sameWindow) {
2542 int enterDepth = 0;
2543 int leaveDepth = 0;
2544 w = enter;
2545 while (!w->isWindow() && (w = w->parentWidget()))
2546 enterDepth++;
2547 w = leave;
2548 while (!w->isWindow() && (w = w->parentWidget()))
2549 leaveDepth++;
2550 QWidget* wenter = enter;
2551 QWidget* wleave = leave;
2552 while (enterDepth > leaveDepth) {
2553 wenter = wenter->parentWidget();
2554 enterDepth--;
2555 }
2556 while (leaveDepth > enterDepth) {
2557 wleave = wleave->parentWidget();
2558 leaveDepth--;
2559 }
2560 while (!wenter->isWindow() && wenter != wleave) {
2561 wenter = wenter->parentWidget();
2562 wleave = wleave->parentWidget();
2563 }
2564
2565 w = leave;
2566 while (w != wleave) {
2567 leaveList.append(w);
2568 w = w->parentWidget();
2569 }
2570 w = enter;
2571 while (w != wenter) {
2572 enterList.prepend(w);
2573 w = w->parentWidget();
2574 }
2575 }
2576
2577 QEvent leaveEvent(QEvent::Leave);
2578 for (int i = 0; i < leaveList.size(); ++i) {
2579 w = leaveList.at(i);
2580 if (!qApp->activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
2581#if defined(Q_WS_WIN) || defined(Q_WS_X11)
2582 if (leaveAfterRelease == w)
2583 leaveAfterRelease = 0;
2584#endif
2585 QApplication::sendEvent(w, &leaveEvent);
2586 if (w->testAttribute(Qt::WA_Hover) &&
2587 (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
2588 Q_ASSERT(instance());
2589 QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), w->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos));
2590 qApp->d_func()->notify_helper(w, &he);
2591 }
2592 }
2593 }
2594 QPoint posEnter = QCursor::pos();
2595 QEvent enterEvent(QEvent::Enter);
2596 for (int i = 0; i < enterList.size(); ++i) {
2597 w = enterList.at(i);
2598 if (!qApp->activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
2599 QApplication::sendEvent(w, &enterEvent);
2600 if (w->testAttribute(Qt::WA_Hover) &&
2601 (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
2602 QHoverEvent he(QEvent::HoverEnter, w->mapFromGlobal(posEnter), QPoint(-1, -1));
2603 qApp->d_func()->notify_helper(w, &he);
2604 }
2605 }
2606 }
2607
2608#ifndef QT_NO_CURSOR
2609 // Update cursor for alien/graphics widgets.
2610
2611 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
2612#if defined(Q_WS_X11)
2613 //Whenever we leave an alien widget on X11, we need to reset its nativeParentWidget()'s cursor.
2614 // This is not required on Windows as the cursor is reset on every single mouse move.
2615 QWidget *parentOfLeavingCursor = 0;
2616 for (int i = 0; i < leaveList.size(); ++i) {
2617 w = leaveList.at(i);
2618 if (!isAlien(w))
2619 break;
2620 if (w->testAttribute(Qt::WA_SetCursor)) {
2621 parentOfLeavingCursor = w->parentWidget();
2622 //continue looping, we need to find the downest alien widget with a cursor.
2623 // (downest on the screen)
2624 }
2625 }
2626 //check that we will not call qt_x11_enforce_cursor twice with the same native widget
2627 if (parentOfLeavingCursor && (!enterOnAlien
2628 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
2629#ifndef QT_NO_GRAPHICSVIEW
2630 if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
2631#endif
2632 {
2633 qt_x11_enforce_cursor(parentOfLeavingCursor,true);
2634 }
2635 }
2636#endif
2637 if (enterOnAlien) {
2638 QWidget *cursorWidget = enter;
2639 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
2640 cursorWidget = cursorWidget->parentWidget();
2641
2642 if (!cursorWidget)
2643 return;
2644
2645#ifndef QT_NO_GRAPHICSVIEW
2646 if (cursorWidget->window()->graphicsProxyWidget()) {
2647 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor());
2648 } else
2649#endif
2650 {
2651#if defined(Q_WS_WIN)
2652 qt_win_set_cursor(cursorWidget, true);
2653#elif defined(Q_WS_X11)
2654 qt_x11_enforce_cursor(cursorWidget, true);
2655#endif
2656 }
2657 }
2658#endif
2659}
2660
2661/* exported for the benefit of testing tools */
2662Q_GUI_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
2663{
2664 return QApplicationPrivate::tryModalHelper(widget, rettop);
2665}
2666
2667/*! \internal
2668 Returns true if \a widget is blocked by a modal window.
2669 */
2670bool QApplicationPrivate::isBlockedByModal(QWidget *widget)
2671{
2672 widget = widget->window();
2673 if (!modalState())
2674 return false;
2675 if (qApp->activePopupWidget() == widget)
2676 return false;
2677
2678 for (int i = 0; i < qt_modal_stack->size(); ++i) {
2679 QWidget *modalWidget = qt_modal_stack->at(i);
2680
2681 {
2682 // check if the active modal widget is our widget or a parent of our widget
2683 QWidget *w = widget;
2684 while (w) {
2685 if (w == modalWidget)
2686 return false;
2687 w = w->parentWidget();
2688 }
2689#ifdef Q_WS_WIN
2690 if ((widget->testAttribute(Qt::WA_WState_Created) || widget->data->winid)
2691 && (modalWidget->testAttribute(Qt::WA_WState_Created) || modalWidget->data->winid)
2692 && IsChild(modalWidget->data->winid, widget->data->winid))
2693 return false;
2694#endif
2695 }
2696
2697 Qt::WindowModality windowModality = modalWidget->windowModality();
2698 if (windowModality == Qt::NonModal) {
2699 // determine the modality type if it hasn't been set on the
2700 // modalWidget, this normally happens when waiting for a
2701 // native dialog. use WindowModal if we are the child of a
2702 // group leader; otherwise use ApplicationModal.
2703 QWidget *m = modalWidget;
2704 while (m && !m->testAttribute(Qt::WA_GroupLeader)) {
2705 m = m->parentWidget();
2706 if (m)
2707 m = m->window();
2708 }
2709 windowModality = (m && m->testAttribute(Qt::WA_GroupLeader))
2710 ? Qt::WindowModal
2711 : Qt::ApplicationModal;
2712 }
2713
2714 switch (windowModality) {
2715 case Qt::ApplicationModal:
2716 {
2717 QWidget *groupLeaderForWidget = widget;
2718 while (groupLeaderForWidget && !groupLeaderForWidget->testAttribute(Qt::WA_GroupLeader))
2719 groupLeaderForWidget = groupLeaderForWidget->parentWidget();
2720
2721 if (groupLeaderForWidget) {
2722 // if \a widget has WA_GroupLeader, it can only be blocked by ApplicationModal children
2723 QWidget *m = modalWidget;
2724 while (m && m != groupLeaderForWidget && !m->testAttribute(Qt::WA_GroupLeader))
2725 m = m->parentWidget();
2726 if (m == groupLeaderForWidget)
2727 return true;
2728 } else if (modalWidget != widget) {
2729 return true;
2730 }
2731 break;
2732 }
2733 case Qt::WindowModal:
2734 {
2735 QWidget *w = widget;
2736 do {
2737 QWidget *m = modalWidget;
2738 do {
2739 if (m == w)
2740 return true;
2741 m = m->parentWidget();
2742 if (m)
2743 m = m->window();
2744 } while (m);
2745 w = w->parentWidget();
2746 if (w)
2747 w = w->window();
2748 } while (w);
2749 break;
2750 }
2751 default:
2752 Q_ASSERT_X(false, "QApplication", "internal error, a modal widget cannot be modeless");
2753 break;
2754 }
2755 }
2756 return false;
2757}
2758
2759/*!\internal
2760 */
2761void QApplicationPrivate::enterModal(QWidget *widget)
2762{
2763 QSet<QWidget*> blocked;
2764 QList<QWidget*> windows = qApp->topLevelWidgets();
2765 for (int i = 0; i < windows.count(); ++i) {
2766 QWidget *window = windows.at(i);
2767 if (window->windowType() != Qt::Tool && isBlockedByModal(window))
2768 blocked.insert(window);
2769 }
2770
2771 enterModal_sys(widget);
2772
2773 windows = qApp->topLevelWidgets();
2774 QEvent e(QEvent::WindowBlocked);
2775 for (int i = 0; i < windows.count(); ++i) {
2776 QWidget *window = windows.at(i);
2777 if (!blocked.contains(window) && window->windowType() != Qt::Tool && isBlockedByModal(window))
2778 QApplication::sendEvent(window, &e);
2779 }
2780}
2781
2782/*!\internal
2783 */
2784void QApplicationPrivate::leaveModal(QWidget *widget)
2785{
2786 QSet<QWidget*> blocked;
2787 QList<QWidget*> windows = qApp->topLevelWidgets();
2788 for (int i = 0; i < windows.count(); ++i) {
2789 QWidget *window = windows.at(i);
2790 if (window->windowType() != Qt::Tool && isBlockedByModal(window))
2791 blocked.insert(window);
2792 }
2793
2794 leaveModal_sys(widget);
2795
2796 windows = qApp->topLevelWidgets();
2797 QEvent e(QEvent::WindowUnblocked);
2798 for (int i = 0; i < windows.count(); ++i) {
2799 QWidget *window = windows.at(i);
2800 if(blocked.contains(window) && window->windowType() != Qt::Tool && !isBlockedByModal(window))
2801 QApplication::sendEvent(window, &e);
2802 }
2803}
2804
2805
2806
2807/*!\internal
2808
2809 Called from qapplication_\e{platform}.cpp, returns true
2810 if the widget should accept the event.
2811 */
2812bool QApplicationPrivate::tryModalHelper(QWidget *widget, QWidget **rettop)
2813{
2814 QWidget *top = QApplication::activeModalWidget();
2815 if (rettop)
2816 *rettop = top;
2817
2818 // the active popup widget always gets the input event
2819 if (qApp->activePopupWidget())
2820 return true;
2821
2822#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
2823 top = QApplicationPrivate::tryModalHelper_sys(top);
2824 if (rettop)
2825 *rettop = top;
2826#endif
2827
2828 return !isBlockedByModal(widget->window());
2829}
2830
2831/*
2832 \internal
2833*/
2834QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint &globalPos,
2835 QPoint &pos, QEvent::Type type,
2836 Qt::MouseButtons buttons, QWidget *buttonDown,
2837 QWidget *alienWidget)
2838{
2839 Q_ASSERT(candidate);
2840
2841 QWidget *mouseGrabber = QWidget::mouseGrabber();
2842 if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease))
2843 && !buttonDown && !mouseGrabber) {
2844 return 0;
2845 }
2846
2847 if (alienWidget && alienWidget->internalWinId())
2848 alienWidget = 0;
2849
2850 QWidget *receiver = candidate;
2851
2852 if (!mouseGrabber)
2853 mouseGrabber = buttonDown ? buttonDown : alienWidget;
2854
2855 if (mouseGrabber && mouseGrabber != candidate) {
2856 receiver = mouseGrabber;
2857 pos = receiver->mapFromGlobal(globalPos);
2858#ifdef ALIEN_DEBUG
2859 qDebug() << " ** receiver adjusted to:" << receiver << "pos:" << pos;
2860#endif
2861 }
2862
2863 return receiver;
2864
2865}
2866
2867/*
2868 \internal
2869*/
2870bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
2871 QWidget *alienWidget, QWidget *nativeWidget,
2872 QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver)
2873{
2874 Q_ASSERT(receiver);
2875 Q_ASSERT(event);
2876 Q_ASSERT(nativeWidget);
2877 Q_ASSERT(buttonDown);
2878
2879 if (alienWidget && !isAlien(alienWidget))
2880 alienWidget = 0;
2881
2882 QPointer<QWidget> receiverGuard = receiver;
2883 QPointer<QWidget> nativeGuard = nativeWidget;
2884 QPointer<QWidget> alienGuard = alienWidget;
2885 QPointer<QWidget> activePopupWidget = qApp->activePopupWidget();
2886
2887 const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen);
2888
2889 if (*buttonDown) {
2890 if (!graphicsWidget) {
2891 // Register the widget that shall receive a leave event
2892 // after the last button is released.
2893 if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber())
2894 leaveAfterRelease = *buttonDown;
2895 if (event->type() == QEvent::MouseButtonRelease && !event->buttons())
2896 *buttonDown = 0;
2897 }
2898 } else if (lastMouseReceiver) {
2899 // Dispatch enter/leave if we move:
2900 // 1) from an alien widget to another alien widget or
2901 // from a native widget to an alien widget (first OR case)
2902 // 2) from an alien widget to a native widget (second OR case)
2903 if ((alienWidget && alienWidget != lastMouseReceiver)
2904 || (isAlien(lastMouseReceiver) && !alienWidget)) {
2905 if (activePopupWidget) {
2906 if (!QWidget::mouseGrabber())
2907 dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver);
2908 } else {
2909 dispatchEnterLeave(receiver, lastMouseReceiver);
2910 }
2911
2912 }
2913 }
2914
2915#ifdef ALIEN_DEBUG
2916 qDebug() << "QApplicationPrivate::sendMouseEvent: receiver:" << receiver
2917 << "pos:" << event->pos() << "alien" << alienWidget << "button down"
2918 << *buttonDown << "last" << lastMouseReceiver << "leave after release"
2919 << leaveAfterRelease;
2920#endif
2921
2922 // We need this quard in case someone opens a modal dialog / popup. If that's the case
2923 // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver.
2924 const bool wasLeaveAfterRelease = leaveAfterRelease != 0;
2925 bool result = QApplication::sendSpontaneousEvent(receiver, event);
2926
2927 if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease
2928 && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) {
2929 // Dispatch enter/leave if:
2930 // 1) the mouse grabber is an alien widget
2931 // 2) the button is released on an alien widget
2932
2933 QWidget *enter = 0;
2934 if (nativeGuard)
2935 enter = alienGuard ? alienWidget : nativeWidget;
2936 else // The receiver is typically deleted on mouse release with drag'n'drop.
2937 enter = QApplication::widgetAt(event->globalPos());
2938
2939 dispatchEnterLeave(enter, leaveAfterRelease);
2940 leaveAfterRelease = 0;
2941 lastMouseReceiver = enter;
2942 } else if (!wasLeaveAfterRelease) {
2943 if (activePopupWidget) {
2944 if (!QWidget::mouseGrabber())
2945 lastMouseReceiver = alienGuard ? alienWidget : (nativeGuard ? nativeWidget : 0);
2946 } else {
2947 lastMouseReceiver = receiverGuard ? receiver : QApplication::widgetAt(event->globalPos());
2948 }
2949 }
2950
2951 return result;
2952}
2953
2954#if defined(Q_WS_WIN) || defined(Q_WS_X11)
2955/*
2956 This function should only be called when the widget changes visibility, i.e.
2957 when the \a widget is shown, hidden or deleted. This function does nothing
2958 if the widget is a top-level or native, i.e. not an alien widget. In that
2959 case enter/leave events are genereated by the underlying windowing system.
2960*/
2961extern QPointer<QWidget> qt_last_mouse_receiver;
2962extern QWidget *qt_button_down;
2963void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget)
2964{
2965#ifndef QT_NO_CURSOR
2966 if (!widget || widget->internalWinId() || widget->isWindow())
2967 return;
2968
2969 const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor;
2970 if (!widgetInShow && widget != qt_last_mouse_receiver)
2971 return; // Widget was not under the cursor when it was hidden/deleted.
2972
2973 if (widgetInShow && widget->parentWidget()->data->in_show)
2974 return; // Ingore recursive show.
2975
2976 QWidget *mouseGrabber = QWidget::mouseGrabber();
2977 if (mouseGrabber && mouseGrabber != widget)
2978 return; // Someone else has the grab; enter/leave should not occur.
2979
2980 QWidget *tlw = widget->window();
2981 if (tlw->data->in_destructor || tlw->data->is_closing)
2982 return; // Closing down the business.
2983
2984 if (widgetInShow && (!qt_last_mouse_receiver || qt_last_mouse_receiver->window() != tlw))
2985 return; // Mouse cursor not inside the widget's top-level.
2986
2987 const QPoint globalPos(QCursor::pos());
2988 QPoint pos = tlw->mapFromGlobal(globalPos);
2989
2990 // Find the current widget under the mouse. If this function was called from
2991 // the widget's destructor, we have to make sure childAt() doesn't take into
2992 // account widgets that are about to be destructed.
2993 QWidget *widgetUnderCursor = tlw->d_func()->childAt_helper(pos, widget->data->in_destructor);
2994 if (!widgetUnderCursor)
2995 widgetUnderCursor = tlw;
2996 else
2997 pos = widgetUnderCursor->mapFrom(tlw, pos);
2998
2999 if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor))
3000 return; // Mouse cursor not inside the widget or any of its children.
3001
3002 if (widget->data->in_destructor && qt_button_down == widget)
3003 qt_button_down = 0;
3004
3005 // Send enter/leave events followed by a mouse move on the entered widget.
3006 QMouseEvent e(QEvent::MouseMove, pos, globalPos, Qt::NoButton, mouse_buttons, modifier_buttons);
3007 sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver);
3008#endif // QT_NO_CURSOR
3009}
3010#endif // Q_WS_WIN || Q_WS_X11
3011
3012/*!
3013 Returns the desktop widget (also called the root window).
3014
3015 The desktop may be composed of multiple screens, so it would be incorrect,
3016 for example, to attempt to \e center some widget in the desktop's geometry.
3017 QDesktopWidget has various functions for obtaining useful geometries upon
3018 the desktop, such as QDesktopWidget::screenGeometry() and
3019 QDesktopWidget::availableGeometry().
3020
3021 On X11, it is also possible to draw on the desktop.
3022*/
3023QDesktopWidget *QApplication::desktop()
3024{
3025 if (!qt_desktopWidget || // not created yet
3026 !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
3027 qt_desktopWidget = new QDesktopWidget();
3028 }
3029 return qt_desktopWidget;
3030}
3031
3032#ifndef QT_NO_CLIPBOARD
3033/*!
3034 Returns a pointer to the application global clipboard.
3035
3036 \note The QApplication object should already be constructed before
3037 accessing the clipboard.
3038*/
3039QClipboard *QApplication::clipboard()
3040{
3041 if (qt_clipboard == 0) {
3042 if (!qApp) {
3043 qWarning("QApplication: Must construct a QApplication before accessing a QClipboard");
3044 return 0;
3045 }
3046 qt_clipboard = new QClipboard(0);
3047 }
3048 return qt_clipboard;
3049}
3050#endif // QT_NO_CLIPBOARD
3051
3052/*!
3053 Sets whether Qt should use the system's standard colors, fonts, etc., to
3054 \a on. By default, this is true.
3055
3056 This function must be called before creating the QApplication object, like
3057 this:
3058
3059 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 6
3060
3061 \sa desktopSettingsAware()
3062*/
3063void QApplication::setDesktopSettingsAware(bool on)
3064{
3065 QApplicationPrivate::obey_desktop_settings = on;
3066}
3067
3068/*!
3069 Returns true if Qt is set to use the system's standard colors, fonts, etc.;
3070 otherwise returns false. The default is true.
3071
3072 \sa setDesktopSettingsAware()
3073*/
3074bool QApplication::desktopSettingsAware()
3075{
3076 return QApplicationPrivate::obey_desktop_settings;
3077}
3078
3079/*!
3080 Returns the current state of the modifier keys on the keyboard. The current
3081 state is updated sychronously as the event queue is emptied of events that
3082 will spontaneously change the keyboard state (QEvent::KeyPress and
3083 QEvent::KeyRelease events).
3084
3085 It should be noted this may not reflect the actual keys held on the input
3086 device at the time of calling but rather the modifiers as last reported in
3087 one of the above events. If no keys are being held Qt::NoModifier is
3088 returned.
3089
3090 \sa mouseButtons()
3091*/
3092
3093Qt::KeyboardModifiers QApplication::keyboardModifiers()
3094{
3095 return QApplicationPrivate::modifier_buttons;
3096}
3097
3098/*!
3099 Returns the current state of the buttons on the mouse. The current state is
3100 updated syncronously as the event queue is emptied of events that will
3101 spontaneously change the mouse state (QEvent::MouseButtonPress and
3102 QEvent::MouseButtonRelease events).
3103
3104 It should be noted this may not reflect the actual buttons held on the
3105 input device at the time of calling but rather the mouse buttons as last
3106 reported in one of the above events. If no mouse buttons are being held
3107 Qt::NoButton is returned.
3108
3109 \sa keyboardModifiers()
3110*/
3111
3112Qt::MouseButtons QApplication::mouseButtons()
3113{
3114 return QApplicationPrivate::mouse_buttons;
3115}
3116
3117/*!
3118 \fn bool QApplication::isSessionRestored() const
3119
3120 Returns true if the application has been restored from an earlier
3121 \l{Session Management}{session}; otherwise returns false.
3122
3123 \sa sessionId(), commitData(), saveState()
3124*/
3125
3126
3127/*!
3128 \fn QString QApplication::sessionId() const
3129
3130 Returns the current \l{Session Management}{session's} identifier.
3131
3132 If the application has been restored from an earlier session, this
3133 identifier is the same as it was in that previous session. The session
3134 identifier is guaranteed to be unique both for different applications
3135 and for different instances of the same application.
3136
3137 \sa isSessionRestored(), sessionKey(), commitData(), saveState()
3138*/
3139
3140/*!
3141 \fn QString QApplication::sessionKey() const
3142
3143 Returns the session key in the current \l{Session Management}{session}.
3144
3145 If the application has been restored from an earlier session, this key is
3146 the same as it was when the previous session ended.
3147
3148 The session key changes with every call of commitData() or saveState().
3149
3150 \sa isSessionRestored(), sessionId(), commitData(), saveState()
3151*/
3152#ifndef QT_NO_SESSIONMANAGER
3153bool QApplication::isSessionRestored() const
3154{
3155 Q_D(const QApplication);
3156 return d->is_session_restored;
3157}
3158
3159QString QApplication::sessionId() const
3160{
3161 Q_D(const QApplication);
3162 return d->session_id;
3163}
3164
3165QString QApplication::sessionKey() const
3166{
3167 Q_D(const QApplication);
3168 return d->session_key;
3169}
3170#endif
3171
3172
3173
3174/*!
3175 \since 4.2
3176 \fn void QApplication::commitDataRequest(QSessionManager &manager)
3177
3178 This signal deals with \l{Session Management}{session management}. It is
3179 emitted when the QSessionManager wants the application to commit all its
3180 data.
3181
3182 Usually this means saving all open files, after getting permission from
3183 the user. Furthermore you may want to provide a means by which the user
3184 can cancel the shutdown.
3185
3186 You should not exit the application within this signal. Instead,
3187 the session manager may or may not do this afterwards, depending on the
3188 context.
3189
3190 \warning Within this signal, no user interaction is possible, \e
3191 unless you ask the \a manager for explicit permission. See
3192 QSessionManager::allowsInteraction() and
3193 QSessionManager::allowsErrorInteraction() for details and example
3194 usage.
3195
3196 \note You should use Qt::DirectConnection when connecting to this signal.
3197
3198 \sa isSessionRestored(), sessionId(), saveState(), {Session Management}
3199*/
3200
3201/*!
3202 This function deals with \l{Session Management}{session management}. It is
3203 invoked when the QSessionManager wants the application to commit all its
3204 data.
3205
3206 Usually this means saving all open files, after getting permission from the
3207 user. Furthermore you may want to provide a means by which the user can
3208 cancel the shutdown.
3209
3210 You should not exit the application within this function. Instead, the
3211 session manager may or may not do this afterwards, depending on the
3212 context.
3213
3214 \warning Within this function, no user interaction is possible, \e
3215 unless you ask the \a manager for explicit permission. See
3216 QSessionManager::allowsInteraction() and
3217 QSessionManager::allowsErrorInteraction() for details and example
3218 usage.
3219
3220 The default implementation requests interaction and sends a close event to
3221 all visible top-level widgets. If any event was rejected, the shutdown is
3222 canceled.
3223
3224 \sa isSessionRestored(), sessionId(), saveState(), {Session Management}
3225*/
3226#ifndef QT_NO_SESSIONMANAGER
3227void QApplication::commitData(QSessionManager& manager )
3228{
3229 emit commitDataRequest(manager);
3230 if (manager.allowsInteraction()) {
3231 QWidgetList done;
3232 QWidgetList list = QApplication::topLevelWidgets();
3233 bool cancelled = false;
3234 for (int i = 0; !cancelled && i < list.size(); ++i) {
3235 QWidget* w = list.at(i);
3236 if (w->isVisible() && !done.contains(w)) {
3237 cancelled = !w->close();
3238 if (!cancelled)
3239 done.append(w);
3240 list = QApplication::topLevelWidgets();
3241 i = -1;
3242 }
3243 }
3244 if (cancelled)
3245 manager.cancel();
3246 }
3247}
3248
3249/*!
3250 \since 4.2
3251 \fn void QApplication::saveStateRequest(QSessionManager &manager)
3252
3253 This signal deals with \l{Session Management}{session management}. It is
3254 invoked when the \l{QSessionManager}{session manager} wants the application
3255 to preserve its state for a future session.
3256
3257 For example, a text editor would create a temporary file that includes the
3258 current contents of its edit buffers, the location of the cursor and other
3259 aspects of the current editing session.
3260
3261 You should never exit the application within this signal. Instead, the
3262 session manager may or may not do this afterwards, depending on the
3263 context. Futhermore, most session managers will very likely request a saved
3264 state immediately after the application has been started. This permits the
3265 session manager to learn about the application's restart policy.
3266
3267 \warning Within this function, no user interaction is possible, \e
3268 unless you ask the \a manager for explicit permission. See
3269 QSessionManager::allowsInteraction() and
3270 QSessionManager::allowsErrorInteraction() for details.
3271
3272 \note You should use Qt::DirectConnection when connecting to this signal.
3273
3274 \sa isSessionRestored(), sessionId(), commitData(), {Session Management}
3275*/
3276
3277/*!
3278 This function deals with \l{Session Management}{session management}. It is
3279 invoked when the \l{QSessionManager}{session manager} wants the application
3280 to preserve its state for a future session.
3281
3282 For example, a text editor would create a temporary file that includes the
3283 current contents of its edit buffers, the location of the cursor and other
3284 aspects of the current editing session.
3285
3286 You should never exit the application within this function. Instead, the
3287 session manager may or may not do this afterwards, depending on the
3288 context. Futhermore, most session managers will very likely request a saved
3289 state immediately after the application has been started. This permits the
3290 session manager to learn about the application's restart policy.
3291
3292 \warning Within this function, no user interaction is possible, \e
3293 unless you ask the \a manager for explicit permission. See
3294 QSessionManager::allowsInteraction() and
3295 QSessionManager::allowsErrorInteraction() for details.
3296
3297 \sa isSessionRestored(), sessionId(), commitData(), {Session Management}
3298*/
3299
3300void QApplication::saveState(QSessionManager &manager)
3301{
3302 emit saveStateRequest(manager);
3303}
3304#endif //QT_NO_SESSIONMANAGER
3305/*
3306 Sets the time after which a drag should start to \a ms ms.
3307
3308 \sa startDragTime()
3309*/
3310
3311void QApplication::setStartDragTime(int ms)
3312{
3313 drag_time = ms;
3314}
3315
3316/*!
3317 \property QApplication::startDragTime
3318 \brief the time in milliseconds that a mouse button must be held down
3319 before a drag and drop operation will begin
3320
3321 If you support drag and drop in your application, and want to start a drag
3322 and drop operation after the user has held down a mouse button for a
3323 certain amount of time, you should use this property's value as the delay.
3324
3325 Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for
3326 starting a drag.
3327
3328 The default value is 500 ms.
3329
3330 \sa startDragDistance(), {Drag and Drop}
3331*/
3332
3333int QApplication::startDragTime()
3334{
3335 return drag_time;
3336}
3337
3338/*
3339 Sets the distance after which a drag should start to \a l pixels.
3340
3341 \sa startDragDistance()
3342*/
3343
3344void QApplication::setStartDragDistance(int l)
3345{
3346 drag_distance = l;
3347}
3348
3349/*!
3350 \property QApplication::startDragDistance
3351
3352 If you support drag and drop in your application, and want to start a drag
3353 and drop operation after the user has moved the cursor a certain distance
3354 with a button held down, you should use this property's value as the
3355 minimum distance required.
3356
3357 For example, if the mouse position of the click is stored in \c startPos
3358 and the current position (e.g. in the mouse move event) is \c currentPos,
3359 you can find out if a drag should be started with code like this:
3360
3361 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 7
3362
3363 Qt uses this value internally, e.g. in QFileDialog.
3364
3365 The default value is 4 pixels.
3366
3367 \sa startDragTime() QPoint::manhattanLength() {Drag and Drop}
3368*/
3369
3370int QApplication::startDragDistance()
3371{
3372 return drag_distance;
3373}
3374
3375/*!
3376 \fn void QApplication::setReverseLayout(bool reverse)
3377
3378 Use setLayoutDirection() instead.
3379*/
3380
3381/*!
3382 \fn void QApplication::reverseLayout()
3383
3384 Use layoutDirection() instead.
3385*/
3386
3387/*!
3388 \fn bool QApplication::isRightToLeft()
3389
3390 Returns true if the application's layout direction is
3391 Qt::RightToLeft; otherwise returns false.
3392
3393 \sa layoutDirection(), isLeftToRight()
3394*/
3395
3396/*!
3397 \fn bool QApplication::isLeftToRight()
3398
3399 Returns true if the application's layout direction is
3400 Qt::LeftToRight; otherwise returns false.
3401
3402 \sa layoutDirection(), isRightToLeft()
3403*/
3404
3405/*!
3406 \property QApplication::layoutDirection
3407 \brief the default layout direction for this application
3408
3409 On system start-up, the default layout direction depends on the
3410 application's language.
3411
3412 \sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft()
3413 */
3414
3415void QApplication::setLayoutDirection(Qt::LayoutDirection direction)
3416{
3417 if (layout_direction == direction)
3418 return;
3419
3420 layout_direction = direction;
3421
3422 QWidgetList list = topLevelWidgets();
3423 for (int i = 0; i < list.size(); ++i) {
3424 QWidget *w = list.at(i);
3425 QEvent ev(QEvent::ApplicationLayoutDirectionChange);
3426 sendEvent(w, &ev);
3427 }
3428}
3429
3430Qt::LayoutDirection QApplication::layoutDirection()
3431{
3432 return layout_direction;
3433}
3434
3435
3436/*!
3437 \obsolete
3438
3439 Strips out vertical alignment flags and transforms an alignment \a align
3440 of Qt::AlignLeft into Qt::AlignLeft or Qt::AlignRight according to the
3441 language used.
3442*/
3443
3444#ifdef QT3_SUPPORT
3445Qt::Alignment QApplication::horizontalAlignment(Qt::Alignment align)
3446{
3447 return QStyle::visualAlignment(layoutDirection(), align);
3448}
3449#endif
3450
3451
3452/*!
3453 \fn QCursor *QApplication::overrideCursor()
3454
3455 Returns the active application override cursor.
3456
3457 This function returns 0 if no application cursor has been defined (i.e. the
3458 internal cursor stack is empty).
3459
3460 \sa setOverrideCursor(), restoreOverrideCursor()
3461*/
3462#ifndef QT_NO_CURSOR
3463QCursor *QApplication::overrideCursor()
3464{
3465 return qApp->d_func()->cursor_list.isEmpty() ? 0 : &qApp->d_func()->cursor_list.first();
3466}
3467
3468/*!
3469 Changes the currently active application override cursor to \a cursor.
3470
3471 This function has no effect if setOverrideCursor() was not called.
3472
3473 \sa setOverrideCursor(), overrideCursor(), restoreOverrideCursor(),
3474 QWidget::setCursor()
3475 */
3476void QApplication::changeOverrideCursor(const QCursor &cursor)
3477{
3478 if (qApp->d_func()->cursor_list.isEmpty())
3479 return;
3480 qApp->d_func()->cursor_list.removeFirst();
3481 setOverrideCursor(cursor);
3482}
3483#endif
3484
3485/*!
3486 \fn void QApplication::setOverrideCursor(const QCursor &cursor, bool replace)
3487
3488 Use changeOverrideCursor(\a cursor) (if \a replace is true) or
3489 setOverrideCursor(\a cursor) (if \a replace is false).
3490*/
3491
3492/*!
3493 Enters the main event loop and waits until exit() is called, then returns
3494 the value that was set to exit() (which is 0 if exit() is called via
3495 quit()).
3496
3497 It is necessary to call this function to start event handling. The main
3498 event loop receives events from the window system and dispatches these to
3499 the application widgets.
3500
3501 Generally, no user interaction can take place before calling exec(). As a
3502 special case, modal widgets like QMessageBox can be used before calling
3503 exec(), because modal widgets call exec() to start a local event loop.
3504
3505 To make your application perform idle processing, i.e., executing a special
3506 function whenever there are no pending events, use a QTimer with 0 timeout.
3507 More advanced idle processing schemes can be achieved using processEvents().
3508
3509 We recommend that you connect clean-up code to the
3510 \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your
3511 application's \c{main()} function because on some platforms the
3512 QApplication::exec() call may not return. For example, on Windows when the
3513 user logs off, the system terminates the process after Qt closes all
3514 top-level windows. Hence, there is no guarantee that the application will
3515 have time to exit its event loop and execute code at the end of the
3516 \c{main()} function after the QApplication::exec() call.
3517
3518 \sa quitOnLastWindowClosed, quit(), exit(), processEvents(),
3519 QCoreApplication::exec()
3520*/
3521int QApplication::exec()
3522{
3523#ifndef QT_NO_ACCESSIBILITY
3524 QAccessible::setRootObject(qApp);
3525#endif
3526 return QCoreApplication::exec();
3527}
3528
3529/*! \reimp
3530 */
3531bool QApplication::notify(QObject *receiver, QEvent *e)
3532{
3533 Q_D(QApplication);
3534 // no events are delivered after ~QCoreApplication() has started
3535 if (QApplicationPrivate::is_app_closing)
3536 return true;
3537
3538 if (receiver == 0) { // serious error
3539 qWarning("QApplication::notify: Unexpected null receiver");
3540 return true;
3541 }
3542
3543#ifndef QT_NO_DEBUG
3544 d->checkReceiverThread(receiver);
3545#endif
3546
3547#ifdef QT3_SUPPORT
3548 if (e->type() == QEvent::ChildRemoved && !receiver->d_func()->pendingChildInsertedEvents.isEmpty())
3549 receiver->d_func()->removePendingChildInsertedEvents(static_cast<QChildEvent *>(e)->child());
3550#endif // QT3_SUPPORT
3551
3552 // capture the current mouse/keyboard state
3553 if(e->spontaneous()) {
3554 if (e->type() == QEvent::KeyPress
3555 || e->type() == QEvent::KeyRelease) {
3556 QKeyEvent *ke = static_cast<QKeyEvent*>(e);
3557 QApplicationPrivate::modifier_buttons = ke->modifiers();
3558 } else if(e->type() == QEvent::MouseButtonPress
3559 || e->type() == QEvent::MouseButtonRelease) {
3560 QMouseEvent *me = static_cast<QMouseEvent*>(e);
3561 QApplicationPrivate::modifier_buttons = me->modifiers();
3562 if(me->type() == QEvent::MouseButtonPress)
3563 QApplicationPrivate::mouse_buttons |= me->button();
3564 else
3565 QApplicationPrivate::mouse_buttons &= ~me->button();
3566 }
3567#if !defined(QT_NO_WHEELEVENT) || !defined(QT_NO_TABLETEVENT)
3568 else if (
3569# ifndef QT_NO_WHEELEVENT
3570 e->type() == QEvent::Wheel ||
3571# endif
3572# ifndef QT_NO_TABLETEVENT
3573 e->type() == QEvent::TabletMove
3574 || e->type() == QEvent::TabletPress
3575 || e->type() == QEvent::TabletRelease
3576# endif
3577 ) {
3578 QInputEvent *ie = static_cast<QInputEvent*>(e);
3579 QApplicationPrivate::modifier_buttons = ie->modifiers();
3580 }
3581#endif // !QT_NO_WHEELEVENT || !QT_NO_TABLETEVENT
3582 }
3583
3584 // User input and window activation makes tooltips sleep
3585 switch (e->type()) {
3586 case QEvent::Wheel:
3587 case QEvent::ActivationChange:
3588 case QEvent::KeyPress:
3589 case QEvent::KeyRelease:
3590 case QEvent::FocusOut:
3591 case QEvent::FocusIn:
3592 case QEvent::MouseButtonPress:
3593 case QEvent::MouseButtonRelease:
3594 case QEvent::MouseButtonDblClick:
3595 d->toolTipFallAsleep.stop();
3596 case QEvent::Leave:
3597 d->toolTipWakeUp.stop();
3598 default:
3599 break;
3600 }
3601
3602 bool res = false;
3603 if (!receiver->isWidgetType()) {
3604 res = d->notify_helper(receiver, e);
3605 } else switch (e->type()) {
3606#if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT)
3607 case QEvent::Accel:
3608 {
3609 if (d->use_compat()) {
3610 QKeyEvent* key = static_cast<QKeyEvent*>(e);
3611 res = d->notify_helper(receiver, e);
3612
3613 if (!res && !key->isAccepted())
3614 res = d->qt_dispatchAccelEvent(static_cast<QWidget *>(receiver), key);
3615
3616 // next lines are for compatibility with Qt <= 3.0.x: old
3617 // QAccel was listening on toplevel widgets
3618 if (!res && !key->isAccepted() && !static_cast<QWidget *>(receiver)->isWindow())
3619 res = d->notify_helper(static_cast<QWidget *>(receiver)->window(), e);
3620 }
3621 break;
3622 }
3623#endif //QT3_SUPPORT && !QT_NO_SHORTCUT
3624 case QEvent::ShortcutOverride:
3625 case QEvent::KeyPress:
3626 case QEvent::KeyRelease:
3627 {
3628 bool isWidget = receiver->isWidgetType();
3629 bool isGraphicsWidget = false;
3630#ifndef QT_NO_GRAPHICSVIEW
3631 isGraphicsWidget = !isWidget && qobject_cast<QGraphicsWidget *>(receiver);
3632#endif
3633 if (!isWidget && !isGraphicsWidget) {
3634 res = d->notify_helper(receiver, e);
3635 break;
3636 }
3637
3638 QKeyEvent* key = static_cast<QKeyEvent*>(e);
3639#if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT)
3640 if (d->use_compat() && d->qt_tryComposeUnicode(static_cast<QWidget*>(receiver), key))
3641 break;
3642#endif
3643 if (key->type()==QEvent::KeyPress) {
3644#ifndef QT_NO_SHORTCUT
3645 // Try looking for a Shortcut before sending key events
3646 if ((res = qApp->d_func()->shortcutMap.tryShortcutEvent(receiver, key)))
3647 return res;
3648#endif
3649 qt_in_tab_key_event = (key->key() == Qt::Key_Backtab
3650 || key->key() == Qt::Key_Tab
3651 || key->key() == Qt::Key_Left
3652 || key->key() == Qt::Key_Up
3653 || key->key() == Qt::Key_Right
3654 || key->key() == Qt::Key_Down);
3655 }
3656 bool def = key->isAccepted();
3657 QPointer<QObject> pr = receiver;
3658 while (receiver) {
3659 if (def)
3660 key->accept();
3661 else
3662 key->ignore();
3663 res = d->notify_helper(receiver, e);
3664 QWidget *w = isWidget ? static_cast<QWidget *>(receiver) : 0;
3665#ifndef QT_NO_GRAPHICSVIEW
3666 QGraphicsWidget *gw = isGraphicsWidget ? static_cast<QGraphicsWidget *>(receiver) : 0;
3667#endif
3668
3669 if ((res && key->isAccepted())
3670 /*
3671 QLineEdit will emit a signal on Key_Return, but
3672 ignore the event, and sometimes the connected
3673 slot deletes the QLineEdit (common in itemview
3674 delegates), so we have to check if the widget
3675 was destroyed even if the event was ignored (to
3676 prevent a crash)
3677
3678 note that we don't have to reset pw while
3679 propagating (because the original receiver will
3680 be destroyed if one of its ancestors is)
3681 */
3682 || !pr
3683 || (isWidget && (w->isWindow() || !w->parentWidget()))
3684#ifndef QT_NO_GRAPHICSVIEW
3685 || (isGraphicsWidget && (gw->isWindow() || !gw->parentWidget()))
3686#endif
3687 ) {
3688 break;
3689 }
3690
3691#ifndef QT_NO_GRAPHICSVIEW
3692 receiver = w ? (QObject *)w->parentWidget() : (QObject *)gw->parentWidget();
3693#else
3694 receiver = w->parentWidget();
3695#endif
3696 }
3697 qt_in_tab_key_event = false;
3698 }
3699 break;
3700 case QEvent::MouseButtonPress:
3701 case QEvent::MouseButtonRelease:
3702 case QEvent::MouseButtonDblClick:
3703 case QEvent::MouseMove:
3704 {
3705 QWidget* w = static_cast<QWidget *>(receiver);
3706
3707 QMouseEvent* mouse = static_cast<QMouseEvent*>(e);
3708 QPoint relpos = mouse->pos();
3709
3710 if (e->spontaneous()) {
3711
3712 if (e->type() == QEvent::MouseButtonPress) {
3713 QWidget *fw = w;
3714 while (fw) {
3715 if (fw->isEnabled()
3716 && QApplicationPrivate::shouldSetFocus(fw, Qt::ClickFocus)) {
3717 fw->setFocus(Qt::MouseFocusReason);
3718 break;
3719 }
3720 if (fw->isWindow())
3721 break;
3722 fw = fw->parentWidget();
3723 }
3724 }
3725
3726 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0) {
3727 d->toolTipWidget = w;
3728 d->toolTipPos = relpos;
3729 d->toolTipGlobalPos = mouse->globalPos();
3730 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive()?20:700, this);
3731 }
3732 }
3733
3734 bool eventAccepted = mouse->isAccepted();
3735
3736 QPointer<QWidget> pw = w;
3737 while (w) {
3738 QMouseEvent me(mouse->type(), relpos, mouse->globalPos(), mouse->button(), mouse->buttons(),
3739 mouse->modifiers());
3740 me.spont = mouse->spontaneous();
3741 // throw away any mouse-tracking-only mouse events
3742 if (!w->hasMouseTracking()
3743 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
3744 // but still send them through all application event filters (normally done by notify_helper)
3745 for (int i = 0; i < d->eventFilters.size(); ++i) {
3746 register QObject *obj = d->eventFilters.at(i);
3747 if (!obj)
3748 continue;
3749 if (obj->d_func()->threadData != w->d_func()->threadData) {
3750 qWarning("QApplication: Object event filter cannot be in a different thread.");
3751 continue;
3752 }
3753 if (obj->eventFilter(w, w == receiver ? mouse : &me))
3754 break;
3755 }
3756 res = true;
3757 } else {
3758 w->setAttribute(Qt::WA_NoMouseReplay, false);
3759 res = d->notify_helper(w, w == receiver ? mouse : &me);
3760 e->spont = false;
3761 }
3762 eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
3763 if (res && eventAccepted)
3764 break;
3765 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3766 break;
3767 relpos += w->pos();
3768 w = w->parentWidget();
3769 }
3770
3771 mouse->setAccepted(eventAccepted);
3772
3773 if (e->type() == QEvent::MouseMove) {
3774 if (!pw)
3775 break;
3776
3777 w = static_cast<QWidget *>(receiver);
3778 relpos = mouse->pos();
3779 QPoint diff = relpos - w->mapFromGlobal(d->hoverGlobalPos);
3780 while (w) {
3781 if (w->testAttribute(Qt::WA_Hover) &&
3782 (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
3783 QHoverEvent he(QEvent::HoverMove, relpos, relpos - diff);
3784 d->notify_helper(w, &he);
3785 }
3786 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3787 break;
3788 relpos += w->pos();
3789 w = w->parentWidget();
3790 }
3791 }
3792
3793 d->hoverGlobalPos = mouse->globalPos();
3794 }
3795 break;
3796#ifndef QT_NO_WHEELEVENT
3797 case QEvent::Wheel:
3798 {
3799 QWidget* w = static_cast<QWidget *>(receiver);
3800 QWheelEvent* wheel = static_cast<QWheelEvent*>(e);
3801 QPoint relpos = wheel->pos();
3802 bool eventAccepted = wheel->isAccepted();
3803
3804 if (e->spontaneous()) {
3805 QWidget *fw = w;
3806 while (fw) {
3807 if (fw->isEnabled()
3808 && QApplicationPrivate::shouldSetFocus(fw, Qt::WheelFocus)) {
3809 fw->setFocus(Qt::MouseFocusReason);
3810 break;
3811 }
3812 if (fw->isWindow())
3813 break;
3814 fw = fw->parentWidget();
3815 }
3816 }
3817
3818 while (w) {
3819 QWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->buttons(),
3820 wheel->modifiers(), wheel->orientation());
3821 we.spont = wheel->spontaneous();
3822 res = d->notify_helper(w, w == receiver ? wheel : &we);
3823 eventAccepted = ((w == receiver) ? wheel : &we)->isAccepted();
3824 e->spont = false;
3825 if ((res && eventAccepted)
3826 || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3827 break;
3828
3829 relpos += w->pos();
3830 w = w->parentWidget();
3831 }
3832 wheel->setAccepted(eventAccepted);
3833 }
3834 break;
3835#endif
3836#ifndef QT_NO_CONTEXTMENU
3837 case QEvent::ContextMenu:
3838 {
3839 QWidget* w = static_cast<QWidget *>(receiver);
3840 QContextMenuEvent *context = static_cast<QContextMenuEvent*>(e);
3841 QPoint relpos = context->pos();
3842 bool eventAccepted = context->isAccepted();
3843 while (w) {
3844 QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers());
3845 ce.spont = e->spontaneous();
3846 res = d->notify_helper(w, w == receiver ? context : &ce);
3847 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
3848 e->spont = false;
3849
3850 if ((res && eventAccepted)
3851 || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3852 break;
3853
3854 relpos += w->pos();
3855 w = w->parentWidget();
3856 }
3857 context->setAccepted(eventAccepted);
3858 }
3859 break;
3860#endif // QT_NO_CONTEXTMENU
3861#ifndef QT_NO_TABLETEVENT
3862 case QEvent::TabletMove:
3863 case QEvent::TabletPress:
3864 case QEvent::TabletRelease:
3865 {
3866 QWidget *w = static_cast<QWidget *>(receiver);
3867 QTabletEvent *tablet = static_cast<QTabletEvent*>(e);
3868 QPoint relpos = tablet->pos();
3869 bool eventAccepted = tablet->isAccepted();
3870 while (w) {
3871 QTabletEvent te(tablet->type(), relpos, tablet->globalPos(),
3872 tablet->hiResGlobalPos(), tablet->device(), tablet->pointerType(),
3873 tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
3874 tablet->tangentialPressure(), tablet->rotation(), tablet->z(),
3875 tablet->modifiers(), tablet->uniqueId());
3876 te.spont = e->spontaneous();
3877 res = d->notify_helper(w, w == receiver ? tablet : &te);
3878 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
3879 e->spont = false;
3880 if ((res && eventAccepted)
3881 || w->isWindow()
3882 || w->testAttribute(Qt::WA_NoMousePropagation))
3883 break;
3884
3885 relpos += w->pos();
3886 w = w->parentWidget();
3887 }
3888 tablet->setAccepted(eventAccepted);
3889 qt_tabletChokeMouse = tablet->isAccepted();
3890 }
3891 break;
3892#endif // QT_NO_TABLETEVENT
3893
3894#if !defined(QT_NO_TOOLTIP) || !defined(QT_NO_WHATSTHIS)
3895 case QEvent::ToolTip:
3896 case QEvent::WhatsThis:
3897 case QEvent::QueryWhatsThis:
3898 {
3899 QWidget* w = static_cast<QWidget *>(receiver);
3900 QHelpEvent *help = static_cast<QHelpEvent*>(e);
3901 QPoint relpos = help->pos();
3902 bool eventAccepted = help->isAccepted();
3903 while (w) {
3904 QHelpEvent he(help->type(), relpos, help->globalPos());
3905 he.spont = e->spontaneous();
3906 res = d->notify_helper(w, w == receiver ? help : &he);
3907 e->spont = false;
3908 eventAccepted = (w == receiver ? help : &he)->isAccepted();
3909 if ((res && eventAccepted) || w->isWindow())
3910 break;
3911
3912 relpos += w->pos();
3913 w = w->parentWidget();
3914 }
3915 help->setAccepted(eventAccepted);
3916 }
3917 break;
3918#endif
3919#if !defined(QT_NO_STATUSTIP) || !defined(QT_NO_WHATSTHIS)
3920 case QEvent::StatusTip:
3921 case QEvent::WhatsThisClicked:
3922 {
3923 QWidget *w = static_cast<QWidget *>(receiver);
3924 while (w) {
3925 res = d->notify_helper(w, e);
3926 if ((res && e->isAccepted()) || w->isWindow())
3927 break;
3928 w = w->parentWidget();
3929 }
3930 }
3931 break;
3932#endif
3933
3934#ifndef QT_NO_DRAGANDDROP
3935 case QEvent::DragEnter: {
3936 QWidget* w = static_cast<QWidget *>(receiver);
3937 QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent *>(e);
3938#ifdef Q_WS_MAC
3939 // HIView has a slight difference in how it delivers events to children and parents
3940 // It will not give a leave to a child's parent when it enters a child.
3941 QWidget *currentTarget = QDragManager::self()->currentTarget();
3942 if (currentTarget) {
3943 // Assume currentTarget did not get a leave
3944 QDragLeaveEvent event;
3945 QApplication::sendEvent(currentTarget, &event);
3946 }
3947#endif
3948#ifndef QT_NO_GRAPHICSVIEW
3949 // QGraphicsProxyWidget handles its own propagation,
3950 // and we must not change QDragManagers currentTarget.
3951 QWExtra *extra = w->window()->d_func()->extra;
3952 if (extra && extra->proxyWidget) {
3953 res = d->notify_helper(w, dragEvent);
3954 break;
3955 }
3956#endif
3957 while (w) {
3958 if (w->isEnabled() && w->acceptDrops()) {
3959 res = d->notify_helper(w, dragEvent);
3960 if (res && dragEvent->isAccepted()) {
3961 QDragManager::self()->setCurrentTarget(w);
3962 break;
3963 }
3964 }
3965 if (w->isWindow())
3966 break;
3967 dragEvent->p = w->mapToParent(dragEvent->p);
3968 w = w->parentWidget();
3969 }
3970 }
3971 break;
3972 case QEvent::DragMove:
3973 case QEvent::Drop:
3974 case QEvent::DragLeave: {
3975 QWidget* w = static_cast<QWidget *>(receiver);
3976#ifndef QT_NO_GRAPHICSVIEW
3977 // QGraphicsProxyWidget handles its own propagation,
3978 // and we must not change QDragManagers currentTarget.
3979 QWExtra *extra = w->window()->d_func()->extra;
3980 bool isProxyWidget = extra && extra->proxyWidget;
3981 if (!isProxyWidget)
3982#endif
3983 w = QDragManager::self()->currentTarget();
3984
3985 if (!w) {
3986#ifdef Q_WS_MAC
3987 // HIView has a slight difference in how it delivers events to children and parents
3988 // It will not give an enter to a child's parent when it leaves the child.
3989 if (e->type() == QEvent::DragLeave)
3990 break;
3991 // Assume that w did not get an enter.
3992 QDropEvent *dropEvent = static_cast<QDropEvent *>(e);
3993 QDragEnterEvent dragEnterEvent(dropEvent->pos(), dropEvent->possibleActions(),
3994 dropEvent->mimeData(), dropEvent->mouseButtons(),
3995 dropEvent->keyboardModifiers());
3996 QApplication::sendEvent(receiver, &dragEnterEvent);
3997 w = QDragManager::self()->currentTarget();
3998 if (!w)
3999#endif
4000 break;
4001 }
4002 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
4003 QDropEvent *dragEvent = static_cast<QDropEvent *>(e);
4004 QWidget *origReciver = static_cast<QWidget *>(receiver);
4005 while (origReciver && w != origReciver) {
4006 dragEvent->p = origReciver->mapToParent(dragEvent->p);
4007 origReciver = origReciver->parentWidget();
4008 }
4009 }
4010 res = d->notify_helper(w, e);
4011 if (e->type() != QEvent::DragMove
4012#ifndef QT_NO_GRAPHICSVIEW
4013 && !isProxyWidget
4014#endif
4015 )
4016 QDragManager::self()->setCurrentTarget(0, e->type() == QEvent::Drop);
4017 }
4018 break;
4019#endif
4020
4021 default:
4022 res = d->notify_helper(receiver, e);
4023 break;
4024 }
4025
4026 return res;
4027}
4028
4029bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e)
4030{
4031 // send to all application event filters
4032 if (sendThroughApplicationEventFilters(receiver, e))
4033 return true;
4034
4035 if (receiver->isWidgetType()) {
4036 QWidget *widget = static_cast<QWidget *>(receiver);
4037
4038#if !defined(Q_OS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
4039 // toggle HasMouse widget state on enter and leave
4040 if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
4041 (!qApp->activePopupWidget() || qApp->activePopupWidget() == widget->window()))
4042 widget->setAttribute(Qt::WA_UnderMouse, true);
4043 else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
4044 widget->setAttribute(Qt::WA_UnderMouse, false);
4045#endif
4046
4047 if (QLayout *layout=widget->d_func()->layout) {
4048 layout->widgetEvent(e);
4049 }
4050 }
4051
4052 // send to all receiver event filters
4053 if (sendThroughObjectEventFilters(receiver, e))
4054 return true;
4055
4056 // deliver the event
4057 bool consumed = receiver->event(e);
4058 e->spont = false;
4059 return consumed;
4060}
4061
4062
4063/*!
4064 \class QSessionManager
4065 \brief The QSessionManager class provides access to the session manager.
4066
4067 \ingroup application
4068 \ingroup environment
4069
4070 A session manager in a desktop environment (in which Qt GUI applications
4071 live) keeps track of a session, which is a group of running applications,
4072 each of which has a particular state. The state of an application contains
4073 (most notably) the documents the application has open and the position and
4074 size of its windows.
4075
4076 The session manager is used to save the session, e.g., when the machine is
4077 shut down, and to restore a session, e.g., when the machine is started up.
4078 We recommend that you use QSettings to save an application's settings,
4079 for example, window positions, recently used files, etc. When the
4080 application is restarted by the session manager, you can restore the
4081 settings.
4082
4083 QSessionManager provides an interface between the application and the
4084 session manager so that the program can work well with the session manager.
4085 In Qt, session management requests for action are handled by the two
4086 virtual functions QApplication::commitData() and QApplication::saveState().
4087 Both provide a reference to a session manager object as argument, to allow
4088 the application to communicate with the session manager. The session
4089 manager can only be accessed through these functions.
4090
4091 No user interaction is possible \e unless the application gets explicit
4092 permission from the session manager. You ask for permission by calling
4093 allowsInteraction() or, if it is really urgent, allowsErrorInteraction().
4094 Qt does not enforce this, but the session manager may.
4095
4096 You can try to abort the shutdown process by calling cancel(). The default
4097 commitData() function does this if some top-level window rejected its
4098 closeEvent().
4099
4100 For sophisticated session managers provided on Unix/X11, QSessionManager
4101 offers further possibilities to fine-tune an application's session
4102 management behavior: setRestartCommand(), setDiscardCommand(),
4103 setRestartHint(), setProperty(), requestPhase2(). See the respective
4104 function descriptions for further details.
4105
4106 \sa QApplication, {Session Management}
4107*/
4108
4109/*! \enum QSessionManager::RestartHint
4110
4111 This enum type defines the circumstances under which this application wants
4112 to be restarted by the session manager. The current values are:
4113
4114 \value RestartIfRunning If the application is still running when the
4115 session is shut down, it wants to be restarted
4116 at the start of the next session.
4117
4118 \value RestartAnyway The application wants to be started at the
4119 start of the next session, no matter what.
4120 (This is useful for utilities that run just
4121 after startup and then quit.)
4122
4123 \value RestartImmediately The application wants to be started immediately
4124 whenever it is not running.
4125
4126 \value RestartNever The application does not want to be restarted
4127 automatically.
4128
4129 The default hint is \c RestartIfRunning.
4130*/
4131
4132
4133/*!
4134 \fn QString QSessionManager::sessionId() const
4135
4136 Returns the identifier of the current session.
4137
4138 If the application has been restored from an earlier session, this
4139 identifier is the same as it was in the earlier session.
4140
4141 \sa sessionKey(), QApplication::sessionId()
4142*/
4143
4144/*!
4145 \fn QString QSessionManager::sessionKey() const
4146
4147 Returns the session key in the current session.
4148
4149 If the application has been restored from an earlier session, this key is
4150 the same as it was when the previous session ended.
4151
4152 The session key changes with every call of commitData() or saveState().
4153
4154 \sa sessionId(), QApplication::sessionKey()
4155*/
4156
4157/*!
4158 \fn void* QSessionManager::handle() const
4159
4160 \internal
4161*/
4162
4163/*!
4164 \fn bool QSessionManager::allowsInteraction()
4165
4166 Asks the session manager for permission to interact with the user. Returns
4167 true if interaction is permitted; otherwise returns false.
4168
4169 The rationale behind this mechanism is to make it possible to synchronize
4170 user interaction during a shutdown. Advanced session managers may ask all
4171 applications simultaneously to commit their data, resulting in a much
4172 faster shutdown.
4173
4174 When the interaction is completed we strongly recommend releasing the user
4175 interaction semaphore with a call to release(). This way, other
4176 applications may get the chance to interact with the user while your
4177 application is still busy saving data. (The semaphore is implicitly
4178 released when the application exits.)
4179
4180 If the user decides to cancel the shutdown process during the interaction
4181 phase, you must tell the session manager that this has happened by calling
4182 cancel().
4183
4184 Here's an example of how an application's QApplication::commitData() might
4185 be implemented:
4186
4187 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 8
4188
4189 If an error occurred within the application while saving its data, you may
4190 want to try allowsErrorInteraction() instead.
4191
4192 \sa QApplication::commitData(), release(), cancel()
4193*/
4194
4195
4196/*!
4197 \fn bool QSessionManager::allowsErrorInteraction()
4198
4199 Returns true if error interaction is permitted; otherwise returns false.
4200
4201 This is similar to allowsInteraction(), but also enables the application to
4202 tell the user about any errors that occur. Session managers may give error
4203 interaction requests higher priority, which means that it is more likely
4204 that an error interaction is permitted. However, you are still not
4205 guaranteed that the session manager will allow interaction.
4206
4207 \sa allowsInteraction(), release(), cancel()
4208*/
4209
4210/*!
4211 \fn void QSessionManager::release()
4212
4213 Releases the session manager's interaction semaphore after an interaction
4214 phase.
4215
4216 \sa allowsInteraction(), allowsErrorInteraction()
4217*/
4218
4219/*!
4220 \fn void QSessionManager::cancel()
4221
4222 Tells the session manager to cancel the shutdown process. Applications
4223 should not call this function without asking the user first.
4224
4225 \sa allowsInteraction(), allowsErrorInteraction()
4226*/
4227
4228/*!
4229 \fn void QSessionManager::setRestartHint(RestartHint hint)
4230
4231 Sets the application's restart hint to \a hint. On application startup, the
4232 hint is set to \c RestartIfRunning.
4233
4234 \note These flags are only hints, a session manager may or may not respect
4235 them.
4236
4237 We recommend setting the restart hint in QApplication::saveState() because
4238 most session managers perform a checkpoint shortly after an application's
4239 startup.
4240
4241 \sa restartHint()
4242*/
4243
4244/*!
4245 \fn QSessionManager::RestartHint QSessionManager::restartHint() const
4246
4247 Returns the application's current restart hint. The default is
4248 \c RestartIfRunning.
4249
4250 \sa setRestartHint()
4251*/
4252
4253/*!
4254 \fn void QSessionManager::setRestartCommand(const QStringList& command)
4255
4256 If the session manager is capable of restoring sessions it will execute
4257 \a command in order to restore the application. The command defaults to
4258
4259 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 9
4260
4261 The \c -session option is mandatory; otherwise QApplication cannot tell
4262 whether it has been restored or what the current session identifier is.
4263 See QApplication::isSessionRestored() and QApplication::sessionId() for
4264 details.
4265
4266 If your application is very simple, it may be possible to store the entire
4267 application state in additional command line options. This is usually a
4268 very bad idea because command lines are often limited to a few hundred
4269 bytes. Instead, use QSettings, temporary files, or a database for this
4270 purpose. By marking the data with the unique sessionId(), you will be able
4271 to restore the application in a future session.
4272
4273 \sa restartCommand(), setDiscardCommand(), setRestartHint()
4274*/
4275
4276/*!
4277 \fn QStringList QSessionManager::restartCommand() const
4278
4279 Returns the currently set restart command.
4280
4281 To iterate over the list, you can use the \l foreach pseudo-keyword:
4282
4283 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 10
4284
4285 \sa setRestartCommand(), restartHint()
4286*/
4287
4288/*!
4289 \fn void QSessionManager::setDiscardCommand(const QStringList& list)
4290
4291 Sets the discard command to the given \a list.
4292
4293 \sa discardCommand(), setRestartCommand()
4294*/
4295
4296
4297/*!
4298 \fn QStringList QSessionManager::discardCommand() const
4299
4300 Returns the currently set discard command.
4301
4302 To iterate over the list, you can use the \l foreach pseudo-keyword:
4303
4304 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 11
4305
4306 \sa setDiscardCommand(), restartCommand(), setRestartCommand()
4307*/
4308
4309/*!
4310 \fn void QSessionManager::setManagerProperty(const QString &name, const QString &value)
4311 \overload
4312
4313 Low-level write access to the application's identification and state
4314 records are kept in the session manager.
4315
4316 The property called \a name has its value set to the string \a value.
4317*/
4318
4319/*!
4320 \fn void QSessionManager::setManagerProperty(const QString& name,
4321 const QStringList& value)
4322
4323 Low-level write access to the application's identification and state record
4324 are kept in the session manager.
4325
4326 The property called \a name has its value set to the string list \a value.
4327*/
4328
4329/*!
4330 \fn bool QSessionManager::isPhase2() const
4331
4332 Returns true if the session manager is currently performing a second
4333 session management phase; otherwise returns false.
4334
4335 \sa requestPhase2()
4336*/
4337
4338/*!
4339 \fn void QSessionManager::requestPhase2()
4340
4341 Requests a second session management phase for the application. The
4342 application may then return immediately from the QApplication::commitData()
4343 or QApplication::saveState() function, and they will be called again once
4344 most or all other applications have finished their session management.
4345
4346 The two phases are useful for applications such as the X11 window manager
4347 that need to store information about another application's windows and
4348 therefore have to wait until these applications have completed their
4349 respective session management tasks.
4350
4351 \note If another application has requested a second phase it may get called
4352 before, simultaneously with, or after your application's second phase.
4353
4354 \sa isPhase2()
4355*/
4356
4357/*****************************************************************************
4358 Stubbed session management support
4359 *****************************************************************************/
4360#ifndef QT_NO_SESSIONMANAGER
4361#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
4362
4363#if defined(Q_OS_WINCE)
4364HRESULT qt_CoCreateGuid(GUID* guid)
4365{
4366 // We will use the following information to create the GUID
4367 // 1. absolute path to application
4368 wchar_t tempFilename[512];
4369 if (!GetModuleFileNameW(0, tempFilename, 512))
4370 return S_FALSE;
4371 unsigned int hash = qHash(QString::fromUtf16((const unsigned short *) tempFilename));
4372 guid->Data1 = hash;
4373 // 2. creation time of file
4374 QFileInfo info(QString::fromUtf16((const unsigned short *) tempFilename));
4375 guid->Data2 = qHash(info.created().toTime_t());
4376 // 3. current system time
4377 guid->Data3 = qHash(QDateTime::currentDateTime().toTime_t());
4378 return S_OK;
4379}
4380#if !defined(OLE32_MCOMGUID) || defined(QT_WINCE_FORCE_CREATE_GUID)
4381#define CoCreateGuid qt_CoCreateGuid
4382#endif
4383
4384#endif
4385
4386class QSessionManagerPrivate : public QObjectPrivate
4387{
4388public:
4389 QStringList restartCommand;
4390 QStringList discardCommand;
4391 QString sessionId;
4392 QString sessionKey;
4393 QSessionManager::RestartHint restartHint;
4394};
4395
4396QSessionManager* qt_session_manager_self = 0;
4397QSessionManager::QSessionManager(QApplication * app, QString &id, QString &key)
4398 : QObject(*new QSessionManagerPrivate, app)
4399{
4400 Q_D(QSessionManager);
4401 setObjectName(QLatin1String("qt_sessionmanager"));
4402 qt_session_manager_self = this;
4403#if defined(Q_WS_WIN)
4404 wchar_t guidstr[40];
4405 GUID guid;
4406 CoCreateGuid(&guid);
4407 StringFromGUID2(guid, guidstr, 40);
4408 id = QString::fromUtf16((ushort*)guidstr);
4409 CoCreateGuid(&guid);
4410 StringFromGUID2(guid, guidstr, 40);
4411 key = QString::fromUtf16((ushort*)guidstr);
4412#endif
4413 d->sessionId = id;
4414 d->sessionKey = key;
4415 d->restartHint = RestartIfRunning;
4416}
4417
4418QSessionManager::~QSessionManager()
4419{
4420 qt_session_manager_self = 0;
4421}
4422
4423QString QSessionManager::sessionId() const
4424{
4425 Q_D(const QSessionManager);
4426 return d->sessionId;
4427}
4428
4429QString QSessionManager::sessionKey() const
4430{
4431 Q_D(const QSessionManager);
4432 return d->sessionKey;
4433}
4434
4435
4436#if defined(Q_WS_X11) || defined(Q_WS_MAC)
4437void* QSessionManager::handle() const
4438{
4439 return 0;
4440}
4441#endif
4442
4443#if !defined(Q_WS_WIN)
4444bool QSessionManager::allowsInteraction()
4445{
4446 return true;
4447}
4448
4449bool QSessionManager::allowsErrorInteraction()
4450{
4451 return true;
4452}
4453void QSessionManager::release()
4454{
4455}
4456
4457void QSessionManager::cancel()
4458{
4459}
4460#endif
4461
4462
4463void QSessionManager::setRestartHint(QSessionManager::RestartHint hint)
4464{
4465 Q_D(QSessionManager);
4466 d->restartHint = hint;
4467}
4468
4469QSessionManager::RestartHint QSessionManager::restartHint() const
4470{
4471 Q_D(const QSessionManager);
4472 return d->restartHint;
4473}
4474
4475void QSessionManager::setRestartCommand(const QStringList& command)
4476{
4477 Q_D(QSessionManager);
4478 d->restartCommand = command;
4479}
4480
4481QStringList QSessionManager::restartCommand() const
4482{
4483 Q_D(const QSessionManager);
4484 return d->restartCommand;
4485}
4486
4487void QSessionManager::setDiscardCommand(const QStringList& command)
4488{
4489 Q_D(QSessionManager);
4490 d->discardCommand = command;
4491}
4492
4493QStringList QSessionManager::discardCommand() const
4494{
4495 Q_D(const QSessionManager);
4496 return d->discardCommand;
4497}
4498
4499void QSessionManager::setManagerProperty(const QString&, const QString&)
4500{
4501}
4502
4503void QSessionManager::setManagerProperty(const QString&, const QStringList&)
4504{
4505}
4506
4507bool QSessionManager::isPhase2() const
4508{
4509 return false;
4510}
4511
4512void QSessionManager::requestPhase2()
4513{
4514}
4515
4516#endif
4517#endif // QT_NO_SESSIONMANAGER
4518
4519/*!
4520 \typedef QApplication::ColorMode
4521 \compat
4522
4523 Use ColorSpec instead.
4524*/
4525
4526/*!
4527 \fn Qt::MacintoshVersion QApplication::macVersion()
4528
4529 Use QSysInfo::MacintoshVersion instead.
4530*/
4531
4532/*!
4533 \fn QApplication::ColorMode QApplication::colorMode()
4534
4535 Use colorSpec() instead, and use ColorSpec as the enum type.
4536*/
4537
4538/*!
4539 \fn void QApplication::setColorMode(ColorMode mode)
4540
4541 Use setColorSpec() instead, and pass a ColorSpec value instead.
4542*/
4543
4544/*!
4545 \fn bool QApplication::hasGlobalMouseTracking()
4546
4547 This feature does not exist anymore. This function always returns true
4548 in Qt 4.
4549*/
4550
4551/*!
4552 \fn void QApplication::setGlobalMouseTracking(bool dummy)
4553
4554 This function does nothing in Qt 4. The \a dummy parameter is ignored.
4555*/
4556
4557/*!
4558 \fn void QApplication::flushX()
4559
4560 Use flush() instead.
4561*/
4562
4563/*!
4564 \fn void QApplication::setWinStyleHighlightColor(const QColor &c)
4565
4566 Use the palette instead.
4567
4568 \oldcode
4569 app.setWinStyleHighlightColor(color);
4570 \newcode
4571 QPalette palette(qApp->palette());
4572 palette.setColor(QPalette::Highlight, color);
4573 qApp->setPalette(palette);
4574 \endcode
4575*/
4576
4577/*!
4578 \fn void QApplication::setPalette(const QPalette &pal, bool b, const char* className = 0)
4579
4580 Use the two-argument overload instead.
4581*/
4582
4583/*!
4584 \fn void QApplication::setFont(const QFont &font, bool b, const char* className = 0)
4585
4586 Use the two-argument overload instead.
4587*/
4588
4589/*!
4590 \fn const QColor &QApplication::winStyleHighlightColor()
4591
4592 Use qApp->palette().color(QPalette::Active, QPalette::Highlight) instead.
4593*/
4594
4595/*!
4596 \fn QWidget *QApplication::widgetAt(int x, int y, bool child)
4597
4598 Use the two-argument widgetAt() overload to get the child widget. To get
4599 the top-level widget do this:
4600
4601 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 12
4602*/
4603
4604/*!
4605 \fn QWidget *QApplication::widgetAt(const QPoint &point, bool child)
4606
4607 Use the single-argument widgetAt() overload to get the child widget. To get
4608 the top-level widget do this:
4609
4610 \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 13
4611*/
4612
4613#ifdef QT3_SUPPORT
4614QWidget *QApplication::mainWidget()
4615{
4616 return QApplicationPrivate::main_widget;
4617}
4618#endif
4619bool QApplicationPrivate::inPopupMode() const
4620{
4621 return QApplicationPrivate::popupWidgets != 0;
4622}
4623
4624/*!
4625 \property QApplication::quitOnLastWindowClosed
4626
4627 \brief whether the application implicitly quits when the last window is
4628 closed.
4629
4630 The default is true.
4631
4632 If this property is true, the applications quits when the last visible
4633 primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose
4634 attribute set is closed. By default this attribute is set for all widgets
4635 except for sub-windows. Refer to \l{Qt::WindowType} for a detailed list of
4636 Qt::Window objects.
4637
4638 \sa quit(), QWidget::close()
4639 */
4640
4641void QApplication::setQuitOnLastWindowClosed(bool quit)
4642{
4643 QApplicationPrivate::quitOnLastWindowClosed = quit;
4644}
4645
4646bool QApplication::quitOnLastWindowClosed()
4647{
4648 return QApplicationPrivate::quitOnLastWindowClosed;
4649}
4650
4651void QApplicationPrivate::emitLastWindowClosed()
4652{
4653 if (qApp && qApp->d_func()->in_exec) {
4654 if (QApplicationPrivate::quitOnLastWindowClosed) {
4655 // get ready to quit, this event might be removed if the
4656 // event loop is re-entered, however
4657 QApplication::postEvent(qApp, new QEvent(QEvent::Quit));
4658 }
4659 emit qApp->lastWindowClosed();
4660 }
4661}
4662
4663/*! \variable QApplication::NormalColors
4664 \compat
4665
4666 Use \l NormalColor instead.
4667*/
4668
4669/*! \variable QApplication::CustomColors
4670 \compat
4671
4672 Use \l CustomColor instead.
4673*/
4674
4675#ifdef QT_KEYPAD_NAVIGATION
4676/*!
4677 Sets whether Qt should use focus navigation suitable for use with a
4678 minimal keypad.
4679
4680 If \a enable is true, Qt::Key_Up and Qt::Key_Down are used to change focus.
4681
4682 This feature is available in Qt for Embedded Linux only.
4683
4684 \sa keypadNavigationEnabled()
4685*/
4686void QApplication::setKeypadNavigationEnabled(bool enable)
4687{
4688 QApplicationPrivate::keypadNavigation = enable;
4689}
4690
4691/*!
4692 Returns true if Qt is set to use keypad navigation; otherwise returns
4693 false. The default is false.
4694
4695 This feature is available in Qt for Embedded Linux only.
4696
4697 \sa setKeypadNavigationEnabled()
4698*/
4699bool QApplication::keypadNavigationEnabled()
4700{
4701 return QApplicationPrivate::keypadNavigation;
4702}
4703#endif
4704
4705/*!
4706 \fn void QApplication::alert(QWidget *widget, int msec)
4707 \since 4.3
4708
4709 Causes an alert to be shown for \a widget if the window is not the active
4710 window. The alert is shown for \a msec miliseconds. If \a msec is zero (the
4711 default), then the alert is shown indefinitely until the window becomes
4712 active again.
4713
4714 Currently this function does nothing on Qt for Embedded Linux.
4715
4716 On Mac OS X, this works more at the application level and will cause the
4717 application icon to bounce in the dock.
4718
4719 On Windows this causes the window's taskbar entry to flash for a time. If
4720 \a msec is zero, the flashing will stop and the taskbar entry will turn a
4721 different color (currently orange).
4722
4723 On X11, this will cause the window to be marked as "demands attention", the
4724 window must not be hidden (i.e. not have hide() called on it, but be
4725 visible in some sort of way) in order for this to work.
4726*/
4727
4728/*!
4729 \property QApplication::cursorFlashTime
4730 \brief the text cursor's flash (blink) time in milliseconds
4731
4732 The flash time is the time required to display, invert and restore the
4733 caret display. Usually the text cursor is displayed for half the cursor
4734 flash time, then hidden for the same amount of time, but this may vary.
4735
4736 The default value on X11 is 1000 milliseconds. On Windows, the control
4737 panel value is used. Widgets should not cache this value since it may be
4738 changed at any time by the user changing the global desktop settings.
4739
4740 \note On Microsoft Windows, setting this property sets the cursor flash
4741 time for all applications.
4742*/
4743
4744/*!
4745 \property QApplication::doubleClickInterval
4746 \brief the time limit in milliseconds that distinguishes a double click from two
4747 consecutive mouse clicks
4748
4749 The default value on X11 is 400 milliseconds. On Windows and Mac OS X, the
4750 operating system's value is used.
4751
4752 On Microsoft Windows, calling this function sets the double click interval
4753 for all applications.
4754*/
4755
4756/*!
4757 \property QApplication::keyboardInputInterval
4758 \brief the time limit in milliseconds that distinguishes a key press
4759 from two consecutive key presses
4760 \since 4.2
4761
4762 The default value on X11 is 400 milliseconds. On Windows and Mac OS X, the
4763 operating system's value is used.
4764*/
4765
4766/*!
4767 \property QApplication::wheelScrollLines
4768 \brief the number of lines to scroll a widget, when the
4769 mouse wheel is rotated.
4770
4771 If the value exceeds the widget's number of visible lines, the widget
4772 should interpret the scroll operation as a single \e{page up} or
4773 \e{page down}. If the widget is an \l{QAbstractItemView}{item view class},
4774 then the result of scrolling one \e line depends on the setting of the
4775 widget's \l{QAbstractItemView::verticalScrollMode()}{scroll mode}. Scroll
4776 one \e line can mean \l{QAbstractItemView::ScrollPerItem}{scroll one item}
4777 or \l{QAbstractItemView::ScrollPerPixel}{scroll one pixel}.
4778
4779 By default, this property has a value of 3.
4780*/
4781
4782/*!
4783 \fn void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
4784
4785 Enables the UI effect \a effect if \a enable is true, otherwise the effect
4786 will not be used.
4787
4788 \note All effects are disabled on screens running at less than 16-bit color
4789 depth.
4790
4791 \sa isEffectEnabled(), Qt::UIEffect, setDesktopSettingsAware()
4792*/
4793
4794/*!
4795 \fn bool QApplication::isEffectEnabled(Qt::UIEffect effect)
4796
4797 Returns true if \a effect is enabled; otherwise returns false.
4798
4799 By default, Qt will try to use the desktop settings. To prevent this, call
4800 setDesktopSettingsAware(false).
4801
4802 \note All effects are disabled on screens running at less than 16-bit color
4803 depth.
4804
4805 \sa setEffectEnabled(), Qt::UIEffect
4806*/
4807
4808/*!
4809 \fn QWidget *QApplication::mainWidget()
4810
4811 Returns the main application widget, or 0 if there is no main widget.
4812*/
4813
4814/*!
4815 \fn void QApplication::setMainWidget(QWidget *mainWidget)
4816
4817 Sets the application's main widget to \a mainWidget.
4818
4819 In most respects the main widget is like any other widget, except that if
4820 it is closed, the application exits. QApplication does \e not take
4821 ownership of the \a mainWidget, so if you create your main widget on the
4822 heap you must delete it yourself.
4823
4824 You need not have a main widget; connecting lastWindowClosed() to quit()
4825 is an alternative.
4826
4827 For X11, this function also resizes and moves the main widget according
4828 to the \e -geometry command-line option, so you should set the default
4829 geometry (using \l QWidget::setGeometry()) before calling setMainWidget().
4830
4831 \sa mainWidget(), exec(), quit()
4832*/
4833
4834/*!
4835 \fn void QApplication::beep()
4836
4837 Sounds the bell, using the default volume and sound. The function is \e not
4838 available in Qt for Embedded Linux.
4839*/
4840
4841/*!
4842 \fn void QApplication::setOverrideCursor(const QCursor &cursor)
4843
4844 Sets the application override cursor to \a cursor.
4845
4846 Application override cursors are intended for showing the user that the
4847 application is in a special state, for example during an operation that
4848 might take some time.
4849
4850 This cursor will be displayed in all the application's widgets until
4851 restoreOverrideCursor() or another setOverrideCursor() is called.
4852
4853 Application cursors are stored on an internal stack. setOverrideCursor()
4854 pushes the cursor onto the stack, and restoreOverrideCursor() pops the
4855 active cursor off the stack. changeOverrideCursor() changes the curently
4856 active application override cursor. Every setOverrideCursor() must
4857 eventually be followed by a corresponding restoreOverrideCursor(),
4858 otherwise the stack will never be emptied.
4859
4860 Example:
4861 \snippet doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp 0
4862
4863 \sa overrideCursor(), restoreOverrideCursor(), changeOverrideCursor(),
4864 QWidget::setCursor()
4865*/
4866
4867/*!
4868 \fn void QApplication::restoreOverrideCursor()
4869
4870 Undoes the last setOverrideCursor().
4871
4872 If setOverrideCursor() has been called twice, calling
4873 restoreOverrideCursor() will activate the first cursor set. Calling this
4874 function a second time restores the original widgets' cursors.
4875
4876 \sa setOverrideCursor(), overrideCursor()
4877*/
4878
4879/*!
4880 \macro qApp
4881 \relates QApplication
4882
4883 A global pointer referring to the unique application object. It is
4884 equivalent to the pointer returned by the QCoreApplication::instance()
4885 function except that, in GUI applications, it is a pointer to a
4886 QApplication instance.
4887
4888 Only one application object can be created.
4889
4890 \sa QCoreApplication::instance()
4891*/
4892
4893// ************************************************************************
4894// Input Method support
4895// ************************************************************************
4896
4897/*!
4898 This function replaces the QInputContext instance used by the application
4899 with \a inputContext.
4900
4901 \sa inputContext()
4902*/
4903void QApplication::setInputContext(QInputContext *inputContext)
4904{
4905 Q_D(QApplication);
4906 Q_UNUSED(d);// only static members being used.
4907 if (!inputContext) {
4908 qWarning("QApplication::setInputContext: called with 0 input context");
4909 return;
4910 }
4911 if (d->inputContext)
4912 delete d->inputContext;
4913 d->inputContext = inputContext;
4914}
4915
4916/*!
4917 Returns the QInputContext instance used by the application.
4918
4919 \sa setInputContext()
4920*/
4921QInputContext *QApplication::inputContext() const
4922{
4923 Q_D(const QApplication);
4924 Q_UNUSED(d);// only static members being used.
4925#ifdef Q_WS_X11
4926 if (!X11)
4927 return 0;
4928 if (!d->inputContext) {
4929 QApplication *that = const_cast<QApplication *>(this);
4930 QInputContext *qic = QInputContextFactory::create(X11->default_im, that);
4931 // fallback to default X Input Method.
4932 if (!qic)
4933 qic = QInputContextFactory::create(QLatin1String("xim"), that);
4934 that->d_func()->inputContext = qic;
4935 }
4936#endif
4937 return d->inputContext;
4938}
4939
4940//Returns the current platform used by keyBindings
4941uint QApplicationPrivate::currentPlatform(){
4942 uint platform = KB_Win;
4943#ifdef Q_WS_MAC
4944 platform = KB_Mac;
4945#elif defined Q_WS_X11
4946 platform = KB_X11;
4947 if (X11->desktopEnvironment == DE_KDE)
4948 platform |= KB_KDE;
4949 if (X11->desktopEnvironment == DE_GNOME)
4950 platform |= KB_Gnome;
4951 if (X11->desktopEnvironment == DE_CDE)
4952 platform |= KB_CDE;
4953#endif
4954 return platform;
4955}
4956
4957bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
4958{
4959 return QCoreApplication::sendSpontaneousEvent(receiver, event);
4960}
4961
4962
4963/*!
4964 \since 4.2
4965
4966 Returns the current keyboard input locale.
4967*/
4968QLocale QApplication::keyboardInputLocale()
4969{
4970 if (!QApplicationPrivate::checkInstance("keyboardInputLocale"))
4971 return QLocale::c();
4972 return qt_keymapper_private()->keyboardInputLocale;
4973}
4974
4975/*!
4976 \since 4.2
4977
4978 Returns the current keyboard input direction.
4979*/
4980Qt::LayoutDirection QApplication::keyboardInputDirection()
4981{
4982 if (!QApplicationPrivate::checkInstance("keyboardInputDirection"))
4983 return Qt::LeftToRight;
4984 return qt_keymapper_private()->keyboardInputDirection;
4985}
4986
4987bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
4988{
4989 QWidget *f = w;
4990 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
4991 f = f->d_func()->extra->focus_proxy;
4992
4993 if ((w->focusPolicy() & policy) != policy)
4994 return false;
4995 if (w != f && (f->focusPolicy() & policy) != policy)
4996 return false;
4997 return true;
4998}
4999
5000QT_END_NAMESPACE
5001
5002#include "moc_qapplication.cpp"
Note: See TracBrowser for help on using the repository browser.