📄 qapplication.cpp
字号:
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()) // widget is a parent w->destroy(true, true); } delete myMapper; } 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);}/*! 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. \warning To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible. 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; QStyle* old = QApplicationPrivate::app_style; QApplicationPrivate::app_style = style; // clean up the old style if (old) { if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { for (QWidgetMapper::ConstIterator it = QWidgetPrivate::mapper->constBegin(); it != QWidgetPrivate::mapper->constEnd(); ++it) { register QWidget *w = *it; if (!(w->windowType() == Qt::Desktop) && // except desktop w->testAttribute(Qt::WA_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 (QApplicationPrivate::set_pal) { QApplication::setPalette(*QApplicationPrivate::set_pal); } else if (QApplicationPrivate::sys_pal) { QApplicationPrivate::initializeWidgetPaletteHash(); QApplicationPrivate::setPalette_helper(*QApplicationPrivate::sys_pal, /*className=*/0, /*clearWidgetPaletteHash=*/false); } else if (!QApplicationPrivate::sys_pal) { // Initialize the sys_pal if it hasn't happened yet... QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); } // initialize the application with the new style QApplicationPrivate::app_style->polish(qApp); // re-polish existing widgets if necessary if (old) { if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { for (QWidgetMapper::ConstIterator it = QWidgetPrivate::mapper->constBegin(); it != QWidgetPrivate::mapper->constEnd(); ++it) { register QWidget *w = *it; if (!(w->windowType() == Qt::Desktop)) { // except desktop if (w->testAttribute(Qt::WA_WState_Polished)) QApplicationPrivate::app_style->polish(w); // repolish QEvent e(QEvent::StyleChange); QApplication::sendEvent(w, &e);#ifdef QT3_SUPPORT w->styleChange(*old);#endif w->update(); } } } delete old; } if (QApplicationPrivate::focus_widget) { QFocusEvent in(QEvent::FocusIn, Qt::OtherFocusReason); QApplication::sendEvent(QApplicationPrivate::focus_widget->style(), &in); QApplicationPrivate::focus_widget->update(); }}/*! \overload Requests a QStyle object for \a style from the QStyleFactory. The string must be one of the QStyleFactory::keys(), typically one of "windows", "motif", "cde", "plastique", "windowsxp", or "macintosh". Style names are case insensitive. Returns 0 if an unknown \a style is passed, otherwise the QStyle object returned is set as the application's GUI style. \warning To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible.*/QStyle* QApplication::setStyle(const QString& style){ QStyle *s = QStyleFactory::create(style); if (!s) return 0; setStyle(s); return s;}/*! Returns the color specification. \sa QApplication::setColorSpec() */int QApplication::colorSpec(){ return QApplicationPrivate::app_cspec;}/*! Sets the color specification for the application to \a spec. The color specification controls how the application allocates colors when run on a display with a limited amount of colors, e.g. 8 bit / 256 color displays. The color specification must be set before you create the QApplication object. The options are: \list \o QApplication::NormalColor. This is the default color allocation strategy. Use this option if your application uses buttons, menus, texts and pixmaps with few colors. With this option, 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 colors. \o QApplication::CustomColor. Use this option if your application needs a small number of custom colors. On X11, this option is the same as NormalColor. On Windows, Qt creates a Windows palette, and allocates colors to it on demand. \o QApplication::ManyColor. Use this option if your application is very color hungry
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -