Source Code (Use browser search to find items of interest.)
Class Index
qt'QApplication (./qt-2.1.0/src/kernel/qapplication.h:53)
class Q_EXPORT QApplication : public QObject
{
Q_OBJECT
public:
QApplication( int &argc, char **argv);
QApplication( int &argc, char **argv, bool GUIenabled );
#if defined(_WS_X11_)
QApplication( Display* dpy );
#endif
virtual ~QApplication();
int argc() const;
char **argv() const;
static QStyle &style();
static void setStyle( QStyle* );
#if 1 /* OBSOLETE */
enum ColorMode { NormalColors, CustomColors };
static ColorMode colorMode();
static void setColorMode( QApplication::ColorMode );
#endif
enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
static int colorSpec();
static void setColorSpec( int );
static QCursor *overrideCursor();
static void setOverrideCursor( const QCursor &, bool replace=FALSE );
static void restoreOverrideCursor();
static bool hasGlobalMouseTracking();
static void setGlobalMouseTracking( bool enable );
static QPalette palette( const QWidget* = 0 );
static void setPalette( const QPalette &, bool informWidgets=FALSE,
const char* className = 0 );
static QFont font( const QWidget* = 0 );
static void setFont( const QFont &, bool informWidgets=FALSE,
const char* className = 0 );
static QFontMetrics fontMetrics();
QWidget *mainWidget() const;
virtual void setMainWidget( QWidget * );
virtual void polish( QWidget * );
static QWidgetList *allWidgets();
static QWidgetList *topLevelWidgets();
static QWidget *desktop();
static QWidget *activePopupWidget();
static QWidget *activeModalWidget();
static QClipboard *clipboard();
QWidget *focusWidget() const;
QWidget *activeWindow() const;
static QWidget *widgetAt( int x, int y, bool child=FALSE );
static QWidget *widgetAt( const QPoint &, bool child=FALSE );
int exec();
void processEvents();
void processEvents( int maxtime );
void processOneEvent();
int enter_loop();
void exit_loop();
int loopLevel() const;
static void exit( int retcode=0 );
static bool sendEvent( QObject *receiver, QEvent *event );
static void postEvent( QObject *receiver, QEvent *event );
static void sendPostedEvents( QObject *receiver, int event_type );
static void sendPostedEvents();
static void removePostedEvents( QObject *receiver );
virtual bool notify( QObject *, QEvent * );
static bool startingUp();
static bool closingDown();
static void flushX();
static void syncX();
static void beep();
void setDefaultCodec( QTextCodec* );
QTextCodec* defaultCodec() const;
void installTranslator( QTranslator * );
void removeTranslator( QTranslator * );
QString translate( const char * scope, const char * key ) const;
static void setWinStyleHighlightColor( const QColor & );
static const QColor &winStyleHighlightColor();
static void setDesktopSettingsAware( bool );
static bool desktopSettingsAware();
static void setCursorFlashTime( int );
static int cursorFlashTime();
static void setDoubleClickInterval( int );
static int doubleClickInterval();
static void setWheelScrollLines( int );
static int wheelScrollLines();
static void setStartDragTime( int ms );
static int startDragTime();
static void setStartDragDistance( int l );
static int startDragDistance();
#if defined(_WS_MAC_)
void do_mouse_down(void *);
virtual bool macEventFilter( MSG * );
int macProcessEvent( MSG * );
#elif defined(_WS_WIN_)
virtual bool winEventFilter( MSG * );
#elif defined(_WS_X11_)
virtual bool x11EventFilter( XEvent * );
virtual int x11ClientMessage( QWidget*, XEvent*, bool passive_only);
int x11ProcessEvent( XEvent* );
#endif
#if defined(_WS_WIN_)
static WindowsVersion winVersion();
void winFocus( QWidget *, bool );
static void winMouseButtonUp();
#endif
// session management
bool isSessionRestored() const;
QString sessionId() const;
virtual void commitData( QSessionManager& sm );
virtual void saveState( QSessionManager& sm );
#if defined(_WS_X11_)
static void create_xim();
static void close_xim();
#endif
void wakeUpGuiThread();
signals:
void lastWindowClosed();
void aboutToQuit();
void guiThreadAwake();
public slots:
void quit();
void closeAllWindows();
private:
bool processNextEvent( bool );
void initialize( int, char ** );
void init_precmdline();
void process_cmdline( int* argcptr, char ** argv );
int app_argc;
char **app_argv;
bool quit_now;
int quit_code;
static QStyle *app_style;
static int app_cspec;
static QPalette *app_pal;
static QFont *app_font;
static QCursor *app_cursor;
static int app_tracking;
static bool is_app_running;
static bool is_app_closing;
static bool app_exit_loop;
static int loop_level;
static QWidget *main_widget;
static QWidget *focus_widget;
static QWidget *active_window;
static bool obey_desktop_settings;
static int cursor_flash_time;
static int mouse_double_click_time;
static int wheel_scroll_lines;
QList<QTranslator> *translators;
QSessionManager *session_manager;
QString session_id;
bool is_session_restored;
static QAsciiDict<QPalette> *app_palettes;
static QAsciiDict<QFont> *app_fonts;
static QWidgetList *popupWidgets;
bool inPopupMode() const;
void closePopup( QWidget *popup );
void openPopup( QWidget *popup );
void setActiveWindow( QWidget* act );
static void removePostedEvent( QEvent * );
friend class QWidget;
friend class QETWidget;
friend class QEvent;
#if defined QT_BASEAPP
friend QNonBaseApplication;
#endif
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
QApplication( const QApplication & );
QApplication &operator=( const QApplication & );
#endif
};
inline int QApplication::argc() const
{
return app_argc;
}
inline char **QApplication::argv() const
{
return app_argv;
}
inline QStyle& QApplication::style()
{
return *app_style;
}
inline QCursor *QApplication::overrideCursor()
{
return app_cursor;
}
inline bool QApplication::hasGlobalMouseTracking()
{
return app_tracking > 0;
}
inline QWidget *QApplication::mainWidget() const
{
return main_widget;
}
inline QWidget *QApplication::focusWidget() const
{
return focus_widget;
}
inline QWidget *QApplication::activeWindow() const
{
return active_window;
}
inline QWidget *QApplication::widgetAt( const QPoint &p, bool child )
{
return widgetAt( p.x(), p.y(), child );
}
inline bool QApplication::inPopupMode() const
{
return popupWidgets != 0;
}
inline bool QApplication::isSessionRestored() const
{
return is_session_restored;
}
inline QString QApplication::sessionId() const
{
return session_id;
}
qt'QApplication::sessionId() (./qt-2.1.0/include/qapplication.h:316)
inline QString QApplication::sessionId() const
{
return session_id;
}
qt'QApplication::sendEvent() (./qt-2.1.0/include/qapplication.h:349)
inline bool QApplication::sendEvent( QObject *receiver, QEvent *event )
{ return qApp->notify( receiver, event ); }
#endif
qt'QApplication::process_cmdline() (./qt-2.1.0/src/kernel/qapplication.cpp:322)
void QApplication::process_cmdline( int* argcptr, char ** argv )
{
// process platform-indep command line
if ( !qt_is_gui_used )
return;
int argc = *argcptr;
int i, j;
j = 1;
for ( i=1; i<argc; i++ ) {
if ( argv[i] && *argv[i] != '-' ) {
argv[j++] = argv[i];
continue;
}
QCString arg = argv[i];
if ( arg == "-qdevel" || arg == "-qdebug") {
makeqdevel = !makeqdevel;
} else if ( stricmp(arg, "-style=windows") == 0 ) {
setStyle( new QWindowsStyle );
} else if ( stricmp(arg, "-style=motif") == 0 ) {
setStyle( new QMotifStyle );
} else if ( stricmp(arg, "-style=platinum") == 0 ) {
setStyle( new QPlatinumStyle );
} else if ( stricmp(arg, "-style=cde") == 0 ) {
setStyle( new QCDEStyle );
} else if ( strcmp(arg,"-style") == 0 && i < argc-1 ) {
QCString s = argv[++i];
s = s.lower();
if ( s == "windows" )
setStyle( new QWindowsStyle );
else if ( s == "motif" )
setStyle( new QMotifStyle );
else if ( s == "platinum" )
setStyle( new QPlatinumStyle );
else if ( s == "cde" )
setStyle( new QCDEStyle );
} else if ( strcmp(arg,"-session") == 0 && i < argc-1 ) {
QCString s = argv[++i];
if ( !s.isEmpty() ) {
session_id = QString::fromLatin1( s );
is_session_restored = TRUE;
}
} else
argv[j++] = argv[i];
}
*argcptr = j;
}
/*!
Initializes the window system and constructs an application object
with the command line arguments \a argc and \a argv.
The global \c qApp pointer refers to this application object. Only
one application object should be created.
This application object must be constructed before any \link
QPaintDevice paint devices\endlink (includes widgets, pixmaps, bitmaps
etc.)
Notice that \a argc and \a argv might be changed. Qt removes
command line arguments that it recognizes. \a argc and \a argv are
can be accessed later by \c qApp->argc() and \c qApp->argv(). The
documentation for argv() contains a detailed description of how to
process command line arguments.
Qt debugging options (not available if Qt was compiled with the
NO_DEBUG flag defined):
<ul>
<li> \c -nograb, tells Qt to never grab the mouse or the keyboard.
<li> \c -dograb (only under X11), running under a debugger can cause
an implicit -nograb, use -dograb to override.
<li> \c -sync (only under X11), switches to synchronous mode for
debugging.
</ul>
See <a href="debug.html">Debugging Techniques</a> for a more
detailed explanation.
All Qt programs automatically support the following command line options:
<ul>
<li> \c -style= \e style, sets the application GUI style. Possible values
are \c motif, \c windows, and \c platinum.
<li> \c -session= \e session, restores the application from an earlier
\link session.html session \endlink.
</ul>
The X11 version of Qt also supports some traditional X11
command line options:
<ul>
<li> \c -display \e display, sets the X display (default is $DISPLAY).
<li> \c -geometry \e geometry, sets the client geometry of the
\link setMainWidget() main widget\endlink.
<li> \c -fn or \c -font \e font, defines the application font.
<li> \c -bg or \c -background \e color, sets the default background color
and an application palette (light and dark shades are calculated).
<li> \c -fg or \c -foreground \e color, sets the default foreground color.
<li> \c -btn or \c -button \e color, sets the default button color.
<li> \c -name \e name, sets the application name.
<li> \c -title \e title, sets the application title (caption).
<li> \c -visual \c TrueColor, forces the application to use a TrueColor visual
on an 8-bit display.
<li> \c -ncols \e count, limits the number of colors allocated in the
color cube on a 8-bit display, if the application is using the
\c QApplication::ManyColor color specification. If \e count is
216 then a 6x6x6 color cube is used (ie. 6 levels of red, 6 of green,
and 6 of blue); for other values, a cube
approximately proportional to a 2x3x1 cube is used.
<li> \c -cmap, causes the application to install a private color map
on an 8-bit display.
</ul>
\sa argc(), argv()
*/
//######### BINARY COMPATIBILITY constructor
qt'QApplication::QApplication() (./qt-2.1.0/src/kernel/qapplication.cpp:438)
QApplication::QApplication( int &argc, char **argv )
{
qt_is_gui_used = TRUE;
init_precmdline();
static char *empty = (char*)"";
if ( argc == 0 || argv == 0 ) {
argc = 0;
argv = ∅
}
qt_init( &argc, argv ); // Must be called before initialize()
process_cmdline( &argc, argv );
initialize( argc, argv );
}
/*!
Constructs an application object with the command line arguments \a
argc and \a argv. If \a GUIenabled is TRUE, a normal application is
constructed, otherwise a non-GUI application is created.
Set \a GUIenabled to FALSE for programs without a graphical user
interface that should be able to run without a window system.
On X11, the window system is initialized if \a GUIenabled is TRUE.
If \a GUIenabled is FALSE, the application does not connect to the
X-server.
On Windows, currently the window system is always initialized,
regardless of the value of GUIenabled. This may change in future
versions of Qt.
The following example shows how to create an application that
uses a graphical interface when available.
\code
int main( int argc, char **argv )
{
#ifdef _WS_X11_
bool useGUI = getenv( "DISPLAY" ) != 0;
#else
bool useGUI = TRUE;
#endif
QApplication app(argc, argv, useGUI);
if ( useGUI ) {
//start GUI version
...
} else {
//start non-GUI version
...
}
return app.exec();
}
\endcode
*/
qt'QApplication::QApplication() (./qt-2.1.0/src/kernel/qapplication.cpp:494)
QApplication::QApplication( int &argc, char **argv, bool GUIenabled )
{
qt_is_gui_used = GUIenabled;
init_precmdline();
static char *empty = (char*)"";
if ( argc == 0 || argv == 0 ) {
argc = 0;
argv = ∅
}
qt_init( &argc, argv ); // Must be called before initialize()
process_cmdline( &argc, argv );
initialize( argc, argv );
}
#if defined(_WS_X11_)
// note: #ifdef'ed stuff is NOT documented.
/*!
Create an application, given an already open display. This is
available only on X11.
*/
qt'QApplication::QApplication() (./qt-2.1.0/src/kernel/qapplication.cpp:516)
QApplication::QApplication( Display* dpy )
{
qt_is_gui_used = TRUE;
init_precmdline();
// ... no command line.
qt_init( dpy );
initialize( 0, 0 );
}
qt'QApplication::init_precmdline() (./qt-2.1.0/src/kernel/qapplication.cpp:528)
void QApplication::init_precmdline()
{
translators = 0;
is_app_closing = FALSE;
is_session_restored = FALSE;
app_exit_loop = FALSE;
#if defined(CHECK_STATE)
if ( qApp )
qWarning( "QApplication: There should be max one application object" );
#endif
qApp = (QNonBaseApplication*)this;
}
/*!
Initializes the QApplication object, called from the constructors.
*/
qt'QApplication::initialize() (./qt-2.1.0/src/kernel/qapplication.cpp:545)
void QApplication::initialize( int argc, char **argv )
{
app_argc = argc;
app_argv = argv;
quit_now = FALSE;
quit_code = 0;
QWidget::createMapper(); // create widget mapper
(void) palette(); // trigger creation of application palette
is_app_running = TRUE; // no longer starting up
if (!app_style) {
#if defined(_WS_WIN_)
app_style = new QWindowsStyle; // default style for Windows
#elif defined(_WS_X11_)
app_style = new QMotifStyle; // default style for X Windows
#elif defined(_WS_MAC_)
app_style = new QPlatinumStyle;
#else
#error "Toto... I have a feeling we're not in Kansas anymore."
#endif
}
qInitPngIO();
app_style->polish( *app_pal );
app_style->polish( qApp ); //##### wrong place, still inside the qapplication constructor...grmbl....
#if 0
if ( makeqdevel ) {
qdevel = new QDeveloper;
qdevel->show();
}
#endif
// connect to the session manager
session_manager = new QSessionManager( qApp, session_id );
}
/*****************************************************************************
Functions returning the active popup and modal widgets.
*****************************************************************************/
/*!
Returns the active popup widget.
A popup widget is a special top level widget that sets the WType_Popup
widget flag, e.g. the QPopupMenu widget. When the application opens a
popup widget, all events are sent to the popup and normal widgets and
modal widgets cannot be accessed before the popup widget is closed.
Only other popup widgets may be opened when a popup widget is shown.
The popup widgets are organized in a stack.
This function returns the active popup widget on top of the stack.
\sa activeModalWidget(), topLevelWidgets()
*/
qt'QApplication::activePopupWidget() (./qt-2.1.0/src/kernel/qapplication.cpp:603)
QWidget *QApplication::activePopupWidget()
{
return popupWidgets ? popupWidgets->getLast() : 0;
}
/*!
Returns the active modal widget.
A modal widget is a special top level widget which is a subclass of
QDialog that specifies the modal parameter of the constructor to TRUE.
A modal widget must be finished before the user can continue with other
parts of the program.
The modal widgets are organized in a stack.
This function returns the active modal widget on top of the stack.
\sa activePopupWidget(), topLevelWidgets()
*/
qt'QApplication::activeModalWidget() (./qt-2.1.0/src/kernel/qapplication.cpp:623)
QWidget *QApplication::activeModalWidget()
{
if ( !qt_modal_stack )
return 0;
QWidget* w = qt_modal_stack->getFirst();
if ( w->testWState( WState_Modal ) )
return w;
// find the real one
QWidgetListIt it( *qt_modal_stack );
while ( it.current() ) {
if ( it.current()->testWState( WState_Modal ) )
return it.current();
--it;
}
return 0;
}
/*!
Cleans up any window system resources that were allocated by this
application. Sets the global variable \c qApp to null. Unlike
former versions of Qt the destructor does \e not delete all
remaining widgets.
*/
qt'QApplication::~QApplication() (./qt-2.1.0/src/kernel/qapplication.cpp:649)
QApplication::~QApplication()
{
delete desktopWidget;
desktopWidget = 0;
is_app_closing = TRUE;
QWidget::destroyMapper();
delete qt_std_pal;
qt_std_pal = 0;
delete app_pal;
app_pal = 0;
delete app_font;
app_font = 0;
delete app_palettes;
app_palettes = 0;
delete app_fonts;
app_fonts = 0;
delete app_style;
app_style = 0;
delete app_cursor;
app_cursor = 0;
qt_cleanup();
/*
Cannot delete objectDict, as then all Class::metaObj variables
become invalid. We could make a separate function to do this
to allow apps to assert "I will not use Qt any more". It is
not sufficient to assume that here, as a new QApplication might
be constructed.
delete objectDict;
objectDict = 0;
*/
qApp = 0;
is_app_running = FALSE;
delete translators;
// Cannot delete codecs until after QDict destructors
// QTextCodec::deleteAllCodecs()
}
/*!
\fn int QApplication::argc() const
Returns the number of command line arguments.
The documentation for argv() contains a detailed description of how to
process command line arguments.
\sa argv(), QApplication::QApplication()
*/
/*!
\fn char **QApplication::argv() const
Returns the command line argument vector.
\c argv()[0] is the program name, \c argv()[1] is the first argument and
\c argv()[argc()-1] is the last argument.
A QApplication object is constructed by passing \e argc and \e argv from
the \c main() function. Some of the arguments may be recognized as Qt
options removed from the argument vector. For example, the X11
version of Qt knows about \c -display, \c -font and a few more options.
Example:
\code
// showargs.cpp - displays program arguments in a list box
#include <qapplication.h>
#include <qlistbox.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QListBox b;
a.setMainWidget( &b );
for ( int i=0; i<a.argc(); i++ ) // a.argc() == argc
b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i]
b.show();
return a.exec();
}
\endcode
If you run <tt>showargs -display unix:0 -font 9x15bold hello
world</tt> under X11, the list box contains the three strings
"showargs", "hello" and "world".
\sa argc(), QApplication::QApplication()
*/
/*!
\fn QStyle& QApplication::style()
Returns the style object of the application.
\sa setStyle(), QStyle
*/
/*!
Sets the application GUI style to \a style. Ownership of the style
object is transfered, i.e. QApplication will delete the style object
on application exit or when a new style is set.
Example usage:
\code
QApplication::setStyle( new QWindowStyle );
\endcode
When switching application styles, the color palette is set back to
the initital colors or the system defaults. This is necessary since
certain styles have to adapt the color palette to be fully
style-guide compliant.
\sa style(), QStyle, setPalette(), desktopSettingsAware()
*/
qt'QApplication::setStyle() (./qt-2.1.0/src/kernel/qapplication.cpp:763)
void QApplication::setStyle( QStyle *style )
{
QStyle* old = app_style;
app_style = style;
if ( startingUp() ) {
delete old;
return;
}
// clean up the old style
if (old) {
if ( is_app_running && !is_app_closing ) {
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets...
++it;
if ( !w->testWFlags(WType_Desktop) && // except desktop
w->testWState(WState_Polished) ) { // has been polished
old->unPolish(w);
}
}
}
old->unPolish( qApp );
}
// take care of possible palette requirements of certain gui
// styles. Do it before polishing the application since the style
// might call QApplication::setStyle() itself
if ( !qt_std_pal )
qt_create_std_palette();
QPalette tmpPal = *qt_std_pal;
app_style->polish( tmpPal );
if ( tmpPal != *app_pal )
setPalette( tmpPal, TRUE );
// initialize the application with the new style
app_style->polish( qApp );
// re-polish existing widgets if necessary
if (old) {
if ( is_app_running && !is_app_closing ) {
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets...
++it;
if ( !w->testWFlags(WType_Desktop) ) { // except desktop
if ( w->testWState(WState_Polished) )
app_style->polish(w); // repolish
w->styleChange( *old );
if ( w->isVisible() ){
w->update();
}
}
}
}
delete old;
}
}
#if 1 /* OBSOLETE */
QApplication::ColorMode QApplication::colorMode()
{
return (QApplication::ColorMode)app_cspec;
}
qt'QApplication::setColorMode() (./qt-2.1.0/src/kernel/qapplication.cpp:832)
void QApplication::setColorMode( QApplication::ColorMode mode )
{
app_cspec = mode;
}
#endif
/*!
Returns the color specification.
\sa QApplication::setColorSpec()
*/
qt'QApplication::colorSpec() (./qt-2.1.0/src/kernel/qapplication.cpp:844)
int QApplication::colorSpec()
{
return app_cspec;
}
/*!
Sets the color specification for the application to \a spec.
The color specification controls how your application allocates colors
whn run on a display with a limited amount of colors, i.e. 8 bit / 256
color displays.
The color specification must be set before you create the QApplication
object.
The choices are:
<ul>
<li> \c QApplication::NormalColor.
This is the default color allocation strategy. Use this choice if
your application uses buttons, menus, texts and pixmaps with few
colors. With this choice, the application uses system global
colors. This works fine for most applications under X11, but on
Windows machines it may cause dithering of non-standard colours.
<li> \c QApplication::CustomColor.
Use this choice if your application needs a small number of custom
colors. On X11, this choice is the same as NormalColor. On Windows, Qt
creates a Windows palette, and allocates colors in it on demand.
<li> \c QApplication::ManyColor.
Use this choice if your application is very color hungry
(e.g. it wants thousands of colors).
Under X11 the effect is: <ul>
<li> For 256-color displays which have at best a 256 color true color
visual, the default visual is used, and colors are allocated
from a color cube.
The color cube is the 6x6x6 (216 color) "Web palette", but the
number of colors can be changed by the \e -ncols option.
The user can force the application to use the true color visual by
the \link QApplication::QApplication() -visual \endlink
option.
<li> For 256-color displays which have a true color visual with more
than 256 colors, use that visual. Silicon Graphics X
servers have this feature, for example. They provide an 8
bit visual by default but can deliver true color when
asked.
</ul>
On Windows, Qt creates a Windows palette, and fills it with a color cube.
</ul>
Be aware that the CustomColor and ManyColor choices may lead to colormap
flashing: The foreground application gets (most) of the available
colors, while the background windows will look less good.
Example:
\code
int main( int argc, char **argv )
{
QApplication::setColorSpec( QApplication::ManyColor );
QApplication a( argc, argv );
...
}
\endcode
QColor provides more functionality for controlling color allocation and
freeing up certain colors. See QColor::enterAllocContext() for more
information.
To see what mode you end up with, you can call QColor::numBitPlanes()
once the QApplication object exists. A value greater than 8 (typically
16, 24 or 32) means true color.
The color cube used by Qt are all those colors with red, green, and blue
components of either 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF.
\sa colorSpec(), QColor::numBitPlanes(), QColor::enterAllocContext() */
qt'QApplication::setColorSpec() (./qt-2.1.0/src/kernel/qapplication.cpp:919)
void QApplication::setColorSpec( int spec )
{
#if defined(CHECK_STATE)
if ( qApp ) {
qWarning( "QApplication::setColorSpec: This function must be "
"called before the QApplication object is created" );
}
#endif
app_cspec = spec;
}
/*!
Returns a pointer to the default application palette. There is
always an application palette, i.e. the returned pointer is
guaranteed to be non-null.
If a widget is passed as argument, the default palette for the
widget's class is returned. This may or may not be the application
palette, but in most cases there won't be a special palette for
certain types of widgets. An exception is the popup menu under
Windows, when the user defined a special background color for menus
in the display settings.
\sa setPalette(), QWidget::palette()
*/
qt'QApplication::palette() (./qt-2.1.0/src/kernel/qapplication.cpp:946)
QPalette QApplication::palette(const QWidget* w)
{
#if defined(CHECK_STATE)
if ( !qApp ) {
qWarning( "QApplication::palette: This function can only be "
"called after the QApplication object has been created" );
}
#endif
if ( !app_pal ) {
if ( !qt_std_pal )
qt_create_std_palette();
app_pal = new QPalette( *qt_std_pal );
qt_fix_tooltips();
}
if ( w && app_palettes ) {
QPalette* wp = app_palettes->find( w->className() );
if ( wp )
return *wp;
QAsciiDictIterator<QPalette> it( *app_palettes );
const char* name;
while ( (name=it.currentKey()) != 0 ) {
if ( w->inherits( name ) )
return *it.current();
++it;
}
}
return *app_pal;
}
/*!
Changes the default application palette to \a palette. If \a informWidgets
is TRUE, then existing widgets are informed about the change and thus
may adjust themselves to the new application setting. Otherwise the
change only affects newly created widgets. If \a className is
passed, the change applies only to classes that inherit \a className
(as reported by QObject::inherits()).
The palette may be changed according to the current GUI style in
QStyle::polish().
\sa QWidget::setPalette(), palette(), QStyle::polish()
*/
qt'QApplication::setPalette() (./qt-2.1.0/src/kernel/qapplication.cpp:992)
void QApplication::setPalette( const QPalette &palette, bool informWidgets,
const char* className )
{
QPalette pal = palette;
if ( !startingUp() )
qApp->style().polish( pal ); // NB: non-const reference
bool all = FALSE;
if ( !className ) {
if ( !app_pal ) {
app_pal = new QPalette( pal );
CHECK_PTR( app_pal );
} else {
*app_pal = pal;
}
all = app_palettes != 0;
delete app_palettes;
app_palettes = 0;
qt_fix_tooltips(); // ### Doesn't (always) work
} else {
if ( !app_palettes ) {
app_palettes = new QAsciiDict<QPalette>;
CHECK_PTR( app_palettes );
app_palettes->setAutoDelete( TRUE );
}
app_palettes->insert( className, new QPalette( pal ) );
}
if ( informWidgets && is_app_running && !is_app_closing ) {
QCustomEvent e( QEvent::ApplicationPaletteChange, 0 );
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets...
++it;
if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
sendEvent( w, &e );
}
}
}
/*!
Returns the default font for a widget. Basically this function uses the
class name of the widget to get a font for it.
If \a w is 0 the default application font is returned.
\sa setFont(), fontMetrics(), QWidget::font()
*/
qt'QApplication::font() (./qt-2.1.0/src/kernel/qapplication.cpp:1040)
QFont QApplication::font( const QWidget *w )
{
if ( w && app_fonts ) {
QFont* wf = app_fonts->find( w->className() );
if ( wf )
return *wf;
QAsciiDictIterator<QFont> it( *app_fonts );
const char* name;
while ( (name=it.currentKey()) != 0 ) {
if ( w->inherits( name ) )
return *it.current();
++it;
}
}
if ( !app_font ) {
app_font = new QFont( "Helvetica" );
CHECK_PTR( app_font );
}
return *app_font;
}
/*! Changes the default application font to \a font. If \a
informWidgets is TRUE, then existing widgets are informed about the
change and thus may adjust themselves to the new application
setting. Otherwise the change only affects newly created widgets.
If \a className is passed, the change applies only to classes that
inherit \a className (as reported by QObject::inherits()).
On application start-up, the default font depends on the window
system. It can vary both with window system version and with
locale. This function lets you override it. Note that overriding
it may be a bad idea, for example some locales need extra-big fonts
to support their special characters.
\sa font(), fontMetrics(), QWidget::setFont()
*/
qt'QApplication::setFont() (./qt-2.1.0/src/kernel/qapplication.cpp:1077)
void QApplication::setFont( const QFont &font, bool informWidgets,
const char* className )
{
bool all = FALSE;
if ( !className ) {
if ( !app_font ) {
app_font = new QFont( font );
CHECK_PTR( app_font );
} else {
*app_font = font;
}
all = app_fonts != 0;
delete app_fonts;
app_fonts = 0;
} else {
if (!app_fonts){
app_fonts = new QAsciiDict<QFont>;
CHECK_PTR( app_fonts );
app_fonts->setAutoDelete( TRUE );
}
QFont* fnt = new QFont(font);
CHECK_PTR( fnt );
app_fonts->insert(className, fnt);
}
if ( informWidgets && is_app_running && !is_app_closing ) {
QCustomEvent e( QEvent::ApplicationFontChange, 0 );
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets...
++it;
if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
sendEvent( w, &e );
}
}
}
/*!
Polishing of widgets.
Usually widgets call this automatically when they are polished. It
may be used to do some style-based central customization of widgets.
Note that you are not limited to public functions of QWidget.
Instead, based on meta information like QObject::className()
you are able to customize any kind of widgets.
\sa QStyle::polish(), QWidget::polish(), setPalette(), setFont()
*/
qt'QApplication::polish() (./qt-2.1.0/src/kernel/qapplication.cpp:1127)
void QApplication::polish( QWidget *w )
{
#if 0
if ( qdevel && w->isTopLevel() )
qdevel->addTopLevelWidget(tlw);
#endif
app_style->polish( w );
}
/*!
Returns a list of the top level widgets in the application.
The list is created using new and must be deleted by the caller.
The list is \link QList::isEmpty() empty \endlink if there are no
top level widgets.
Note that some of the top level widgets may be hidden, for example
all the popup menus of a menubar.
Example:
\code
//
// Shows all hidden top level widgets.
//
QWidgetList *list = QApplication::topLevelWidgets();
QWidgetListIt it( *list ); // iterate over the widgets
while ( it.current() ) { // for each top level widget...
if ( !it.current()->isVisible() )
it.current()->show();
++it;
}
delete list; // delete the list, not the widgets
\endcode
\warning Delete the list away as soon you have finished using it.
The widgets in the list may be deleted by someone else at any time.
\sa allWidgets(), QWidget::isTopLevel(), QWidget::isVisible(),
QList::isEmpty()
*/
qt'QApplication::topLevelWidgets() (./qt-2.1.0/src/kernel/qapplication.cpp:1172)
QWidgetList *QApplication::topLevelWidgets()
{
return QWidget::tlwList();
}
/*!
Returns a list of all the widgets in the application.
The list is created using new and must be deleted by the caller.
The list is \link QList::isEmpty() empty \endlink if there are no
widgets.
Note that some of the widgets may be hidden.
Example:
\code
//
// Updates all widgets.
//
QWidgetList *list = QApplication::allWidgets();
QWidgetListIt it( *list ); // iterate over the widgets
while ( it.current() ) { // for each top level widget...
it.current()->update();
++it;
}
delete list; // delete the list, not the widgets
\endcode
The QWidgetList class is defined in the qwidcoll.h header file.
\warning
Delete the list away as soon you have finished using it.
You can get in serious trouble if you for instance try to access
a widget that has been deleted.
\sa topLevelWidgets(), QWidget::isVisible(), QList::isEmpty(),
*/
qt'QApplication::allWidgets() (./qt-2.1.0/src/kernel/qapplication.cpp:1211)
QWidgetList *QApplication::allWidgets()
{
return QWidget::wList();
}
/*!
\fn QWidget *QApplication::focusWidget() const
Returns the application widget that has the keyboard input focus, or null
if no application widget has the focus.
\sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow()
*/
/*!
\fn QWidget *QApplication::activeWindow() const
Returns the application toplevel window that has the keyboard input
focus, or null if no application window has the focus. Note that
there might be an activeWindow even if there is no focusWidget, if
no widget in that window accepts key events.
\sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget()
*/
/*!
Returns display (screen) font metrics for the application font.
\sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics()
*/
qt'QApplication::fontMetrics() (./qt-2.1.0/src/kernel/qapplication.cpp:1239)
QFontMetrics QApplication::fontMetrics()
{
return desktop()->fontMetrics();
}
/*!
Tells the application to exit with a return code.
After this function has been called, the application leaves the main
event loop and returns from the call to exec(). The exec() function
returns \a retcode.
By convention, \a retcode 0 means success, any non-zero value indicates
an error.
Note that unlike the C library exit function, this function \e does
returns to the caller - it is event processing that stops.
\sa quit(), exec()
*/
qt'QApplication::exit() (./qt-2.1.0/src/kernel/qapplication.cpp:1261)
void QApplication::exit( int retcode )
{
if ( !qApp ) // no global app object
return;
if ( ((QApplication*)qApp)->quit_now ) // don't overwrite quit code...
return;
((QApplication*)qApp)->quit_code = retcode; // here
((QApplication*)qApp)->quit_now = TRUE;
((QApplication*)qApp)->app_exit_loop = TRUE;
}
/*!
Tells the application to exit with return code 0 (success).
Equivalent to calling QApplication::exit( 0 ).
This function is a \link metaobjects.html slot\endlink, i.e. you
may connect any signal to activate quit().
Example:
\code
QPushButton *quitButton = new QPushButton( "Quit" );
connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );
\endcode
\sa exit(), aboutToQuit()
*/
qt'QApplication::quit() (./qt-2.1.0/src/kernel/qapplication.cpp:1289)
void QApplication::quit()
{
QApplication::exit( 0 );
}
/*!
A convenience function that closes all toplevel windows.
The function is particularly useful for applications with many
toplevel windows. It could for example be connected to a "Quit"
entry in the file menu as shown in the following code example:
\code
// the "Quit" menu entry should try to close all windows
QPopupMenu* file = new QPopupMenu( this );
file->insertItem( tr("&Quit"), qApp, SLOT(closeAllWindows()), CTRL+Key_Q );
// when the last window was closed, the application should quit
connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );
\endcode
The windows are closed in random order, until one window does not
accept the close event.
\sa QWidget::close(), QWidget::closeEvent(), lastWindowClosed(),
quit(), topLevelWidgets(), QWidget::isTopLevel()
*/
qt'QApplication::closeAllWindows() (./qt-2.1.0/src/kernel/qapplication.cpp:1318)
void QApplication::closeAllWindows()
{
QWidgetList *list = QApplication::topLevelWidgets();
bool did_close = TRUE;
QWidget* w = list->first();
while ( did_close && w ) {
if ( !w->testWState( WState_ForceHide ) ) {
did_close = w->close();
delete list;
list = QApplication::topLevelWidgets();
w = list->first();
}
else
w = list->next();
}
delete list;
}
/*!
\fn void QApplication::lastWindowClosed()
This signal is emitted when the user has closed the last remaining
top level window.
The signal is very useful when your application has many top level
widgets but no main widget. You can then connect it to the quit() slot.
For convenience, transient toplevel widgets such as popup menus and
dialogs are omitted.
\sa mainWidget(), topLevelWidgets(), QWidget::isTopLevel(), QWidget::close()
*/
/*!
\fn void QApplication::aboutToQuit()
This signal is emitted when the application is about to quit the
main event loop. This may happen either after a call to quit() from
inside the applicaton or when the users shuts down the entire
desktop session.
The signal is particularly useful if your application has to do some
last-second cleanups. Note that no user interaction is possible at
this state.
\sa quit()
*/
/*!
\fn void QApplication::guiThreadAwake()
This signal is emitted when the GUI threads is about to process a cycle
of the event loop.
\sa wakeUpGuiThread()
*/
/*!
\fn bool QApplication::sendEvent( QObject *receiver, QEvent *event )
Sends an event directly to a receiver, using the notify() function.
Returns the value that was returned from the event handler.
\sa postEvent(), notify()
*/
/*!
Sends \a event to \a receiver: <code>receiver->event( event )</code>
Returns the value that is returned from the receiver's event handler.
Reimplementing this virtual function is one of five ways to process
an event: <ol> <li> Reimplementing this function. Very powerful,
you get \e complete control, but of course only one subclass can be
qApp.
<li> Installing an event filter on qApp. Such an event filter gets
to process all events for all widgets, so it's just as powerful as
reimplementing notify(), and in this way it's possible to have more
than one application-global event filter. Global event filter get
to see even mouse events for \link QWidget::isEnabled() disabled
widgets, \endlink and if \link setGlobalMouseTracking() global mouse
tracking \endlink is enabled, mouse move events for all widgets.
<li> Reimplementing QObject::event() (as QWidget does). If you do
this you get tab key-presses, and you get to see the events before
any widget-specific event filters.
<li> Installing an event filter on the object. Such an even filter
gets all the events except Tab and Shift-Tab key presses.
<li> Finally, reimplementing paintEvent(), mousePressEvent() and so
on. This is the normal, easiest and least powerful way. </ol>
\sa QObject::event(), installEventFilter()
*/
qt'QApplication::notify() (./qt-2.1.0/src/kernel/qapplication.cpp:1416)
bool QApplication::notify( QObject *receiver, QEvent *event )
{
// no events are delivered after ~QApplication has started
if ( is_app_closing )
return FALSE;
if ( receiver == 0 ) { // serious error
#if defined(CHECK_NULL)
qWarning( "QApplication::notify: Unexpected null receiver" );
#endif
return FALSE;
}
#if 0
if ( qdevel && event->type() == QEvent::Reparent
&& receiver->isWidgetType()
&& ((QWidget*)receiver)->isTopLevel() )
qdevel->addTopLevelWidget( (QWidget*)receiver );
#endif
if ( receiver->pendEvent && event->type() == QEvent::ChildRemoved ) {
// if this is a child remove event an the child insert hasn't been
// dispatched yet, kill that insert and return.
QObject * c = ((QChildEvent*)event)->child();
QPostEventListIt it( *postedEvents );
QPostEvent * pe;
while( ( pe = it.current()) != 0 ) {
++it;
if ( pe->event && pe->receiver == receiver &&
pe->event->type() == QEvent::ChildInserted &&
((QChildEvent*)pe->event)->child() == c ) {
postedEvents->take( postedEvents->findRef( pe ) );
pe->event->posted = FALSE;
delete pe;
return TRUE;
}
}
}
if ( eventFilters ) {
QObjectListIt it( *eventFilters );
register QObject *obj;
while ( (obj=it.current()) != 0 ) { // send to all filters
++it; // until one returns TRUE
if ( obj->eventFilter(receiver,event) )
return TRUE;
}
}
// throw away mouse events to disabled widgets
if ( event->type() <= QEvent::MouseMove &&
event->type() >= QEvent::MouseButtonPress &&
( receiver->isWidgetType() &&
!((QWidget *)receiver)->isEnabled() ) )
return FALSE;
// throw away any mouse-tracking-only mouse events
if ( event->type() == QEvent::MouseMove &&
(((QMouseEvent*)event)->state()&QMouseEvent::MouseButtonMask) == 0 &&
( receiver->isWidgetType() &&
!((QWidget *)receiver)->hasMouseTracking() ) )
return TRUE;
return receiver->event( event );
}
/*!
Returns TRUE if an application object has not been created yet.
\sa closingDown()
*/
qt'QApplication::startingUp() (./qt-2.1.0/src/kernel/qapplication.cpp:1489)
bool QApplication::startingUp()
{
return !is_app_running;
}
/*!
Returns TRUE if the application objects are being destroyed.
\sa startingUp()
*/
qt'QApplication::closingDown() (./qt-2.1.0/src/kernel/qapplication.cpp:1499)
bool QApplication::closingDown()
{
return is_app_closing;
}
/*!
Processes pending events, for 3 seconds or until there
are no more events to process, then return.
You can call this function occasionally when your program is busy doing a
long operation (e.g. copying a file).
\sa processOneEvent(), exec(), QTimer
*/
qt'QApplication::processEvents() (./qt-2.1.0/src/kernel/qapplication.cpp:1515)
void QApplication::processEvents()
{
processEvents( 3000 );
}
/*!
Waits for an event to occur, processes it, then returns.
This function is useful for adapting Qt to situations where the event
processing must be grafted into existing program loops. Beware
that using this function in new applications may be an indication
of design problems.
\sa processEvents(), exec(), QTimer
*/
qt'QApplication::processOneEvent() (./qt-2.1.0/src/kernel/qapplication.cpp:1531)
void QApplication::processOneEvent()
{
processNextEvent(TRUE);
}
#if !defined(_WS_X11_)
// The doc and X implementation of these functions is in qapplication_x11.cpp
qt'QApplication::flushX() (./qt-2.1.0/src/kernel/qapplication.cpp:1541)
void QApplication::flushX() {} // do nothing
qt'QApplication::syncX() (./qt-2.1.0/src/kernel/qapplication.cpp:1543)
void QApplication::syncX() {} // do nothing
#endif
/*!\obsolete
Sets the color used to mark selections in windows style for all widgets
in the application. Will repaint all widgets if the color is changed.
The default color is \c darkBlue.
\sa winStyleHighlightColor()
*/
qt'QApplication::setWinStyleHighlightColor() (./qt-2.1.0/src/kernel/qapplication.cpp:1557)
void QApplication::setWinStyleHighlightColor( const QColor &c )
{
QPalette p( palette() );
p.setColor( QColorGroup::Highlight, c );
setPalette( p, TRUE);
}
/*!\obsolete
Returns the color used to mark selections in windows style.
\sa setWinStyleHighlightColor()
*/
qt'QApplication::winStyleHighlightColor() (./qt-2.1.0/src/kernel/qapplication.cpp:1569)
const QColor& QApplication::winStyleHighlightColor()
{
return palette().normal().highlight();
}
/*!
\fn Qt::WindowsVersion QApplication::winVersion()
Returns the version of the Windows operating system running:
<ul>
<li> \c Qt::WV_95 Windows 95.
<li> \c Qt::WV_98 Windows 98.
<li> \c Qt::WV_NT Windows NT (NT4).
<li> \c Qt::WV_2000 Windows 2000 (NT5).
</ul>
Note that this function is implemented for the Windows version
of Qt only.
*/
/*!
Adds \a mf to the list of message files to be used for
localization. Message files are searched starting with the most
recently added file.
\sa removeTranslator() translate() QObject::tr()
*/
qt'QApplication::installTranslator() (./qt-2.1.0/src/kernel/qapplication.cpp:1600)
void QApplication::installTranslator( QTranslator * mf )
{
if ( !translators )
translators = new QList<QTranslator>;
if ( mf )
translators->insert( 0, mf );
}
/*!
Removes \a mf from the list of message files used by this
application. Does not, of course, delete mf.
\sa installTranslator() translate(), QObject::tr()
*/
qt'QApplication::removeTranslator() (./qt-2.1.0/src/kernel/qapplication.cpp:1616)
void QApplication::removeTranslator( QTranslator * mf )
{
if ( !translators || !mf )
return;
translators->first();
while( translators->current() && translators->current() != mf )
translators->next();
translators->take();
}
/*!
If the literal quoted text in the program is not in the Latin1
encoding, this function can be used to
set the appropriate encoding. For example, software developed
by Korean programmers might use eucKR for all the text in the program,
in which case main() would be:
\code
main(int argc, char** argv)
{
QApplication app(argc, argv);
... install any additional codecs ...
app.setDefaultCodec( QTextCodec::codecForName("eucKR") );
...
}
\endcode
Note that this is \e not the way to select the encoding that the
\e user has chosen. For example, to convert an application containing
literal English strings to Korean, all that is needed is for the English
strings to be passed through tr() and for translation files to be
loaded. For details of internationalization, see the \link i18n.html
Qt Internationalization documentation\endlink.
Note also that some Qt built-in classes call tr() with various
strings. These strings are in English, so for a full translation, a
codec would be required for these strings.
*/
qt'QApplication::setDefaultCodec() (./qt-2.1.0/src/kernel/qapplication.cpp:1656)
void QApplication::setDefaultCodec( QTextCodec* codec )
{
default_codec = codec;
}
/*!
Returns the default codec (see setDefaultCodec()).
Returns 0 by default (no codec).
*/
qt'QApplication::defaultCodec() (./qt-2.1.0/src/kernel/qapplication.cpp:1666)
QTextCodec* QApplication::defaultCodec() const
{
return default_codec;
}
/*!
Returns the best available translation for \a key in \a scope, by
querying the installed messages files. The message file that was
installed last is asked first.
QObject::tr() offers a more convenient way to use this functionality.
\a scope is typically a class name (e.g. \c MyDialog) and \a is
either English text or a short marker text, if the output text will
be very long (as for help texts).
If none of the message files contain a translation for \a key in \a
scope, this function returns \a key.
This function is not virtual, but you can add alternative translation
techniques by installing subclasses of QTranslator.
\sa QObject::tr() installTranslator() removeTranslator() QTranslator
*/
qt'QApplication::translate() (./qt-2.1.0/src/kernel/qapplication.cpp:1691)
QString QApplication::translate( const char * scope, const char * key ) const
{
if ( !key )
return QString::null;
// scope can be null, for global stuff
if ( translators ) {
QListIterator<QTranslator> it( *translators );
QTranslator * mf;
QString result;
while( (mf=it.current()) != 0 ) {
++it;
result = mf->find( scope, key );
if ( !result.isNull() )
return result;
}
}
if ( default_codec ) {
return default_codec->toUnicode(key);
} else {
return QString::fromLatin1(key);
}
}
/*****************************************************************************
QApplication management of posted events
*****************************************************************************/
//see also notify(), which does the removal of ChildInserted when ChildRemoved.
/*!
Stores the event in a queue and returns immediately.
The event must be allocated on the heap, as it is deleted when the event
has been posted.
When control returns to the main event loop, all events that are
stored in the queue will be sent using the notify() function.
\sa sendEvent()
*/
qt'QApplication::postEvent() (./qt-2.1.0/src/kernel/qapplication.cpp:1734)
void QApplication::postEvent( QObject *receiver, QEvent *event )
{
if ( !postedEvents ) { // create list
postedEvents = new QList<QPostEvent>;
CHECK_PTR( postedEvents );
postedEvents->setAutoDelete( TRUE );
qAddPostRoutine( cleanupPostedEvents );
}
if ( receiver == 0 ) {
#if defined(CHECK_NULL)
qWarning( "QApplication::postEvent: Unexpected null receiver" );
#endif
return;
}
receiver->pendEvent = TRUE;
event->posted = TRUE;
postedEvents->append( new QPostEvent(receiver,event) );
}
/*! Dispatches all posted events. */
qt'QApplication::sendPostedEvents() (./qt-2.1.0/src/kernel/qapplication.cpp:1756)
void QApplication::sendPostedEvents()
{
if ( !postedEvents )
return;
int abortAfter = 16*postedEvents->count();
QPostEventListIt it( * postedEvents );
QPostEvent *pe;
while ( (pe=it.current()) ) {
++it;
if ( pe->event &&
( pe->event->type() == QEvent::LayoutHint ||
pe->event->type() == QEvent::ChildInserted ||
pe->event->type() == QEvent::Move ||
pe->event->type() == QEvent::Resize ||
pe->event->type() == QEvent::Paint ) ) {
// uglehack: get rid of this sort of event now, by calling
// the more-specific function
sendPostedEvents( pe->receiver, pe->event->type() );
} else {
postedEvents->take( postedEvents->findRef( pe ) );
QApplication::sendEvent( pe->receiver, pe->event );
pe->event->posted = FALSE;
delete pe;
}
if ( abortAfter-- < 1 )
return; // if a posted events generates another, don't freeze.
}
}
/*##############
The following was in the documentation. The code did not implement it.
If \a receiver is 0, all objects get their events. If \a event_type is
0, all types of events are dispatched.
*/
/*!
Immediately dispatches all events which have been previously enqueued
with QApplication::postEvent() and which are for the object \a receiver
and have the \a event_type.
Some event compression may occur. Note that events from the
window system are \e not dispatched by this function.
*/
qt'QApplication::sendPostedEvents() (./qt-2.1.0/src/kernel/qapplication.cpp:1804)
void QApplication::sendPostedEvents( QObject *receiver, int event_type )
{
if ( receiver == 0 ) { // serious error
#if defined(CHECK_NULL)
qWarning( "QApplication::sendPostedEvents: Unexpected null receiver" );
#endif
return;
}
if ( !receiver->pendEvent || !postedEvents )
return;
QPostEventListIt it(*postedEvents);
QPostEvent *pe;
// For accumulating compressed events
QPoint oldpos, newpos;
QSize oldsize, newsize;
QRegion paintRegion;
QRegion erasePaintRegion;
bool first=TRUE;
bool pendEvent = FALSE;
receiver->pendEvent = FALSE;
while ( (pe = it.current()) ) {
++it;
if ( pe->event && pe->receiver == receiver ) {
if ( pe->event->type() != event_type ) {
pendEvent = TRUE;
} else {
postedEvents->take( postedEvents->findRef( pe ) );
pe->event->posted = FALSE;
switch ( event_type ) {
case QEvent::Move:
if ( first ) {
oldpos = ((QMoveEvent*)pe->event)->oldPos();
first = FALSE;
}
newpos = ((QMoveEvent*)pe->event)->pos();
break;
case QEvent::Resize:
if ( first ) {
oldsize = ((QResizeEvent*)pe->event)->oldSize();
first = FALSE;
}
newsize = ((QResizeEvent*)pe->event)->size();
break;
case QEvent::LayoutHint:
first = FALSE;
break;
case QEvent::Paint:
if ( ((QPaintEvent*)pe->event)->erased() )
erasePaintRegion = erasePaintRegion.unite( ((QPaintEvent*)pe->event)->region() );
else
paintRegion = paintRegion.unite( ((QPaintEvent*)pe->event)->region() );
first = FALSE;
break;
default:
sendEvent( receiver, pe->event );
}
delete pe;
}
}
}
if ( !first ) {
if ( event_type == QEvent::LayoutHint ) {
QEvent e( QEvent::LayoutHint );
sendEvent( receiver, &e );
} else if ( event_type == QEvent::Move ) {
QMoveEvent e(newpos, oldpos);
sendEvent( receiver, &e );
} else if ( event_type == QEvent::Resize ) {
QResizeEvent e(newsize, oldsize);
sendEvent( receiver, &e );
} else if ( event_type == QEvent::Paint ) {
if ( receiver->isWidgetType() && ((QWidget*)receiver)->isVisible() ) {
QWidget* w = (QWidget*)receiver;
if ( !erasePaintRegion.isEmpty() )
w->repaint( erasePaintRegion, TRUE );
if ( !paintRegion.isEmpty() )
w->repaint( paintRegion, FALSE );
}
}
}
receiver->pendEvent = receiver->pendEvent || pendEvent;
}
qt'QApplication::removePostedEvents() (./qt-2.1.0/src/kernel/qapplication.cpp:1908)
void QApplication::removePostedEvents( QObject *receiver )
{
if ( !postedEvents || !receiver || !receiver->pendEvent )
return;
QPostEventListIt it( *postedEvents );
QPostEvent * pe;
while( (pe = it.current()) != 0 ) {
++it;
if ( pe->receiver == receiver ) {
postedEvents->take( postedEvents->findRef( pe ) );
pe->event->posted = FALSE;
delete pe;
}
}
}
/*!
Removes \a event from the queue of posted events, and emits a
warning message if appropriate.
*/
qt'QApplication::removePostedEvent() (./qt-2.1.0/src/kernel/qapplication.cpp:1931)
void QApplication::removePostedEvent( QEvent * event )
{
if ( !event || !event->posted || !postedEvents )
return;
QPostEventListIt it( *postedEvents );
QPostEvent * pe;
while( (pe = it.current()) != 0 ) {
++it;
if ( pe->event == event ) {
postedEvents->take( postedEvents->findRef( pe ) );
event->posted = FALSE;
#if defined(DEBUG)
const char *n;
switch ( event->type() ) {
case QEvent::Timer:
n = "Timer";
break;
case QEvent::MouseButtonPress:
n = "MouseButtonPress";
break;
case QEvent::MouseButtonRelease:
n = "MouseButtonRelease";
break;
case QEvent::MouseButtonDblClick:
n = "MouseButtonDblClick";
break;
case QEvent::MouseMove:
n = "MouseMove";
break;
case QEvent::Wheel:
n = "Wheel";
break;
case QEvent::KeyPress:
n = "KeyPress";
break;
case QEvent::KeyRelease:
n = "KeyRelease";
break;
case QEvent::FocusIn:
n = "FocusIn";
break;
case QEvent::FocusOut:
n = "FocusOut";
break;
case QEvent::Enter:
n = "Enter";
break;
case QEvent::Leave:
n = "Leave";
break;
case QEvent::Paint:
n = "Paint";
break;
case QEvent::Move:
n = "Move";
break;
case QEvent::Resize:
n = "Resize";
break;
case QEvent::Create:
n = "Create";
break;
case QEvent::Destroy:
n = "Destroy";
break;
case QEvent::Close:
n = "Close";
break;
case QEvent::Quit:
n = "Quit";
break;
default:
n = "<other>";
break;
}
qWarning("QEvent: Warning: %s event deleted while posted to %s %s",
n,
pe->receiver ? pe->receiver->className() : "null ",
pe->receiver ? pe->receiver->name() : "object" );
// note the beautiful uglehack if !pe->receiver :)
#endif
delete pe;
return;
}
}
}
/*!\internal
Sets the active window as a reaction on a system event. Call this
from the platform specific event handlers.
It sets the activeWindow() and focusWidget() attributes and sends
proper WindowActivate/WindowDeactivate and FocusIn/FocusOut events
to all appropriate widgets.
\sa activeWindow()
*/
qt'QApplication::setActiveWindow() (./qt-2.1.0/src/kernel/qapplication.cpp:2030)
void QApplication::setActiveWindow( QWidget* act )
{
QWidget* window = act?act->topLevelWidget():0;
if ( active_window == window )
return;
QWidget* old_active = active_window;
// first the activation / deactivation events
if ( old_active ) {
active_window = 0;
QCustomEvent e( QEvent::WindowDeactivate, 0 );
QApplication::sendEvent( old_active, &e );
}
active_window = window;
if ( active_window ) {
QCustomEvent e( QEvent::WindowActivate, 0 );
QApplication::sendEvent( active_window, &e );
}
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets...
++it;
if ( (w->topLevelWidget() == old_active || w->topLevelWidget()==active_window )
&& w->palette().active() != w->palette().inactive() )
w->update();
}
// then focus events
QFocusEvent::setReason( QFocusEvent::ActiveWindow );
if ( !active_window && focus_widget ) {
QFocusEvent out( QEvent::FocusOut );
QWidget *tmp = focus_widget;
focus_widget = 0;
QApplication::sendEvent( tmp, &out );
} else if ( active_window ) {
QWidget *w = active_window->focusWidget();
if ( w )
w->setFocus();
else
active_window->focusNextPrevChild( TRUE );
}
QFocusEvent::resetReason();
}
/*!
Returns the desktop widget (also called the root window).
The desktop widget is useful for obtaining the size of the screen.
It can also be used to draw on the desktop.
\code
QWidget *d = QApplication::desktop();
int w=d->width(); // returns screen width
int h=d->height(); // returns screen height
d->setBackgroundColor( red ); // makes desktop red
\endcode
*/
qt'QApplication::desktop() (./qt-2.1.0/src/kernel/qapplication.cpp:2093)
QWidget *QApplication::desktop()
{
if ( !desktopWidget || // not created yet
!desktopWidget->testWFlags( WType_Desktop ) ) { // recreated away
desktopWidget = new QWidget( 0, "desktop", WType_Desktop );
CHECK_PTR( desktopWidget );
}
return desktopWidget;
}
/*!
By default, Qt will try to get the current standard colors, fonts
etc. from the underlying window system's desktop settings (resources),
and use them for all relevant widgets. This behavior can be switched off
by calling this function with \a on set to FALSE.
This static function must be called before creating the QApplication
object, like this:
\code
int main( int argc, char** argv ) {
QApplication::setDesktopSettingsAware( FALSE ); // I know better than the user
QApplication myApp( argc, argv ); // gimme default fonts & colors
...
}
\endcode
\sa desktopSettingsAware()
*/
qt'QApplication::setDesktopSettingsAware() (./qt-2.1.0/src/kernel/qapplication.cpp:2124)
void QApplication::setDesktopSettingsAware( bool on )
{
obey_desktop_settings = on;
}
/*!
Returns the value set by setDesktopSettingsAware(), by default TRUE.
\sa setDesktopSettingsAware()
*/
qt'QApplication::desktopSettingsAware() (./qt-2.1.0/src/kernel/qapplication.cpp:2135)
bool QApplication::desktopSettingsAware()
{
return obey_desktop_settings;
}
/*!
This function enters the main event loop (recursively).
Do not call it unless you really know what you are doing.
\sa exit_loop(), loopLevel()
*/
qt'QApplication::enter_loop() (./qt-2.1.0/src/kernel/qapplication.cpp:2147)
int QApplication::enter_loop()
{
loop_level++;
bool old_app_exit_loop = app_exit_loop;
app_exit_loop = FALSE;
while ( !app_exit_loop )
processNextEvent( TRUE );
app_exit_loop = old_app_exit_loop || quit_now;
loop_level--;
if ( app_exit_loop && !loop_level )
emit aboutToQuit();
return 0;
}
/*!
This function leaves from a recursive call to the main event loop.
Do not call it unless you are an expert.
\sa enter_loop(), loopLevel()
*/
qt'QApplication::exit_loop() (./qt-2.1.0/src/kernel/qapplication.cpp:2173)
void QApplication::exit_loop()
{
app_exit_loop = TRUE;
}
/*!
Returns the current loop level
\sa enter_loop(), exit_loop()
*/
qt'QApplication::loopLevel() (./qt-2.1.0/src/kernel/qapplication.cpp:2185)
int QApplication::loopLevel() const
{
return loop_level;
}
/*!
\fn bool QApplication::isSessionRestored() const
Returns whether the application has been restored from an earlier
\link session.html session \endlink.
\sa sessionId(), commitData(), saveState()
*/
/*!
\fn QString QApplication::sessionId() const
Returns the identifier of the current \link session.html session
\endlink.
If the application has been restored from an earlier session, this
identifier is the same as it was in that previous session.
The session identifier is guaranteed to be unique for both different
applications and different instances of the same application.
\sa isSessionRestored(), commitData(), saveState()
*/
/*!
\fn void QApplication::commitData( QSessionManager& sm )
This function deals with \link session.html session management
\endlink. It is invoked when the \link QSessionManager session
manager \endlink wants the application to commit all its data.
Usually this means saving of all open files, after getting
permission from the user. Furthermore you may want to provide the
user a way to cancel the shutdown.
Note that you should not exit the application within this function.
Instead, the session manager may or may not do this afterwards,
depending on the context.
<strong>Important</strong><br> Within this function, no user
interaction is possible, \e unless you ask the session manager \a sm
for explicit permission. See QSessionManager::allowsInteraction()
and QSessionManager::allowsErrorInteraction() for details and
example usage.
The default implementation requests interaction and sends a close
event to all visible toplevel widgets. If at least one event was
rejected, the shutdown is cancelled.
Details about session management in general can be found \link
session.html here \endlink.
\sa isSessionRestored(), sessionId(), saveState()
*/
qt'QApplication::commitData() (./qt-2.1.0/src/kernel/qapplication.cpp:2248)
void QApplication::commitData( QSessionManager& sm )
{
if ( sm.allowsInteraction() ) {
QWidgetList done;
QWidgetList *list = QApplication::topLevelWidgets();
bool cancelled = FALSE;
QWidget* w = list->first();
while ( !cancelled && w ) {
if ( !w->testWState( WState_ForceHide ) ) {
QCloseEvent e;
sendEvent( w, &e );
cancelled = !e.isAccepted();
if ( !cancelled )
done.append( w );
delete list; // one never knows...
list = QApplication::topLevelWidgets();
w = list->first();
} else {
w = list->next();
}
while ( w && done.containsRef( w ) )
w = list->next();
}
delete list;
if ( cancelled )
sm.cancel();
}
}
/*!
\fn void QApplication::saveState( QSessionManager& sm )
This function deals with \link session.html session management
\endlink It is invoked when the \link QSessionManager session
manager \endlink wants the application to preserve its state for a
future session.
For a text editor this would mean creating a temporary file that
includes the current contents of the edit buffers, the location of
the cursor and other aspects of the current editing session.
Note that you should never exit the application within this
function. Instead, the session manager may or may not do this
afterwards, depending on the context. Futhermore, most session
managers will very likely request a saved state immediately after
the application has been started. This permits the session manager
to learn about the application's restart policy.
<strong>Important</strong><br> Within this function, no user
interaction is possible, \e unless you ask the session manager \a sm
for explicit permission. See QSessionManager::allowsInteraction()
and QSessionManager::allowsErrorInteraction() for details.
Details about session management in general can be found \link
session.html here \endlink
\sa isSessionRestored(), sessionId(), commitData()
*/
qt'QApplication::saveState() (./qt-2.1.0/src/kernel/qapplication.cpp:2309)
void QApplication::saveState( QSessionManager& /* sm */ )
{
}
/*!
Sets the time after which a drag should start.
\sa startDragTime()
*/
qt'QApplication::setStartDragTime() (./qt-2.1.0/src/kernel/qapplication.cpp:2319)
void QApplication::setStartDragTime( int ms )
{
drag_time = ms;
}
/*!
If you support drag'n'drop in you application and a drag should
start after a mouse click and after a certain time elapsed, you
should use the value which this method returns as delay (in ms).
Qt internally uses also this delay e.g. in QMultiLineEdit for starting
a drag.
The defaul value is set to 250 ms.
\sa setStartDragTime(), startDragDistance()
*/
qt'QApplication::startDragTime() (./qt-2.1.0/src/kernel/qapplication.cpp:2337)
int QApplication::startDragTime()
{
return drag_time;
}
/*!
Sets the distance after which a drag should start.
\sa startDragDistance()
*/
qt'QApplication::setStartDragDistance() (./qt-2.1.0/src/kernel/qapplication.cpp:2348)
void QApplication::setStartDragDistance( int l )
{
drag_distance = l;
}
/*!
If you support drag'n'drop in you application and a drag should
start after a mouse click and after moving the mouse a certain distance,
you should use the value which this method returns as the distance. So
if the mouse position of the click is stored in \c startPos and the current
position (e.g. in the mouse move event) is \c currPos, you can find out if a
drag should be started with a code like this:
\code
if ( ( startPos - currPos ).manhattanLength() > QApplication::startDragDistance() )
startTheDrag();
\endcode
Qt internally uses this value too, e.g. in the QFileDialog.
The default value is set to 4 pixels.
\sa setStartDragDistance(), startDragTime(), QPoint::manhattanLength()
*/
qt'QApplication::startDragDistance() (./qt-2.1.0/src/kernel/qapplication.cpp:2373)
int QApplication::startDragDistance()
{
return drag_distance;
}
/*!
\class QSessionManager qsessionmanager.h
\brief The QSessionManager class provides access to the session manager.
\ingroup environment
The QSessionManager class provides access to the session manager
during a \link session.html session management \endlink action. In
Qt, session management actions are handled in the two virtual
functions QApplication::commitData() and QApplication::saveState().
Both functions provide a reference to a session manager object as
argument, thus allowing the application to communicate with the
session manager.
During a session management action, i.e. within one of the two
mentioned functions, no user interaction is possible, \e unless the
application got explicit permission from the session manager. An
ordinary permission can be requested with allowsInteraction(). With
allowsErrorInteraction(), applications can ask for a higher priority
interaction permission in case an error occured.
Another important function is cancel(), which asks the session
manager to cancel the shutdown process.
For sophisticated session managers as provided on Unix/X11,
QSessionManager offers further possibilites to fine-tune an
application's session management behaviour: setRestartCommand(),
setDiscardCommand(), setRestartHint(), setProperty(),
requestPhase2(). Please see the respective function descriptions
for further details.
*/
/*! \enum QSessionManager::RestartHint
This enum type defines the circumstances under which this
application wants to be restarted by the session manager. The
current values are: <ul>
<li> \c RestartIfRunning - if the application still runs by the time
the session is shut down, it wants to be restarted at the start of
the next session.
<li> \c RestartAnyway - the application wants to be started at the
start of the next session, no matter what. (This is useful for
utilities that run just after startup, then quit.)
<li> \c RestartImmediately - the application wants to be started
immediately whenever it is not running.
<li> \c RestartNever - the application does not want to be restarted
automatically.
</ul>
The default hint is \c RestartIfRunning.
*/
/*!
\fn QString QSessionManager::sessionId() const
Returns the identifier of the current \link session.html session
\endlink.
If the application has been restored from an earlier session, this
identifier is the same as it was in that previous session.
\sa QApplication::sessionId()
*/
// ### Note: This function is undocumented, since it is #ifdef'd.
/*!
\fn void* QSessionManager::handle() const
X11 only: returns a handle to the current \c SmcConnection.
*/
/*!
\fn bool QSessionManager::allowsInteraction()
Asks the session manager for permission to interact with the
user. Returns TRUE if the interaction was granted, FALSE
otherwise.
The rationale behind this is to make it possible to synchronize user
interaction during a shutdown. Advanced session managers on
multitasking operating systems may ask all applications
simultaniously to commit their data, which results in a much faster
shutdown.
After the interaction we recommend releasing the user interaction
semaphore with a call to release(). This way, other applications
may get the chance to interact with the user while your application
is still busy saving data.
If the user decides to cancel the shutdown process during the
interaction phase, you must tell the session manager by calling to
cancel().
Here's an example usage of the mentioned functions that may occur
in the QApplication::commitData() function of an application:
\code
void MyApplication::commitData( QSessionManager& sm ) {
if ( sm.allowsInteraction() ) {
switch ( QMessageBox::warning( yourMainWindow, "Application Name",
"Save changes to Document Foo?",
tr("&Yes"),
tr("&No"),
tr("Cancel"),
0, 2) ) {
case 0: // yes
sm.release();
// save document here. If saving fails, call sm.cancel()
break;
case 1: // no
break;
default: // cancel
sm.cancel();
break;
}
} else {
// we did not get permission to interact, then
// do something reasonable instead.
}
}
\endcode
If an error occured within the application while saving its data,
you may want to try allowsErrorInteraction() instead.
\sa QApplication::commitData(), release(), cancel()
*/
/*!
\fn bool QSessionManager::allowsErrorInteraction()
Like allowsInteraction() but tells the session manager in addition
that an error occured. Session managers may treat error interaction
requests with higher priority. That means it is more likely that an
error interaction is granted. However, you are still not guaranteed
that the session manager will grant your request.
\sa allowsInteraction(), release(), cancel()
*/
/*!
\fn void QSessionManager::release()
Releases the session manager's interaction semaphore after an
interaction phase.
\sa allowsInteraction(), allowsErrorInteraction()
*/
/*!
\fn void QSessionManager::cancel()
Tells the session manager to cancel the shutdown process.
Applications should not call this function without asking the user
first.
\sa allowsInteraction(), allowsErrorInteraction()
*/
/*!
\fn void QSessionManager::setRestartHint( RestartHint hint )
Sets the application's restart hint to \a hint. On application
start-up the hint is set to \c RestartIfRunning.
Note that these flags are only hints, a session manager may or may
not obey them.
We recommend setting the restart hint in QApplication::saveState()
since most session managers perform a checkpoint shortly after an
application's startup.
\sa restartHint()
*/
/*!
\fn QSessionManager::RestartHint QSessionManager::restartHint() const
Returns the application's current restart hint. The default is
\c RestartIfRunning.
\sa setRestartHint()
*/
/*!
\fn void QSessionManager::setRestartCommand( const QStringList& command)
If the session manager is capable of restoring sessions, it will
execute \a command in order to restore the application. The command
defaults to
\code
appname -session id
\endcode
The \c -session option is mandatory, otherwise QApplication can not
tell whether it has been restored or what the current session
identifier is. See QApplication::isSessionRestored() and
QApplication::sessionId() for details. If your application is very
simple, it may be possible to store the entire application state in
additional command line options. In general, this is a very bad
idea, since command lines are often limited to a few hundred bytes.
Instead, use temporary files or a database for this purpose. By
marking the data with the unique sessionId(), you will be able to
restore the application in a future session.
\sa restartCommand(), setDiscardCommand(), setRestartHint()
*/
/*!
\fn QStringList QSessionManager::restartCommand() const
Returns the currently set restart command.
\sa setRestartCommand(), restartHint()
*/
/*!
\fn void QSessionManager::setDiscardCommand( const QStringList& )
\sa discardCommand(), setRestartCommand()
*/
/*!
\fn QStringList QSessionManager::discardCommand() const
Returns the currently set discard command.
\sa setDiscardCommand(), restartCommand(), setRestartCommand()
*/
/*!
\fn void QSessionManager::setProperty( const QString& name, const QString& value )
Low-level write access to the application's identification and state
record kept in the session manager.
*/
/*!
\fn void QSessionManager::setProperty( const QString& name, const QStringList& value )
Low-level write access to the application's identification and state
record kept in the session manager.
*/
/*!
\fn bool QSessionManager::isPhase2() const
Returns whether the session manager is currently performing a second
session management phase.
\sa requestPhase2()
*/
/*!
\fn void QSessionManager::requestPhase2()
Requests a second session management phase for the application. The
application may then simply return from the
QApplication::commitData() or QApplication::saveState() function.
The respective function will be called again after the first session
management phase has been finished, this time with isPhase2()
returning TRUE.
The two phases are useful for applications like X11 window manager,
that need to store informations about other application's windows
and therefore have to wait until these applications finished their
respective session management tasks.
\sa isPhase2()
*/
qt'QApplication::sessionId() (./qt-2.1.0/src/kernel/qapplication.h:316)
inline QString QApplication::sessionId() const
{
return session_id;
}
qt'QApplication::sendEvent() (./qt-2.1.0/src/kernel/qapplication.h:349)
inline bool QApplication::sendEvent( QObject *receiver, QEvent *event )
{ return qApp->notify( receiver, event ); }
#endif
qt'QApplication::close_xim() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:400)
void QApplication::close_xim()
{
#if !defined(NO_XIM)
// Calling XCloseIM gives a Purify FMR error
// XCloseIM( qt_xim );
// We prefer a less serious memory leak
qt_xim = 0;
QWidgetList *list= qApp->topLevelWidgets();
QWidgetListIt it(*list);
while(it.current()) {
it.current()->topData()->xic=0;
++it;
}
delete list;
#endif
}
/*****************************************************************************
Default X error handlers
*****************************************************************************/
#if defined(Q_C_CALLBACKS)
extern "C" {
qt'QApplication::create_xim() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:814)
void QApplication::create_xim()
{
#if !defined(NO_XIM)
qt_xim = XOpenIM( appDpy, 0, 0, 0 );
if ( qt_xim ) {
#ifdef USE_X11R6_XIM
XIMCallback destroy;
destroy.callback = (XIMProc)xim_destroy_callback;
destroy.client_data = NULL;
if ( XSetIMValues( qt_xim, XNDestroyCallback, &destroy, NULL) != 0 )
qWarning( "Xlib dosn't support destroy callback");
#endif
XIMStyles *styles=0;
XGetIMValues(qt_xim, XNQueryInputStyle, &styles, NULL, NULL);
if ( styles ) {
int i;
for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ )
if ( styles->supported_styles[i] == xim_preferred_style )
qt_xim_style = xim_preferred_style;
// if the preferred input style couldn't be found, look for
// Nothing
for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ )
if ( styles->supported_styles[i] == (XIMPreeditNothing |
XIMStatusNothing) )
qt_xim_style = XIMPreeditNothing | XIMStatusNothing;
// ... and failing that, None.
for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ )
if ( styles->supported_styles[i] == (XIMPreeditNone |
XIMStatusNone) )
qt_xim_style = XIMPreeditNone | XIMStatusNone;
XFree( styles );
}
if ( qt_xim_style ) {
#ifdef USE_X11R6_XIM
XUnregisterIMInstantiateCallback(appDpy,0,0,0,
(XIMProc )create_xim,0);
#endif
QWidgetList *list= qApp->topLevelWidgets();
QWidgetListIt it(*list);
QWidget * w;
while( (w=it.current()) != 0 ) {
++it;
w->createTLSysExtra();
}
delete list;
} else {
// Give up
qWarning( "No supported input style found."
" See InputMethod documentation.");
close_xim();
}
}
#endif
}
qt'QApplication::setMainWidget() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1431)
void QApplication::setMainWidget( QWidget *mainWidget )
{
extern int qwidget_tlw_gravity; // in qwidget_x11.cpp
main_widget = mainWidget;
if ( main_widget ) { // give WM command line
XSetWMProperties( main_widget->x11Display(), main_widget->winId(),
0, 0, app_argv, app_argc, 0, 0, 0 );
if ( mwTitle )
XStoreName( appDpy, main_widget->winId(), mwTitle );
if ( mwGeometry ) { // parse geometry
int x, y;
int w, h;
int m = XParseGeometry( mwGeometry, &x, &y, (uint*)&w, (uint*)&h );
QSize minSize = main_widget->minimumSize();
QSize maxSize = main_widget->maximumSize();
if ( (m & XValue) == 0 )
x = main_widget->geometry().x();
if ( (m & YValue) == 0 )
y = main_widget->geometry().y();
if ( (m & WidthValue) == 0 )
w = main_widget->width();
if ( (m & HeightValue) == 0 )
h = main_widget->height();
w = QMIN(w,maxSize.width());
h = QMIN(h,maxSize.height());
w = QMAX(w,minSize.width());
h = QMAX(h,minSize.height());
if ( (m & XNegative) ) {
x = desktop()->width() + x - w;
qwidget_tlw_gravity = 3;
}
if ( (m & YNegative) ) {
y = desktop()->height() + y - h;
qwidget_tlw_gravity = (m & XNegative) ? 9 : 7;
}
main_widget->setGeometry( x, y, w, h );
}
}
}
/*****************************************************************************
QApplication cursor stack
*****************************************************************************/
qt'QApplication::setOverrideCursor() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1519)
void QApplication::setOverrideCursor( const QCursor &cursor, bool replace )
{
if ( !cursorStack ) {
cursorStack = new QCursorList;
CHECK_PTR( cursorStack );
cursorStack->setAutoDelete( TRUE );
}
app_cursor = new QCursor( cursor );
CHECK_PTR( app_cursor );
if ( replace )
cursorStack->removeLast();
cursorStack->append( app_cursor );
QWidget* amw = activeModalWidget();
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // for all widgets that have
if ( w->testWState(WState_OwnCursor) &&
( !amw || !w->isVisible() || w->topLevelWidget() == amw ) ) // set a cursor
XDefineCursor( w->x11Display(), w->winId(), app_cursor->handle() );
++it;
}
XFlush( appDpy ); // make X execute it NOW
}
/*!
Restores the effect of setOverrideCursor().
If setOverrideCursor() has been called twice, calling
restoreOverrideCursor() will activate the first cursor set. Calling
this function a second time restores the original widgets cursors.
Application cursors are stored on an internal stack. setOverrideCursor()
pushes the cursor onto the stack, and restoreOverrideCursor() pops the
active cursor off the stack. Every setOverrideCursor() must have an
corresponding restoreOverrideCursor(), otherwise the stack will get out
of sync. overrideCursor() returns 0 if the cursor stack is empty.
\sa setOverrideCursor(), overrideCursor().
*/
qt'QApplication::restoreOverrideCursor() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1560)
void QApplication::restoreOverrideCursor()
{
if ( !cursorStack ) // no cursor stack
return;
cursorStack->removeLast();
app_cursor = cursorStack->last();
if ( QWidget::mapper != 0 && !closingDown() ) {
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) { // set back to original cursors
if ( w->testWState(WState_OwnCursor) )
XDefineCursor( w->x11Display(), w->winId(),
app_cursor ? app_cursor->handle()
: w->cursor().handle() );
++it;
}
XFlush( appDpy );
}
if ( !app_cursor ) {
delete cursorStack;
cursorStack = 0;
}
}
/*!
\fn bool QApplication::hasGlobalMouseTracking()
Returns TRUE if global mouse tracking is enabled, otherwise FALSE.
\sa setGlobalMouseTracking()
*/
/*!
Enables global mouse tracking if \a enable is TRUE or disables it
if \a enable is FALSE.
Enabling global mouse tracking makes it possible for widget event
filters or application event filters to get all mouse move events, even
when no button is depressed. This is useful for special GUI elements,
e.g. tool tips.
Global mouse tracking does not affect widgets and their
mouseMoveEvent(). For a widget to get mouse move events when no button
is depressed, it must do QWidget::setMouseTracking(TRUE).
This function has an internal counter. Each
setGlobalMouseTracking(TRUE) must have a corresponding
setGlobalMouseTracking(FALSE).
\sa hasGlobalMouseTracking(), QWidget::hasMouseTracking()
*/
qt'QApplication::setGlobalMouseTracking() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1612)
void QApplication::setGlobalMouseTracking( bool enable )
{
bool tellAllWidgets;
if ( enable ) {
tellAllWidgets = (++app_tracking == 1);
} else {
tellAllWidgets = (--app_tracking == 0);
}
if ( tellAllWidgets ) {
QWidgetIntDictIt it( *((QWidgetIntDict*)QWidget::mapper) );
register QWidget *w;
while ( (w=it.current()) ) {
if ( app_tracking > 0 ) { // switch on
if ( !w->testWState(WState_MouseTracking) ) {
w->setMouseTracking( TRUE );
w->clearWState(WState_MouseTracking);
}
} else { // switch off
if ( !w->testWState(WState_MouseTracking) ) {
w->setWState(WState_MouseTracking);
w->setMouseTracking( FALSE );
}
}
++it;
}
}
}
/*****************************************************************************
Routines to find a Qt widget from a screen position
*****************************************************************************/
qt'QApplication::widgetAt() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1704)
QWidget *QApplication::widgetAt( int x, int y, bool child )
{
int lx, ly;
Window target;
if ( !XTranslateCoordinates(appDpy, appRootWin, appRootWin,
x, y, &lx, &ly, &target) )
return 0;
if ( !target || target == appRootWin )
return 0;
QWidget *w, *c;
w = QWidget::find( (WId)target );
if ( !w ) {
qt_ignore_badwindow();
target = qt_x11_findClientWindow( target, qt_wm_state, TRUE );
if (qt_badwindow() )
return 0;
w = QWidget::find( (WId)target );
if ( FALSE && !w ) {
// Perhaps the widgets at (x,y) is inside a foreign application?
// Search all toplevel widgets to see if one is within target
QWidgetList *list = topLevelWidgets();
QWidget *widget = list->first();
while ( widget && !w ) {
Window ctarget = target;
if ( widget->isVisible() && !widget->isDesktop() ) {
Window wid = widget->winId();
while ( ctarget && !w ) {
XTranslateCoordinates(appDpy, appRootWin, ctarget,
x, y, &lx, &ly, &ctarget);
if ( ctarget == wid ) {
// Found
w = widget;
XTranslateCoordinates(appDpy, appRootWin, ctarget,
x, y, &lx, &ly, &ctarget);
}
}
}
widget = list->next();
}
delete list;
}
}
if ( child && w ) {
if ( (c = findChildWidget( w, w->mapFromGlobal(QPoint(x, y ) ) ) ) )
return c;
}
return w;
}
/*!
\overload QWidget *QApplication::widgetAt( const QPoint &pos, bool child )
*/
/*!
Flushes the X event queue in the X11 implementation.
Does nothing on other platforms.
\sa syncX()
*/
qt'QApplication::flushX() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1766)
void QApplication::flushX()
{
if ( appDpy )
XFlush( appDpy );
}
/*!
Synchronizes with the X server in the X11 implementation.
Does nothing on other platforms.
\sa flushX()
*/
qt'QApplication::syncX() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1778)
void QApplication::syncX()
{
if ( appDpy )
XSync( appDpy, FALSE ); // don't discard events
}
/*!
Sounds the bell, using the default volume and sound.
*/
qt'QApplication::beep() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:1789)
void QApplication::beep()
{
if ( appDpy )
XBell( appDpy, 0 );
}
/*****************************************************************************
Special lookup functions for windows that have been reparented recently
*****************************************************************************/
qt'QApplication::exec() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2055)
int QApplication::exec()
{
quit_now = FALSE;
quit_code = 0;
enter_loop();
return quit_code;
}
/*!
Processes the next event and returns TRUE if there was an event
(excluding posted events or zero-timer events) to process.
This function returns immediately if \e canWait is FALSE. It might go
into a sleep/wait state if \e canWait is TRUE.
\sa processEvents()
*/
qt'QApplication::processNextEvent() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2074)
bool QApplication::processNextEvent( bool canWait )
{
XEvent event;
int nevents = 0;
emit guiThreadAwake();
if (qt_is_gui_used ) {
sendPostedEvents();
// Two loops so that posted events accumulate
while ( XPending(appDpy) ) {
while ( XPending(appDpy) ) { // also flushes output buffer
if ( app_exit_loop ) // quit between events
return FALSE;
XNextEvent( appDpy, &event ); // get next event
nevents++;
if ( x11ProcessEvent( &event ) == 1 )
return TRUE;
}
sendPostedEvents();
}
}
if ( app_exit_loop ) // break immediately
return FALSE;
sendPostedEvents();
static timeval zerotm;
timeval *tm = qt_wait_timer(); // wait for timer or X event
if ( !canWait ) {
if ( !tm )
tm = &zerotm;
tm->tv_sec = 0; // no time to wait
tm->tv_usec = 0;
}
if ( sn_highest >= 0 ) { // has socket notifier(s)
if ( sn_read )
app_readfds = sn_readfds;
else
FD_ZERO( &app_readfds );
if ( sn_write )
app_writefds = sn_writefds;
if ( sn_except )
app_exceptfds = sn_exceptfds;
} else {
FD_ZERO( &app_readfds );
}
int highest = sn_highest;
if ( qt_is_gui_used ) {
FD_SET( app_Xfd, &app_readfds );
highest = QMAX( highest, app_Xfd );
XFlush( appDpy );
}
int nsel;
#if defined(UNIX) && defined(QT_THREAD_SUPPORT)
FD_SET( qt_thread_pipe[0], &app_readfds );
highest = QMAX( highest, qt_thread_pipe[0] );
#endif
if ( qt_preselect_handler )
qt_preselect_handler();
qt'QApplication::wakeUpGuiThread() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2187)
void QApplication::wakeUpGuiThread()
{
#if defined(UNIX) && defined(QT_THREAD_SUPPORT)
char c = '*';
int nbytes;
if ( ::ioctl(qt_thread_pipe[1], FIONREAD, (char*)&nbytes) >= 0 && nbytes == 0 ) {
::write( qt_thread_pipe[1], &c, 1 );
}
#endif
}
qt'QApplication::x11ClientMessage() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2198)
int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only)
{
QETWidget *widget = (QETWidget*)w;
if ( event->xclient.format == 32 && event->xclient.message_type ) {
if ( event->xclient.message_type == qt_wm_protocols ) {
Atom a = event->xclient.data.l[0];
if ( a == qt_wm_delete_window ) {
if ( passive_only ) return 0;
widget->translateCloseEvent(event);
}
else if ( a == qt_wm_take_focus ) {
QWidget * amw = activeModalWidget();
if ( (ulong) event->xclient.data.l[1] > qt_x_time )
qt_x_time = event->xclient.data.l[1];
if ( amw && amw != widget ) {
amw->raise(); // help broken window managers
XSetInputFocus( appDpy, amw->winId(),
RevertToParent, qt_x_time );
}
} else if ( a == qt_net_wm_context_help ) {
QWhatsThis::enterWhatsThisMode();
}
} else if ( event->xclient.message_type == qt_qt_scrolldone ) {
widget->translateScrollDoneEvent(event);
} else if ( event->xclient.message_type == qt_xdnd_position ) {
qt_handle_xdnd_position( widget, event, passive_only );
} else if ( event->xclient.message_type == qt_xdnd_enter ) {
qt_handle_xdnd_enter( widget, event, passive_only );
} else if ( event->xclient.message_type == qt_xdnd_status ) {
qt_handle_xdnd_status( widget, event, passive_only );
} else if ( event->xclient.message_type == qt_xdnd_leave ) {
qt_handle_xdnd_leave( widget, event, passive_only );
} else if ( event->xclient.message_type == qt_xdnd_drop ) {
qt_handle_xdnd_drop( widget, event, passive_only );
} else if ( event->xclient.message_type == qt_xdnd_finished ) {
qt_handle_xdnd_finished( widget, event, passive_only );
} else {
if ( passive_only ) return 0;
// All other are interactions
}
} else {
qt_motifdnd_handle_msg( widget, event, passive_only );
}
return 0;
}
/*!
Returns
1 if the event was consumed by special handling,
0 if the event was consumed by normal handling, and
-1 if the event was for an unrecognized widget.
\internal
This documentation is unclear.
*/
qt'QApplication::x11ProcessEvent() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2256)
int QApplication::x11ProcessEvent( XEvent* event )
{
if ( qt_x11EventFilter(event) ) // send through app filter
return 1;
QETWidget *widget = (QETWidget*)QWidget::find( (WId)event->xany.window );
if ( wPRmapper ) { // just did a widget reparent?
if ( widget == 0 ) { // not in std widget mapper
switch ( event->type ) { // only for mouse/key events
case ButtonPress:
case ButtonRelease:
case MotionNotify:
case XKeyPress:
case XKeyRelease:
widget = qPRFindWidget( event->xany.window );
break;
}
}
else if ( widget->testWState(WState_Reparented) )
qPRCleanup( widget ); // remove from alt mapper
}
QETWidget *keywidget=0;
bool grabbed=FALSE;
if ( event->type==XKeyPress || event->type==XKeyRelease ) {
keywidget = (QETWidget*)QWidget::keyboardGrabber();
if ( keywidget ) {
grabbed = TRUE;
} else {
if ( focus_widget )
keywidget = (QETWidget*)focus_widget;
else if ( inPopupMode() )
widget = (QETWidget*) activePopupWidget();
if ( !keywidget && widget )
keywidget = widget->focusWidget()?(QETWidget*)widget->focusWidget():widget;
}
}
int xkey_keycode = event->xkey.keycode;
if ( XFilterEvent( event, keywidget ? keywidget->topLevelWidget()->winId() : None ) ) {
if ( keywidget )
composingKeycode = xkey_keycode; // ### not documented in xlib
return 1;
}
if ( event->type == MappingNotify ) { // keyboard mapping changed
XRefreshKeyboardMapping( &event->xmapping );
return 0;
}
if ( event->type == PropertyNotify ) { // some properties changed
qt_x_time = event->xproperty.time;
if ( event->xproperty.window == appRootWin ) { // root properties
if ( event->xproperty.atom == qt_selection_sentinel ) {
if ( qt_check_selection_sentinel( event ) )
emit clipboard()->dataChanged();
}
else if ( obey_desktop_settings ) {
if ( event->xproperty.atom == qt_resource_manager )
qt_set_x11_resources();
else if ( event->xproperty.atom == qt_desktop_properties )
qt_set_desktop_properties();
}
} else if ( widget ) { // widget properties
// nothing yet
}
return 0;
}
if ( !widget ) { // don't know this window
QWidget* popup = QApplication::activePopupWidget();
if ( popup ) {
/*
That is more than suboptimal. The real solution should
do some keyevent and buttonevent translation, so that
the popup still continues to work as the user expects.
Unfortunately this translation is currently only
possible with a known widget. I'll change that soon
(Matthias).
*/
// Danger - make sure we don't lock the server
switch ( event->type ) {
case ButtonPress:
case ButtonRelease:
case XKeyPress:
case XKeyRelease:
do {
popup->close();
} while ( (popup = qApp->activePopupWidget()) );
return 1;
}
} else {
void qt_np_process_foreign_event(XEvent*); // in qnpsupport.cpp
if ( !activeModalWidget() ||
( event->type != ButtonRelease &&
event->type != ButtonPress &&
event->type != MotionNotify &&
event->type != XKeyPress &&
event->type != XKeyRelease ) )
qt_np_process_foreign_event( event );
}
return -1;
}
if ( app_do_modal ) // modal event handling
if ( !qt_try_modal(widget, event) ) {
if ( event->type == ClientMessage )
x11ClientMessage( widget, event, TRUE );
return 1;
}
if ( widget->x11Event(event) ) // send through widget filter
return 1;
switch ( event->type ) {
case ButtonPress: // mouse event
case ButtonRelease:
case MotionNotify:
qt_x_time = (event->type == MotionNotify) ?
event->xmotion.time : event->xbutton.time;
widget->translateMouseEvent( event );
break;
case XKeyPress: // keyboard event
case XKeyRelease: {
qt_x_time = event->xkey.time;
if ( keywidget ) // should always exist
keywidget->translateKeyEvent( event, grabbed );
}
break;
case GraphicsExpose:
case Expose: // paint event
widget->translatePaintEvent( event );
break;
case ConfigureNotify: // window move/resize event
widget->translateConfigEvent( event );
break;
case XFocusIn: { // got focus
if ( widget == desktop() )
break;
if ( inPopupMode() ) // some delayed focus event to ignore
break;
if ( !widget->isTopLevel() )
break;
if ( event->xfocus.mode != NotifyNormal )
break;
if ( event->xfocus.detail != NotifyAncestor &&
event->xfocus.detail != NotifyInferior &&
event->xfocus.detail != NotifyNonlinear )
break;
setActiveWindow( widget );
}
break;
case XFocusOut: // lost focus
if ( widget == desktop() )
break;
if ( !widget->isTopLevel() )
break;
if ( event->xfocus.mode != NotifyNormal )
break;
if ( event->xfocus.detail != NotifyAncestor &&
event->xfocus.detail != NotifyNonlinearVirtual &&
event->xfocus.detail != NotifyNonlinear )
break;
if ( !inPopupMode() && widget == active_window )
setActiveWindow( 0 );
break;
case EnterNotify: { // enter window
qt_x_time = event->xcrossing.time;
if ( QWidget::mouseGrabber() && widget != QWidget::mouseGrabber() )
break;
if ( inPopupMode() && widget->topLevelWidget() != activePopupWidget() )
break;
if ( event->xcrossing.mode != NotifyNormal ||
event->xcrossing.detail == NotifyVirtual ||
event->xcrossing.detail == NotifyNonlinearVirtual )
break;
curWin = widget->winId();
QEvent e( QEvent::Enter );
QApplication::sendEvent( widget, &e );
widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it
}
break;
case LeaveNotify: { // leave window
qt_x_time = event->xcrossing.time;
if ( QWidget::mouseGrabber() && widget != QWidget::mouseGrabber() )
break;
if ( widget->winId() != curWin )
break;
if ( event->xcrossing.mode != NotifyNormal )
break;
if ( !widget->isDesktop() )
widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it
QEvent e( QEvent::Leave );
QApplication::sendEvent( widget, &e );
}
break;
case UnmapNotify: // window hidden
if ( widget->isTopLevel() && widget->isVisible() && !widget->isPopup() ) {
widget->clearWState( WState_Visible );
QHideEvent e( TRUE );
QApplication::sendEvent( widget, &e );
widget->sendHideEventsToChildren( TRUE );
}
break;
case MapNotify: // window shown
if ( widget->isTopLevel() && !widget->isVisible()
&& !widget->testWState( WState_ForceHide ) ) {
widget->setWState( WState_Visible );
widget->sendShowEventsToChildren( TRUE );
QShowEvent e( TRUE );
QApplication::sendEvent( widget, &e );
}
break;
case ClientMessage: // client message
return x11ClientMessage(widget,event,FALSE);
case ReparentNotify: // window manager reparents
while ( XCheckTypedWindowEvent( widget->x11Display(),
widget->winId(),
ReparentNotify,
event ) )
; // skip old reparent events
if ( event->xreparent.parent == appRootWin ) {
if ( widget->isTopLevel() ) {
widget->topData()->parentWinId = event->xreparent.parent;
if ( qt_deferred_map_contains( widget ) ) {
qt_deferred_map_take( widget );
XMapWindow( appDpy, widget->winId() );
}
}
}
else if (!QWidget::find((WId)event->xreparent.parent) )
{
Window parent = event->xreparent.parent;
int x = event->xreparent.x;
int y = event->xreparent.y;
XWindowAttributes a;
qt_ignore_badwindow();
XGetWindowAttributes( widget->x11Display(), parent, &a );
if (qt_badwindow())
break;
QRect& r = widget->crect;
QRect frect ( r );
// help OL(V)WM to get things right: they sometimes
// need a little bit longer, i.e. both a and x/y may
// contain bogus values at this point in time.
int count = 0;
while ( count < 10 && a.x == 0 && a.y == 0 && ( a.width < r.width() || a.height < r.height() ) ) {
count++;
QApplication::syncX();
qt_ignore_badwindow();
XGetWindowAttributes( widget->x11Display(), parent, &a );
if (qt_badwindow())
break;
}
if ( x <= 4 && y <= 4 && a.width <= r.width()+8 && a.height <= r.height()+8 ) {
// multi reparenting window manager, parent is
// just a shell. The 4 is for safety to support
// BlackBox...
Window root_return, parent_return, *children_return;
unsigned int nchildren;
if ( XQueryTree( widget->x11Display(), parent,
&root_return, &parent_return,
&children_return, &nchildren) ) {
if ( children_return )
XFree( (void*) children_return );
XWindowAttributes a2;
qt_ignore_badwindow();
XGetWindowAttributes( widget->x11Display(), parent_return,
&a2 );
if (qt_badwindow())
break;
x += a.x;
y += a.y;
frect.setRect(r.left() - x , r.top() - y, a2.width, a2.height );
}
} else {
if ( x == y && x == 0 && a.x == r.x() && a.y == r.y() ) {
// we do not believe this, OL(V)M tries to lie to us
XWindowAttributes aw;
qt_ignore_badwindow();
XGetWindowAttributes( widget->x11Display(), widget->winId(), &aw );
if (qt_badwindow())
break;
x = aw.x;
y = aw.y;
}
// single reparenting window manager
frect.setRect(r.left() - x, r.top() - y, a.width, a.height );
}
widget->fpos = frect.topLeft();
widget->topData()->fsize = frect.size();
// store the parent. Useful for many things, embedding for instance.
widget->topData()->parentWinId = parent;
}
break;
case SelectionRequest:
if ( qt_xdnd_selection ) {
XSelectionRequestEvent *req = &event->xselectionrequest;
if ( req && req->selection == qt_xdnd_selection ) {
qt_xdnd_handle_selection_request( req );
break;
}
}
// FALL THROUGH
case SelectionClear:
case SelectionNotify:
if ( qt_clipboard ) {
QCustomEvent e( QEvent::Clipboard, event );
QApplication::sendEvent( qt_clipboard, &e );
}
break;
default:
break;
}
return 0;
}
/*!
Processes pending events, for \a maxtime milliseconds or until there
are no more events to process, then return.
You can call this function occasionally when you program is busy doing a
long operation (e.g. copying a file).
\sa processOneEvent(), exec(), QTimer
*/
qt'QApplication::processEvents() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2607)
void QApplication::processEvents( int maxtime )
{
QTime start = QTime::currentTime();
QTime now;
while ( !app_exit_loop && processNextEvent(FALSE) ) {
now = QTime::currentTime();
if ( start.msecsTo(now) > maxtime )
break;
}
}
/*!
This virtual function is only implemented under X11.
If you create an application that inherits QApplication and reimplement this
function, you get direct access to all X events that the are received
from the X server.
Return TRUE if you want to stop the event from being dispatched, or return
FALSE for normal event dispatching.
*/
qt'QApplication::x11EventFilter() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2630)
bool QApplication::x11EventFilter( XEvent * )
{
return FALSE;
}
/*****************************************************************************
Modal widgets; Since Xlib has little support for this we roll our own
modal widget mechanism.
A modal widget without a parent becomes application-modal.
A modal widget with a parent becomes modal to its parent and grandparents..
qt_enter_modal()
Enters modal state
Arguments:
QWidget *widget A modal widget
qt_leave_modal()
Leaves modal state for a widget
Arguments:
QWidget *widget A modal widget
*****************************************************************************/
qt'QApplication::openPopup() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2766)
void QApplication::openPopup( QWidget *popup )
{
if ( !popupWidgets ) { // create list
popupWidgets = new QWidgetList;
CHECK_PTR( popupWidgets );
if ( !activeBeforePopup )
activeBeforePopup = new QGuardedPtr<QWidget>;
(*activeBeforePopup) = active_window;
}
popupWidgets->append( popup ); // add to end of list
if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard
int r;
r = XGrabKeyboard( popup->x11Display(), popup->winId(), TRUE,
GrabModeSync, GrabModeAsync, CurrentTime );
if ( (popupGrabOk = (r == GrabSuccess)) ) {
r = XGrabPointer( popup->x11Display(), popup->winId(), TRUE,
(uint)(ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | EnterWindowMask |
LeaveWindowMask | PointerMotionMask),
GrabModeSync, GrabModeAsync,
None, None, CurrentTime );
if ( (popupGrabOk = (r == GrabSuccess)) ) {
XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime );
} else {
XUngrabKeyboard( popup->x11Display(), CurrentTime );
}
}
}
// popups are not focus-handled by the window system (the first
// popup grabbed the keyboard), so we have to do that manually: A
// new popup gets the focus
QFocusEvent::setReason( QFocusEvent::Popup );
if ( popup->focusWidget())
popup->focusWidget()->setFocus();
else
popup->setFocus();
QFocusEvent::resetReason();
}
qt'QApplication::closePopup() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:2806)
void QApplication::closePopup( QWidget *popup )
{
if ( !popupWidgets )
return;
popupWidgets->removeRef( popup );
if (popup == popupOfPopupButtonFocus) {
popupButtonFocus = 0;
popupOfPopupButtonFocus = 0;
}
if ( popupWidgets->count() == 0 ) { // this was the last popup
popupCloseDownMode = TRUE; // control mouse events
delete popupWidgets;
popupWidgets = 0;
if ( !qt_nograb() && popupGrabOk ) { // grabbing not disabled
XUngrabKeyboard( popup->x11Display(), CurrentTime );
if ( mouseButtonState != 0
|| popup->geometry(). contains(QPoint(mouseGlobalXPos, mouseGlobalYPos) ) )
{ // mouse release event or inside
XAllowEvents( popup->x11Display(), AsyncPointer,
CurrentTime );
} else { // mouse press event
mouseButtonPressTime -= 10000; // avoid double click
XAllowEvents( popup->x11Display(), ReplayPointer,CurrentTime );
}
XUngrabPointer( popup->x11Display(), CurrentTime );
XFlush( popup->x11Display() );
}
active_window = (*activeBeforePopup);
// restore the former active window immediately, although
// we'll get a focusIn later from X
if ( active_window ) {
QFocusEvent::setReason( QFocusEvent::Popup );
if (active_window->focusWidget())
active_window->focusWidget()->setFocus();
else
active_window->setFocus();
QFocusEvent::resetReason();
}
}
else {
// popups are not focus-handled by the window system (the
// first popup grabbed the keyboard), so we have to do that
// manually: A popup was closed, so the previous popup gets
// the focus.
QFocusEvent::setReason( QFocusEvent::Popup );
QWidget* aw = popupWidgets->getLast();
if (aw->focusWidget())
aw->focusWidget()->setFocus();
else
aw->setFocus();
QFocusEvent::resetReason();
}
}
/*****************************************************************************
Timer handling; Xlib has no application timer support so we'll have to
make our own from scratch.
NOTE: These functions are for internal use. QObject::startTimer() and
QObject::killTimer() are for public use.
The QTimer class provides a high-level interface which translates
timer events into signals.
qStartTimer( interval, obj )
Starts a timer which will run until it is killed with qKillTimer()
Arguments:
int interval timer interval in milliseconds
QObject *obj where to send the timer event
Returns:
int timer identifier, or zero if not successful
qKillTimer( timerId )
Stops a timer specified by a timer identifier.
Arguments:
int timerId timer identifier
Returns:
bool TRUE if successful
qKillTimer( obj )
Stops all timers that are sent to the specified object.
Arguments:
QObject *obj object receiving timer events
Returns:
bool TRUE if successful
*****************************************************************************/
//
// Internal data structure for timers
//
qt'QApplication::setCursorFlashTime() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4160)
void QApplication::setCursorFlashTime( int msecs )
{
cursor_flash_time = msecs;
}
/*!
Returns the text cursor's flash time in milliseconds. The flash time is the
time requried to display, invert and restore the caret display.
The default value is 1000 milliseconds. Under Windows, the control
panel value is used.
Widgets should not cache this value since it may vary any time the
user changes the global desktop settings.
\sa setCursorFlashTime()
*/
qt'QApplication::cursorFlashTime() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4178)
int QApplication::cursorFlashTime()
{
return cursor_flash_time;
}
/*!
Sets the time limit that distinguishes a double click from two
consecutive mouse clicks to \a ms milliseconds.
Under windows, calling this function sets the double click
interval for all windows.
\sa doubleClickInterval()
*/
qt'QApplication::setDoubleClickInterval() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4193)
void QApplication::setDoubleClickInterval( int ms )
{
mouse_double_click_time = ms;
}
/*!
Returns the maximum duration for a double click.
The default value is 400 milliseconds. Under Windows, the control
panel value is used.
\sa setDoubleClickInterval()
*/
qt'QApplication::doubleClickInterval() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4208)
int QApplication::doubleClickInterval()
{
return mouse_double_click_time;
}
/*!
Sets the number of lines to scroll when the mouse wheel is
rotated.
If this number exceeds the number of visible lines in a certain
widget, the widget should interpreted the scroll operation as a
single page up / page down operation instead.
\sa wheelScrollLines()
*/
qt'QApplication::setWheelScrollLines() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4224)
void QApplication::setWheelScrollLines( int n )
{
wheel_scroll_lines = n;
}
/*!
Returns the number of lines to scroll when the mouse wheel is rotated.
\sa setWheelScrollLines()
*/
qt'QApplication::wheelScrollLines() (./qt-2.1.0/src/kernel/qapplication_x11.cpp:4234)
int QApplication::wheelScrollLines()
{
return wheel_scroll_lines;
}
/*****************************************************************************
Session management support (-D QT_SM_SUPPORT to enable it)
*****************************************************************************/
qt'QApplication::clipboard() (./qt-2.1.0/src/kernel/qclipboard.cpp:134)
QClipboard *QApplication::clipboard()
{
if ( qt_clipboard == 0 ) {
qt_clipboard = new QClipboard;
CHECK_PTR( qt_clipboard );
qAddPostRoutine( cleanupClipboard );
}
return (QClipboard *)qt_clipboard;
}
/*!
Returns the clipboard text, or a
\link QString::operator!() null string\endlink
if the clipboard does not contain any text.
\sa setText() data()
*/