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

📄 qbutton.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*!  \fn bool QButton::autoRepeat() const  Returns TRUE if the button is auto-repeating, else FALSE.  The default is FALSE.  \sa setAutoRepeat()*//*!  Turns on auto-repeat for the button if \a enable is TRUE, or  turns it off if \a enable is FALSE.  When auto-repeat is enabled, the clicked() signal is emitted at  regular intervals while the buttons \link isDown() is down. \endlink  setAutoRepeat() has no effect for \link setToggleButton() toggle  buttons. \endlink  \sa isDown(), autoRepeat(), clicked()*/void QButton::setAutoRepeat( bool enable ){    repeat = (uint)enable;    if ( repeat && mlbDown )	timer()->start( autoRepeatDelay, TRUE );}/*!  Performs an animated click: The button is pressed and a short while  later released.  pressed(), released(), clicked(), toggled(), and stateChanged()  signals are emitted as appropriate.  This function does nothing if the button is \link setEnabled()  disabled. \endlink  \sa setAccel()*/void QButton::animateClick(){    if ( !isEnabled() || animation )	return;    animation  = TRUE;    buttonDown = TRUE;    repaint( FALSE );    emit pressed();    QTimer::singleShot( 100, this, SLOT(animateTimeout()) );}/*!  \fn bool QButton::isDown() const  Returns TRUE if the button pressed down, or FALSE if it is standing up.  \sa setDown()*//*!  Sets the state of the button to pressed down if \e enable is TRUE  or to standing up if \e enable is FALSE.  If the button is a toggle button, it is \e not toggled.  Call  toggle() as well if you need to do that.  The pressed() and  released() signals are not emitted by this function.  This method is provided in case you need to reimplement the mouse event  handlers.  \sa isDown(), setOn(), toggle(), toggled()*/void QButton::setDown( bool enable ){    if ( d )	timer()->stop();    mlbDown = FALSE;				// the safe setting    if ( (bool)buttonDown != enable ) {	buttonDown = enable;	repaint( FALSE );    }}/*!  \fn QButton::ToggleType QButton::toggleType() const  Returns the current toggle type.  \sa setToggleType()*//*!  \fn void QButton::setState( ToggleState t)  This protected function sets the button state into state t but does  \e not cause repainting.  \sa setToggleType()*//*!  \fn QButton::ToggleState QButton::state() const  Returns the state of the button.  \sa ToggleState ToggleType setState()*//*!  \fn bool QButton::isOn() const  Returns TRUE if this toggle button is switched on, or FALSE if it is  switched off.  \sa setOn(), isToggleButton()*//*!  \fn void QButton::setOn( bool enable )  Switches a toggle button on if \e enable is TRUE or off if \e enable is  FALSE.  This function should be called only for toggle buttons.  \sa isOn(), isToggleButton()*/void QButton::setState( ToggleState s ){    if ( !toggleTyp ) {#if defined(CHECK_STATE)	qWarning( "QButton::setState() / setOn: (%s) Only toggle buttons "		 "may be switched", name( "unnamed" ) );#endif	return;    }    if ( (ToggleState)stat != s ) {		// changed state	bool was = stat != Off;	stat = s;    if ( autoMask() )        updateMask();	repaint( FALSE );	if ( was != (stat != Off) )	    emit toggled( stat != Off );	emit stateChanged( s );    }}/*!  \fn bool QButton::isToggleButton() const  Returns TRUE if the button is a toggle button.  \sa setToggleButton()*//*!  \fn void QButton::setToggleButton( bool enable )  Makes the button a toggle button if \e enable is TRUE, or a normal button  if \e enable is FALSE.  Note that this function is protected. It is called from subclasses  to enable the toggle functionality. QCheckBox and QRadioButton are  toggle buttons. QPushButton is initially not a toggle button, but  QPushButton::setToggleButton() can be called to create toggle buttons.  \sa isToggleButton()*//*!  Returns TRUE if \e pos is inside the clickable button rectangle, or  FALSE if it is outside.  Per default, the clickable area is the entire widget. Subclasses may  reimplement it, though.*/bool QButton::hitButton( const QPoint &pos ) const{    return rect().contains( pos );}/*!  Draws the button.  The default implementation does nothing.  This virtual function is reimplemented by subclasses to draw real  buttons. At some point in time, these reimplementations are supposed  to call drawButtonLabel().  \sa drawButtonLabel(), paintEvent()*/void QButton::drawButton( QPainter * ){    return;}/*!  Draws the button text or pixmap.  This virtual function is reimplemented by subclasses to draw real  buttons. It's invoked by drawButton().  \sa drawButton(), paintEvent()*/void QButton::drawButtonLabel( QPainter * ){    return;}static bool got_a_release = FALSE; // ### binary compatibility trick, keyReleaseEvent is new/*!\reimp*/void QButton::keyPressEvent( QKeyEvent *e ){    switch ( e->key() ) {    case Key_Enter:    case Key_Return:	if ( inherits("QPushButton") )	    emit clicked();	else	    e->ignore();	break;#ifdef QT_KEYPAD_MODE    case Key_Select:#endif    case Key_Space:	if ( !e->isAutoRepeat() ) {	    if ( got_a_release )		setDown( TRUE );	    else {		buttonDown = TRUE;		repaint( FALSE );	    }	    if ( inherits("QPushButton") )		emit pressed();#ifdef QT_KEYPAD_MODE	    else if ( inherits("QToolButton") )		emit pressed();#endif	    else		e->ignore();	}	break;    case Key_Up:    case Key_Left:#ifdef QT_KEYPAD_MODE	if( !qt_modalEditingEnabled || e->key() == Key_Up ) {#endif# ifndef QT_NO_BUTTONGROUP	if ( group() )	    group()->moveFocus( e->key() );	else# endif	    focusNextPrevChild( FALSE );#ifdef QT_KEYPAD_MODE	}	if( e->key() != Key_Up && qt_modalEditingEnabled )	    e->ignore();// won't reach default case so must ignore here#endif	break;    case Key_Down:    case Key_Right:#ifdef QT_KEYPAD_MODE	if( !qt_modalEditingEnabled || e->key() == Key_Down ) {#endif# ifndef QT_NO_BUTTONGROUP	    if ( group() )		group()->moveFocus( e->key() );	    else# endif		focusNextPrevChild( TRUE );#ifdef QT_KEYPAD_MODE	}	if( e->key() != Key_Down && qt_modalEditingEnabled )	    e->ignore(); // won't reach default case so must ignore here#endif	break;    case Key_Escape:	if ( buttonDown ) {	    buttonDown = FALSE;	    update();	    break;	}	// fall through    default:	e->ignore();    }}/*!  \reimp */void QButton::keyReleaseEvent( QKeyEvent * e){    got_a_release = TRUE;    switch ( e->key() ) {#ifdef QT_KEYPAD_MODE    case Key_Enter:    case Key_Return:	if( !qt_modalEditingEnabled )	    break;    case Key_Select:#endif    case Key_Space:	if ( buttonDown && !e->isAutoRepeat() ) {	    buttonDown = FALSE;	    nextState();	    emit released();	    emit clicked();	}	break;    default:	e->ignore();    }}/*! \reimp */bool QButton::focusNextPrevChild( bool next ){    // we do not want this any more    return QWidget::focusNextPrevChild( next );}/*!\reimp*/void QButton::mousePressEvent( QMouseEvent *e ){    if ( e->button() != LeftButton )	return;    bool hit = hitButton( e->pos() );    if ( hit ) {				// mouse press on button	mlbDown = TRUE;				// left mouse button down	buttonDown = TRUE;    if ( autoMask() )        updateMask();	repaint( FALSE );	emit pressed();	if ( repeat )	    timer()->start( autoRepeatDelay, TRUE );    }}/*!\reimp*/void QButton::mouseReleaseEvent( QMouseEvent *e){    if ( e->button() != LeftButton || !mlbDown )	return;    if ( d )	timer()->stop();    mlbDown = FALSE;				// left mouse button up    buttonDown = FALSE;    if ( hitButton( e->pos() ) ) {		// mouse release on button    nextState();        emit released();    emit clicked();    } else {	    repaint( FALSE );	    emit released();    }}/*!\reimp*/void QButton::mouseMoveEvent( QMouseEvent *e ){    if ( !((e->state() & LeftButton) && mlbDown) )	return;					// left mouse button is up    if ( hitButton( e->pos() ) ) {		// mouse move in button	if ( !buttonDown ) {	    buttonDown = TRUE;	    repaint( FALSE );	    emit pressed();	}    } else {					// mouse move outside button	if ( buttonDown ) {	    buttonDown = FALSE;	    repaint( FALSE );	    emit released();	}    }}extern QPoint qt_backgroundOffset(const QWidget *w);/*!  Handles paint events for buttons.  Small and typically complex  buttons (less than 300x100 pixels) are painted double-buffered to  reduce flicker. The actually drawing is done in the virtual functions  drawButton() and drawButtonLabel().  \sa drawButton(), drawButtonLabel()*/void QButton::paintEvent( QPaintEvent *event ){    if ( event &&	 width() <= drawingPixWidth &&	 height() <= drawingPixHeight &&	 backgroundMode() != X11ParentRelative ) {	makeDrawingPixmap(); // makes file-static drawpm variable	drawpm->fill( this, 0, 0 );	QPainter paint;	paint.begin( drawpm, this );	drawButton( &paint );	paint.end();	paint.begin( this );	paint.drawPixmap( 0, 0, *drawpm );	paint.end();    } else {	erase( event->region() );	QPainter paint( this );	drawButton( &paint );    }}/*!\reimp*/void QButton::focusInEvent( QFocusEvent * e){    QWidget::focusInEvent( e );}/*!\reimp*/void QButton::focusOutEvent( QFocusEvent * e ){    buttonDown = FALSE;    QWidget::focusOutEvent( e );}/*!  Internal slot used for auto repeat.*/void QButton::autoRepeatTimeout(){    if ( mlbDown && isEnabled() && autoRepeat() ) {	if ( buttonDown ) {	    emit released();	    emit clicked();	    emit pressed();	}	timer()->start( autoRepeatPeriod, TRUE );    }}/*!  Internal slot used for the second stage of animateClick().*/void QButton::animateTimeout(){    if ( !animation )	return;    animation  = FALSE;    buttonDown = FALSE;    nextState();    emit released();    emit clicked();}void QButton::nextState(){    bool t = isToggleButton() && !( isOn() && isExclusiveToggle() );    bool was = stat != Off;    if ( t ) {	if ( toggleTyp == Tristate )	    stat = ( stat + 1 ) % 3;	else	    stat = stat ? Off : On;    }    if ( autoMask() )        updateMask();    repaint( FALSE );    if ( t ) {	if ( was != (stat != Off) )	    emit toggled( stat != Off );	emit stateChanged( stat );    }}/*! \reimp */void QButton::enabledChange( bool e ){    if ( !e )	setDown( FALSE );    QWidget::enabledChange( e );}/*!  if this is a toggle button, toggles it. */void QButton::toggle(){    if ( isToggleButton() )	 setOn( !isOn() );}/*!  Sets the type of toggling behavior.  The default is \a SingleShot.  Subclasses use this, and present it with a more comfortable interface.*/void QButton::setToggleType( ToggleType type ){    toggleTyp = type;    if ( type != Tristate && stat == NoChange )	setState( On );}/*!  Returns TRUE if this button behaves exclusively inside a QButtonGroup.  In that case, this button can only be toggled off by another button  being toggled on.*/bool QButton::isExclusiveToggle() const{#ifndef QT_NO_BUTTONGROUP    return group() && ( group()->isExclusive() ||			group()->isRadioButtonExclusive() &&			inherits( "QRadioButton" ) );#else    return FALSE;#endif}#endif

⌨️ 快捷键说明

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