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