⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtoolbutton.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  Returns TRUE if this tool button puts a text label below the button  pixmap, and FALSE if it does not. \sa setUsesTextLabel()  setTextLabel() usesBigPixmap()*//*!  Sets this tool button to be on if \a enable is TRUE, and off it  \a enable is FALSE.  This function has no effect on \link isToggleButton() non-toggling  buttons. \endlink  \sa isToggleButton() toggle()*/void QToolButton::setOn( bool enable ){    if ( !isToggleButton() )	return;    QButton::setOn( enable );}/*!  Toggles the state of this tool button.  This function has no effect on \link isToggleButton() non-toggling  buttons. \endlink  \sa isToggleButton() toggled()*/void QToolButton::toggle(){    if ( !isToggleButton() )	return;    QButton::setOn( !isOn() );}/*! \reimp */void QToolButton::drawButton( QPainter * p ){    style().drawToolButton( this, p );    drawButtonLabel( p );    if ( hasFocus() && !focusProxy() ) {#ifdef QT_KEYPAD_MODE	if( qt_modalEditingEnabled ) {	    p->setPen(colorGroup().highlight());	    p->drawRect( 2, 2, width()-4, height()-4 );	    p->drawRect( 3, 3, width()-6, height()-6 );	    return;	}#endif	if ( style() == WindowsStyle ) {	    p->drawWinFocusRect( 3, 3, width()-6, height()-6,				 colorGroup().background() );	} else {	    p->setPen( black );	    p->drawRect( 3, 3, width()-6, height()-6 );	}    }}/*!\reimp */void QToolButton::drawButtonLabel( QPainter * p ){    int sx = 0;    int sy = 0;    int x, y, w, h;    style().toolButtonRect(0, 0, width(), height() ).rect( &x, &y, &w, &h );    if (isDown() || (isOn()&&!son) ) {	style().getButtonShift(sx, sy);	x+=sx;	y+=sy;    }    if ( hasArrow ) {	style().drawArrow( p, d->arrow, isDown(), x, y, w, h, colorGroup(), isEnabled() );	return;    }    if ( !text().isNull() ) {	style().drawItem( p, x, y, w, h,			  AlignCenter + ShowPrefix,			  colorGroup(), isEnabled(),			  0, text() );    } else {	QPixmap pm;	if ( usesBigPixmap() ) {	    if ( !isEnabled() )		pm = iconSet( isOn() ).pixmap( QIconSet::Large, QIconSet::Disabled );	    else if ( uses3D() )		pm = iconSet( isOn() ).pixmap( QIconSet::Large, QIconSet::Active );	    else		pm = iconSet( isOn() ).pixmap( QIconSet::Large, QIconSet::Normal );	} else {	    if ( !isEnabled() )		pm = iconSet( isOn() ).pixmap( QIconSet::Small, QIconSet::Disabled );	    else if ( uses3D() )		pm = iconSet( isOn() ).pixmap( QIconSet::Small, QIconSet::Active );	    else		pm = iconSet( isOn() ).pixmap( QIconSet::Small, QIconSet::Normal );	}	if ( usesTextLabel() ) {	    int fh = fontMetrics().height();	    style().drawItem( p, x, y, w, h - fh,			      AlignCenter, colorGroup(), TRUE, &pm, QString::null );	    p->setFont( font() );	    style().drawItem( p, x, h - fh, w, fh,			      AlignCenter + ShowPrefix,			      colorGroup(), isEnabled(),			      0, textLabel() ); 	} else {	    style().drawItem( p, x, y, w, h,			      AlignCenter, colorGroup(), TRUE, &pm, QString::null );	}    }}/*!\reimp */void QToolButton::enterEvent( QEvent * e ){    if ( autoRaise() ) {	threeDeeButton = this;	if ( isEnabled() )	    repaint(FALSE);    }    QButton::enterEvent( e );}/*!\reimp */void QToolButton::leaveEvent( QEvent * e ){    if ( autoRaise() ) {	QToolButton * o = threeDeeButton;	threeDeeButton = 0;	if ( o && o->isEnabled() )	    o->repaint(FALSE);    }    QButton::leaveEvent( e );}/*!\reimp */void QToolButton::moveEvent( QMoveEvent * ){    //   Reimplemented to handle pseudo transparency in case the toolbars    //   has a fancy pixmap background.    if ( parentWidget() && parentWidget()->backgroundPixmap() &&	 autoRaise() && !uses3D() )	repaint( FALSE );}/*!  Returns TRUE if this button should be drawn using raised edges.  \sa drawButton() */bool QToolButton::uses3D() const{    return !autoRaise() || ( threeDeeButton == this && isEnabled() );}/*!  Sets the label of this button to \a newLabel, and automatically  sets it as tool tip too.*/void QToolButton::setTextLabel( const QString &newLabel ){    setTextLabel( newLabel, TRUE );}/*!  Sets the label of this button to \a newLabel, and automatically  sets it as tool tip too if \a tipToo is TRUE.*/void QToolButton::setTextLabel( const QString &newLabel , bool tipToo ){    if ( tl == newLabel )	return;#ifndef QT_NO_TOOLTIP    if ( tipToo ) {        QToolTip::remove( this );        QToolTip::add( this, newLabel );    }#endif    tl = newLabel;    if ( usesTextLabel() && isVisible() ) {	update();	updateGeometry();    }}/*!  Sets the icon that is used when the button  is in on-state.  \sa setIconSet()*/void QToolButton::setOnIconSet( const QIconSet& set ){    setIconSet( set, TRUE );}/*!  Sets the icon that is used when the button  is in off-state.  \sa setIconSet()*/void QToolButton::setOffIconSet( const QIconSet& set ){    setIconSet( set, FALSE );}/*!  Returns the icon set which is used if the toolbutton  is in on-state.  \sa iconSet()*/QIconSet QToolButton::onIconSet() const{    return iconSet( TRUE );}/*!  Returns the icon set which is used if the toolbutton  is in off-state.  \sa iconSet()*/QIconSet QToolButton::offIconSet( ) const{    return iconSet( FALSE );}/*!  Sets this tool button to display the icons in \a set.  (setPixmap() is effectively a wrapper for this function.)  For toggle buttons it is possible to set an extra icon set with \a  on equals TRUE, which will be used exclusively for the on-state.  QToolButton makes a copy of \a set, so you must delete \a set  yourself.  \sa iconSet() QIconSet, setToggleButton(), isOn()*/void QToolButton::setIconSet( const QIconSet & set, bool on ){    if ( !on ) {	if ( s )	    delete s;	s = new QIconSet( set );    } else {	if ( son )	    delete son;	son = new QIconSet( set );    }    if ( isVisible() )	update();}/*!  Returns a copy of the icon set in use.  If no icon set has been  set, iconSet() creates one from the pixmap().  If the button doesn't have a pixmap either, iconSet()'s return value  is meaningless.  If \a on equals TRUE, the special icon set for the on-state of the  button is returned.  \sa setIconSet() QIconSet*/QIconSet QToolButton::iconSet( bool on ) const{    QToolButton * that = (QToolButton *)this;    if ( on && that->son )	return *that->son;    if ( pixmap() && (!that->s || (that->s->pixmap().serialNumber() !=	pixmap()->serialNumber())) ) {	if ( that->s )	    delete that->s;	that->s = new QIconSet( *pixmap() );    }    if ( that->s )	return *that->s;    QPixmap tmp1;    QIconSet tmp2( tmp1, QIconSet::Small );    return tmp2;}#ifndef QT_NO_POPUPMENU/*!  Associates the popup menu \a popup with this toolbutton.  The popup will be shown each time the toolbutton has been pressed  down for a certain amount of time. A typical application example is  the "back" button in a web browser's toolbar. If the user clicks it,  the browser simply browses back to the previous page. If the user  holds the button down for a while, they receive a menu containing  the current history list.  Ownership of the popup menu is not transferred.  \sa popup() */void QToolButton::setPopup( QPopupMenu* popup ){    if ( popup && !d->popupTimer ) {	connect( this, SIGNAL( pressed() ), this, SLOT( popupPressed() ) );	d->popupTimer = new QTimer( this );	connect( d->popupTimer, SIGNAL( timeout() ), this, SLOT( popupTimerDone() ) );    }    d->popup = popup;}/*!  Returns the associated popup menu or 0 if no popup menu has been  defined.  \sa setPopup() */QPopupMenu* QToolButton::popup() const{    return d->popup;}void QToolButton::popupPressed(){    if ( d->popupTimer )	d->popupTimer->start( d->delay, TRUE );}void QToolButton::popupTimerDone(){    if ( isDown() && d->popup ) {	d->repeat = autoRepeat();	setAutoRepeat( FALSE );	bool horizontal = TRUE;	bool topLeft = TRUE;#ifndef QT_NO_TOOLBAR	if ( parentWidget() && parentWidget()->inherits("QToolBar") ) {	    if ( ( (QToolBar*) parentWidget() )->orientation() == Vertical )		horizontal = FALSE;	}#endif	if ( horizontal ) {	    if ( topLeft ) {		if ( mapToGlobal( QPoint( 0, rect().bottom() ) ).y() + d->popup->sizeHint().height() <= qApp->desktop()->height() )		    d->popup->exec( mapToGlobal( rect().bottomLeft() ) );		else		    d->popup->exec( mapToGlobal( rect().topLeft() - QPoint( 0, d->popup->sizeHint().height() ) ) );	    } else {		QSize sz( d->popup->sizeHint() );		QPoint p = mapToGlobal( rect().topLeft() );		p.ry() -= sz.height();		d->popup->exec( p );	    }	}	else {	    if ( topLeft ) {		if ( mapToGlobal( QPoint( rect().right(), 0 ) ).x() + d->popup->sizeHint().width() <= qApp->desktop()->width() )		    d->popup->exec( mapToGlobal( rect().topRight() ) );		else		    d->popup->exec( mapToGlobal( rect().topLeft() - QPoint( d->popup->sizeHint().width(), 0 ) ) );	    } else {		QSize sz( d->popup->sizeHint() );		QPoint p = mapToGlobal( rect().topLeft() );		p.rx() -= sz.width();		d->popup->exec( p );	    }	}	setDown( FALSE );	if ( d->repeat )	    setAutoRepeat( TRUE );    }}/*!  Sets the time delay between pressing the button and the appearance of  the associated popupmenu in milliseconds. Usually this is around 1/2 of  a second.  \sa popupDelay(), setPopup()*/void QToolButton::setPopupDelay( int delay ){    d->delay = delay;}/*!  Returns the delay between pressing the button and the appearance of  the associated popupmenu in milliseconds.  \sa setPopupDelay(), setPopup()*/int QToolButton::popupDelay() const{    return d->delay;}#endif/*!  Enables or disables auto-raising according to \a enable.  \sa autoRaise */void QToolButton::setAutoRaise( bool enable ){    d->autoraise = enable;}/*!  Returns whether auto-raising is enabled or not.  \sa setAutoRaise */bool QToolButton::autoRaise() const{    return d->autoraise;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -