qapplication.cpp

来自「QT 开发环境里面一个很重要的文件」· C++ 代码 · 共 2,012 行 · 第 1/5 页

CPP
2,012
字号
/*!  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 as  true. A modal widget must be closed before the user can continue  with other parts of the program.  Modal widgets are organized in a stack. This function returns  the active modal widget at the top of the stack.  \sa activePopupWidget(), topLevelWidgets()*/QWidget *QApplication::activeModalWidget(){    return qt_modal_stack && !qt_modal_stack->isEmpty() ? qt_modal_stack->first() : 0;}/*!  Cleans up any window system resources that were allocated by this  application. Sets the global variable \c qApp to 0.*/QApplication::~QApplication(){    Q_D(QApplication);#ifndef QT_NO_CLIPBOARD    // flush clipboard contents    if (qt_clipboard) {        QEvent event(QEvent::Clipboard);        QApplication::sendEvent(qt_clipboard, &event);    }#endif    //### this should probable be done even later    qt_call_post_routines();    // kill timers before closing down the dispatcher    d->toolTipWakeUp.stop();    d->toolTipFallAsleep.stop();    d->eventDispatcher->closingDown();    d->eventDispatcher = 0;    delete qt_desktopWidget;    qt_desktopWidget = 0;    QApplicationPrivate::is_app_closing = true;    QApplicationPrivate::is_app_running = false;#ifndef QT_NO_CLIPBOARD    delete qt_clipboard;    qt_clipboard = 0;#endif    // delete widget mapper    if (QWidgetPrivate::mapper) {        QWidgetMapper * myMapper = QWidgetPrivate::mapper;        QWidgetPrivate::mapper = 0;        for (QWidgetMapper::Iterator it = myMapper->begin(); it != myMapper->end(); ++it) {            register QWidget *w = *it;            if (!w->parent())                        // window                w->destroy(true, true);        }        delete myMapper;    }    // delete uncreated widgets    if (QWidgetPrivate::uncreatedWidgets) {        QWidgetSet *mySet = QWidgetPrivate::uncreatedWidgets;        QWidgetPrivate::uncreatedWidgets = 0;        for (QWidgetSet::Iterator it = mySet->begin(); it != mySet->end(); ++it) {            register QWidget *w = *it;            if (!w->parent())                        // window                w->destroy(true, true);        }        delete mySet;    }    delete QApplicationPrivate::app_pal;    QApplicationPrivate::app_pal = 0;    delete QApplicationPrivate::sys_pal;    QApplicationPrivate::sys_pal = 0;    delete QApplicationPrivate::set_pal;    QApplicationPrivate::set_pal = 0;    app_palettes()->clear();    delete QApplicationPrivate::app_font;    QApplicationPrivate::app_font = 0;    app_fonts()->clear();    delete QApplicationPrivate::app_style;    QApplicationPrivate::app_style = 0;    delete QApplicationPrivate::app_icon;    QApplicationPrivate::app_icon = 0;#ifndef QT_NO_CURSOR    d->cursor_list.clear();#endif#ifndef QT_NO_DRAGANDDROP    if (qt_is_gui_used)        delete QDragManager::self();#endif    qt_cleanup();    if (QApplicationPrivate::widgetCount)        qDebug("Widgets left: %i    Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances);#ifndef QT_NO_SESSIONMANAGER    delete d->session_manager;    d->session_manager = 0;#endif //QT_NO_SESSIONMANAGER    qt_app_has_font = false;    QApplicationPrivate::obey_desktop_settings = true;    QApplicationPrivate::cursor_flash_time = 1000;    QApplicationPrivate::mouse_double_click_time = 400;    QApplicationPrivate::keyboard_input_time = 400;#ifndef QT_NO_WHEELEVENT    QApplicationPrivate::wheel_scroll_lines = 3;#endif    drag_time = 500;    drag_distance = 4;    layout_direction = Qt::LeftToRight;    QApplicationPrivate::app_strut = QSize(0, 0);    QApplicationPrivate::animate_ui = true;    QApplicationPrivate::animate_menu = false;    QApplicationPrivate::fade_menu = false;    QApplicationPrivate::animate_combo = false;    QApplicationPrivate::animate_tooltip = false;    QApplicationPrivate::fade_tooltip = false;    QApplicationPrivate::widgetCount = false;}/*!    \fn QWidget *QApplication::widgetAt(const QPoint &point)    Returns the widget at global screen position \a point, or 0 if there    is no Qt widget there.    This function can be slow.    \sa QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard()*/QWidget *QApplication::widgetAt(const QPoint &p){    QWidget *window = QApplication::topLevelAt(p);    if (!window)        return 0;    QWidget *child = 0;    if (!window->testAttribute(Qt::WA_TransparentForMouseEvents))        child = window->childAt(window->mapFromGlobal(p));    if (child)        return child;    if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) {        //shoot a hole in the widget and try once again,        //suboptimal on Qt/E where we do know the stacking order        //of the toplevels.        int x = p.x();        int y = p.y();        QRegion oldmask = window->mask();        QPoint wpoint = window->mapFromGlobal(QPoint(x, y));        QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask)                          - QRegion(wpoint.x(), wpoint.y(), 1, 1);        window->setMask(newmask);        QWidget *recurse = 0;        if (QApplication::topLevelAt(p) != window) // verify recursion will terminate            recurse = widgetAt(x, y);        if (oldmask.isEmpty())            window->clearMask();        else            window->setMask(oldmask);        return recurse;    }    return window;}/*!    \fn QWidget *QApplication::widgetAt(int x, int y)    \overload    Returns the widget at global screen position (\a x, \a y), or 0    if there is no Qt widget there.*//*!    \fn void QApplication::setArgs(int argc, char **argv)    \internal*//*!    \internal*/bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents){    if ((event->type() == QEvent::UpdateRequest#ifdef QT3_SUPPORT          || event->type() == QEvent::LayoutHint#endif          || event->type() == QEvent::LayoutRequest          || event->type() == QEvent::Resize          || event->type() == QEvent::Move          || event->type() == QEvent::LanguageChange	  || event->type() == QEvent::InputMethod)) {        for (int i = 0; i < postedEvents->size(); ++i) {            const QPostEvent &cur = postedEvents->at(i);            if (cur.receiver != receiver || cur.event == 0 || cur.event->type() != event->type())                continue;            if (cur.event->type() == QEvent::LayoutRequest#ifdef QT3_SUPPORT                 || cur.event->type() == QEvent::LayoutHint#endif                 || cur.event->type() == QEvent::UpdateRequest) {                ;            }            else if (cur.event->type() == QEvent::Resize) {                ((QResizeEvent *)(cur.event))->s = ((QResizeEvent *)event)->s;            } else if (cur.event->type() == QEvent::Move) {                ((QMoveEvent *)(cur.event))->p = ((QMoveEvent *)event)->p;            } else if (cur.event->type() == QEvent::LanguageChange) {                ;	    } else if ( cur.event->type() == QEvent::InputMethod ) {                *(QInputMethodEvent *)(cur.event) = *(QInputMethodEvent *)event;            } else {                continue;            }            return true;        }        return false;    }    return QCoreApplication::compressEvent(event, receiver, postedEvents);}#ifndef QT_NO_STYLE_STYLESHEET/*!    \property QApplication::styleSheet    \brief the application style sheet    \since 4.2    \sa QWidget::setStyle(), {Customizing Widgets using Style Sheets}*/QString QApplication::styleSheet() const{    return QApplicationPrivate::styleSheet;}void QApplication::setStyleSheet(const QString& styleSheet){    QApplicationPrivate::styleSheet = styleSheet;    QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle*>(QApplicationPrivate::app_style);    if (styleSheet.isEmpty()) { // application style sheet removed        if (!proxy)            return; // there was no stylesheet before        setStyle(proxy->base);    } else if (proxy) { // style sheet update, just repolish        proxy->repolish(qApp);    } else { // stylesheet set the first time        QStyleSheetStyle *newProxy = new QStyleSheetStyle(QApplicationPrivate::app_style);        QApplicationPrivate::app_style->setParent(newProxy);        setStyle(newProxy);    }}#endif // QT_NO_STYLE_STYLESHEET/*!  Returns the application's style object.  \sa setStyle(), QStyle*/QStyle *QApplication::style(){    if (QApplicationPrivate::app_style)        return QApplicationPrivate::app_style;    if (!qt_is_gui_used)        qFatal("No style available in non-gui applications!");#if defined(Q_WS_X11)    if(!QApplicationPrivate::styleOverride)        QApplicationPrivate::x11_initialize_style(); // run-time search for default style#endif    if (!QApplicationPrivate::app_style) {        // Compile-time search for default style        //        QString style;        if (QApplicationPrivate::styleOverride) {            style = *QApplicationPrivate::styleOverride;            delete QApplicationPrivate::styleOverride;            QApplicationPrivate::styleOverride = 0;        } else {#  if defined(Q_WS_WIN) && defined(Q_OS_TEMP)            style = QLatin1String("PocketPC");#elif defined(Q_WS_WIN)            if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP                && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))                style = QLatin1String("WindowsXP");            else                style = QLatin1String("Windows");                // default styles for Windows#elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS)            style = QLatin1String("CDE");                        // default style for X11 on Solaris#elif defined(Q_WS_X11) && defined(Q_OS_IRIX)            style = QLatin1String("SGI");                        // default style for X11 on IRIX#elif defined(Q_WS_X11)                style = QLatin1String("Motif");                // default style for X11#elif defined(Q_WS_MAC)                style = QLatin1String("Macintosh");                // default style for all Mac's#elif defined(Q_WS_QWS)            style = QLatin1String("Plastique");                // default style for small devices#endif        }        QStyle *&app_style = QApplicationPrivate::app_style;        app_style = QStyleFactory::create(style);        if (!app_style) {            QStringList styles = QStyleFactory::keys();            for (int i = 0; i < styles.size(); ++i) {                if ((app_style = QStyleFactory::create(styles.at(i))))                    break;            }        }        if (!app_style)            qFatal("No styles available!");    }    if (!QApplicationPrivate::sys_pal)        QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette());    if (QApplicationPrivate::set_pal) // repolish set palette with the new style        QApplication::setPalette(*QApplicationPrivate::set_pal);    QApplicationPrivate::app_style->polish(qApp);    return QApplicationPrivate::app_style;}/*!    Sets the application's GUI style to \a style. Ownership of the style    object is transferred to QApplication, so QApplication will delete    the style object on application exit or when a new style is set.    Example usage:    \code        QApplication::setStyle(new QWindowsStyle);    \endcode    When switching application styles, the color palette is set back to    the initial colors or the system defaults. This is necessary since    certain styles have to adapt the color palette to be fully    style-guide compliant.    Note that setting the style before a palette has been set    (i.e. before creating QApplication) will cause the application to    use QStyle::standardPalette() for the palette.    \sa style(), QStyle, setPalette(), desktopSettingsAware()*/void QApplication::setStyle(QStyle *style){    if (!style || style == QApplicationPrivate::app_style)        return;    QWidgetList all = allWidgets();    // clean up the old style    if (QApplicationPrivate::app_style) {        if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {            for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {                register QWidget *w = *it;                if (!(w->windowType() == Qt::Desktop) &&        // except desktop                     w->testAttribute(Qt::WA_WState_Polished)) { // has been polished                    QApplicationPrivate::app_style->unpolish(w);                }            }        }        QApplicationPrivate::app_style->unpolish(qApp);    }    QStyle *old = QApplicationPrivate::app_style; // save#ifndef QT_NO_STYLE_STYLESHEET    if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast<QStyleSheetStyle *>(style)) {        // we have a stylesheet already and a new style is being set        QStyleSheetStyle *newProxy = new QStyleSheetStyle(style);        style->setParent(newProxy);        QApplicationPrivate::app_style = newProxy;    } else#endif // QT_NO_STYLE_STYLESHEET        QApplicationPrivate::app_style = style;    QApplicationPrivate::app_style->setParent(qApp); // take ownership    // take care of possible palette requirements of certain gui    // styles. Do it before polishing the application since the style

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?