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

📄 qpushbutton.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	h = pm->height() + style().buttonMargin();    } else {	QString s( text() );	if ( s.isEmpty() )	    s = QString::fromLatin1("XXXX");	QFontMetrics fm = fontMetrics();	QSize sz = fm.size( ShowPrefix, s );	w = sz.width() + style().buttonMargin();	h = sz.height() + sz.height()/8 + 4 + style().buttonMargin();#ifndef _WS_QWS_	w += h;#else	w += sz.height()/8 + 4;#endif    }    if ( iconSet() && !iconSet()->isNull() ) {	int iw = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4;	int ih = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();	w += iw + style().buttonMargin() - 2;	h = QMAX( h, ih + style().buttonMargin() );    }    if ( isDefault() || autoDefault() ) {	w += 2*style().buttonDefaultIndicatorWidth();	h += 2*style().buttonDefaultIndicatorWidth();    }    if ( isMenuButton() )	w += style().menuButtonIndicatorWidth( h );#ifndef _WS_QWS_     if ( style() == WindowsStyle ) {	// in windows style, try a little harder to conform to	// microsoft's size specifications	int il = style().pixelMetric(QStyle::IdealHeightLimit); // 25	int ih = style().pixelMetric(QStyle::IdealHeight); // 22	if ( h <= il )	    h = ih;	if ( w < 85 && !pixmap() && ( isDefault() || autoDefault() ) )	    w = 80;     } else if ( !pixmap() && ( isDefault() || autoDefault() ) ) {	 // un-unglify motifstyles until we fix boxlayout to treat	 // pushbuttons differently	 if ( w < 80 )	     w = 80;     }#endif     return QSize( w, h ).expandedTo( QApplication::globalStrut() );}/*!\reimp*/QSizePolicy QPushButton::sizePolicy() const{    //### removeme 3.0    return QWidget::sizePolicy();}/*!\reimp*/void QPushButton::move( int x, int y ){    QWidget::move( x, y );}/*!\reimp*/void QPushButton::move( const QPoint &p ){    move( p.x(), p.y() );}/*!\reimp*/void QPushButton::resize( int w, int h ){    QWidget::resize( w, h );}/*!\reimp*/void QPushButton::resize( const QSize &s ){    resize( s.width(), s.height() );}/*!\reimp*/void QPushButton::setGeometry( int x, int y, int w, int h ){    QWidget::setGeometry( x, y, w, h );}/*!\reimp*/void QPushButton::setGeometry( const QRect &r ){    QWidget::setGeometry( r );}/*!\reimp */void QPushButton::resizeEvent( QResizeEvent * ){    if ( autoMask() )	updateMask();}/*!\reimp*/void QPushButton::drawButton( QPainter *paint ){    int diw = 0;    if ( isDefault() || autoDefault() ) {	diw = style().buttonDefaultIndicatorWidth();	if ( diw > 0 ) {	    if (backgroundMode() == X11ParentRelative) {		erase( 0, 0, width(), diw );		erase( 0, 0, diw, height() );		erase( 0, height() - diw, width(), diw );		erase( width() - diw, 0, diw, height() );	    } else if ( parentWidget() && parentWidget()->backgroundPixmap() ){		// pseudo tranparency		paint->drawTiledPixmap( 0, 0, width(), diw,					*parentWidget()->backgroundPixmap(),					x(), y() );		paint->drawTiledPixmap( 0, 0, diw, height(),					*parentWidget()->backgroundPixmap(),					x(), y() );		paint->drawTiledPixmap( 0, height()-diw, width(), diw,					*parentWidget()->backgroundPixmap(),					x(), y() );		paint->drawTiledPixmap( width()-diw, 0, diw, height(),					*parentWidget()->backgroundPixmap(),					x(), y() );	    } else {		paint->fillRect( 0, 0, width(), diw,				 colorGroup().brush(QColorGroup::Background) );		paint->fillRect( 0, 0, diw, height(),				 colorGroup().brush(QColorGroup::Background) );		paint->fillRect( 0, height()-diw, width(), diw,				 colorGroup().brush(QColorGroup::Background) );		paint->fillRect( width()-diw, 0, diw, height(),				 colorGroup().brush(QColorGroup::Background) );	    }	}    }    style().drawPushButton(this, paint);    drawButtonLabel( paint );    int x1, y1, x2, y2;    style().pushButtonContentsRect( this ).coords( &x1, &y1, &x2, &y2 );// get coordinates    if ( hasFocus() ) { 	QRect r(x1+2, y1+2, x2-x1-3, y2-y1-3); 	style().drawFocusRect( paint, r , colorGroup(), &colorGroup().button() );    }    lastEnabled = isEnabled();}/*!\reimp*/void QPushButton::drawButtonLabel( QPainter *paint ){    style().drawPushButtonLabel( this, paint );}/*!\reimp */void QPushButton::updateMask(){    QBitmap bm( size() );    bm.fill( color0 );    {	QPainter p( &bm, this );	p.setPen( color1 );	p.setBrush( color1 );	style().drawButtonMask( &p, 0, 0, width(), height() );    }    setMask( bm );}/*!\reimp*/void QPushButton::focusInEvent( QFocusEvent *e ){    if ( autoDefButton )	setDefault( TRUE );#ifndef QT_NO_DIALOG    else {	if ( topLevelWidget()->inherits("QDialog") )	    ((QDialog*)topLevelWidget())->hideDefault();    }#endif    QButton::focusInEvent( e );}/*!\reimp*/void QPushButton::focusOutEvent( QFocusEvent *e ){#ifndef QT_NO_DIALOG    if ( defButton && autoDefButton ) {	if ( topLevelWidget()->inherits("QDialog") )	    ((QDialog*)topLevelWidget())->setDefault( 0 );    }#endif    QButton::focusOutEvent( e );    if ( popup() && popup()->isVisible() )	// restore pressed status	setDown( TRUE );}/*!  \obsolete  Tells this button to draw a menu indication triangle if \a enable  is TRUE,  and to not draw one if \a enable is FALSE (the default).  setIsMenuButton() does not cause the button to do anything other  than draw the menu indication.  \sa isMenuButton()*/void QPushButton::setIsMenuButton( bool enable ){    if ( (bool)hasMenuArrow == enable )	return;    hasMenuArrow = enable ? 1 : 0;    update();    updateGeometry();}/*!  \obsolete  Returns TRUE if this button indicates to the user that pressing  it will pop up a menu, and FALSE otherwise.  The default is FALSE.  \sa setIsMenuButton()*/bool QPushButton::isMenuButton() const{    return hasMenuArrow;}/*!  Associates the popup menu \a popup with this push button and  thus turns it into a menu button.  Ownership of the popup menu is not transferred.  \sa popup() */void QPushButton::setPopup( QPopupMenu* popup ){    if ( popup && !::d( this )->popup ) {	connect( this, SIGNAL( pressed() ), this, SLOT( popupPressed() ) );    }    ::d( this )->popup = popup;    autoDefButton = FALSE;    setIsMenuButton( popup != 0 );}/*!  Sets the button to display the icon \a icon in addition to its text  or pixmap  \sa iconSet() */void QPushButton::setIconSet( const QIconSet& icon ){    if (! icon.isNull()) {	if ( ::d( this )->iconset )	    *::d( this )->iconset = icon;	else	    ::d( this )->iconset = new QIconSet( icon );    } else if (::d(this)->iconset) {	delete (::d(this)->iconset);	::d(this)->iconset = 0;    }    update();    updateGeometry();}/*!  Returns the button's icon or 0 if no icon has been defined.  \sa setIconSet() */QIconSet* QPushButton::iconSet() const{    if ( !::has_d( this ) )	return 0;    return ::d( this )->iconset;}/*!  Returns the associated popup menu or 0 if no popup menu has been  defined.  \sa setPopup()*/QPopupMenu* QPushButton::popup() const{    if ( !::has_d( this ) )	return 0;    return ::d( this )->popup;}void QPushButton::popupPressed(){    QPopupMenu* popup = ::d( this )->popup;    if (#ifndef QT_KEYPAD_MODE     isDown() &&#endif     popup ) {	bool horizontal = TRUE;	bool topLeft = TRUE;			// ### always 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() + popup->sizeHint().height() <= qApp->desktop()->height() )		    popup->exec( mapToGlobal( rect().bottomLeft() ) );		else		    popup->exec( mapToGlobal( rect().topLeft() - QPoint( 0, popup->sizeHint().height() ) ) );	    } else {		QSize sz( popup->sizeHint() );		QPoint p = mapToGlobal( rect().topLeft() );		p.ry() -= sz.height();		popup->exec( p );	    }	}	else {	    if ( topLeft ) {		if ( mapToGlobal( QPoint( rect().right(), 0 ) ).x() + popup->sizeHint().width() <= qApp->desktop()->width() )		    popup->exec( mapToGlobal( rect().topRight() ) );		else		    popup->exec( mapToGlobal( rect().topLeft() - QPoint( popup->sizeHint().width(), 0 ) ) );	    } else {		QSize sz( popup->sizeHint() );		QPoint p = mapToGlobal( rect().topLeft() );		p.rx() -= sz.width();		popup->exec( p );	    }	}	setDown( FALSE );    }}/*!  Disable the border.  \sa flat()*/void QPushButton::setFlat( bool f ){    flt = f;    update();}/*!  Returns whether the border is disabled.  \sa setFlat()*/bool QPushButton::isFlat() const{    return flt;}#endif

⌨️ 快捷键说明

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