1/****************************************************************************
2**
3** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** GNU Lesser General Public License Usage
10** This file may be used under the terms of the GNU Lesser General Public
11** License version 2.1 as published by the Free Software Foundation and
12** appearing in the file LICENSE.LGPL included in the packaging of this
13** file. Please review the following information to ensure the GNU Lesser
14** General Public License version 2.1 requirements will be met:
15** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16**
17** In addition, as a special exception, Nokia gives you certain additional
18** rights. These rights are described in the Nokia Qt LGPL Exception
19** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20**
21** GNU General Public License Usage
22** Alternatively, this file may be used under the terms of the GNU General
23** Public License version 3.0 as published by the Free Software Foundation
24** and appearing in the file LICENSE.GPL included in the packaging of this
25** file. Please review the following information to ensure the GNU General
26** Public License version 3.0 requirements will be met:
27** http://www.gnu.org/copyleft/gpl.html.
28**
29** Other Usage
30** Alternatively, this file may be used in accordance with the terms and
31** conditions contained in a signed written agreement between you and Nokia.
32**
33**
34**
35**
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QAPPLICATION_H
43#define QAPPLICATION_H
44
45#include <QtCore/qcoreapplication.h>
46#include <QtGui/qwindowdefs.h>
47#include <QtCore/qpoint.h>
48#include <QtCore/qsize.h>
49#include <QtGui/qcursor.h>
50#ifdef QT_INCLUDE_COMPAT
51# include <QtGui/qdesktopwidget.h>
52#endif
53#ifdef QT3_SUPPORT
54# include <QtGui/qwidget.h>
55# include <QtGui/qpalette.h>
56#endif
57#ifdef Q_WS_QWS
58# include <QtGui/qrgb.h>
59# include <QtGui/qtransportauth_qws.h>
60#endif
61
62QT_BEGIN_HEADER
63
64#if defined(Q_OS_SYMBIAN)
65class CApaApplication;
66#endif
67
68QT_BEGIN_NAMESPACE
69
70QT_MODULE(Gui)
71
72class QSessionManager;
73class QDesktopWidget;
74class QStyle;
75class QEventLoop;
76class QIcon;
77class QInputContext;
78template <typename T> class QList;
79class QLocale;
80#if defined(Q_WS_QWS)
81class QDecoration;
82#elif defined(Q_WS_QPA)
83class QPlatformNativeInterface;
84#endif
85#if defined(Q_OS_SYMBIAN)
86class QSymbianEvent;
87#endif
88
89class QApplication;
90class QApplicationPrivate;
91#if defined(qApp)
92#undef qApp
93#endif
94#define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
95
96
97class Q_GUI_EXPORT QApplication : public QCoreApplication
98{
99 Q_OBJECT
100 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
101 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
102 Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
103 Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
104 Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
105#ifndef QT_NO_WHEELEVENT
106 Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines)
107#endif
108 Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut)
109 Q_PROPERTY(int startDragTime READ startDragTime WRITE setStartDragTime)
110 Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance)
111 Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
112#ifndef QT_NO_STYLE_STYLESHEET
113 Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
114#endif
115#ifdef Q_WS_WINCE
116 Q_PROPERTY(int autoMaximizeThreshold READ autoMaximizeThreshold WRITE setAutoMaximizeThreshold)
117#endif
118 Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
119
120public:
121 enum Type { Tty, GuiClient, GuiServer };
122
123#ifdef Q_OS_SYMBIAN
124 typedef CApaApplication * (*QS60MainApplicationFactory)();
125#endif
126
127#ifndef qdoc
128 QApplication(int &argc, char **argv, int = ApplicationFlags);
129 QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags);
130 QApplication(int &argc, char **argv, Type, int = ApplicationFlags);
131#if defined(Q_WS_X11)
132 QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = ApplicationFlags);
133 QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = ApplicationFlags);
134#endif
135#if defined(Q_OS_SYMBIAN)
136 QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv, int = ApplicationFlags);
137#endif
138#endif
139 virtual ~QApplication();
140
141 static Type type();
142
143 static QStyle *style();
144 static void setStyle(QStyle*);
145 static QStyle *setStyle(const QString&);
146 enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
147 static int colorSpec();
148 static void setColorSpec(int);
149 static void setGraphicsSystem(const QString &);
150
151#ifndef QT_NO_CURSOR
152 static QCursor *overrideCursor();
153 static void setOverrideCursor(const QCursor &);
154 static void changeOverrideCursor(const QCursor &);
155 static void restoreOverrideCursor();
156#endif
157 static QPalette palette();
158 static QPalette palette(const QWidget *);
159 static QPalette palette(const char *className);
160 static void setPalette(const QPalette &, const char* className = 0);
161 static QFont font();
162 static QFont font(const QWidget*);
163 static QFont font(const char *className);
164 static void setFont(const QFont &, const char* className = 0);
165 static QFontMetrics fontMetrics();
166
167 static void setWindowIcon(const QIcon &icon);
168 static QIcon windowIcon();
169
170
171#ifdef QT3_SUPPORT
172 static QT3_SUPPORT QWidget *mainWidget();
173 static QT3_SUPPORT void setMainWidget(QWidget *);
174#endif
175
176 static QWidgetList allWidgets();
177 static QWidgetList topLevelWidgets();
178
179 static QDesktopWidget *desktop();
180
181 static QWidget *activePopupWidget();
182 static QWidget *activeModalWidget();
183#ifndef QT_NO_CLIPBOARD
184 static QClipboard *clipboard();
185#endif
186 static QWidget *focusWidget();
187
188 static QWidget *activeWindow();
189 static void setActiveWindow(QWidget* act);
190
191 static QWidget *widgetAt(const QPoint &p);
192 static inline QWidget *widgetAt(int x, int y) { return widgetAt(QPoint(x, y)); }
193 static QWidget *topLevelAt(const QPoint &p);
194 static inline QWidget *topLevelAt(int x, int y) { return topLevelAt(QPoint(x, y)); }
195
196 static void syncX();
197 static void beep();
198 static void alert(QWidget *widget, int duration = 0);
199
200 static Qt::KeyboardModifiers keyboardModifiers();
201 static Qt::KeyboardModifiers queryKeyboardModifiers();
202 static Qt::MouseButtons mouseButtons();
203
204 static void setDesktopSettingsAware(bool);
205 static bool desktopSettingsAware();
206
207 static void setCursorFlashTime(int);
208 static int cursorFlashTime();
209
210 static void setDoubleClickInterval(int);
211 static int doubleClickInterval();
212
213 static void setKeyboardInputInterval(int);
214 static int keyboardInputInterval();
215
216#ifndef QT_NO_WHEELEVENT
217 static void setWheelScrollLines(int);
218 static int wheelScrollLines();
219#endif
220 static void setGlobalStrut(const QSize &);
221 static QSize globalStrut();
222
223 static void setStartDragTime(int ms);
224 static int startDragTime();
225 static void setStartDragDistance(int l);
226 static int startDragDistance();
227
228 static void setLayoutDirection(Qt::LayoutDirection direction);
229 static Qt::LayoutDirection layoutDirection();
230
231 static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
232 static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
233
234 static bool isEffectEnabled(Qt::UIEffect);
235 static void setEffectEnabled(Qt::UIEffect, bool enable = true);
236
237#if defined(Q_WS_MAC)
238 virtual bool macEventFilter(EventHandlerCallRef, EventRef);
239#endif
240#if defined(Q_WS_X11)
241 virtual bool x11EventFilter(XEvent *);
242 virtual int x11ClientMessage(QWidget*, XEvent*, bool passive_only);
243 int x11ProcessEvent(XEvent*);
244#endif
245#if defined(Q_OS_SYMBIAN)
246 int symbianProcessEvent(const QSymbianEvent *event);
247 virtual bool symbianEventFilter(const QSymbianEvent *event);
248#endif
249#if defined(Q_WS_QWS)
250 virtual bool qwsEventFilter(QWSEvent *);
251 int qwsProcessEvent(QWSEvent*);
252 void qwsSetCustomColors(QRgb *colortable, int start, int numColors);
253#ifndef QT_NO_QWS_MANAGER
254 static QDecoration &qwsDecoration();
255 static void qwsSetDecoration(QDecoration *);
256 static QDecoration *qwsSetDecoration(const QString &decoration);
257#endif
258#endif
259
260#if defined(Q_WS_QPA)
261 static QPlatformNativeInterface *platformNativeInterface();
262#endif
263
264
265#if defined(Q_WS_WIN)
266 void winFocus(QWidget *, bool);
267 static void winMouseButtonUp();
268#endif
269#ifndef QT_NO_SESSIONMANAGER
270 // session management
271 bool isSessionRestored() const;
272 QString sessionId() const;
273 QString sessionKey() const;
274 virtual void commitData(QSessionManager& sm);
275 virtual void saveState(QSessionManager& sm);
276#endif
277
278#ifndef QT_NO_IM
279 void setInputContext(QInputContext *);
280 QInputContext *inputContext() const;
281#endif
282
283 static QLocale keyboardInputLocale();
284 static Qt::LayoutDirection keyboardInputDirection();
285
286 static int exec();
287 bool notify(QObject *, QEvent *);
288
289
290 static void setQuitOnLastWindowClosed(bool quit);
291 static bool quitOnLastWindowClosed();
292
293#ifdef QT_KEYPAD_NAVIGATION
294 static Q_DECL_DEPRECATED void setKeypadNavigationEnabled(bool);
295 static bool keypadNavigationEnabled();
296 static void setNavigationMode(Qt::NavigationMode mode);
297 static Qt::NavigationMode navigationMode();
298#endif
299
300Q_SIGNALS:
301 void lastWindowClosed();
302 void focusChanged(QWidget *old, QWidget *now);
303 void fontDatabaseChanged();
304#ifndef QT_NO_SESSIONMANAGER
305 void commitDataRequest(QSessionManager &sessionManager);
306 void saveStateRequest(QSessionManager &sessionManager);
307#endif
308#ifdef Q_OS_SYMBIAN
309 void aboutToReleaseGpuResources();
310 void aboutToUseGpuResources();
311#endif
312
313public:
314 QString styleSheet() const;
315public Q_SLOTS:
316#ifndef QT_NO_STYLE_STYLESHEET
317 void setStyleSheet(const QString& sheet);
318#endif
319#ifdef Q_WS_WINCE
320 void setAutoMaximizeThreshold(const int threshold);
321 int autoMaximizeThreshold() const;
322#endif
323 void setAutoSipEnabled(const bool enabled);
324 bool autoSipEnabled() const;
325 static void closeAllWindows();
326 static void aboutQt();
327
328protected:
329#if defined(Q_WS_QWS)
330 void setArgs(int, char **);
331#endif
332 bool event(QEvent *);
333 bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
334
335#ifdef QT3_SUPPORT
336public:
337 static inline QT3_SUPPORT void setReverseLayout(bool b) { setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight); }
338 static inline bool QT3_SUPPORT reverseLayout() { return layoutDirection() == Qt::RightToLeft; }
339 static QT3_SUPPORT Qt::Alignment horizontalAlignment(Qt::Alignment align);
340 typedef int ColorMode;
341 enum { NormalColors = NormalColor, CustomColors = CustomColor };
342 static inline QT3_SUPPORT ColorMode colorMode() { return static_cast<ColorMode>(colorSpec()); }
343 static inline QT3_SUPPORT void setColorMode(ColorMode mode) { setColorSpec(int(mode)); }
344#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
345 static QT3_SUPPORT Qt::WindowsVersion winVersion() { return (Qt::WindowsVersion)QSysInfo::WindowsVersion; }
346#endif
347#if defined(Q_OS_MAC)
348 static QT3_SUPPORT Qt::MacintoshVersion macVersion() { return (Qt::MacintoshVersion)QSysInfo::MacintoshVersion; }
349#endif
350# ifndef QT_NO_CURSOR
351 inline static QT3_SUPPORT void setOverrideCursor(const QCursor &cursor, bool replace)
352 { if (replace) changeOverrideCursor(cursor); else setOverrideCursor(cursor); }
353# endif
354 inline static QT3_SUPPORT bool hasGlobalMouseTracking() {return true;}
355 inline static QT3_SUPPORT void setGlobalMouseTracking(bool) {}
356 inline static QT3_SUPPORT void flushX() { flush(); }
357 static inline QT3_SUPPORT void setWinStyleHighlightColor(const QColor &c) {
358 QPalette p(palette());
359 p.setColor(QPalette::Highlight, c);
360 setPalette(p);
361 }
362 static inline QT3_SUPPORT const QColor &winStyleHighlightColor()
363 { return palette().color(QPalette::Active, QPalette::Highlight); }
364 static inline QT3_SUPPORT void setPalette(const QPalette &pal, bool, const char* className = 0)
365 { setPalette(pal, className); }
366 static inline QT3_SUPPORT void setFont(const QFont &font, bool, const char* className = 0)
367 { setFont(font, className); }
368
369 static inline QT3_SUPPORT QWidget *widgetAt(int x, int y, bool child)
370 { QWidget *w = widgetAt(x, y); return child ? w : (w ? w->window() : 0); }
371 static inline QT3_SUPPORT QWidget *widgetAt(const QPoint &p, bool child)
372 { QWidget *w = widgetAt(p); return child ? w : (w ? w->window() : 0); }
373#endif // QT3_SUPPORT
374
375#if defined(Q_INTERNAL_QAPP_SRC) || defined(qdoc)
376 QApplication(int &argc, char **argv);
377 QApplication(int &argc, char **argv, bool GUIenabled);
378 QApplication(int &argc, char **argv, Type);
379#if defined(Q_WS_X11)
380 QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0);
381 QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
382#endif
383#if defined(Q_OS_SYMBIAN) || defined(qdoc)
384 QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv);
385#endif
386#endif
387
388private:
389 Q_DISABLE_COPY(QApplication)
390 Q_DECLARE_PRIVATE(QApplication)
391
392 friend class QGraphicsWidget;
393 friend class QGraphicsItem;
394 friend class QGraphicsScene;
395 friend class QGraphicsScenePrivate;
396 friend class QWidget;
397 friend class QWidgetPrivate;
398 friend class QETWidget;
399 friend class Q3AccelManager;
400 friend class QTranslator;
401 friend class QWidgetAnimator;
402#ifndef QT_NO_SHORTCUT
403 friend class QShortcut;
404 friend class QLineEdit;
405 friend class QTextControl;
406#endif
407 friend class QAction;
408 friend class QFontDatabasePrivate;
409
410#if defined(Q_WS_QWS)
411 friend class QInputContext;
412 friend class QWSDirectPainterSurface;
413 friend class QDirectPainter;
414 friend class QDirectPainterPrivate;
415#endif
416#ifndef QT_NO_GESTURES
417 friend class QGestureManager;
418#endif
419
420#if defined(Q_WS_MAC) || defined(Q_WS_X11)
421 Q_PRIVATE_SLOT(d_func(), void _q_alertTimeOut())
422#endif
423#if defined(QT_RX71_MULTITOUCH)
424 Q_PRIVATE_SLOT(d_func(), void _q_readRX71MultiTouchEvents())
425#endif
426#if defined(Q_OS_SYMBIAN)
427 Q_PRIVATE_SLOT(d_func(), void _q_aboutToQuit())
428#endif
429};
430
431QT_END_NAMESPACE
432
433QT_END_HEADER
434
435#endif // QAPPLICATION_H
436