📄 qmainwindow.cpp
字号:
return; // add a window to an area, placing done relative to the previous d_func()->layout->addDockWidget(area, dockwidget, orientation);}/*! \fn void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation) Splits the space covered by the \a first dock widget into two parts, moves the \a first dock widget into the first part, and moves the \a second dock widget into the second part. The \a orientation specifies how the space is divided: A Qt::Horizontal split places the second dock widget to the right of the first; a Qt::Vertical split places the second dock widget below the first. \e Note: if \a first is currently in a tabbed docked area, \a second will be added as a new tab, not as a neighbor of \a first. This is because a single tab can contain only one dock widget. \e Note: The Qt::LayoutDirection influences the order of the dock widgets in the two parts of the divided area. When right-to-left layout direction is enabled, the placing of the dock widgets will be reversed. \sa tabifyDockWidget(), addDockWidget(), removeDockWidget()*/void QMainWindow::splitDockWidget(QDockWidget *after, QDockWidget *dockwidget, Qt::Orientation orientation){ d_func()->layout->splitDockWidget(after, dockwidget, orientation);}/*! \fn void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second) Moves \a second dock widget on top of \a first dock widget, creating a tabbed docked area in the main window.*/void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second){ d_func()->layout->tabifyDockWidget(first, second);}/*! Removes the \a dockwidget from the main window layout and hides it. Note that the \a dockwidget is \e not deleted.*/void QMainWindow::removeDockWidget(QDockWidget *dockwidget){ if (dockwidget) { d_func()->layout->removeWidget(dockwidget); dockwidget->hide(); }}/*! Returns the Qt::DockWidgetArea for \a dockwidget. If \a dockwidget has not been added to the main window, this function returns \c Qt::NoDockWidgetArea. \sa addDockWidget() splitDockWidget() Qt::DockWidgetArea*/Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const{ return d_func()->layout->dockWidgetArea(dockwidget); }#endif // QT_NO_DOCKWIDGET/*! Saves the current state of this mainwindow's toolbars and dockwidgets. The \a version number is stored as part of the data. The \link QObject::objectName objectName\endlink property is used to identify each QToolBar and QDockWidget. You should make sure that this property is unique for each QToolBar and QDockWidget you add to the QMainWindow To restore the saved state, pass the return value and \a version number to restoreState(). \sa restoreState()*/QByteArray QMainWindow::saveState(int version) const{ QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); stream << QMainWindowLayout::VersionMarker; stream << version; d_func()->layout->saveState(stream); return data;}/*! Restores the \a state of this mainwindow's toolbars and dockwidgets. The \a version number is compared with that stored in \a state. If they do not match, the mainwindow's state is left unchanged, and this function returns \c false; otherwise, the state is restored, and this function returns \c true. \sa saveState()*/bool QMainWindow::restoreState(const QByteArray &state, int version){ if (state.isEmpty()) return false; QByteArray sd = state; QDataStream stream(&sd, QIODevice::ReadOnly); int marker, v; stream >> marker; stream >> v; if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version) return false; bool restored = d_func()->layout->restoreState(stream); return restored;}#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR)QCursor QMainWindowPrivate::separatorCursor(const QList<int> &path) const{ QDockAreaLayoutInfo *info = layout->layoutState.dockAreaLayout.info(path); Q_ASSERT(info != 0); if (path.size() == 1) { // is this the "top-level" separator which separates a dock area // from the central widget? switch (path.first()) { case QInternal::LeftDock: case QInternal::RightDock: return Qt::SplitHCursor; case QInternal::TopDock: case QInternal::BottomDock: return Qt::SplitVCursor; default: break; } } // no, it's a splitter inside a dock area, separating two dock widgets return info->o == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor;}void QMainWindowPrivate::adjustCursor(const QPoint &pos){ Q_Q(QMainWindow); hoverPos = pos; if (pos == QPoint(0, 0)) { if (!hoverSeparator.isEmpty()) q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); hoverSeparator.clear(); q->unsetCursor(); } else { QList<int> pathToSeparator = layout->layoutState.dockAreaLayout.findSeparator(pos); if (pathToSeparator != hoverSeparator) { if (!hoverSeparator.isEmpty()) q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); hoverSeparator = pathToSeparator; if (hoverSeparator.isEmpty()) { q->unsetCursor(); } else { q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); QCursor cursor = separatorCursor(hoverSeparator); q->setCursor(cursor); } } }}#endif/*! \reimp */bool QMainWindow::event(QEvent *event){ Q_D(QMainWindow); switch (event->type()) {#ifndef QT_NO_DOCKWIDGET case QEvent::Paint: { QPainter p(this); QRegion r = static_cast<QPaintEvent*>(event)->region(); d->layout->layoutState.dockAreaLayout.paintSeparators(&p, this, r, d->hoverPos); break; }#ifndef QT_NO_CURSOR case QEvent::HoverMove: { d->adjustCursor(static_cast<QHoverEvent*>(event)->pos()); break; } // We don't want QWidget to call update() on the entire QMainWindow // on HoverEnter and HoverLeave, hence accept the event (return true). case QEvent::HoverEnter: return true; case QEvent::HoverLeave: d->adjustCursor(QPoint(0, 0)); return true; case QEvent::ShortcutOverride: // when a menu pops up d->adjustCursor(QPoint(0, 0)); break;#endif // QT_NO_CURSOR case QEvent::MouseButtonPress: { QMouseEvent *e = static_cast<QMouseEvent*>(event); if (e->button() == Qt::LeftButton && d->layout->startSeparatorMove(e->pos())) { // The click was on a separator, eat this event e->accept(); return true; } break; } case QEvent::MouseMove: { QMouseEvent *e = static_cast<QMouseEvent*>(event);#ifndef QT_NO_CURSOR d->adjustCursor(e->pos());#endif if (e->buttons() & Qt::LeftButton) { if (d->layout->separatorMove(e->pos())) { // We're moving a separator, eat this event e->accept(); return true; } } break; } case QEvent::MouseButtonRelease: { QMouseEvent *e = static_cast<QMouseEvent*>(event); if (d->layout->endSeparatorMove(e->pos())) { // We've released a separator, eat this event e->accept(); return true; } break; }#endif#ifndef QT_NO_TOOLBAR case QEvent::ToolBarChange: { d->layout->toggleToolBarsVisible(); return true; }#endif#ifndef QT_NO_STATUSTIP case QEvent::StatusTip:#ifndef QT_NO_STATUSBAR if (QStatusBar *sb = d->layout->statusBar()) sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip()); else#endif static_cast<QStatusTipEvent*>(event)->ignore(); return true;#endif // QT_NO_STATUSTIP case QEvent::StyleChange: if (!d->explicitIconSize) setIconSize(QSize()); break;#ifdef Q_WS_MAC case QEvent::Show: { if (unifiedTitleAndToolBarOnMac()) ShowHideWindowToolbar(qt_mac_window_for(this), true, false); break; }#endif default: break; } return QWidget::event(event);}#ifndef QT_NO_TOOLBAR/*! \property QMainWindow::unifiedTitleAndToolBarOnMac \brief whether the window uses the unified title and toolbar look on Mac OS X \since 4.3 This property is false by default and only has any effect on Mac OS X 10.4 or higher. If set to true, then the top toolbar area is replaced with a Carbon HIToolbar and all toolbars in the top toolbar area are moved to that. Any toolbars added afterwards will also be added to the Carbon HIToolbar. This means a couple of things. \list \i QToolBars in this toolbar area are not movable and you cannot drag other toolbars to it \i Toolbar breaks are not respected or preserved \i Any custom widgets in the toolbar will not be shown if the toolbar becomes too small (only actions will be shown) \i If you call showFullScreen() on the main window, the QToolbar will disappear since it is considered to be part of the title bar. You can work around this by doing the following by turning off the unified toolbar before you call showFullScrenn() and restore the value after you call showNormal(). \endlist Setting this back to false will remove these restrictions. The Qt::WA_MacBrushedMetal attribute takes precedence over this property.*/void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set){#ifdef Q_WS_MAC Q_D(QMainWindow); if (!isWindow() || d->useHIToolBar == set || QSysInfo::MacintoshVersion < QSysInfo::MV_10_3) return; d->useHIToolBar = set; createWinId(); // We need the hiview for down below. d->layout->updateHIToolBarStatus();#else Q_UNUSED(set)#endif}bool QMainWindow::unifiedTitleAndToolBarOnMac() const{#ifdef Q_WS_MAC return d_func()->useHIToolBar && !testAttribute(Qt::WA_MacBrushedMetal);#endif return false;}#endif // QT_NO_TOOLBAR/*! \internal*/bool QMainWindow::isSeparator(const QPoint &pos) const{#ifndef QT_NO_DOCKWIDGET Q_D(const QMainWindow); return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty();#else Q_UNUSED(pos); return false;#endif}/*! \reimp*/void QMainWindow::contextMenuEvent(QContextMenuEvent *event){ // only show the context menu for direct QDockWidget and QToolBar // children and for the menu bar as well QWidget *child = childAt(event->pos()); while (child && child != this) {#ifndef QT_NO_MENUBAR if (QMenuBar *mb = qobject_cast<QMenuBar *>(child)) { if (mb->parentWidget() != this) return; break; }#endif#ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) { if (dw->parentWidget() != this) return; if (dw->widget() && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) { // ignore the event if the mouse is over the QDockWidget contents return; } break; }#endif // QT_NO_DOCKWIDGET#ifndef QT_NO_TOOLBAR if (QToolBar *tb = qobject_cast<QToolBar *>(child)) { if (tb->parentWidget() != this) return; break; }#endif child = child->parentWidget(); } if (child == this) return;#ifndef QT_NO_MENU QMenu *popup = createPopupMenu(); if (!popup) return; popup->exec(event->globalPos()); delete popup; event->accept();#endif}#ifndef QT_NO_MENU/*! Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the main window. If there are no toolbars and dock widgets present, this function returns a null pointer. By default, this function is called by the main window when the user activates a context menu, typically by right-clicking on a toolbar or a dock widget. If you want to create a custom popup menu, reimplement this function and return a newly-created popup menu. Ownership of the popup menu is transferred to the caller. \sa addDockWidget(), addToolBar(), menuBar()*/QMenu *QMainWindow::createPopupMenu(){ Q_D(QMainWindow); QMenu *menu = 0;#ifndef QT_NO_DOCKWIDGET QList<QDockWidget *> dockwidgets = qFindChildren<QDockWidget *>(this); if (dockwidgets.size()) { menu = new QMenu(this); for (int i = 0; i < dockwidgets.size(); ++i) { QDockWidget *dockWidget = dockwidgets.at(i); if (dockWidget->parentWidget() == this && !d->layout->layoutState.dockAreaLayout.indexOf(dockWidget).isEmpty()) { menu->addAction(dockwidgets.at(i)->toggleViewAction()); } } menu->addSeparator(); }#endif // QT_NO_DOCKWIDGET#ifndef QT_NO_TOOLBAR QList<QToolBar *> toolbars = qFindChildren<QToolBar *>(this); if (toolbars.size()) { if (!menu) menu = new QMenu(this); for (int i = 0; i < toolbars.size(); ++i) { QToolBar *toolBar = toolbars.at(i); if (toolBar->parentWidget() == this && !d->layout->layoutState.toolBarAreaLayout.indexOf(toolBar).isEmpty()) { menu->addAction(toolbars.at(i)->toggleViewAction()); } } }#endif Q_UNUSED(d); return menu;}#endif // QT_NO_MENU#endif // QT_NO_MAINWINDOW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -