Eneboo - Documentación para desarrolladores
src/qt/src/kernel/qapplication.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qapplication.h   3.3.8   edited Jan 16 10:54 $
00003 **
00004 ** Definition of QApplication class
00005 **
00006 ** Created : 931107
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QAPPLICATION_H
00039 #define QAPPLICATION_H
00040 
00041 #ifndef QT_H
00042 #include "qdesktopwidget.h"
00043 #include "qasciidict.h"
00044 #include "qpalette.h"
00045 #include "qtranslator.h"
00046 #include "qstrlist.h"
00047 #include "qstringlist.h"
00048 #endif // QT_H
00049 
00050 // ### AbanQ
00051 class FLApplication;
00052 // ###
00053 
00054 class QSessionManager;
00055 class QStyle;
00056 class QTranslator;
00057 class QEventLoop;
00058 #if defined(Q_WS_QWS)
00059 class QWSDecoration;
00060 #endif
00061 
00062 #ifdef QT_THREAD_SUPPORT
00063 class QMutex;
00064 #endif // QT_THREAD_SUPPORT
00065 
00066 
00067 class QApplication;
00068 extern Q_EXPORT QApplication *qApp;             // global application object
00069 
00070 
00071 class Q_EXPORT QApplication : public QObject
00072 {
00073     Q_OBJECT
00074 public:
00075     QApplication( int &argc, char **argv );
00076     QApplication( int &argc, char **argv, bool GUIenabled );
00077     enum Type { Tty, GuiClient, GuiServer };
00078     QApplication( int &argc, char **argv, Type );
00079 #if defined(Q_WS_X11)
00080     QApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
00081     QApplication( Display *dpy, int argc, char **argv,
00082                   HANDLE visual = 0, HANDLE cmap= 0 );
00083 #endif
00084     virtual ~QApplication();
00085 
00086     int             argc()      const;
00087     char          **argv()      const;
00088 
00089     Type type() const;
00090 
00091 #ifndef QT_NO_STYLE
00092     static QStyle  &style();
00093     static void     setStyle( QStyle* );
00094     static QStyle*  setStyle( const QString& );
00095 #endif
00096 #ifndef Q_QDOC
00097     enum ColorMode { NormalColors, CustomColors };
00098     static ColorMode colorMode();
00099     static void      setColorMode( QApplication::ColorMode );
00100 #endif
00101 
00102     enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
00103     static int       colorSpec();
00104     static void      setColorSpec( int );
00105 #ifndef QT_NO_CURSOR
00106     static QCursor  *overrideCursor();
00107     static void      setOverrideCursor( const QCursor &, bool replace=FALSE );
00108     static void      restoreOverrideCursor();
00109 #endif
00110     static bool      hasGlobalMouseTracking();
00111     static void      setGlobalMouseTracking( bool enable );
00112 #ifndef QT_NO_PALETTE
00113     static QPalette  palette( const QWidget* = 0 );
00114     static void      setPalette( const QPalette &, bool informWidgets=FALSE,
00115                                  const char* className = 0 );
00116 #endif
00117     static QFont     font( const QWidget* = 0 );
00118     static void      setFont( const QFont &, bool informWidgets=FALSE,
00119                               const char* className = 0 );
00120     static QFontMetrics fontMetrics();
00121 
00122     QWidget         *mainWidget()  const;
00123     virtual void     setMainWidget( QWidget * );
00124     virtual void     polish( QWidget * );
00125 
00126     static QWidgetList *allWidgets();
00127     static QWidgetList *topLevelWidgets();
00128 
00129     static QDesktopWidget   *desktop();
00130 
00131     static QWidget     *activePopupWidget();
00132     static QWidget     *activeModalWidget();
00133 #ifndef QT_NO_CLIPBOARD
00134     static QClipboard  *clipboard();
00135 #endif
00136     QWidget            *focusWidget() const;
00137     QWidget            *activeWindow() const;
00138 
00139     static QWidget  *widgetAt( int x, int y, bool child=FALSE );
00140     static QWidget  *widgetAt( const QPoint &, bool child=FALSE );
00141 
00142     static QEventLoop *eventLoop();
00143 
00144     int              exec();
00145     void             processEvents();
00146     void             processEvents( int maxtime );
00147     void             processOneEvent();
00148     bool             hasPendingEvents();
00149     int              enter_loop();
00150     void             exit_loop();
00151     int              loopLevel() const;
00152     static void      exit( int retcode=0 );
00153 
00154     static bool      sendEvent( QObject *receiver, QEvent *event );
00155     static void      postEvent( QObject *receiver, QEvent *event );
00156     static void      sendPostedEvents( QObject *receiver, int event_type );
00157     static void      sendPostedEvents();
00158 
00159     static void      removePostedEvents( QObject *receiver );
00160 
00161     virtual bool     notify( QObject *, QEvent * );
00162 
00163     static bool      startingUp();
00164     static bool      closingDown();
00165 
00166     static void      flushX();
00167     static void flush();
00168     static void      syncX();
00169 
00170     static void      beep();
00171 
00172 #ifndef QT_NO_TRANSLATION
00173 # ifndef QT_NO_TEXTCODEC
00174     void             setDefaultCodec( QTextCodec * );
00175     QTextCodec*      defaultCodec() const;
00176 # endif
00177     void             installTranslator( QTranslator * );
00178     void             removeTranslator( QTranslator * );
00179 #endif
00180     enum Encoding { DefaultCodec, UnicodeUTF8 };
00181     // ### AbanQ
00182     virtual
00183     // ###
00184     QString          translate( const char * context,
00185                                 const char * key,
00186                                 const char * comment = 0,
00187                                 Encoding encoding = DefaultCodec ) const;
00188 #ifndef QT_NO_DIR
00189     QString   applicationDirPath();
00190     QString   applicationFilePath();
00191 #endif
00192 #ifndef QT_NO_PALETTE
00193     // obsolete functions
00194     static void      setWinStyleHighlightColor( const QColor &c ) {
00195         QPalette p( palette() );
00196         p.setColor( QColorGroup::Highlight, c );
00197         setPalette( p, TRUE);
00198     }
00199     static const QColor &winStyleHighlightColor() {
00200         return palette().active().highlight();
00201     }
00202 #endif
00203     static void      setDesktopSettingsAware( bool );
00204     static bool      desktopSettingsAware();
00205 
00206     static void      setCursorFlashTime( int );
00207     static int       cursorFlashTime();
00208 
00209     static void      setDoubleClickInterval( int );
00210     static int       doubleClickInterval();
00211 #ifndef QT_NO_WHEELEVENT
00212     static void      setWheelScrollLines( int );
00213     static int       wheelScrollLines();
00214 #endif
00215     static void      setGlobalStrut( const QSize & );
00216 #ifdef QT_NO_INLINE_GLOBALSTRUT
00217     static QSize                 &globalStrut();
00218 #else 
00219     static QSize     globalStrut();
00220 #endif 
00221 
00222 #ifndef QT_NO_COMPONENT
00223     static void      setLibraryPaths( const QStringList & );
00224     static QStringList libraryPaths();
00225     static void      addLibraryPath( const QString & );
00226     static void      removeLibraryPath( const QString & );
00227 #endif // QT_NO_COMPONENT
00228     static void setStartDragTime( int ms );
00229     static int startDragTime();
00230     static void setStartDragDistance( int l );
00231     static int startDragDistance();
00232 
00233     static void setReverseLayout( bool b );
00234     static bool reverseLayout();
00235 
00236     static int horizontalAlignment( int align );
00237 
00238     static bool     isEffectEnabled( Qt::UIEffect );
00239     static void     setEffectEnabled( Qt::UIEffect, bool enable = TRUE );
00240 
00241 #if defined(Q_WS_MAC)
00242     virtual bool     macEventFilter( EventHandlerCallRef, EventRef );
00243 #endif
00244 #if defined(Q_WS_WIN)
00245     virtual bool     winEventFilter( MSG * );
00246 #endif
00247 #if defined(Q_WS_X11)
00248     virtual bool     x11EventFilter( XEvent * );
00249     virtual int      x11ClientMessage( QWidget*, XEvent*, bool passive_only);
00250     int              x11ProcessEvent( XEvent* );
00251 #endif
00252 #if defined(Q_WS_QWS)
00253     virtual bool     qwsEventFilter( QWSEvent * );
00254     int              qwsProcessEvent( QWSEvent* );
00255     void             qwsSetCustomColors( QRgb *colortable, int start, int numColors );
00260     bool          qwsIsGUIServer();
00261 #ifndef QT_NO_QWS_MANAGER
00262     static QWSDecoration &qwsDecoration();
00263     static void      qwsSetDecoration( QWSDecoration *);
00264 #endif
00265 #endif
00266 
00267 #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
00268     static WindowsVersion winVersion();
00269 #elif defined(Q_OS_MAC)
00270     static MacintoshVersion macVersion();
00271 #endif
00272 #if defined(Q_WS_WIN)
00273     void             winFocus( QWidget *, bool );
00274     static void      winMouseButtonUp();
00275 #endif
00276 
00277 #ifndef QT_NO_SESSIONMANAGER
00278     // session management
00279     bool             isSessionRestored() const;
00280     QString     sessionId() const;
00281     QString     sessionKey() const;
00282     virtual void     commitData( QSessionManager& sm );
00283     virtual void     saveState( QSessionManager& sm );
00284 #endif
00285 #if defined(Q_WS_X11)
00286     static void create_xim();
00287     static void close_xim();
00288     static bool x11_apply_settings();
00289 #endif
00290     void             wakeUpGuiThread();
00291 #if defined(QT_THREAD_SUPPORT)
00292     void             lock();
00293     void             unlock(bool wakeUpGui = TRUE);
00294     bool             locked();
00295     bool             tryLock();
00296 #endif
00297 
00298 signals:
00299     void             lastWindowClosed();
00300     void             aboutToQuit();
00301     void             guiThreadAwake();
00302 
00303 public slots:
00304     void             quit();
00305     void             closeAllWindows();
00306     void             aboutQt();
00307 
00308 #if defined(Q_WS_QWS)
00309 protected:
00310     void setArgs(int, char **);
00311 #endif
00312 
00313 protected:
00314     bool event(QEvent *);
00315 
00316 private:
00317     void construct( int &argc, char **argv, Type );
00318     void initialize( int, char ** );
00319     void init_precmdline();
00320     void process_cmdline( int* argcptr, char ** argv );
00321     bool internalNotify( QObject *, QEvent * );
00322 #if defined(Q_WS_QWS)
00323     static QWidget *findChildWidget( const QWidget *p, const QPoint &pos );
00324     static QWidget *findWidget( const QObjectList&, const QPoint &, bool rec );
00325 #endif
00326 
00327 #if defined(Q_WS_MAC)
00328     bool do_mouse_down(Point *, bool *);
00329     static QMAC_PASCAL OSStatus globalEventProcessor(EventHandlerCallRef,  EventRef, void *);
00330     static QMAC_PASCAL OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
00331     static QMAC_PASCAL void qt_context_timer_callbk(EventLoopTimerRef, void *);
00332     static QMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
00333     static bool qt_mac_apply_settings();
00334     friend class QMacInputMethod;
00335     friend QMAC_PASCAL OSStatus qt_window_event(EventHandlerCallRef, EventRef, void *);
00336     friend void qt_mac_update_os_settings();
00337     friend bool qt_set_socket_handler( int, int, QObject *, bool);
00338     friend void qt_mac_destroy_widget(QWidget *);
00339     friend void qt_init(int *, char **, QApplication::Type);
00340 #endif
00341 
00342 #ifdef QT_THREAD_SUPPORT
00343     static QMutex   *qt_mutex;
00344 #endif // QT_THREAD_SUPPORT
00345 
00346     int              app_argc;
00347     char           **app_argv;
00348     bool             quit_now;
00349     int              quit_code;
00350     static QStyle   *app_style;
00351     static int       app_cspec;
00352 #ifndef QT_NO_PALETTE
00353     static QPalette *app_pal;
00354 #endif
00355     static QFont    *app_font;
00356 #ifndef QT_NO_CURSOR
00357     static QCursor  *app_cursor;
00358 #endif
00359     static QEventLoop* eventloop;
00360     static int       app_tracking;
00361     static bool      is_app_running;
00362     static bool      is_app_closing;
00363     static bool      app_exit_loop;
00364     static int       loop_level;
00365     static QWidget  *main_widget;
00366     static QWidget  *focus_widget;
00367     static QWidget  *active_window;
00368     static bool      obey_desktop_settings;
00369     static int       cursor_flash_time;
00370     static int       mouse_double_click_time;
00371     static int       wheel_scroll_lines;
00372     static int       composedUnicode; // Value, meta-composed character
00373 
00374     static bool      animate_ui;
00375     static bool      animate_menu;
00376     static bool      animate_tooltip;
00377     static bool      animate_combo;
00378     static bool      fade_menu;
00379     static bool      fade_tooltip;
00380     static bool      animate_toolbox;
00381     static bool      widgetCount; // Coupled with -widgetcount switch
00382     static bool      metaComposeUnicode;
00383 
00384     QValueList<QTranslator*> *translators;
00385 #ifndef QT_NO_SESSIONMANAGER
00386     QSessionManager *session_manager;
00387     QString          session_id;
00388     static QString* session_key;
00389     bool             is_session_restored;
00390 #endif
00391 #if defined(Q_WS_X11) && !defined (QT_NO_STYLE )
00392     static void x11_initialize_style();
00393 #endif
00394 
00395     static QSize     app_strut;
00396 #ifndef QT_NO_COMPONENT
00397     static QStringList *app_libpaths;
00398 #endif
00399     static QAsciiDict<QPalette> *app_palettes;
00400     static QAsciiDict<QFont>    *app_fonts;
00401 
00402     static QWidgetList *popupWidgets;
00403     bool             inPopupMode() const;
00404     void             closePopup( QWidget *popup );
00405     void             openPopup( QWidget *popup );
00406     void             setActiveWindow( QWidget* act );
00407 
00408     static bool      sendSpontaneousEvent( QObject *receiver, QEvent *event );
00409     static void      removePostedEvent( QEvent * );
00410 
00411     // ### AbanQ
00412     friend class FLApplication;
00413     // ###
00414     
00415     friend class QWidget;
00416     friend class QETWidget;
00417     friend class QDialog;
00418     friend class QAccelManager;
00419     friend class QEvent;
00420     friend class QTranslator;
00421     friend class QEventLoop;
00422     friend Q_EXPORT void qt_ucm_initialize( QApplication * );
00423 #if defined(Q_WS_WIN)
00424     friend bool qt_sendSpontaneousEvent( QObject*, QEvent* );
00425 #endif
00426 #if defined(Q_WS_QWS)
00427     friend class QInputContext;
00428 #endif
00429 private: // Disabled copy constructor and operator=
00430 #if defined(Q_DISABLE_COPY)
00431     QApplication( const QApplication & );
00432     QApplication &operator=( const QApplication & );
00433 #endif
00434 };
00435 
00436 inline int QApplication::argc() const
00437 {
00438     return app_argc;
00439 }
00440 
00441 inline char **QApplication::argv() const
00442 {
00443     return app_argv;
00444 }
00445 
00446 #if defined(Q_WS_QWS)
00447 inline void QApplication::setArgs(int c, char **v)
00448 {
00449         app_argc = c;
00450             app_argv = v;
00451 }
00452 #endif
00453 
00454 #ifndef QT_NO_CURSOR
00455 inline QCursor *QApplication::overrideCursor()
00456 {
00457     return app_cursor;
00458 }
00459 #endif
00460 inline bool QApplication::hasGlobalMouseTracking()
00461 {
00462     return app_tracking > 0;
00463 }
00464 
00465 inline QWidget *QApplication::mainWidget() const
00466 {
00467     return main_widget;
00468 }
00469 
00470 inline QWidget *QApplication::focusWidget() const
00471 {
00472     return focus_widget;
00473 }
00474 
00475 inline QWidget *QApplication::activeWindow() const
00476 {
00477     return active_window;
00478 }
00479 
00480 inline QWidget *QApplication::widgetAt( const QPoint &p, bool child )
00481 {
00482     return widgetAt( p.x(), p.y(), child );
00483 }
00484 
00485 inline bool QApplication::inPopupMode() const
00486 {
00487     return popupWidgets != 0;
00488 }
00489 #ifndef QT_NO_SESSIONMANAGER
00490 inline bool QApplication::isSessionRestored() const
00491 {
00492     return is_session_restored;
00493 }
00494 
00495 inline QString QApplication::sessionId() const
00496 {
00497     return session_id;
00498 }
00499 
00500 inline QString QApplication::sessionKey() const
00501 {
00502     return session_key ? *session_key : QString::null;
00503 }
00504 #endif
00505 #ifndef QT_NO_INLINE_GLOBALSTRUT
00506 inline QSize QApplication::globalStrut()
00507 {
00508     return app_strut;
00509 }
00510 #endif 
00511 
00512 inline bool QApplication::sendEvent( QObject *receiver, QEvent *event )
00513 {  if ( event ) event->spont = FALSE; return qApp ? qApp->notify( receiver, event ) : FALSE; }
00514 
00515 inline bool QApplication::sendSpontaneousEvent( QObject *receiver, QEvent *event )
00516 { if ( event ) event->spont = TRUE; return qApp ? qApp->notify( receiver, event ) : FALSE; }
00517 
00518 #ifdef QT_NO_TRANSLATION
00519 // Simple versions
00520 inline QString QApplication::translate( const char *, const char *sourceText,
00521                                         const char *, Encoding encoding ) const
00522 {
00523 #ifndef QT_NO_TEXTCODEC
00524     if ( encoding == UnicodeUTF8 )
00525         return QString::fromUtf8( sourceText );
00526     else
00527 #endif
00528         return QString::fromLatin1( sourceText );
00529 }
00530 #endif
00531 
00532 inline int QApplication::horizontalAlignment( int align )
00533 {
00534     align &= AlignHorizontal_Mask;
00535     if ( align == AlignAuto ) {
00536         if ( reverseLayout() )
00537             align = AlignRight;
00538         else
00539             align = AlignLeft;
00540     }
00541     return align;
00542 }
00543 
00544 #endif // QAPPLICATION_H
00545 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'