1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QAPPLICATION_H
43 #define QAPPLICATION_H
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 <QtWidgets/qdesktopwidget.h>
54 # include <QtWidgets/qwidget.h>
55 # include <QtGui/qpalette.h>
58 # include <QtGui/qrgb.h>
59 # include <QtGui/qtransportauth_qws.h>
62 # include <QtGui/qguiapplication.h>
67 #if defined(Q_OS_SYMBIAN)
68 class CApaApplication;
75 class QSessionManager;
81 template <typename T> class QList;
85 #elif defined(Q_WS_QPA)
86 class QPlatformNativeInterface;
88 #if defined(Q_OS_SYMBIAN)
93 class QApplicationPrivate;
97 #define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
100 #define QApplicationBase QGuiApplication
102 #define QApplicationBase QCoreApplication
105 class Q_WIDGETS_EXPORT QApplication : public QApplicationBase
108 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
109 Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
110 Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
111 Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
112 #ifndef QT_NO_WHEELEVENT
113 Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines)
115 Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut)
116 Q_PROPERTY(int startDragTime READ startDragTime WRITE setStartDragTime)
117 Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance)
118 Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
119 #ifndef QT_NO_STYLE_STYLESHEET
120 Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
123 Q_PROPERTY(int autoMaximizeThreshold READ autoMaximizeThreshold WRITE setAutoMaximizeThreshold)
125 Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
128 enum Type { Tty, GuiClient, GuiServer };
131 typedef CApaApplication * (*QS60MainApplicationFactory)();
135 QApplication(int &argc, char **argv, int = ApplicationFlags);
136 QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags);
137 QApplication(int &argc, char **argv, Type, int = ApplicationFlags);
138 #if defined(Q_WS_X11)
139 QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = ApplicationFlags);
140 QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = ApplicationFlags);
142 #if defined(Q_OS_SYMBIAN)
143 QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv, int = ApplicationFlags);
146 virtual ~QApplication();
150 static QStyle *style();
151 static void setStyle(QStyle*);
152 static QStyle *setStyle(const QString&);
153 enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
154 static int colorSpec();
155 static void setColorSpec(int);
156 // ### Qt4 compatibility, remove?
157 static inline void setGraphicsSystem(const QString &) {}
159 using QGuiApplication::palette;
160 static QPalette palette(const QWidget *);
161 static QPalette palette(const char *className);
162 static void setPalette(const QPalette &, const char* className = 0);
164 static QFont font(const QWidget*);
165 static QFont font(const char *className);
166 static void setFont(const QFont &, const char* className = 0);
167 static QFontMetrics fontMetrics();
169 static void setWindowIcon(const QIcon &icon);
170 static QIcon windowIcon();
174 static QT3_SUPPORT QWidget *mainWidget();
175 static QT3_SUPPORT void setMainWidget(QWidget *);
178 static QWidgetList allWidgets();
179 static QWidgetList topLevelWidgets();
181 static QDesktopWidget *desktop();
183 static QWidget *activePopupWidget();
184 static QWidget *activeModalWidget();
185 #if !defined(Q_WS_QPA) && !defined(QT_NO_CLIPBOARD)
186 static QClipboard *clipboard();
188 static QWidget *focusWidget();
190 static QWidget *activeWindow();
191 static void setActiveWindow(QWidget* act);
193 static QWidget *widgetAt(const QPoint &p);
194 static inline QWidget *widgetAt(int x, int y) { return widgetAt(QPoint(x, y)); }
195 static QWidget *topLevelAt(const QPoint &p);
196 static inline QWidget *topLevelAt(int x, int y) { return topLevelAt(QPoint(x, y)); }
200 static void alert(QWidget *widget, int duration = 0);
202 static Qt::KeyboardModifiers keyboardModifiers();
203 static Qt::KeyboardModifiers queryKeyboardModifiers();
204 static Qt::MouseButtons mouseButtons();
206 static void setDesktopSettingsAware(bool);
207 static bool desktopSettingsAware();
209 static void setCursorFlashTime(int);
210 static int cursorFlashTime();
212 static void setDoubleClickInterval(int);
213 static int doubleClickInterval();
215 static void setKeyboardInputInterval(int);
216 static int keyboardInputInterval();
218 #ifndef QT_NO_WHEELEVENT
219 static void setWheelScrollLines(int);
220 static int wheelScrollLines();
222 static void setGlobalStrut(const QSize &);
223 static QSize globalStrut();
225 static void setStartDragTime(int ms);
226 static int startDragTime();
227 static void setStartDragDistance(int l);
228 static int startDragDistance();
230 static bool isEffectEnabled(Qt::UIEffect);
231 static void setEffectEnabled(Qt::UIEffect, bool enable = true);
233 #if defined(Q_WS_MAC)
234 virtual bool macEventFilter(EventHandlerCallRef, EventRef);
236 #if defined(Q_WS_X11)
237 virtual bool x11EventFilter(XEvent *);
238 virtual int x11ClientMessage(QWidget*, XEvent*, bool passive_only);
239 int x11ProcessEvent(XEvent*);
241 #if defined(Q_OS_SYMBIAN)
242 int symbianProcessEvent(const QSymbianEvent *event);
243 virtual bool symbianEventFilter(const QSymbianEvent *event);
245 #if defined(Q_WS_QWS)
246 virtual bool qwsEventFilter(QWSEvent *);
247 int qwsProcessEvent(QWSEvent*);
248 void qwsSetCustomColors(QRgb *colortable, int start, int numColors);
249 #ifndef QT_NO_QWS_MANAGER
250 static QDecoration &qwsDecoration();
251 static void qwsSetDecoration(QDecoration *);
252 static QDecoration *qwsSetDecoration(const QString &decoration);
256 #if defined(Q_WS_QPA)
257 static QPlatformNativeInterface *platformNativeInterface();
261 #if defined(Q_WS_WIN)
262 void winFocus(QWidget *, bool);
263 static void winMouseButtonUp();
265 #ifndef QT_NO_SESSIONMANAGER
266 // session management
267 bool isSessionRestored() const;
268 QString sessionId() const;
269 QString sessionKey() const;
270 virtual void commitData(QSessionManager& sm);
271 virtual void saveState(QSessionManager& sm);
275 void setInputContext(QInputContext *);
276 QInputContext *inputContext() const;
280 bool notify(QObject *, QEvent *);
283 static void setQuitOnLastWindowClosed(bool quit);
284 static bool quitOnLastWindowClosed();
286 #ifdef QT_KEYPAD_NAVIGATION
287 static Q_DECL_DEPRECATED void setKeypadNavigationEnabled(bool);
288 static bool keypadNavigationEnabled();
289 static void setNavigationMode(Qt::NavigationMode mode);
290 static Qt::NavigationMode navigationMode();
294 void lastWindowClosed();
295 void focusChanged(QWidget *old, QWidget *now);
296 #ifndef QT_NO_SESSIONMANAGER
297 void commitDataRequest(QSessionManager &sessionManager);
298 void saveStateRequest(QSessionManager &sessionManager);
302 QString styleSheet() const;
304 #ifndef QT_NO_STYLE_STYLESHEET
305 void setStyleSheet(const QString& sheet);
308 void setAutoMaximizeThreshold(const int threshold);
309 int autoMaximizeThreshold() const;
311 void setAutoSipEnabled(const bool enabled);
312 bool autoSipEnabled() const;
313 static void closeAllWindows();
314 static void aboutQt();
317 #if defined(Q_WS_QWS)
318 void setArgs(int, char **);
320 bool event(QEvent *);
321 bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
325 static inline QT3_SUPPORT void setReverseLayout(bool b) { setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight); }
326 static inline bool QT3_SUPPORT reverseLayout() { return layoutDirection() == Qt::RightToLeft; }
327 static QT3_SUPPORT Qt::Alignment horizontalAlignment(Qt::Alignment align);
328 typedef int ColorMode;
329 enum { NormalColors = NormalColor, CustomColors = CustomColor };
330 static inline QT3_SUPPORT ColorMode colorMode() { return static_cast<ColorMode>(colorSpec()); }
331 static inline QT3_SUPPORT void setColorMode(ColorMode mode) { setColorSpec(int(mode)); }
332 #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
333 static QT3_SUPPORT Qt::WindowsVersion winVersion() { return (Qt::WindowsVersion)QSysInfo::WindowsVersion; }
335 #if defined(Q_OS_MAC)
336 static QT3_SUPPORT Qt::MacintoshVersion macVersion() { return (Qt::MacintoshVersion)QSysInfo::MacintoshVersion; }
338 # ifndef QT_NO_CURSOR
339 inline static QT3_SUPPORT void setOverrideCursor(const QCursor &cursor, bool replace)
340 { if (replace) changeOverrideCursor(cursor); else setOverrideCursor(cursor); }
342 inline static QT3_SUPPORT bool hasGlobalMouseTracking() {return true;}
343 inline static QT3_SUPPORT void setGlobalMouseTracking(bool) {}
344 inline static QT3_SUPPORT void flushX() { flush(); }
345 static inline QT3_SUPPORT void setWinStyleHighlightColor(const QColor &c) {
346 QPalette p(palette());
347 p.setColor(QPalette::Highlight, c);
350 static inline QT3_SUPPORT const QColor &winStyleHighlightColor()
351 { return palette().color(QPalette::Active, QPalette::Highlight); }
352 static inline QT3_SUPPORT void setPalette(const QPalette &pal, bool, const char* className = 0)
353 { setPalette(pal, className); }
354 static inline QT3_SUPPORT void setFont(const QFont &font, bool, const char* className = 0)
355 { setFont(font, className); }
357 static inline QT3_SUPPORT QWidget *widgetAt(int x, int y, bool child)
358 { QWidget *w = widgetAt(x, y); return child ? w : (w ? w->window() : 0); }
359 static inline QT3_SUPPORT QWidget *widgetAt(const QPoint &p, bool child)
360 { QWidget *w = widgetAt(p); return child ? w : (w ? w->window() : 0); }
361 #endif // QT3_SUPPORT
363 #if defined(Q_INTERNAL_QAPP_SRC) || defined(qdoc)
364 QApplication(int &argc, char **argv);
365 QApplication(int &argc, char **argv, bool GUIenabled);
366 QApplication(int &argc, char **argv, Type);
367 #if defined(Q_WS_X11)
368 QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0);
369 QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
371 #if defined(Q_OS_SYMBIAN) || defined(qdoc)
372 QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv);
377 Q_DISABLE_COPY(QApplication)
378 Q_DECLARE_PRIVATE(QApplication)
380 friend class QGraphicsWidget;
381 friend class QGraphicsItem;
382 friend class QGraphicsScene;
383 friend class QGraphicsScenePrivate;
384 friend class QWidget;
385 friend class QWidgetPrivate;
386 friend class QWidgetWindow;
387 friend class QETWidget;
388 friend class Q3AccelManager;
389 friend class QTranslator;
390 friend class QWidgetAnimator;
391 #ifndef QT_NO_SHORTCUT
392 friend class QShortcut;
393 friend class QLineEdit;
394 friend class QWidgetTextControl;
396 friend class QAction;
398 #if defined(Q_WS_QWS)
399 friend class QInputContext;
400 friend class QWSDirectPainterSurface;
401 friend class QDirectPainter;
402 friend class QDirectPainterPrivate;
404 #ifndef QT_NO_GESTURES
405 friend class QGestureManager;
408 #if defined(Q_WS_MAC) || defined(Q_WS_X11)
409 Q_PRIVATE_SLOT(d_func(), void _q_alertTimeOut())
411 #if defined(QT_RX71_MULTITOUCH)
412 Q_PRIVATE_SLOT(d_func(), void _q_readRX71MultiTouchEvents())
414 #if defined(Q_OS_SYMBIAN)
415 Q_PRIVATE_SLOT(d_func(), void _q_aboutToQuit())
423 #endif // QAPPLICATION_H