?? qbuttongroup.cpp
字號:
This signal is emitted when a button in the group is \link QButton::pressed() pressed\endlink. The \e id argument is the button's identifier.*//*! \fn void QButtonGroup::released( int id ) This signal is emitted when a button in the group is \link QButton::released() released\endlink. The \e id argument is the button's identifier.*//*! \fn void QButtonGroup::clicked( int id ) This signal is emitted when a button in the group is \link QButton::clicked() clicked\endlink. The \e id argument is the button's identifier.*//*! \internal This slot is activated when one of the buttons in the group emits the QButton::pressed() signal.*/void QButtonGroup::buttonPressed(){ // introduce a QButtonListIt if calling anything int id = -1; QButton *bt = (QButton *)sender(); // object that sent the signal for ( register QButtonItem *i=buttons->first(); i; i=buttons->next() ) if ( bt == i->button ) { // button was clicked id = i->id; break; } if ( id != -1 ) emit pressed( id );}/*! \internal This slot is activated when one of the buttons in the group emits the QButton::released() signal.*/void QButtonGroup::buttonReleased(){ // introduce a QButtonListIt if calling anything int id = -1; QButton *bt = (QButton *)sender(); // object that sent the signal for ( register QButtonItem *i=buttons->first(); i; i=buttons->next() ) if ( bt == i->button ) { // button was clicked id = i->id; break; } if ( id != -1 ) emit released( id );}/*! \internal This slot is activated when one of the buttons in the group emits the QButton::clicked() signal.*/void QButtonGroup::buttonClicked(){ // introduce a QButtonListIt if calling anything int id = -1; QButton *bt = (QButton *)sender(); // object that sent the signal#if defined(CHECK_NULL) ASSERT( bt->inherits("QButton") );#endif for ( register QButtonItem *i=buttons->first(); i; i=buttons->next() ) { if ( bt == i->button ) { // button was clicked id = i->id; break; } } if ( id != -1 ) emit clicked( id );}/*! \internal This slot is activated when one of the buttons in the group emits the QButton::toggled() signal.*/void QButtonGroup::buttonToggled( bool on ){ // introduce a QButtonListIt if calling anything if ( !on || !excl_grp && !radio_excl ) return; QButton *bt = (QButton *)sender(); // object that sent the signal#if defined(CHECK_NULL) ASSERT( bt->inherits("QButton") ); ASSERT( bt->isToggleButton() );#endif if ( !excl_grp && !bt->inherits("QRadioButton") ) return; QButtonItem * i = buttons->first(); bool hasTabFocus = FALSE; while( i != 0 && hasTabFocus == FALSE ) { if ( ( excl_grp || i->button->inherits("QRadioButton") ) && (i->button->focusPolicy() & TabFocus) ) hasTabFocus = TRUE; i = buttons->next(); } i = buttons->first(); while( i ) { if ( bt != i->button && i->button->isToggleButton() && i->button->isOn() && ( excl_grp || i->button->inherits( "QRadioButton" ) ) ) i->button->setOn( FALSE );#ifdef QT_KEYPAD_MODE if( !qt_modalEditingEnabled )#endif if ( ( excl_grp || i->button->inherits( "QRadioButton" ) ) && i->button->isToggleButton() && hasTabFocus ) i->button->setFocusPolicy( (FocusPolicy)(i->button->focusPolicy() & ~TabFocus) ); i = buttons->next(); }#ifdef QT_KEYPAD_MODE if( !qt_modalEditingEnabled )#endif if ( hasTabFocus ) bt->setFocusPolicy( (FocusPolicy)(bt->focusPolicy() | TabFocus) );}/*! Sets the button with id \a id to be on, and if this is an exclusive group, all other button in the group to be off.*/void QButtonGroup::setButton( int id ){ QButton * b = find( id ); if ( b ) b->setOn( TRUE );}/*! \fn bool QButtonGroup::isRadioButtonExclusive () const Returns whether this button group will treat radio buttons as mutually exclusive. The default is TRUE. \sa setRadioButtonExclusive()*//*! If \a on is TRUE, this button group will treat radio buttons as mutually exclusive, and other buttons according to isExclusive(). */void QButtonGroup::setRadioButtonExclusive( bool on){ radio_excl = on;}/*! Moves the keyboard focus according to \a key, and if appropriate checks the new focus item. This function does nothing unless the keyboard focus points to one of the button group members and \a key is one of \c Key_Up, \c Key_Down, \c Key_Left and \c Key_Right.*/void QButtonGroup::moveFocus( int key ){ QWidget * f = qApp->focusWidget(); QButtonItem * i; i = buttons->first(); while( i && i->button != f ) i = buttons->next(); if ( !i || !i->button ) return; QWidget * candidate = 0; int bestScore = -1; QPoint goal( f->mapToGlobal( f->geometry().center() ) ); i = buttons->first(); while( i && i->button ) { if ( i->button != f && i->button->isEnabled() ) { QPoint p(i->button->mapToGlobal(i->button->geometry().center())); int score = (p.y() - goal.y())*(p.y() - goal.y()) + (p.x() - goal.x())*(p.x() - goal.x()); switch( key ) { case Key_Up: if ( p.y() < goal.y() && QABS( p.x() - goal.x() ) < QABS( p.y() - goal.y() ) && ( score < bestScore || !candidate ) ) { candidate = i->button; bestScore = score; } break; case Key_Down: if ( p.y() > goal.y() && QABS( p.x() - goal.x() ) < QABS( p.y() - goal.y() ) && ( score < bestScore || !candidate ) ) { candidate = i->button; bestScore = score; } break; case Key_Left: if ( p.x() < goal.x() && QABS( p.y() - goal.y() ) < QABS( p.x() - goal.x() ) && ( score < bestScore || !candidate ) ) { candidate = i->button; bestScore = score; } break; case Key_Right: if ( p.x() > goal.x() && QABS( p.y() - goal.y() ) < QABS( p.x() - goal.x() ) && ( score < bestScore || !candidate ) ) { candidate = i->button; bestScore = score; } break; } } i = buttons->next(); }#ifdef QT_KEYPAD_MODE if( !qt_modalEditingEnabled ) #endif { if ( candidate && f && f->inherits( "QButton" ) && ((QButton*)f)->isOn() && candidate->inherits( "QButton" ) && ((QButton*)candidate)->isToggleButton() && ( isExclusive() || ( f->inherits( "QRadioButton" ) && candidate->inherits( "QRadioButton" )))) { if ( f->focusPolicy() & TabFocus ) { f->setFocusPolicy( (FocusPolicy)(f->focusPolicy() & ~TabFocus) ); candidate->setFocusPolicy( (FocusPolicy)(candidate->focusPolicy()| TabFocus) ); } ((QButton*)candidate)->setOn( TRUE ); ((QButton*)candidate)->animateClick(); ((QButton*)candidate)->animateTimeout(); // ### crude l&f hack } if ( candidate ) candidate->setFocus(); }#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) { if ( candidate ) { candidate->setFocus(); } else { switch( key ) { case Key_Left: case Key_Up: focusNextPrevChild( FALSE ); break; case Key_Right: case Key_Down: focusNextPrevChild( TRUE ); break; default: break; } } }#endif}/*! Returns a pointer to the selected radio button in this group, if one exists, or 0 if there is no selected radio button in this group. <b>Warning: </b>In future versions of Qt, the selected toggle button will be returned.*/QButton * QButtonGroup::selected(){ if ( !buttons ) return 0; QButtonListIt it( *buttons ); QButtonItem *i; while( (i=it.current()) != 0 ) { ++it; if ( i->button && i->button->inherits("QRadioButton") && i->button->isToggleButton() && i->button->isOn() ) return i->button; } return 0;}/*! Returns the id of \a button, or -1 if \a button is not a member of this group.*/int QButtonGroup::id( QButton * button ) const{ QButtonItem *i = buttons->first(); while ( i && i->button != button ) i = buttons->next(); return i ? i->id : -1;}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -