?? qmainwindow.cpp
字號:
} else { QMainWindowPrivate::ToolBar *t = dl->first(); int i = 0; // find index for moving the toolbar before or after the relative one if ( ipos != QMainWindowPrivate::Above && ipos != QMainWindowPrivate::Below ) { for ( ; t; t = dl->next(), ++i ) { if ( t->t == relative ) break; } if ( ipos == QMainWindowPrivate::After ) ++i; } else if ( ipos == QMainWindowPrivate::Below ) { // find the index for moving it below relative int ry = 0; bool doIt = FALSE; for ( ; t; t = dl->next(), ++i ) { if ( t->t == relative ) { ry = tb_pos( t->t, o, TRUE ); doIt = TRUE; } if ( doIt && tb_pos( t->t, o, TRUE ) > ry ) { break; } } } else if ( ipos == QMainWindowPrivate::Above ) { // find index for moving it above relative int ry = 0; bool doIt = FALSE; t = dl->last(); i = dl->count(); for ( ; t; t = dl->prev(), --i ) { if ( t->t == relative ) { ry = tb_pos( t->t, o, TRUE ); doIt = TRUE; } if ( doIt && tb_pos( t->t, o, TRUE ) < ry ) { break; } } } // sanity chek if ( i > (int)dl->count() ) i = dl->count(); // and finally move the toolbar to the calculated index dl->insert( i, ct ); // do some new-line corrections if ( oldDock != d->hidden ) { bool after = ipos == QMainWindowPrivate::After; if ( ipos == QMainWindowPrivate::Before && (int)dl->count() > i + 1 && dl->at( i + 1 )->nl ) { dl->at( i + 1 )->nl = FALSE; dl->at( i )->nl = TRUE; } if ( after && ct->nl ) { ct->nl = FALSE; } if ( ipos == QMainWindowPrivate::Below ) { dl->at( i )->nl = TRUE; if ( (int)dl->count() > i + 1 ) { dl->at( i + 1 )->nl = TRUE; } } if ( ipos == QMainWindowPrivate::Above ) { dl->at( i )->nl = TRUE; if ( (int)dl->count() > i + 1 ) { dl->at( i + 1 )->nl = TRUE; } } } } if ( edge != Minimized ) { ct->oldDock = edge; ct->oldIndex = dl->findRef( ct ); } } else { addToolBar( toolBar, edge, nl ); QMainWindowPrivate::ToolBarDock *dummy; QMainWindowPrivate::ToolBar *tb = d->findToolbar( toolBar, dummy ); if ( tb ) tb->disabledDocks = dd; if ( tb && edge != Minimized ) { tb->oldDock = edge; tb->oldIndex = 0; } } triggerLayout(); // update, so that the line below the menubar may be drawn/earsed update(); emit toolBarPositionChanged( toolBar );}/*! Moves \a toolBar to this the end of \a edge. 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 ){ moveToolBar( toolBar, edge, (QToolBar*)0, TRUE );}/*! Moves \a toolBar to the position \a index of \a edge. 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, bool nl, int index, int extraOffset ){ QMainWindowPrivate::ToolBarDock * dl = 0; switch ( edge ) { case Left: dl = d->left; break; case Right: dl = d->right; break; case Top: dl = d->top; break; case Bottom: dl = d->bottom; break; case Unmanaged: dl = d->unmanaged; break; case Minimized: dl = d->hidden; break; case TornOff: dl = d->tornOff; break; } QMainWindowPrivate::ToolBarDock *dummy; QMainWindowPrivate::ToolBar *tt = d->findToolbar( toolBar, dummy ); tt->extraOffset = extraOffset; if ( nl && tt ) tt->nl = nl; if ( !dl ) { moveToolBar( toolBar, edge, (QToolBar*)0, QMainWindowPrivate::After ); } else { QMainWindowPrivate::ToolBar *tb = 0; bool after = FALSE; if ( index >= (int)dl->count() ) { tb = 0; } else { if ( index > 0 && !nl ) { after = TRUE; tb = dl->at( index - 1 ); } else { tb = dl->at( index ); } } if ( !tb ) moveToolBar( toolBar, edge, (QToolBar*)0, QMainWindowPrivate::After ); else moveToolBar( toolBar, edge, tb->t, after ? QMainWindowPrivate::After : QMainWindowPrivate::Before ); }}/*! Removes \a toolBar from this main window's docking area, if \a toolBar is non-null and known by this main window.*/void QMainWindow::removeToolBar( QToolBar * toolBar ){ if ( !toolBar ) return; QMainWindowPrivate::ToolBar * ct; ct = d->takeToolBarFromDock( toolBar ); if ( ct ) { toolBar->mw = 0; delete ct; triggerLayout(); }}#endif/*! Sets up the geometry management of this window. Called automatically when needed, so you should never need to call this.*/void QMainWindow::setUpLayout(){ //### Must rewrite!#ifndef QT_NO_MENUBAR if ( !d->mb ) { // slightly evil hack here. reconsider this after 2.0 QObjectList * l = ((QObject*)this)->queryList( "QMenuBar", 0, FALSE, FALSE ); if ( l && l->count() ) d->mb = menuBar(); delete l; }#endif#ifndef QT_NO_STATUSBAR if ( !d->sb ) { // as above. QObjectList * l = ((QObject*)this)->queryList( "QStatusBar", 0, FALSE, FALSE ); if ( l && l->count() ) d->sb = statusBar(); delete l; }#endif delete d->tll; d->tll = new QBoxLayout( this, QBoxLayout::Down );#ifndef QT_NO_MENUBAR if ( d->mb && d->mb->isVisibleTo( this ) ) { d->tll->setMenuBar( d->mb ); }#endif#ifndef QT_NO_TOOLBAR d->hideDock->setFixedHeight( style().toolBarHandleExtend() ); if ( d->hidden && !d->hidden->isEmpty() ) { if ( style() == WindowsStyle ) d->tll->addSpacing( 2 ); int visibles = 0; d->hideDock->show(); QMainWindowPrivate::ToolBar *tb; for ( tb = d->hidden->first(); tb; tb = d->hidden->next() ) { if ( tb->t->isVisibleTo( this ) ) visibles++; tb->t->resize( 0, 0 ); tb->t->move( -tb->t->width() - 2, -tb->t->height() - 2 ); d->hideDock->raise(); if ( d->mb ) d->mb->raise(); } if ( !visibles ) { d->hideDock->hide(); } else { d->hideDock->repaint( TRUE ); update(); } } else { d->hideDock->hide(); } d->tll->addWidget( d->hideDock ); if ( d->top && !d->top->isEmpty() && style() == WindowsStyle ) d->tll->addSpacing( d->movable ? 1 : 2 ); d->lTop = new QToolLayout( d->tll, d->top, QBoxLayout::Down, d->justify );#endif QMainWindowLayout *mwl = new QMainWindowLayout( d->tll ); d->tll->setStretchFactor( mwl, 100 );#ifndef QT_NO_TOOLBAR d->lLeft = new QToolLayout( mwl, d->left, QBoxLayout::LeftToRight, d->justify ); mwl->setLeftDock( d->lLeft );#endif if ( centralWidget() ) mwl->setCentralWidget( centralWidget() );#ifndef QT_NO_TOOLBAR d->lRight = new QToolLayout( mwl, d->right, QBoxLayout::LeftToRight, d->justify ); mwl->setRightDock( d->lRight ); d->lBottom = new QToolLayout( d->tll, d->bottom, QBoxLayout::Down, d->justify );#endif#ifndef QT_NO_STATUSBAR if ( d->sb ) { d->tll->addWidget( d->sb, 0 ); // make the sb stay on top of tool bars if there isn't enough space d->sb->raise(); }#endif}/*! \reimp */void QMainWindow::show(){ if ( !d->tll) setUpLayout(); QWidget::show();}/*! \reimp */QSize QMainWindow::sizeHint() const{ QMainWindow* that = (QMainWindow*) this; // Workaround: because d->tll get's deleted in // totalSizeHint->polish->sendPostedEvents->childEvent->triggerLayout // [eg. canvas example on Qt/Embedded] QApplication::sendPostedEvents( that, QEvent::ChildInserted ); if ( !that->d->tll ) that->setUpLayout(); return that->d->tll->totalSizeHint();}/*! \reimp */QSize QMainWindow::minimumSizeHint() const{ if ( !d->tll ) { QMainWindow* that = (QMainWindow*) this; that->setUpLayout(); } return d->tll->totalMinimumSize();}/*! Sets the central widget for this window to \a w. The central widget is the one around which the toolbars etc. are arranged.*/void QMainWindow::setCentralWidget( QWidget * w ){ if ( d->mc ) d->mc->removeEventFilter( this ); d->mc = w; if ( d->mc ) d->mc->installEventFilter( this ); triggerLayout();}/*! Returns a pointer to the main child of this main widget. The main child is the big widget around which the tool bars are arranged. \sa setCentralWidget()*/QWidget * QMainWindow::centralWidget() const{ return d->mc;}/*! \reimp */void QMainWindow::paintEvent( QPaintEvent * ){#ifndef QT_NO_STYLE if ( d->rectPainter ) return; if ( style() == WindowsStyle && d->mb#ifndef QT_NO_TOOLBAR && ( ( d->top && !d->top->isEmpty() ) || ( d->hidden && !d->hidden->isEmpty() ) )#endif ) { QPainter p( this ); int y = d->mb->height() + 1; style().drawSeparator( &p, 0, y, width(), y, colorGroup() ); }#endif}/*! \reimp*/bool QMainWindow::eventFilter( QObject* o, QEvent *e ){#ifndef QT_NO_TOOLBAR if ( d->dockMenu && e->type() == QEvent::MouseButtonPress && o == this && !d->inMovement && ( (QMouseEvent*)e )->button() == RightButton ) { QMouseEvent *me = (QMouseEvent*)e; rightMouseButtonMenu( me->globalPos() ); return TRUE; } else if ( ( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonRelease ) && o && o->inherits( "QToolBar" ) ) { QMouseEvent *me = (QMouseEvent*)e; if ( d->movable && ( ( me->button() & LeftButton || me->state() & LeftButton ) || ( ( me->button() & RightButton ) && d->dockMenu ) ) ) { moveToolBar( (QToolBar *)o, me ); return TRUE; } } else#endif if ( e->type() == QEvent::LayoutHint ) {#ifndef QT_NO_TOOLBAR if ( o->inherits( "QToolBar" ) ) { if ( isVisible() && ( (QToolBar*)o )->isVisible() ) QTimer::singleShot( 0, (QToolBar*)o, SLOT( updateArrowStuff() ) ); } else#endif if ( o == this && centralWidget() && !centralWidget()->isVisible() ) { centralWidget()->show(); } } else if ( e->type() == QEvent::Show && o == this ) { if ( !d->tll ) setUpLayout(); d->tll->activate(); } return QWidget::eventFilter( o, e );}/*! Monitors events to ensure layout is updated.*/void QMainWindow::resizeEvent( QResizeEvent* ){}/*! Monitors events to ensure layout is updated.*/void QMainWindow::childEvent( QChildEvent* e){ if ( e->type() == QEvent::ChildRemoved ) { if ( e->child() == 0 || !e->child()->isWidgetType() || ((QWidget*)e->child())->testWFlags( WType_TopLevel ) ) { // nothing#ifndef QT_NO_STATUSBAR } else if ( e->child() == d->sb ) { d->sb = 0; triggerLayout();#endif } else if ( e->child() == d->mb ) { d->mb = 0; triggerLayout(); } else if ( e->child() == d->mc ) { d->mc = 0; triggerLayout(); } else if ( e->child()->isWidgetType() ) {#ifndef QT_NO_TOOLBAR removeToolBar( (QToolBar *)(e->child()) );#endif triggerLayout(); } } else if ( e->type() == QEvent::ChildInserted ) {#ifndef QT_NO_STATUSBAR if ( e->child()->inherits( "QStatusBar" ) ) { d->sb = (QStatusBar*)e->child(); if ( d->tll ) { if ( !d->tll->findWidget( d->sb ) ) d->tll->addWidget( (QStatusBar*)e->child() ); } else { triggerLayout(); } }#endif }}/*!\reimp*/bool QMainWindow::event( QEvent * e ) //### remove 3.0{ if ( e->type() == QEvent::ChildRemoved && ( (QChildEvent*)e )->child() == d->mc ) { d->mc->removeEventFilter( this ); d->mc = 0; } return QWidget::event( e );}/*! Returns the state last set by setUsesBigPixmaps(). The initial state is FALSE. \sa setUsesBigPixmaps();*/bool QMainWindow::usesBigPixmaps() const{ return d->ubp;}/*! Sets tool buttons in this main windows to use big pixmaps if \a enable is TRUE, and small pixmaps if \a enable is FALSE. The default is FALSE. Tool buttons and other interested widgets are responsible for reading the correct state on startup, and for connect
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -