📄 qmainwindow.cpp
字号:
d->mb->installEventFilter( this ); triggerLayout();}/*! Returns the menu bar for this window. If there isn't any, menuBar() creates an empty menu bar on the fly. \sa statusBar()*/QMenuBar * QMainWindow::menuBar() const{ if ( d->mb ) return d->mb; QObjectList * l = ((QObject*)this)->queryList( "QMenuBar", 0, FALSE, FALSE ); QMenuBar * b; if ( l && l->count() ) { b = (QMenuBar *)l->first(); } else { b = new QMenuBar( (QMainWindow *)this, "automatic menu bar" ); b->show(); } delete l; d->mb = b; d->mb->installEventFilter( this ); ((QMainWindow *)this)->triggerLayout(); return b;}#endif // QT_NO_MENUBAR/*! Sets this main window to use the status bar \a newStatusBar. The old status bar, if there was any, is deleted along with its contents. Note that \a newStatusBar must be a child of this main window, and that it is not automatically displayed. If you call this function after show(), you probably also need to call \a newStatusBar->show(). Note that \a newStatusBar must be a child of this main window, and that it is not automatically displayed. If you call this function after show(), you probably also need to call \a newStatusBar->show(). \sa setMenuBar() statusBar()*/void QMainWindow::setStatusBar( QStatusBar * newStatusBar ){#ifndef QT_NO_STATUSBAR if ( !newStatusBar || newStatusBar == d->sb ) return; if ( d->sb ) delete d->sb; d->sb = newStatusBar; d->sb->installEventFilter( this );#ifndef QT_NO_TOOLTIP // ### this code can cause unnecessary creation of a tool tip group connect( toolTipGroup(), SIGNAL(showTip(const QString&)), d->sb, SLOT(message(const QString&)) ); connect( toolTipGroup(), SIGNAL(removeTip()), d->sb, SLOT(clear()) );#endif triggerLayout();#endif}/*! Returns the status bar for this window. If there isn't any, statusBar() creates an empty status bar on the fly, and if necessary a tool tip group too. \sa menuBar() toolTipGroup()*/QStatusBar * QMainWindow::statusBar() const{#ifndef QT_NO_STATUSBAR if ( d->sb ) return d->sb; QObjectList * l = ((QObject*)this)->queryList( "QStatusBar", 0, FALSE, FALSE ); QStatusBar * s; if ( l && l->count() ) { s = (QStatusBar *)l->first(); } else { s = new QStatusBar( (QMainWindow *)this, "automatic status bar" ); s->show(); } delete l; ((QMainWindow *)this)->setStatusBar( s ); ((QMainWindow *)this)->triggerLayout(); return s;#else return 0;#endif}/*! Sets this main window to use the tool tip group \a newToolTipGroup. The old tool tip group, if there was any, is deleted along with its contents. All the tool tips connected to it lose the ability to display the group texts. \sa menuBar() toolTipGroup()*/void QMainWindow::setToolTipGroup( QToolTipGroup * newToolTipGroup ){#ifndef QT_NO_TOOLTIP if ( !newToolTipGroup || newToolTipGroup == d->ttg ) return; if ( d->ttg ) delete d->ttg; d->ttg = newToolTipGroup;#ifndef QT_NO_STATUSBAR connect( toolTipGroup(), SIGNAL(showTip(const QString&)), statusBar(), SLOT(message(const QString&)) ); connect( toolTipGroup(), SIGNAL(removeTip()), statusBar(), SLOT(clear()) );#endif //### triggerLayout();#endif}/*! Returns the tool tip group for this window. If there isn't any, toolTipGroup() creates an empty tool tip group on the fly. \sa menuBar() statusBar()*/QToolTipGroup * QMainWindow::toolTipGroup() const{#ifndef QT_NO_TOOLTIP if ( d->ttg ) return d->ttg; QToolTipGroup * t = new QToolTipGroup( (QMainWindow*)this, "automatic tool tip group" ); ((QMainWindowPrivate*)d)->ttg = t; //### ((QMainWindow *)this)->triggerLayout(); return t;#else return 0;#endif}#ifndef QT_NO_TOOLBAR/*! Sets \a dock to be available if \a enable is TRUE, and not available if \a enable is FALSE. The user can drag a toolbar to any enabled dock.*/void QMainWindow::setDockEnabled( ToolBarDock dock, bool enable ){ if ( enable ) { switch ( dock ) { case Top: if ( !d->top ) d->top = new QMainWindowPrivate::ToolBarDock(); break; case Left: if ( !d->left ) d->left = new QMainWindowPrivate::ToolBarDock(); break; case Right: if ( !d->right ) d->right = new QMainWindowPrivate::ToolBarDock(); break; case Bottom: if ( !d->bottom ) d->bottom = new QMainWindowPrivate::ToolBarDock(); break; case TornOff: if ( !d->tornOff ) d->tornOff = new QMainWindowPrivate::ToolBarDock(); break; case Unmanaged: if ( !d->unmanaged ) d->unmanaged = new QMainWindowPrivate::ToolBarDock(); break; case Minimized: if ( !d->hidden ) d->hidden = new QMainWindowPrivate::ToolBarDock(); break; } d->dockable[ (int)dock ] = TRUE; } else { d->dockable[ (int)dock ] = FALSE; }}/*! Returns TRUE if \a dock is enabled, or FALSE if it is not. \sa setDockEnabled()*/bool QMainWindow::isDockEnabled( ToolBarDock dock ) const{ switch ( dock ) { case Top: return d->dockable[ (int)dock ]; case Left: return d->dockable[ (int)dock ]; case Right: return d->dockable[ (int)dock ]; case Bottom: return d->dockable[ (int)dock ]; case TornOff: return d->dockable[ (int)dock ]; case Unmanaged: return d->dockable[ (int)dock ]; case Minimized: return d->dockable[ (int)dock ]; } return FALSE; // for illegal values of dock}/*! Sets \a dock to be available for the toolbar \a tb if \a enable is TRUE, and not available if \a enable is FALSE. The user can drag the toolbar to any enabled dock.*/void QMainWindow::setDockEnabled( QToolBar *tb, ToolBarDock dock, bool enable ){ QMainWindowPrivate::ToolBarDock *dummy; QMainWindowPrivate::ToolBar *t = d->findToolbar( tb, dummy ); if ( !t ) return; if ( enable ) { if ( t->disabledDocks.contains( (int)dock ) ) t->disabledDocks.remove( (int)dock ); } else { if ( !t->disabledDocks.contains( (int)dock ) ) t->disabledDocks.append( (int)dock ); }}/*! Returns TRUE if \a dock is enabled for the toolbar \a tb , or FALSE if it is not. \sa setDockEnabled()*/bool QMainWindow::isDockEnabled( QToolBar *tb, ToolBarDock dock ) const{ QMainWindowPrivate::ToolBarDock *dummy; QMainWindowPrivate::ToolBar *t = d->findToolbar( tb, dummy ); if ( !t ) return FALSE; return !(bool)t->disabledDocks.contains( (int)dock );}/*! Adds \a toolBar to this the end of \a edge and makes it start anew line of tool bars if \a newLine is TRUE.If \a toolBar is already managed by some main window, it is firstremoved from that window.*/void QMainWindow::addToolBar( QToolBar * toolBar, ToolBarDock edge, bool newLine ){ if ( !toolBar ) return; if ( toolBar->mw ) { QMainWindow *old_mw = toolBar->mw; toolBar->mw->removeToolBar( toolBar ); if ( old_mw != this ) { toolBar->removeEventFilter( old_mw ); toolBar->reparent( this, 0, QPoint( 0, 0 ), TRUE ); } toolBar->mw = this; } setDockEnabled( edge, TRUE ); setDockEnabled( toolBar, edge, TRUE ); QMainWindowPrivate::ToolBarDock * dl = 0; if ( edge == Top ) { dl = d->top; toolBar->setOrientation( QToolBar::Horizontal ); toolBar->installEventFilter( this ); } else if ( edge == Left ) { dl = d->left; toolBar->setOrientation( QToolBar::Vertical ); toolBar->installEventFilter( this ); } else if ( edge == Bottom ) { dl = d->bottom; toolBar->setOrientation( QToolBar::Horizontal ); toolBar->installEventFilter( this ); } else if ( edge == Right ) { dl = d->right; toolBar->setOrientation( QToolBar::Vertical ); toolBar->installEventFilter( this ); } else if ( edge == TornOff ) { dl = d->tornOff; } else if ( edge == Unmanaged ) { dl = d->unmanaged; } else if ( edge == Minimized ) { dl = d->hidden; } if ( !dl ) return; QMainWindowPrivate::ToolBar *tb = new QMainWindowPrivate::ToolBar( toolBar, newLine ); dl->append( tb ); if ( tb && edge != Minimized ) { tb->oldDock = edge; tb->oldIndex = dl->findRef( tb ); } triggerLayout();}/*! Adds \a toolBar to this the end of \a edge, labelling it \a labeland makes it start a new line of tool bars if \a newLine is TRUE.If \a toolBar is already managed by some main window, it is firstremoved from that window.*/void QMainWindow::addToolBar( QToolBar * toolBar, const QString &label, ToolBarDock edge, bool newLine ){ if ( toolBar ) { toolBar->setLabel( label ); addToolBar( toolBar, edge, newLine ); }}/*! Moves \a toolBar to be positioned relative to \a relative. The \a ipos parameter can be 0, to position before, or 1, to position after the \a relative item. If \a toolBar is already managed by some main window, it is moved from that window to this.*/void QMainWindow::moveToolBar( QToolBar *toolBar, ToolBarDock edge, QToolBar *relative, int ipos ){ if ( !toolBar ) return; if ( !isDockEnabled( edge ) ) return; if ( !isDockEnabled( edge ) ) return; // if the toolbar is just moved a bit (offset change), but the order in the dock doesn't change, // then don't do the hard work if ( relative == toolBar || ipos == QMainWindowPrivate::SameIndex ) {#ifdef QMAINWINDOW_DEBUG QMainWindowPrivate::ToolBarDock *dummy; QMainWindowPrivate::ToolBar *t = d->findToolbar( toolBar, dummy ); qDebug( "move to same index, offset: %d", t ? t->extraOffset : -2 );#endif triggerLayout(); emit toolBarPositionChanged( toolBar ); return; } bool nl = FALSE; QValueList<int> dd; QMainWindowPrivate::ToolBarDock *oldDock; QMainWindowPrivate::ToolBar *tb = d->findToolbar( toolBar, oldDock ); // if the toolbar is moved here from a different mainwindow, remove it from the old one if ( toolBar->mw && toolBar->mw != this ) { if ( tb ) { nl = tb->nl; dd = tb->disabledDocks; } toolBar->mw->removeToolBar( toolBar ); } // Now take the toolbar from the dock QMainWindowPrivate::ToolBar * ct; ct = d->takeToolBarFromDock( toolBar, edge == Minimized ); Qt::Orientation o; if ( edge == QMainWindow::Top || edge == QMainWindow::Bottom ) o = Qt::Horizontal; else o = Qt::Vertical; // if the toolbar is valid if ( ct ) { // enable the dock where it will be moved to setDockEnabled( edge, TRUE ); setDockEnabled( toolBar, edge, TRUE ); // find the data struct of the dock QMainWindowPrivate::ToolBarDock * dl = 0; if ( edge == Top ) { dl = d->top; toolBar->setOrientation( QToolBar::Horizontal ); toolBar->installEventFilter( this ); } else if ( edge == Left ) { dl = d->left; toolBar->setOrientation( QToolBar::Vertical ); toolBar->installEventFilter( this ); } else if ( edge == Bottom ) { dl = d->bottom; toolBar->setOrientation( QToolBar::Horizontal ); toolBar->installEventFilter( this ); } else if ( edge == Right ) { dl = d->right; toolBar->setOrientation( QToolBar::Vertical ); toolBar->installEventFilter( this ); } else if ( edge == TornOff ) { dl = d->tornOff; } else if ( edge == Unmanaged ) { dl = d->unmanaged; } else if ( edge == Minimized ) { dl = d->hidden; } // if the dock couldn't be found if ( !dl ) { if ( edge != Minimized ) { ct->oldDock = edge; ct->oldIndex = dl->findRef( ct ); } delete ct; return; } if ( oldDock != d->hidden ) { ct->hiddenBefore = 0; ct->hiddenAfter = 0; } // if the toolbar is restored from the minimized dock, // try to find exactly the place and move it there if ( oldDock == d->hidden ) { QMainWindowPrivate::ToolBar *t = dl->first(); int i = 0; bool found = FALSE; for ( ; t; t = dl->next(), ++i ) { if ( t->hiddenBefore == ct ) {#ifdef QMAINWINDOW_DEBUG qDebug( "insert minimized toolbar before %s", t->t->label().latin1() );#endif dl->insert( i, ct ); if ( !ct->nl && t->nl ) ct->nl = TRUE; t->nl = FALSE; t->hiddenBefore = 0; found = TRUE; break; } if ( t->hiddenAfter == ct ) {#ifdef QMAINWINDOW_DEBUG qDebug( "insert minimized toolbar after %s", t->t->label().latin1() );#endif dl->insert( i + 1, ct ); if ( !t->nl && ct->nl ) t->nl = TRUE; ct->nl = FALSE; t->hiddenAfter = 0; found = TRUE; break; } } if ( found ) { triggerLayout(); // update, so that the line below the menubar may be drawn/earsed update(); emit toolBarPositionChanged( toolBar ); return; } } if ( !relative ) { // no relative toolbar, so just append it dl->append( ct );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -