📄 q3mainwindow.cpp
字号:
d->tll->addWidget(d->sb, 0); // make the sb stay on top of tool bars if there isn't enough space d->sb->raise(); }}/*! \reimp */void Q3MainWindow::setVisible(bool visible){ Q_D(Q3MainWindow); if (visible) { if (!d->tll) setUpLayout(); // show all floating dock windows not explicitly hidden if (!isVisible()) { for (int i = 0; i < d->dockWindows.size(); ++i) { Q3DockWindow *dw = d->dockWindows.at(i); if (dw->isWindow() && !dw->isVisible() && !dw->testAttribute(Qt::WA_WState_Hidden)) { reinterpret_cast<Q3MainWindow *>(dw)->setAttribute(Qt::WA_WState_Hidden); dw->show(); } } } } else if (isVisible()) { for (int i = 0; i < d->dockWindows.size(); ++i) { Q3DockWindow *dw = d->dockWindows.at(i); if (dw->isWindow() && dw->isVisible()) { dw->hide(); // implicit hide, so clear forcehide reinterpret_cast<Q3MainWindow *>(dw)->setAttribute(Qt::WA_WState_Hidden, false); } } } QWidget::setVisible(visible);}/*! \reimp */QSize Q3MainWindow::sizeHint() const{ Q3MainWindow* that = (Q3MainWindow*) this; // Workaround: because d->tll get's deleted in // totalSizeHint->polish->sendPostedEvents->childEvent->triggerLayout QApplication::sendPostedEvents(that, QEvent::ChildInserted); if (!that->d_func()->tll) that->setUpLayout(); return that->d_func()->tll->totalSizeHint();}/*! \reimp */QSize Q3MainWindow::minimumSizeHint() const{ Q_D(const Q3MainWindow); if (!d->tll) { Q3MainWindow* that = (Q3MainWindow*) this; that->setUpLayout(); } return d->tll->totalMinimumSize();}/*! Sets the central widget for this main window to \a w. The central widget is surrounded by the left, top, right and bottom dock areas. The menu bar is above the top dock area. \sa centralWidget()*/void Q3MainWindow::setCentralWidget(QWidget * w){ Q_D(Q3MainWindow); if (d->mc) d->mc->removeEventFilter(this); d->mc = w; if (d->mc) d->mc->installEventFilter(this); triggerLayout();}/*! Returns a pointer to the main window's central widget. The central widget is surrounded by the left, top, right and bottom dock areas. The menu bar is above the top dock area. \sa setCentralWidget()*/QWidget * Q3MainWindow::centralWidget() const{ return d_func()->mc;}/*! \reimp */void Q3MainWindow::paintEvent(QPaintEvent *){ Q_D(Q3MainWindow); if (d->mb && style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this)) { QPainter p(this); int y = d->mb->height() + 1; QStyleOption opt(0, QStyleOption::SO_Default); opt.rect.setRect(0, y, width(), 1); opt.palette = palette(); opt.state = QStyle::State_Sunken; style()->drawPrimitive(QStyle::PE_Q3Separator, &opt, &p, this); }}bool Q3MainWindow::dockMainWindow(QObject *dock) const{ while (dock) { if (dock->parent() && dock->parent() == const_cast<Q3MainWindow*>(this)) return true; if (qobject_cast<Q3MainWindow*>(dock->parent())) return false; dock = dock->parent(); } return false;}/*! \reimp*/bool Q3MainWindow::eventFilter(QObject* o, QEvent *e){ Q_D(Q3MainWindow); if (e->type() == QEvent::Show && o == this) { if (!d->tll) setUpLayout(); d->tll->activate(); } else if (e->type() == QEvent::ContextMenu && d->dockMenu && (qobject_cast<Q3DockArea*>(o) && dockMainWindow(o) || o == d->hideDock || o == d->mb)) { if (showDockMenu(((QMouseEvent*)e)->globalPos())) { ((QContextMenuEvent*)e)->accept(); return true; } } return QWidget::eventFilter(o, e);}/*! Monitors events, received in \a e, to ensure the layout is updated.*/void Q3MainWindow::childEvent(QChildEvent* e){ Q_D(Q3MainWindow); if (e->type() == QEvent::ChildRemoved) { if (e->child() == 0 || !e->child()->isWidgetType() || ((QWidget*)e->child())->isWindow()) { // nothing } else if (e->child() == d->sb) { d->sb = 0; triggerLayout(); } else if (e->child() == d->mb) { d->mb = 0; triggerLayout(); } else if (e->child() == d->mc) { d->mc = 0; d->mwl->setCentralWidget(0); triggerLayout(); } else if (qobject_cast<Q3DockWindow*>(e->child())) { removeDockWindow((Q3DockWindow *)(e->child())); d->appropriate.remove((Q3DockWindow*)e->child()); triggerLayout(); } } else if (e->type() == QEvent::ChildInserted && !d->sb) { d->sb = qobject_cast<QStatusBar*>(e->child()); if (d->sb) { if (d->tll) { if (!d->tll->findWidget(d->sb)) d->tll->addWidget(d->sb); } else { triggerLayout(); } } }}/*! \reimp*/bool Q3MainWindow::event(QEvent * e){ Q_D(Q3MainWindow);#ifndef QT_NO_STATUSTIP if (e->type() == QEvent::StatusTip) { if (d->sb) { d->sb->showMessage(static_cast<QStatusTipEvent*>(e)->tip()); return true; } }#endif if (e->type() == QEvent::ToolBarChange) { // Keep compatibility with the Qt 3 main window, use the real main window // or reimplement if you want proper handling. int deltaH = 0; Q3DockArea *area = topDock(); if (area->width() >= area->height()) { deltaH = area->sizeHint().height(); if (!area->isVisible()) { area->show(); } else { area->hide(); deltaH = -deltaH; } } if (deltaH) { QApplication::sendPostedEvents(this, QEvent::LayoutRequest); resize(width(), height() + deltaH); } return true; } if (e->type() == QEvent::ChildRemoved && ((QChildEvent*)e)->child() == d->mc) { d->mc->removeEventFilter(this); d->mc = 0; d->mwl->setCentralWidget(0); } if (e->type() == QEvent::MenubarUpdated) { QMenubarUpdatedEvent * const event = static_cast<QMenubarUpdatedEvent *>(e); if (event->menuBar() && event->menuBar()->parent() == this) { triggerLayout(); update(); } } return QWidget::event(e);}/*! \property Q3MainWindow::usesBigPixmaps \brief whether big pixmaps are enabled If false (the default), the tool buttons will use small pixmaps; otherwise big pixmaps will be used. Tool buttons and other widgets that wish to respond to this setting are responsible for reading the correct state on startup, and for connecting to the main window's widget's pixmapSizeChanged() signal.*/bool Q3MainWindow::usesBigPixmaps() const{ return d_func()->ubp;}void Q3MainWindow::setUsesBigPixmaps(bool enable){ Q_D(Q3MainWindow); if (enable == (bool)d->ubp) return; d->ubp = enable; emit pixmapSizeChanged(enable); QObjectList l = queryList("QLayout"); for (int i = 0; i < l.size(); ++i) static_cast<QLayout *>(l.at(i))->activate();}/*! \property Q3MainWindow::usesTextLabel \brief whether text labels for toolbar buttons are enabled If disabled (the default), the tool buttons will not use text labels. If enabled, text labels will be used. Tool buttons and other widgets that wish to respond to this setting are responsible for reading the correct state on startup, and for connecting to the main window's widget's usesTextLabelChanged() signal. \sa QToolButton::setUsesTextLabel()*/bool Q3MainWindow::usesTextLabel() const{ return d_func()->utl;}void Q3MainWindow::setUsesTextLabel(bool enable){ Q_D(Q3MainWindow); if (enable == (bool)d->utl) return; d->utl = enable; emit usesTextLabelChanged(enable); QObjectList l = queryList("QLayout"); for (int i = 0; i < l.size(); ++i) static_cast<QLayout *>(l.at(i))->activate(); triggerLayout(false);}/*! \fn void Q3MainWindow::pixmapSizeChanged(bool b) This signal is emitted whenever the setUsesBigPixmaps() is called with a value different to the current setting. The new value is passed in \a b. All widgets that should respond to such changes, e.g. toolbar buttons, must connect to this signal.*//*! \fn void Q3MainWindow::usesTextLabelChanged(bool b) This signal is emitted whenever the setUsesTextLabel() is called with a value different to the current setting. The new value is passed in \a b. All widgets that should respond to such changes, e.g. toolbar buttons, must connect to this signal.*//*! \fn void Q3MainWindow::dockWindowPositionChanged(Q3DockWindow *dockWindow) This signal is emitted when the \a dockWindow has changed its position. A change in position occurs when a dock window is moved within its dock area or moved to another dock area (including the \c Minimized and \c TearOff dock areas). \sa getLocation()*/void Q3MainWindow::setRightJustification(bool enable){ Q_D(Q3MainWindow); if (enable == (bool)d->justify) return; d->justify = enable; triggerLayout(true);}/*! \property Q3MainWindow::rightJustification \brief whether the main window right-justifies its dock windows If disabled (the default), stretchable dock windows are expanded, and non-stretchable dock windows are given the minimum space they need. Since most dock windows are not stretchable, this usually results in an unjustified right edge (or unjustified bottom edge for a vertical dock area). If enabled, the main window will right-justify its dock windows. \sa Q3DockWindow::setVerticalStretchable(), Q3DockWindow::setHorizontalStretchable()*/bool Q3MainWindow::rightJustification() const{ return d_func()->justify;}/*! \internal */void Q3MainWindow::triggerLayout(bool deleteLayout){ Q_D(Q3MainWindow); if (deleteLayout || !d->tll) setUpLayout(); QApplication::postEvent(this, new QEvent(QEvent::LayoutHint));}/*! Enters 'What's This?' mode and returns immediately. This is the same as QWhatsThis::enterWhatsThisMode(), but implemented as a main window object's slot. This way it can easily be used for popup menus, for example: \code Q3PopupMenu * help = new Q3PopupMenu(this); help->insertItem("What's &This", this , SLOT(enterWhatsThis()), Qt::SHIFT+Qt::Key_F1); \endcode \sa Q3WhatsThis::enterWhatsThisMode()*/void Q3MainWindow::whatsThis(){#ifndef QT_NO_WHATSTHIS QWhatsThis::enterWhatsThisMode();#endif}/*! Finds the location of the dock window \a dw. If the \a dw dock window is found in the main window the function returns true and populates the \a dock variable with the dw's dock area and the \a index with the dw's position within the dock area. It also sets \a nl to true if the \a dw begins a new line (otherwise false), and \a extraOffset with the dock window's offset. If the \a dw dock window is not found then the function returns false and the state of \a dock, \a index, \a nl and \a extraOffset is undefined. If you want to save and restore dock window positions then use operator>>() and operator<<().*/bool Q3MainWindow::getLocation(Q3DockWindow *dw, Qt::Dock &dock, int &index, bool &nl, int &extraOffset) const{ Q_D(const Q3MainWindow); dock = Qt::DockTornOff; if (d->topDock->hasDockWindow(dw, &index)) dock = Qt::DockTop; else if (d->bottomDock->hasDockWindow(dw, &index)) dock = Qt::DockBottom; else if (d->leftDock->hasDockWindow(dw, &index)) dock = Qt::DockLeft; else if (d->rightDock->hasDockWindow(dw, &index)) dock = Qt::DockRight; else if (dw->parentWidget() == d->hideDock) { index = 0; dock = Qt::DockMinimized; } else { index = 0; } nl = dw->newLine(); extraOffset = dw->offset();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -