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

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

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

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