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

Last change on this file since 95 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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