?? qtoolbar.cpp
字號:
} else if ( e->type() == QEvent::ChildRemoved ) { QObject * child = ((QChildEvent*)e)->child(); if ( child == d->arrow ) d->arrow = 0; if ( child == d->menu ) d->menu = 0; if ( child == d->back ) d->back = 0; } return r;}/*! \reimp */bool QToolBar::eventFilter( QObject * obj, QEvent * e ){ //Does nothing, present for binary compatibility return QWidget::eventFilter( obj, e );}/*! Sets the label of this tool bar to \a label. The label is notcurrently used; it will be used in a forthcoming tool barconfiguration dialog.\sa label()*/void QToolBar::setLabel( const QString & label ){ l = label;}/*! Returns the label of this tool bar. \sa setLabel()*/QString QToolBar::label() const{ return l;}/*! Clears the toolbar, deleting all childwidgets. */void QToolBar::clear(){ if ( !children() ) return; QObjectListIt it( *children() ); QObject * obj; while( (obj=it.current()) != 0 ) { ++it; if ( obj->isWidgetType() ) delete obj; } d->menu = 0; d->arrow = 0; d->back = 0; if ( isVisible() ) updateArrowStuff();}/*! \internal*/void QToolBar::startMoving( QToolBar *tb ){ if ( tb == this ) { d->moving = TRUE; bool du = !isUpdatesEnabled(); if ( du ) setUpdatesEnabled( TRUE ); repaint( FALSE ); if ( du ) setUpdatesEnabled( FALSE); }}/*! \internal*/void QToolBar::endMoving( QToolBar *tb ){ if ( tb == this && d->moving ) { bool du = !isUpdatesEnabled(); if ( du ) setUpdatesEnabled( TRUE ); d->moving = FALSE; repaint( TRUE ); if ( du ) setUpdatesEnabled( FALSE); }}/*! Sets the toolbar to be horizontally stretchable if \a b is TRUE, or non-stretchable otherwise. A stretchable toolbar fills the available width in a toolbar dock. A non-stretchable toolbar usually gets just the space it needs. The default is FALSE. \sa QMainWindow::setRightJustification(), isHorizontalStretchable(), setVerticalStretchable(), isVerticalStretchable()*/void QToolBar::setHorizontalStretchable( bool b ){ if ( d->stretchable[ 0 ] != b ) { d->stretchable[ 0 ] = b; if ( mw ) mw->triggerLayout( FALSE ); }}/*! Sets the toolbar to be vertically stretchable if \a b is TRUE, or non-stretchable otherwise. A stretchable toolbar fills the available height in a toolbar dock. A non-stretchable toolbar usually gets just the space it needs. The default is FALSE. \sa QMainWindow::setRightJustification(), isVerticalStretchable(), setHorizontalStretchable(), isHorizontalStretchable()*/void QToolBar::setVerticalStretchable( bool b ){ if ( d->stretchable[ 1 ] != b ) { d->stretchable[ 1 ] = b; if ( mw ) mw->triggerLayout( FALSE ); }}/*! Returns whether the toolbar is stretchable horizontally. A stretchable toolbar fills all available width in a toolbar dock. A non-stretchable toolbar usually gets just the space it needs. \sa setHorizontalStretchable(), setVerticalStretchable(), isVerticalStretchable()*/bool QToolBar::isHorizontalStretchable() const{ return d->stretchable[ 0 ];}/*! Returns whether the toolbar is stretchable vertically. A stretchable toolbar fills all available height in a toolbar dock. A non-stretchable toolbar usually gets just the space it needs. \sa setHorizontalStretchable(), setVerticalStretchable(), isHorizontalStretchable()*/bool QToolBar::isVerticalStretchable() const{ return d->stretchable[ 1 ];}/*! \fn void QToolBar::orientationChanged( Orientation newOrientation ) This signal is emitted when the toolbar changed its orientation to \a newOrientation.*//*! \reimp*/QSize QToolBar::minimumSize() const{ if ( orientation() == Horizontal ) return QSize( 0, QWidget::minimumSize().height() ); return QSize( QWidget::minimumSize().width(), 0 );}/*! \reimp*/QSize QToolBar::minimumSizeHint() const{ if ( orientation() == Horizontal ) return QSize( 0, QWidget::minimumSizeHint().height() ); return QSize( QWidget::minimumSizeHint().width(), 0 );}/*! \reimp*/void QToolBar::resizeEvent( QResizeEvent *e ){ QWidget::resizeEvent( e ); if ( isVisible() ) updateArrowStuff();}void QToolBar::updateArrowStuff(){#ifndef QT_NO_POPUPMENU if ( !isVisible() ) return; if ( orientation() == Horizontal ) { int shw = sizeHint().width(); if ( d->arrow && d->back && d->arrow->isVisible() && d->back->isVisible() ) shw -= QMAX( d->arrow->width(), d->back->width() ); if ( width() < shw ) { setUpdatesEnabled( TRUE ); setupArrowMenu(); if ( !d->back ) { d->back = new QArrowWidget( orientation(), this ); } if ( !d->arrow ) { d->arrow = new QToolButton( RightArrow, this ); d->arrow->setAutoRaise( TRUE ); d->arrow->setAutoRepeat( FALSE ); d->arrow->setPopupDelay( 0 ); } if ( d->menu && d->menu->count() > 0 ) { d->back->show(); d->back->raise(); d->arrow->show(); d->arrow->raise(); d->arrow->setPopup( d->menu ); } else if ( d->menu ) { d->back->hide(); d->arrow->hide(); } if ( d->back->geometry() != QRect( width() - 20, 1, 20, height() - 2 ) ) d->back->setGeometry( width() - 20, 1, 20, height() - 2 ); if ( d->arrow->geometry() != QRect( width() - 14, 3, 13, height() - 6 ) ) d->arrow->setGeometry( width() - 14, 3, 13, height() - 6 ); paintToolBar(); setUpdatesEnabled( FALSE ); } else { setUpdatesEnabled( TRUE ); if ( d->arrow || d->back ) { if ( d->back && d->back->isVisible() ) { d->back->hide(); if ( layout() ) layout()->activate(); } if ( d->arrow && d->arrow->isVisible() ) { d->arrow->hide(); if ( layout() ) layout()->activate(); } } update(); } } else { int shh = sizeHint().height(); if ( d->arrow && d->back && d->arrow->isVisible() && d->back->isVisible() ) shh -= QMAX( d->arrow->height(), d->back->height() ); if ( height() < shh ) { setUpdatesEnabled( TRUE ); setupArrowMenu(); if ( !d->back ) { d->back = new QArrowWidget( orientation(), this ); } if ( !d->arrow ) { d->arrow = new QToolButton( DownArrow, this ); d->arrow->setAutoRepeat( FALSE ); d->arrow->setAutoRaise( TRUE ); d->arrow->setPopupDelay( 0 ); } if ( d->menu && d->menu->count() > 0 ) { d->back->show(); d->back->raise(); d->arrow->show(); d->arrow->raise(); d->arrow->setPopup( d->menu ); } else if ( d->menu ) { d->back->hide(); d->arrow->hide(); } if ( d->back->geometry() != QRect( 1, height() - 20, width() - 2, 20 ) ) d->back->setGeometry( 1, height() - 20, width() - 2, 20 ); if ( d->arrow->geometry() != QRect( 3, height() - 14, width() - 6, 13 ) ) d->arrow->setGeometry( 3, height() - 14, width() - 6, 13 ); paintToolBar(); setUpdatesEnabled( FALSE ); } else { setUpdatesEnabled( TRUE ); if ( d->arrow || d->back ) { if ( d->back && d->back->isVisible() ) { d->back->hide(); if ( layout() ) layout()->activate(); } if ( d->arrow && d->arrow->isVisible() ) { d->arrow->hide(); if ( layout() ) layout()->activate(); } } update(); } }#endif}void QToolBar::setupArrowMenu(){#ifndef QT_NO_POPUPMENU if ( !isVisible() ) return; if ( !d->menu ) { d->menu = new QPopupMenu( this ); connect( d->menu, SIGNAL( activated(int) ), this, SLOT( popupSelected(int) ) ); connect( d->menu, SIGNAL( aboutToShow() ), this, SLOT( setupArrowMenu() ) ); } QObjectList *childs = queryList( "QWidget" ); if ( childs ) { d->menu->clear(); d->menu->setCheckable( TRUE ); d->hiddenItems.clear(); bool justHadSep = TRUE; QObject *ob = 0; for ( ob = childs->first(); ob; ob = childs->next() ) { if ( ob->isWidgetType() && ( (QWidget*)ob )->isVisible() && ob->parent() == this && ob != d->arrow && ob != d->menu && ob->inherits( "QButton" ) ) { QWidget *w = (QWidget*)ob; bool mv = FALSE; if ( orientation() == Horizontal ) mv = ( w->x() + w->width() > width() - 20); else mv = ( w->y() + w->height() > height() - 20); if ( mv ) { if ( w->inherits( "QToolButton" ) ) { QToolButton *b = (QToolButton*)w; QString s = b->textLabel(); if ( s.isEmpty() ) s = ""; int id;#ifndef QT_NO_POPUPMENU if ( b->popup() && b->popupDelay() == 0 ) id = d->menu->insertItem( b->iconSet(), s, b->popup() ); else#endif id = d->menu->insertItem( b->iconSet(), s ); d->hiddenItems.insert( id, b ); if ( b->isToggleButton() ) d->menu->setItemChecked( id, b->isOn() ); if ( !b->isEnabled() ) d->menu->setItemEnabled( id, FALSE ); justHadSep = FALSE; } else if ( w->inherits( "QButton" ) ) { QButton *b = (QButton*)w; QString s = b->text(); if ( s.isEmpty() ) s = ""; int id = -1; if ( b->pixmap() ) id = d->menu->insertItem( *b->pixmap(), s ); else id = d->menu->insertItem( s ); d->hiddenItems.insert( id, b ); if ( b->isToggleButton() ) d->menu->setItemChecked( id, b->isOn() ); if ( !b->isEnabled() ) d->menu->setItemEnabled( id, FALSE ); justHadSep = FALSE; } } } else if ( ob->inherits( "QToolBarSeparator" ) ) { if ( !justHadSep ) d->menu->insertSeparator(); justHadSep = TRUE; } } } delete childs;#endif}void QToolBar::popupSelected( int id ){ QButton *b = d->hiddenItems.find( id ); d->button = b; if ( d->button ) QTimer::singleShot( 0, this, SLOT( emulateButtonClicked() ) );}void QToolBar::emulateButtonClicked(){ if ( !d->button ) return;#ifndef QT_NO_PUSHBUTTON if ( d->button->inherits( "QPushButton" ) && ( (QPushButton*)d->button )->popup() ) { ( (QPushButton*)d->button )->popup()->exec( QCursor::pos() ); } else#endif#ifndef QT_NO_POPUPMENU if ( d->button->inherits( "QToolButton" ) && ( (QToolButton*)d->button )->popup() ) { ( (QToolButton*)d->button )->popup()->exec( QCursor::pos() ); } else#endif if ( d->button->isToggleButton() ) { d->button->setOn( !d->button->isOn() ); emit d->button->pressed(); emit d->button->released(); emit d->button->clicked(); if ( d->button->inherits( "QWhatsThisButton" ) ) d->button->setOn( FALSE ); } else { emit d->button->pressed(); emit d->button->released(); emit d->button->clicked(); } if ( d ) { // we might got deleted, so check to be sure d->button = 0; QTimer::singleShot( 0, this, SLOT( updateArrowStuff() ) ); }}void QToolBar::paintToolBar(){ if ( mw && !mw->toolBarsMovable() ) return; QPainter p( this ); int w = width(); int h = height(); if ( orientation() == Horizontal && w < sizeHint().width() ) w++; else if ( orientation() == Vertical && h < sizeHint().height() ) h++; style().drawPanel( &p, 0, 0, w, h, colorGroup(), FALSE, 1, 0 ); style().drawToolBarHandle( &p, QRect( 0, 0, width(), height() ), orientation(), d->moving, colorGroup() );}/* from chaunsee:1. Toolbars should contain only high-frequency functions. Avoid puttingthings like About and Exit on a toolbar unless they are frequent functions.2. All toolbar buttons must have some keyboard access method (it can be amenu or shortcut key or a function in a dialog box that can be accessedthrough the keyboard).3. Make toolbar functions as efficient as possible (the common example is toPrint in Microsoft applications, it doesn't bring up the Print dialog box, itprints immediately to the default printer).4. Avoid turning toolbars into graphical menu bars. To me, a toolbar shouldbe efficient. Once you make almost all the items in a toolbar into graphicalpull-down menus, you start to lose efficiency.5. Make sure that adjacent icons are distinctive. There are some toolbarswhere you see a group of 4-5 icons that represent related functions, but theyare so similar that you can't differentiate among them. These toolbars areoften a poor attempt at a "common visual language".6. Use any de facto standard icons of your platform (for windows use thecut, copy, and paste icons provided in dev kits rather than designing yourown).7. Avoid putting a highly destructive toolbar button (delete database) by asafe, high-frequency button (Find) -- this will yield 1-0ff errors).8. Tooltips in many Microsoft products simply reiterate the menu text evenwhen that is not explanatory. Consider making your tooltips slightly moreverbose and explanatory than the corresponding menu item.9. Keep the toolbar as stable as possible when you click on differentobjects. Consider disabling toolbar buttons if they are used in most, but notall contexts.10. If you have multiple toolbars (like the Microsoft MMC snap-ins have),put the most stable toolbar to at the left with less stable ones to theright. This arrangement (stable to less stable) makes the toolbar somewhatmore predictable.11. Keep a single toolbar to fewer than 20 items divided into 4-7 groups ofitems.*/#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -