src/gui/kernel/qapplication.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QAPPLICATION_H
00025 #define QAPPLICATION_H
00026 
00027 #include <QtCore/qcoreapplication.h>
00028 #include <QtGui/qwindowdefs.h>
00029 #include <QtCore/qpoint.h>
00030 #include <QtCore/qsize.h>
00031 #include <QtGui/qcursor.h>
00032 #ifdef QT_INCLUDE_COMPAT
00033 # include <QtGui/qdesktopwidget.h>
00034 #endif
00035 #ifdef QT3_SUPPORT
00036 # include <QtGui/qwidget.h>
00037 # include <QtGui/qpalette.h>
00038 #endif
00039 #ifdef Q_WS_QWS
00040 # include <QtGui/qrgb.h>
00041 # include <QtGui/qtransportauth_qws.h>
00042 #endif
00043 
00044 QT_BEGIN_HEADER
00045 
00046 QT_MODULE(Gui)
00047 
00048 class QSessionManager;
00049 class QDesktopWidget;
00050 class QStyle;
00051 class QEventLoop;
00052 class QIcon;
00053 class QInputContext;
00054 template <typename T> class QList;
00055 class QLocale;
00056 #if defined(Q_WS_QWS)
00057 class QDecoration;
00058 #endif
00059 
00060 class QApplication;
00061 class QApplicationPrivate;
00062 #define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
00063 
00064 class Q_GUI_EXPORT QApplication : public QCoreApplication
00065 {
00066     Q_OBJECT
00067     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
00068     Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
00069     Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
00070     Q_PROPERTY(int doubleClickInterval  READ doubleClickInterval WRITE setDoubleClickInterval)
00071     Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
00072 #ifndef QT_NO_WHEELEVENT
00073     Q_PROPERTY(int wheelScrollLines  READ wheelScrollLines WRITE setWheelScrollLines)
00074 #endif
00075     Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut)
00076     Q_PROPERTY(int startDragTime  READ startDragTime WRITE setStartDragTime)
00077     Q_PROPERTY(int startDragDistance  READ startDragDistance WRITE setStartDragDistance)
00078     Q_PROPERTY(bool quitOnLastWindowClosed  READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
00079 #ifndef QT_NO_STYLE_STYLESHEET
00080     Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
00081 #endif
00082 
00083 public:
00084     enum Type { Tty, GuiClient, GuiServer };
00085 #ifndef qdoc
00086     QApplication(int &argc, char **argv, int = QT_VERSION);
00087     QApplication(int &argc, char **argv, bool GUIenabled, int = QT_VERSION);
00088     QApplication(int &argc, char **argv, Type, int = QT_VERSION);
00089 #if defined(Q_WS_X11)
00090     QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = QT_VERSION);
00091     QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = QT_VERSION);
00092 #endif
00093 #endif
00094     virtual ~QApplication();
00095 
00096     static Type type();
00097 
00098     static QStyle *style();
00099     static void setStyle(QStyle*);
00100     static QStyle *setStyle(const QString&);
00101     enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
00102     static int colorSpec();
00103     static void setColorSpec(int);
00104 
00105 #ifndef QT_NO_CURSOR
00106     static QCursor *overrideCursor();
00107     static void setOverrideCursor(const QCursor &);
00108     static void changeOverrideCursor(const QCursor &);
00109     static void restoreOverrideCursor();
00110 #endif
00111     static QPalette palette();
00112     static QPalette palette(const QWidget *);
00113     static QPalette palette(const char *className);
00114     static void setPalette(const QPalette &, const char* className = 0);
00115     static QFont font();
00116     static QFont font(const QWidget*);
00117     static QFont font(const char *className);
00118     static void setFont(const QFont &, const char* className = 0);
00119     static QFontMetrics fontMetrics();
00120 
00121     static void setWindowIcon(const QIcon &icon);
00122     static QIcon windowIcon();
00123 
00124 
00125 #ifdef QT3_SUPPORT
00126     static QT3_SUPPORT QWidget *mainWidget();
00127     static QT3_SUPPORT void setMainWidget(QWidget *);
00128 #endif
00129 
00130     static QWidgetList allWidgets();
00131     static QWidgetList topLevelWidgets();
00132 
00133     static QDesktopWidget *desktop();
00134 
00135     static QWidget *activePopupWidget();
00136     static QWidget *activeModalWidget();
00137 #ifndef QT_NO_CLIPBOARD
00138     static QClipboard *clipboard();
00139 #endif
00140     static QWidget *focusWidget();
00141 
00142     static QWidget *activeWindow();
00143     static void setActiveWindow(QWidget* act);
00144 
00145     static QWidget *widgetAt(const QPoint &p);
00146     static inline QWidget *widgetAt(int x, int y) { return widgetAt(QPoint(x, y)); }
00147     static QWidget *topLevelAt(const QPoint &p);
00148     static inline QWidget *topLevelAt(int x, int y)  { return topLevelAt(QPoint(x, y)); }
00149 
00150     static void syncX();
00151     static void beep();
00152 
00153     static Qt::KeyboardModifiers keyboardModifiers();
00154     static Qt::MouseButtons mouseButtons();
00155 
00156     static void setDesktopSettingsAware(bool);
00157     static bool desktopSettingsAware();
00158 
00159     static void setCursorFlashTime(int);
00160     static int cursorFlashTime();
00161 
00162     static void setDoubleClickInterval(int);
00163     static int doubleClickInterval();
00164 
00165     static void setKeyboardInputInterval(int);
00166     static int keyboardInputInterval();
00167 
00168 #ifndef QT_NO_WHEELEVENT
00169     static void setWheelScrollLines(int);
00170     static int wheelScrollLines();
00171 #endif
00172     static void setGlobalStrut(const QSize &);
00173     static QSize globalStrut();
00174 
00175     static void setStartDragTime(int ms);
00176     static int startDragTime();
00177     static void setStartDragDistance(int l);
00178     static int startDragDistance();
00179 
00180     static void setLayoutDirection(Qt::LayoutDirection direction);
00181     static Qt::LayoutDirection layoutDirection();
00182 
00183     static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
00184     static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
00185 
00186     static bool isEffectEnabled(Qt::UIEffect);
00187     static void setEffectEnabled(Qt::UIEffect, bool enable = true);
00188 
00189 #if defined(Q_WS_MAC)
00190     virtual bool macEventFilter(EventHandlerCallRef, EventRef);
00191 #endif
00192 #if defined(Q_WS_X11)
00193     virtual bool x11EventFilter(XEvent *);
00194     virtual int x11ClientMessage(QWidget*, XEvent*, bool passive_only);
00195     int x11ProcessEvent(XEvent*);
00196 #endif
00197 #if defined(Q_WS_QWS)
00198     virtual bool qwsEventFilter(QWSEvent *);
00199     int qwsProcessEvent(QWSEvent*);
00200     void qwsSetCustomColors(QRgb *colortable, int start, int numColors);
00201 #ifndef QT_NO_QWS_MANAGER
00202     static QDecoration &qwsDecoration();
00203     static void qwsSetDecoration(QDecoration *);
00204     static QDecoration *qwsSetDecoration(const QString &decoration);
00205 #endif
00206 #endif
00207 
00208 
00209 #if defined(Q_WS_WIN)
00210     void winFocus(QWidget *, bool);
00211     static void winMouseButtonUp();
00212 #endif
00213 
00214 #ifndef QT_NO_SESSIONMANAGER
00215     // session management
00216     bool isSessionRestored() const;
00217     QString sessionId() const;
00218     QString sessionKey() const;
00219     virtual void commitData(QSessionManager& sm);
00220     virtual void saveState(QSessionManager& sm);
00221 #endif
00222     void setInputContext(QInputContext *);
00223     QInputContext *inputContext() const;
00224 
00225     static QLocale keyboardInputLocale();
00226     static Qt::LayoutDirection keyboardInputDirection();
00227 
00228     static int exec();
00229     bool notify(QObject *, QEvent *);
00230 
00231 
00232     static void setQuitOnLastWindowClosed(bool quit);
00233     static bool quitOnLastWindowClosed();
00234 
00235 #ifdef QT_KEYPAD_NAVIGATION
00236     static void setKeypadNavigationEnabled(bool);
00237     static bool keypadNavigationEnabled();
00238 #endif
00239 
00240 Q_SIGNALS:
00241     void lastWindowClosed();
00242     void focusChanged(QWidget *old, QWidget *now);
00243 #ifndef QT_NO_SESSIONMANAGER
00244     void commitDataRequest(QSessionManager &sessionManager);
00245     void saveStateRequest(QSessionManager &sessionManager);
00246 #endif
00247 
00248 public:
00249     QString styleSheet() const;
00250 public Q_SLOTS:
00251 #ifndef QT_NO_STYLE_STYLESHEET
00252     void setStyleSheet(const QString& sheet);
00253 #endif
00254     static void closeAllWindows();
00255     static void aboutQt();
00256 
00257 protected:
00258 #if defined(Q_WS_QWS)
00259     void setArgs(int, char **);
00260 #endif
00261     bool event(QEvent *);
00262     bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
00263 
00264 #ifdef QT3_SUPPORT
00265 public:
00266     static inline QT3_SUPPORT void setReverseLayout(bool b) { setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight); }
00267     static inline bool QT3_SUPPORT reverseLayout() { return layoutDirection() == Qt::RightToLeft; }
00268     static QT3_SUPPORT Qt::Alignment horizontalAlignment(Qt::Alignment align);
00269     typedef int ColorMode;
00270     enum { NormalColors = NormalColor, CustomColors = CustomColor };
00271     static inline QT3_SUPPORT ColorMode colorMode() { return static_cast<ColorMode>(colorSpec()); }
00272     static inline QT3_SUPPORT void setColorMode(ColorMode mode) { setColorSpec(int(mode)); }
00273 #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
00274     static QT3_SUPPORT Qt::WindowsVersion winVersion() { return (Qt::WindowsVersion)QSysInfo::WindowsVersion; }
00275 #endif
00276 #if defined(Q_OS_MAC)
00277     static QT3_SUPPORT Qt::MacintoshVersion macVersion() { return (Qt::MacintoshVersion)QSysInfo::MacintoshVersion; }
00278 #endif
00279     inline static  QT3_SUPPORT void setOverrideCursor(const QCursor &cursor, bool replace)
00280         { if (replace) changeOverrideCursor(cursor); else setOverrideCursor(cursor); }
00281     inline static QT3_SUPPORT bool hasGlobalMouseTracking() {return true;}
00282     inline static QT3_SUPPORT void setGlobalMouseTracking(bool) {};
00283     inline static QT3_SUPPORT void flushX() { flush(); }
00284     static inline QT3_SUPPORT void setWinStyleHighlightColor(const QColor &c) {
00285         QPalette p(palette());
00286         p.setColor(QPalette::Highlight, c);
00287         setPalette(p);
00288     }
00289     static inline QT3_SUPPORT const QColor &winStyleHighlightColor()
00290         { return palette().color(QPalette::Active, QPalette::Highlight); }
00291     static inline QT3_SUPPORT void setPalette(const QPalette &pal, bool, const char* className = 0)
00292         { setPalette(pal, className); };
00293     static inline QT3_SUPPORT void setFont(const QFont &font, bool, const char* className = 0)
00294         { setFont(font, className); }
00295 
00296     static inline QT3_SUPPORT QWidget *widgetAt(int x, int y, bool child)
00297         { QWidget *w = widgetAt(x, y); return child ? w : (w ? w->window() : 0); }
00298     static inline QT3_SUPPORT QWidget *widgetAt(const QPoint &p, bool child)
00299         { QWidget *w = widgetAt(p); return child ? w : (w ? w->window() : 0); }
00300 #endif // QT3_SUPPORT
00301 
00302 #if defined(Q_INTERNAL_QAPP_SRC) || defined(qdoc)
00303     QApplication(int &argc, char **argv);
00304     QApplication(int &argc, char **argv, bool GUIenabled);
00305     QApplication(int &argc, char **argv, Type);
00306 #if defined(Q_WS_X11)
00307     QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0);
00308     QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
00309 #endif
00310 #endif
00311 
00312 private:
00313     Q_DISABLE_COPY(QApplication)
00314     Q_DECLARE_PRIVATE(QApplication)
00315 
00316     friend class QWidget;
00317     friend class QWidgetPrivate;
00318     friend class QETWidget;
00319     friend class Q3AccelManager;
00320     friend class QTranslator;
00321 #ifndef QT_NO_SHORTCUT
00322     friend class QShortcut;
00323 #endif
00324     friend class QAction;
00325 
00326 #if defined(Q_WS_QWS)
00327     friend class QInputContext;
00328     friend class QWSDirectPainterSurface;
00329     friend class QDirectPainter;
00330     friend class QDirectPainterPrivate;
00331 #endif
00332 
00333     Q_PRIVATE_SLOT(d_func(), void _q_tryEmitLastWindowClosed())
00334 };
00335 
00336 QT_END_HEADER
00337 
00338 #endif // QAPPLICATION_H

Generated on Thu Mar 15 11:55:03 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1