?? qmainwindow.cpp
字號:
{ int n = dock->count(); if ( n == 0 ) return 0; Qt::Orientation o = dock->first()->t->orientation(); QMainWindowPrivate::ToolBar *t = dock->first(), *t2 = 0; QList<QMainWindowPrivate::ToolBar> row; row.setAutoDelete( FALSE ); int stretchs = 0; int e = 0; int pos = rect_pos( r, o, TRUE ); int lineExtend = 0; for (;;) { QSize sh = t ? size_hint( t->t ) : QSize(); int nx = e; if ( t && t->extraOffset != -1 && t->extraOffset > e ) nx = t->extraOffset; if ( nx + size_extend( sh, o ) > rect_extend( r, o ) ) nx = QMAX( e, rect_extend( r, o ) - size_extend( sh, o ) ); if ( !t || t->nl || nx + size_extend( sh, o ) > rect_extend( r, o ) ) { QValueList<QRect> rects; int s = stretchs > 0 ? ( rect_extend( r, o ) - e + rect_pos( r, o ) ) / stretchs : 0; int p = rect_pos( r, o ); QMainWindowPrivate::ToolBar *tmp = 0; for ( t2 = row.first(); t2; t2= row.next() ) { QRect g; int oldPos = p; int space = 0; if ( t2->extraOffset > p ) { space = t2->extraOffset - p; p = t2->extraOffset; } if ( o == Qt::Horizontal ) { int ext = size_hint( t2->t ).width(); if ( p + ext > r.width() && p == t2->extraOffset ) p = QMAX( p - space, r.width() - ext ); if ( p > oldPos && tmp && ( tmp->t->isHorizontalStretchable() || fill ) ) { QRect r = rects.last(); int d = p - ( r.x() + r.width() ); rects.last().setWidth( r.width() + d ); } if ( t2->t->isHorizontalStretchable() || fill ) ext += QMAX( 0, ( t2->t->isHorizontalStretchable() || fill ? s : 0 ) ); if ( p + ext > r.width() && ( t2->t->isHorizontalStretchable() || fill ) ) ext = r.width() - p; g = QRect( p, pos, ext , lineExtend ); } else { int ext = size_hint( t2->t ).height(); if ( p + ext > r.y() + r.height() && p == t2->extraOffset ) p = QMAX( p - space, ( r.y() + r.height() ) - ext ); if ( p > oldPos && tmp && ( tmp->t->isVerticalStretchable() || fill ) ) { QRect r = rects.last(); int d = p - ( r.y() + r.height() ); rects.last().setHeight( r.height() + d ); } if ( t2->t->isVerticalStretchable() || fill ) ext += QMAX( 0, ( t2->t->isVerticalStretchable() || fill ? s : 0 ) ); if ( p + ext > r.y() + r.height() && ( t2->t->isVerticalStretchable() || fill ) ) ext = ( r.y() + r.height() ) - p; g = QRect( pos, p, lineExtend, ext ); } rects.append( g ); p = rect_pos( g, o ) + rect_extend( g, o ); tmp = t2; } if ( !testonly ) { QValueList<QRect>::Iterator it = rects.begin(); for ( t2 = row.first(); t2; t2= row.next(), ++it ) { QRect tr = *it; if ( o == Qt::Horizontal ) { if ( tr.width() > r.width() ) tr.setWidth( r.width() ); } else { if ( tr.height() > r.height() ) tr.setHeight( r.height() ); } t2->t->setGeometry( tr ); } } stretchs = 0; e = 0; pos += lineExtend; lineExtend = 0; row.clear(); nx = 0; if ( t && t->extraOffset != -1 && t->extraOffset > e ) nx = t->extraOffset; } if ( !t ) break; e = nx + size_extend( sh, o ); lineExtend = QMAX( lineExtend, size_extend( sh, o, TRUE ) ); row.append( t ); if ( ( o == Qt::Horizontal && t->t->isHorizontalStretchable() || o == Qt::Vertical && t->t->isVerticalStretchable() ) || fill ) ++stretchs; t = dock->next(); } return pos - rect_pos( r, o, TRUE ) - spacing();}int QToolLayout::heightForWidth( int w ) const{ if ( cached_width != w ) { //Not all C++ compilers support "mutable" yet: QToolLayout * mthis = (QToolLayout*)this; mthis->cached_width = w; int h = mthis->layoutItems( QRect(0,0,w,0), TRUE ); mthis->cached_hfw = h; return h; } return cached_hfw;}int QToolLayout::widthForHeight( int h ) const{ if ( cached_height != h ) { //Not all C++ compilers support "mutable" yet: QToolLayout * mthis = (QToolLayout*)this; mthis->cached_height = h; int w = mthis->layoutItems( QRect( 0, 0, 0, h ), TRUE ); mthis->cached_wfh = w; return w; } return cached_wfh;}void QToolLayout::addItem( QLayoutItem * /*item*/ ){ //evil // list.append( item );}class QToolLayoutIterator :public QGLayoutIterator{public: QToolLayoutIterator( QList<QLayoutItem> *l ) :idx(0), list(l) {} uint count() const { return list ? list->count() : 0; } QLayoutItem *current() { return list && idx < (int)count() ? list->at(idx) : 0; } QLayoutItem *next() { idx++; return current(); } QLayoutItem *takeCurrent() { return list ? list->take( idx ) : 0; }private: int idx; QList<QLayoutItem> *list;};QLayoutIterator QToolLayout::iterator(){ //This is evil. Pretend you didn't see this. return QLayoutIterator( new QToolLayoutIterator( 0/*&list*/ ) );}void QToolLayout::setGeometry( const QRect &r ){ QLayout::setGeometry( r ); layoutItems( r );}#endif//************************************************************************************************// --------------------------------- QMainWindowLayout -----------------------//************************************************************************************************class QMainWindowLayout : public QLayout{ Q_OBJECTpublic: QMainWindowLayout( QLayout* parent = 0 ); ~QMainWindowLayout() {} void addItem( QLayoutItem *item); void setLeftDock( QToolLayout *l ); void setRightDock( QToolLayout *r ); void setCentralWidget( QWidget *w ); bool hasHeightForWidth() const { return FALSE; } QSize sizeHint() const; QSize minimumSize() const; QLayoutIterator iterator(); QSizePolicy::ExpandData expanding() const { return QSizePolicy::BothDirections; } void invalidate() {}protected: void setGeometry( const QRect &r ) { QLayout::setGeometry( r ); layoutItems( r ); }private: int layoutItems( const QRect&, bool testonly = FALSE ); int cached_height; int cached_wfh;#ifndef QT_NO_TOOLBAR QToolLayout *left, *right;#endif QWidget *central;};QSize QMainWindowLayout::sizeHint() const{ int w = 0, h = 0;#ifndef QT_NO_TOOLBAR if ( left ) { w = QMAX( w, left->sizeHint().width() ); h = QMAX( h, left->sizeHint().height() ); } if ( right ) { w = QMAX( w, right->sizeHint().width() ); h = QMAX( h, right->sizeHint().height() ); }#endif if ( central ) { w = QMAX( w, central->sizeHint().width() ); h = QMAX( h, central->sizeHint().height() ); } return QSize( w, h );}QSize QMainWindowLayout::minimumSize() const{ int w = 0, h = 0;#ifndef QT_NO_TOOLBAR if ( left ) { w += left->minimumSize().width(); h = QMAX( h, left->minimumSize().height() ); } if ( right ) { w += right->minimumSize().width(); h = QMAX( h, right->minimumSize().height() ); }#endif if ( central ) { QSize min = central->minimumSize().isNull() ? central->minimumSizeHint() : central->minimumSize(); w += min.width(); h = QMAX( h, min.height() ); } return QSize( w, h );}QMainWindowLayout::QMainWindowLayout( QLayout* parent ) : QLayout( parent ),#ifndef QT_NO_TOOLBAR left( 0 ), right( 0 ),#endif central( 0 ){ cached_height = -1; cached_wfh = -1;}#ifndef QT_NO_TOOLBARvoid QMainWindowLayout::setLeftDock( QToolLayout *l ){ left = l;}void QMainWindowLayout::setRightDock( QToolLayout *r ){ right = r;}#endifvoid QMainWindowLayout::setCentralWidget( QWidget *w ){ central = w;}int QMainWindowLayout::layoutItems( const QRect &r, bool testonly ){ if (#ifndef QT_NO_TOOLBAR !left && !right &&#endif !central ) return 0; int wl = 0, wr = 0;#ifndef QT_NO_TOOLBAR if ( left ) wl = left->widthForHeight( r.height() ); if ( right ) wr = right->widthForHeight( r.height() );#endif int w = r.width() - wr - wl; if ( w < 0 ) w = 0; if ( !testonly ) { QRect g( geometry() );#ifndef QT_NO_TOOLBAR if ( left ) left->setGeometry( QRect( g.x(), g.y(), wl, r.height() ) ); if ( right ) right->setGeometry( QRect( g.x() + g.width() - wr, g.y(), wr, r.height() ) );#endif if ( central ) central->setGeometry( g.x() + wl, g.y(), w, r.height() ); } w = wl + wr; if ( central ) w += central->minimumSize().width(); return w;}void QMainWindowLayout::addItem( QLayoutItem * /*item*/ ){}class QMainWindowLayoutIterator : public QGLayoutIterator{public: QMainWindowLayoutIterator( QList<QLayoutItem> *l ) :idx(0), list(l) {} uint count() const { return list ? list->count() : 0; } QLayoutItem *current() { return list && idx < (int)count() ? list->at(idx) : 0; } QLayoutItem *next() { idx++; return current(); } QLayoutItem *takeCurrent() { return list ? list->take( idx ) : 0; }private: int idx; QList<QLayoutItem> *list;};QLayoutIterator QMainWindowLayout::iterator(){ //This is evil. Pretend you didn't see this. return QLayoutIterator( new QMainWindowLayoutIterator( 0/*&list*/ ) );}/************************************************************************************************* --------------------------------- Minimized Dock -----------------------************************************************************************************************/#ifndef QT_NO_TOOLBAR#ifndef QT_NO_TOOLTIPclass QHideToolTip : public QToolTip{public: QHideToolTip( QWidget *parent ) : QToolTip( parent ) {} void maybeTip( const QPoint &pos );};#endifclass QHideDock : public QWidget{public: QHideDock( QMainWindow *parent, QMainWindowPrivate *p ) : QWidget( parent, "hide-dock" ) { hide(); setFixedHeight( style().toolBarHandleExtend() ); d = p; pressedHandle = -1; pressed = FALSE; setMouseTracking( TRUE ); win = parent;#ifndef QT_NO_TOOLTIP tip = new QHideToolTip( this );#endif } ~QHideDock() {#ifndef QT_NO_TOOLTIP delete tip;#endif }protected: void paintEvent( QPaintEvent *e ) { if ( !d->hidden || d->hidden->isEmpty() ) return; QPainter p( this ); p.setClipRegion( e->rect() ); p.fillRect( e->rect(), colorGroup().brush( QColorGroup::Background ) ); QMainWindowPrivate::ToolBar *tb; int x = 0; int i = 0; for ( tb = d->hidden->first(); tb; tb = d->hidden->next(), ++i ) { if ( !tb->t->isVisible() ) continue; style().drawToolBarHandle( &p, QRect( x, 0, 30, 10 ), Qt::Vertical, i == pressedHandle, colorGroup(), TRUE ); x += 30; } } void mousePressEvent( QMouseEvent *e ) { pressed = TRUE; if ( !d->hidden || d->hidden->isEmpty() ) return; mouseMoveEvent( e ); if ( e->button() == RightButton && win->isDockMenuEnabled() ) { if ( pressedHandle != -1 ) { QMainWindowPrivate::ToolBar *tb = d->hidden->at( pressedHandle ); QPopupMenu menu( this ); int left = menu.insertItem( QMainWindow::tr( "&Left" ) ); menu.setItemEnabled( left, win->isDockEnabled( QMainWindow::Left ) && win->isDockEnabled( tb->t, QMainWindow::Left ) ); int right = menu.insertItem( QMainWindow::tr( "&Right" ) ); menu.setItemEnabled( right, win->isDockEnabled( QMainWindow::Right ) && win->isDockEnabled( tb->t, QMainWindow::Right ) ); int top = menu.insertItem( QMainWindow::tr( "&Top" ) ); menu.setItemEnabled( top, win->isDockEnabled( QMainWindow::Top ) && win->isDockEnabled( tb->t, QMainWindow::Top ) ); int bottom = menu.insertItem( QMainWindow::tr( "&Bottom" ) ); menu.setItemEnabled( bottom, win->isDockEnabled( QMainWindow::Bottom ) && win->isDockEnabled( tb->t, QMainWindow::Bottom ) ); menu.insertSeparator(); int hide = menu.insertItem( QMainWindow::tr( "R&estore" ) ); QMainWindow::ToolBarDock dock = tb->oldDock; menu.setItemEnabled( hide, win->isDockEnabled( dock ) && win->isDockEnabled( tb->t, dock ) ); int res = menu.exec( e->globalPos() ); pressed = FALSE; pressedHandle = -1; repaint( TRUE ); if ( res == left ) win->moveToolBar( tb->t, QMainWindow::Left ); else if ( res == right ) win->moveToolBar( tb->t, QMainWindow::Right ); else if ( res == top ) win->moveToolBar( tb->t, QMainWindow::Top ); else if ( res == bottom ) win->moveToolBar( tb->t, QMainWindow::Bottom ); else if ( res == hide ) win->moveToolBar( tb->t, tb->oldDock, tb->nl, tb->oldIndex, tb->extraOffset ); else return; tb->t->show(); } else { win->rightMouseButtonMenu( e->globalPos() ); } } } void mouseMoveEvent( QMouseEvent *e ) { if ( !d->hidden || d->hidden->isEmpty() ) return; if ( !pressed ) return; QMainWindowPrivate::ToolBar *tb; int x = 0; int i = 0; if ( e->y() >= 0 && e->y() <= height() ) { for ( tb = d->hidden->first(); tb; tb = d->hidden->next(), ++i ) { if ( !tb->t->isVisible() ) continue; if ( e->x() >= x && e->x() <= x + 30 ) { int old = pressedHandle; pressedHandle = i; if ( pressedHandle != old ) repaint( TRUE ); return; } x += 30; } } int old = pressedHandle; pressedHandle = -1; if ( old != -1 ) repaint( TRUE ); } void mouseReleaseEvent( QMouseEvent *e ) { pressed = FALSE; if ( pressedHandle == -1 ) return; if ( !d->hidden || d->hidden->isEmpty() ) return; if ( e->button() == LeftButton ) { if ( e->y() >= 0 && e->y() <= height() ) { QMainWindowPrivate::ToolBar *tb = d->hidden->at( pressedHandle ); tb->t->show(); win->moveToolBar( tb->t, tb->oldDock, tb->nl, tb->oldIndex, tb->extraOffset ); } } pressedHandle = -1; repaint( TRUE ); }private: QMainWindowPrivate *d;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -