📄 qapplication.cpp
字号:
/*! Initializes the QApplication object, called from the constructors.*/void QApplicationPrivate::initialize(){ QWidgetPrivate::mapper = new QWidgetMapper; QWidgetPrivate::uncreatedWidgets = new QWidgetSet; if (qt_appType != QApplication::Tty) (void) QApplication::style(); // trigger creation of application style // trigger registering of QVariant's GUI types extern int qRegisterGuiVariant(); qRegisterGuiVariant(); is_app_running = true; // no longer starting up#ifndef QT_NO_SESSIONMANAGER // connect to the session manager Q_Q(QApplication); session_manager = new QSessionManager(q, session_id, session_key);#endif}/*! Returns the type of application (\l Tty, GuiClient, or GuiServer). The type is set when constructing the QApplication object.*/QApplication::Type QApplication::type(){ return qt_appType;}/***************************************************************************** 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 \c Qt::WType_Popup widget flag, e.g. the QMenu widget. When the application opens a popup widget, all events are sent to the popup. 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 at the top of the stack. \sa activeModalWidget(), topLevelWidgets()*/QWidget *QApplication::activePopupWidget(){ return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? QApplicationPrivate::popupWidgets->last() : 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 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; delete QApplicationPrivate::set_font; QApplicationPrivate::set_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 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; // trigger unregistering of QVariant's GUI types extern int qUnregisterGuiVariant(); qUnregisterGuiVariant();}/*! \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; } delete event; 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(), {Qt 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_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) style = QLatin1String("WindowsVista"); else 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) || defined(Q_WS_QWS) style = QLatin1String("Plastique"); // default style for X11 and small devices#elif defined(Q_WS_MAC) style = QLatin1String("Macintosh"); // default style for all Mac's#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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -