Qt 4.8
qapplication.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
63 
64 #if defined(Q_OS_SYMBIAN)
65 class CApaApplication;
66 #endif
67 
69 
70 QT_MODULE(Gui)
71 
72 class QSessionManager;
73 class QDesktopWidget;
74 class QStyle;
75 class QEventLoop;
76 class QIcon;
77 #ifndef QT_NO_IM
78 class QInputContext;
79 #endif
80 template <typename T> class QList;
81 class QLocale;
82 #if defined(Q_WS_QWS)
83 class QDecoration;
84 #elif defined(Q_WS_QPA)
86 #endif
87 #if defined(Q_OS_SYMBIAN)
88 class QSymbianEvent;
89 #endif
90 
91 class QApplication;
93 #if defined(qApp)
94 #undef qApp
95 #endif
96 #define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
97 
98 
100 {
101  Q_OBJECT
107 #ifndef QT_NO_WHEELEVENT
109 #endif
114 #ifndef QT_NO_STYLE_STYLESHEET
116 #endif
117 #ifdef Q_WS_WINCE
119 #endif
121 
122 public:
123  enum Type { Tty, GuiClient, GuiServer };
124 
125 #ifdef Q_OS_SYMBIAN
126  typedef CApaApplication * (*QS60MainApplicationFactory)();
127 #endif
128 
129 #ifndef qdoc
130  QApplication(int &argc, char **argv, int = ApplicationFlags);
131  QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags);
132  QApplication(int &argc, char **argv, Type, int = ApplicationFlags);
133 #if defined(Q_WS_X11)
134  QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = ApplicationFlags);
135  QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = ApplicationFlags);
136 #endif
137 #if defined(Q_OS_SYMBIAN)
138  QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv, int = ApplicationFlags);
139 #endif
140 #endif
141  virtual ~QApplication();
142 
143  static Type type();
144 
145  static QStyle *style();
146  static void setStyle(QStyle*);
147  static QStyle *setStyle(const QString&);
148  enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
149  static int colorSpec();
150  static void setColorSpec(int);
151  static void setGraphicsSystem(const QString &);
152 
153 #ifndef QT_NO_CURSOR
154  static QCursor *overrideCursor();
155  static void setOverrideCursor(const QCursor &);
156  static void changeOverrideCursor(const QCursor &);
157  static void restoreOverrideCursor();
158 #endif
159  static QPalette palette();
160  static QPalette palette(const QWidget *);
161  static QPalette palette(const char *className);
162  static void setPalette(const QPalette &, const char* className = 0);
163  static QFont font();
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();
168 
169  static void setWindowIcon(const QIcon &icon);
170  static QIcon windowIcon();
171 
172 
173 #ifdef QT3_SUPPORT
174  static QT3_SUPPORT QWidget *mainWidget();
175  static QT3_SUPPORT void setMainWidget(QWidget *);
176 #endif
177 
178  static QWidgetList allWidgets();
179  static QWidgetList topLevelWidgets();
180 
181  static QDesktopWidget *desktop();
182 
183  static QWidget *activePopupWidget();
184  static QWidget *activeModalWidget();
185 #ifndef QT_NO_CLIPBOARD
186  static QClipboard *clipboard();
187 #endif
188  static QWidget *focusWidget();
189 
190  static QWidget *activeWindow();
191  static void setActiveWindow(QWidget* act);
192 
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)); }
197 
198  static void syncX();
199  static void beep();
200  static void alert(QWidget *widget, int duration = 0);
201 
202  static Qt::KeyboardModifiers keyboardModifiers();
203  static Qt::KeyboardModifiers queryKeyboardModifiers();
204  static Qt::MouseButtons mouseButtons();
205 
206  static void setDesktopSettingsAware(bool);
207  static bool desktopSettingsAware();
208 
209  static void setCursorFlashTime(int);
210  static int cursorFlashTime();
211 
212  static void setDoubleClickInterval(int);
213  static int doubleClickInterval();
214 
215  static void setKeyboardInputInterval(int);
216  static int keyboardInputInterval();
217 
218 #ifndef QT_NO_WHEELEVENT
219  static void setWheelScrollLines(int);
220  static int wheelScrollLines();
221 #endif
222  static void setGlobalStrut(const QSize &);
223  static QSize globalStrut();
224 
225  static void setStartDragTime(int ms);
226  static int startDragTime();
227  static void setStartDragDistance(int l);
228  static int startDragDistance();
229 
230  static void setLayoutDirection(Qt::LayoutDirection direction);
231  static Qt::LayoutDirection layoutDirection();
232 
233  static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
234  static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
235 
236  static bool isEffectEnabled(Qt::UIEffect);
237  static void setEffectEnabled(Qt::UIEffect, bool enable = true);
238 
239 #if defined(Q_WS_MAC)
240  virtual bool macEventFilter(EventHandlerCallRef, EventRef);
241 #endif
242 #if defined(Q_WS_X11)
243  virtual bool x11EventFilter(XEvent *);
244  virtual int x11ClientMessage(QWidget*, XEvent*, bool passive_only);
245  int x11ProcessEvent(XEvent*);
246 #endif
247 #if defined(Q_OS_SYMBIAN)
248  int symbianProcessEvent(const QSymbianEvent *event);
249  virtual bool symbianEventFilter(const QSymbianEvent *event);
250 #endif
251 #if defined(Q_WS_QWS)
252  virtual bool qwsEventFilter(QWSEvent *);
253  int qwsProcessEvent(QWSEvent*);
254  void qwsSetCustomColors(QRgb *colortable, int start, int numColors);
255 #ifndef QT_NO_QWS_MANAGER
256  static QDecoration &qwsDecoration();
257  static void qwsSetDecoration(QDecoration *);
258  static QDecoration *qwsSetDecoration(const QString &decoration);
259 #endif
260 #endif
261 
262 #if defined(Q_WS_QPA)
263  static QPlatformNativeInterface *platformNativeInterface();
264 #endif
265 
266 
267 #if defined(Q_WS_WIN)
268  void winFocus(QWidget *, bool);
269  static void winMouseButtonUp();
270 #endif
271 #ifndef QT_NO_SESSIONMANAGER
272  // session management
273  bool isSessionRestored() const;
274  QString sessionId() const;
275  QString sessionKey() const;
276  virtual void commitData(QSessionManager& sm);
277  virtual void saveState(QSessionManager& sm);
278 #endif
279 
280 #ifndef QT_NO_IM
281  void setInputContext(QInputContext *);
282  QInputContext *inputContext() const;
283 #endif
284 
285  static QLocale keyboardInputLocale();
286  static Qt::LayoutDirection keyboardInputDirection();
287 
288  static int exec();
289  bool notify(QObject *, QEvent *);
290 
291 
292  static void setQuitOnLastWindowClosed(bool quit);
293  static bool quitOnLastWindowClosed();
294 
295 #ifdef QT_KEYPAD_NAVIGATION
296  static Q_DECL_DEPRECATED void setKeypadNavigationEnabled(bool);
297  static bool keypadNavigationEnabled();
298  static void setNavigationMode(Qt::NavigationMode mode);
299  static Qt::NavigationMode navigationMode();
300 #endif
301 
302 Q_SIGNALS:
303  void lastWindowClosed();
304  void focusChanged(QWidget *old, QWidget *now);
305  void fontDatabaseChanged();
306 #ifndef QT_NO_SESSIONMANAGER
307  void commitDataRequest(QSessionManager &sessionManager);
308  void saveStateRequest(QSessionManager &sessionManager);
309 #endif
310 #ifdef Q_OS_SYMBIAN
311  void aboutToReleaseGpuResources();
312  void aboutToUseGpuResources();
313 #endif
314 
315 public:
316  QString styleSheet() const;
317 public Q_SLOTS:
318 #ifndef QT_NO_STYLE_STYLESHEET
319  void setStyleSheet(const QString& sheet);
320 #endif
321 #ifdef Q_WS_WINCE
322  void setAutoMaximizeThreshold(const int threshold);
323  int autoMaximizeThreshold() const;
324 #endif
325  void setAutoSipEnabled(const bool enabled);
326  bool autoSipEnabled() const;
327  static void closeAllWindows();
328  static void aboutQt();
329 
330 protected:
331 #if defined(Q_WS_QWS)
332  void setArgs(int, char **);
333 #endif
334  bool event(QEvent *);
335  bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
336 
337 public:
338 #ifdef QT3_SUPPORT
339  static inline QT3_SUPPORT void setReverseLayout(bool b) { setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight); }
340  static inline bool QT3_SUPPORT reverseLayout() { return layoutDirection() == Qt::RightToLeft; }
341  static QT3_SUPPORT Qt::Alignment horizontalAlignment(Qt::Alignment align);
342  typedef int ColorMode;
343  enum { NormalColors = NormalColor, CustomColors = CustomColor };
344  static inline QT3_SUPPORT ColorMode colorMode() { return static_cast<ColorMode>(colorSpec()); }
345  static inline QT3_SUPPORT void setColorMode(ColorMode mode) { setColorSpec(int(mode)); }
346 #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
347  static QT3_SUPPORT Qt::WindowsVersion winVersion() { return (Qt::WindowsVersion)QSysInfo::WindowsVersion; }
348 #endif
349 #if defined(Q_OS_MAC)
350  static QT3_SUPPORT Qt::MacintoshVersion macVersion() { return (Qt::MacintoshVersion)QSysInfo::MacintoshVersion; }
351 #endif
352 # ifndef QT_NO_CURSOR
353  inline static QT3_SUPPORT void setOverrideCursor(const QCursor &cursor, bool replace)
354  { if (replace) changeOverrideCursor(cursor); else setOverrideCursor(cursor); }
355 # endif
356  inline static QT3_SUPPORT bool hasGlobalMouseTracking() {return true;}
357  inline static QT3_SUPPORT void setGlobalMouseTracking(bool) {}
358  inline static QT3_SUPPORT void flushX() { flush(); }
359  static inline QT3_SUPPORT void setWinStyleHighlightColor(const QColor &c) {
360  QPalette p(palette());
362  setPalette(p);
363  }
364  static inline QT3_SUPPORT const QColor &winStyleHighlightColor()
365  { return palette().color(QPalette::Active, QPalette::Highlight); }
366  static inline QT3_SUPPORT void setPalette(const QPalette &pal, bool, const char* className = 0)
367  { setPalette(pal, className); }
368  static inline QT3_SUPPORT void setFont(const QFont &font, bool, const char* className = 0)
369  { setFont(font, className); }
370 
371  static inline QT3_SUPPORT QWidget *widgetAt(int x, int y, bool child)
372  { QWidget *w = widgetAt(x, y); return child ? w : (w ? w->window() : 0); }
373  static inline QT3_SUPPORT QWidget *widgetAt(const QPoint &p, bool child)
374  { QWidget *w = widgetAt(p); return child ? w : (w ? w->window() : 0); }
375 #endif // QT3_SUPPORT
376 
377 #if defined(Q_INTERNAL_QAPP_SRC) || defined(qdoc)
378  QApplication(int &argc, char **argv);
379  QApplication(int &argc, char **argv, bool GUIenabled);
380  QApplication(int &argc, char **argv, Type);
381 #if defined(Q_WS_X11)
382  QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0);
383  QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
384 #endif
385 #if defined(Q_OS_SYMBIAN) || defined(qdoc)
386  QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv);
387 #endif
388 #endif
389 
390 private:
391  Q_DISABLE_COPY(QApplication)
392  Q_DECLARE_PRIVATE(QApplication)
393 
398  friend class QWidget;
400  friend class QETWidget;
401  friend class Q3AccelManager;
404 #ifndef QT_NO_SHORTCUT
405  friend class QShortcut;
406  friend class QLineEdit;
407  friend class QTextControl;
408 #endif
409  friend class QAction;
410  friend class QFontDatabasePrivate;
411 
412 #if defined(Q_WS_QWS)
413  friend class QInputContext;
415  friend class QDirectPainter;
416  friend class QDirectPainterPrivate;
417 #endif
418 #ifndef QT_NO_GESTURES
419  friend class QGestureManager;
420 #endif
421 
422 #if defined(Q_WS_MAC) || defined(Q_WS_X11)
423  Q_PRIVATE_SLOT(d_func(), void _q_alertTimeOut())
424 #endif
425 #if defined(QT_RX71_MULTITOUCH)
426  Q_PRIVATE_SLOT(d_func(), void _q_readRX71MultiTouchEvents())
427 #endif
428 #if defined(Q_OS_SYMBIAN)
429  Q_PRIVATE_SLOT(d_func(), void _q_aboutToQuit())
430 #endif
431 };
432 
434 
436 
437 #endif // QAPPLICATION_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static QWaylandClipboard * clipboard
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
unsigned int QRgb
Definition: qrgb.h:53
static QWidgetList topLevelWidgets()
int type
Definition: qmetatype.cpp:239
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
unsigned char c[8]
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
bool autoSipEnabled
toggles automatic SIP (software input panel) visibility
Definition: qapplication.h:120
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
static int exec()
Enters the main event loop and waits until exit() is called.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
friend class QApplication
static QColor cmap[256]
Definition: qgl_mac.mm:760
ColorSpec
See setColorSpec() for full details.
Definition: qapplication.h:148
QIcon windowIcon
the default window icon
Definition: qapplication.h:103
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
static QWidget * topLevelAt(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qapplication.h:196
#define Q_SLOTS
Definition: qobjectdefs.h:71
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
The QDirectPainter class provides direct access to the underlying hardware in Qt for Embedded Linux...
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QSysInfo::MacVersion macVersion()
Use QSysInfo::MacintoshVersion instead.
Definition: qglobal.cpp:2077
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *)
Returns true if event was compressed away (possibly deleted) and should not be added to the list...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
const char * className
Definition: qwizard.cpp:137
The QShortcut class is used to create keyboard shortcuts.
Definition: qshortcut.h:57
The QDecoration class is a base class for window decorations in Qt for Embedded Linux.
union _XEvent XEvent
Definition: qwindowdefs.h:116
The QWSEvent class encapsulates an event in Qt for Embedded Linux.
Definition: qwsevent_qws.h:59
virtual bool notify(QObject *, QEvent *)
Sends event to receiver: {receiver}->event(event).
The QSessionManager class provides access to the session manager.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
static bool isLeftToRight()
Returns true if the application&#39;s layout direction is Qt::LeftToRight; otherwise returns false...
Definition: qapplication.h:234
Qt::LayoutDirection layoutDirection
the default layout direction for this application
Definition: qapplication.h:102
LayoutDirection
Definition: qnamespace.h:1580
QString styleSheet
the application style sheet
Definition: qapplication.h:115
The QClipboard class provides access to the window system clipboard.
Definition: qclipboard.h:62
static QWidget * widgetAt(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qapplication.h:194
UIEffect
Definition: qnamespace.h:1252
void * HANDLE
Definition: qnamespace.h:1671
QSize globalStrut
the minimum size that any GUI element that the user can interact with should have ...
Definition: qapplication.h:110
#define Q_OBJECT
Definition: qobjectdefs.h:157
struct OpaqueEventRef * EventRef
NavigationMode
Definition: qnamespace.h:1781
The QTranslator class provides internationalization support for text output.
Definition: qtranslator.h:59
struct _XDisplay Display
Definition: qwindowdefs.h:115
The QCoreApplication class provides an event loop for console Qt applications.
int startDragTime
the time in milliseconds that a mouse button must be held down before a drag and drop operation will ...
Definition: qapplication.h:111
int keyboardInputInterval
the time limit in milliseconds that distinguishes a key press from two consecutive key presses ...
Definition: qapplication.h:106
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static bool x11EventFilter(void *message, long *result)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
QFactoryLoader * l
int cursorFlashTime
the text cursor&#39;s flash (blink) time in milliseconds
Definition: qapplication.h:104
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
int wheelScrollLines
the number of lines to scroll a widget, when the mouse wheel is rotated.
Definition: qapplication.h:108
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
int startDragDistance
If you support drag and drop in your application, and want to start a drag and drop operation after t...
Definition: qapplication.h:112
bool quitOnLastWindowClosed
whether the application implicitly quits when the last window is closed.
Definition: qapplication.h:113
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
int doubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks ...
Definition: qapplication.h:105
#define class
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
static bool isRightToLeft()
Returns true if the application&#39;s layout direction is Qt::RightToLeft; otherwise returns false...
Definition: qapplication.h:233
int autoMaximizeThreshold
defines a threshold for auto maximizing widgets
Definition: qapplication.h:118
#define enabled
#define Q_DECL_DEPRECATED
Definition: qglobal.h:1058
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
static void flush()
Flushes the platform specific event queues.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Qt::LayoutDirection direction
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60