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

Last change on this file since 869 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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