/*! \reimp */ bool QButtonGroup::event( QEvent * e ) { if ( e->type() == QEvent::ChildInserted ) { QChildEvent * ce = (QChildEvent *) e; if ( radio_excl && ::qt_cast<QRadioButton*>(ce->child()) ) { QButton * button = (QButton *) ce->child(); if ( button->isToggleButton() && !button->isOn() && selected() && (selected()->focusPolicy() & TabFocus) != 0 ) button->setFocusPolicy( (FocusPolicy)(button->focusPolicy() & ~TabFocus) ); } } return QGroupBox::event( e ); }
void QButtonGroup::buttonToggled( bool on ) { // introduce a QButtonListIt if calling anything if ( !on || !excl_grp && !radio_excl ) return; QButton *bt = ::qt_cast<QButton*>(sender()); // object that sent the signal #if defined(QT_CHECK_NULL) Q_ASSERT( bt ); Q_ASSERT( bt->isToggleButton() ); #endif if ( !excl_grp && !::qt_cast<QRadioButton*>(bt) ) return; QButtonItem * i = buttons->first(); bool hasTabFocus = FALSE; while( i != 0 && hasTabFocus == FALSE ) { if ( ( excl_grp || ::qt_cast<QRadioButton*>(i->button) ) && (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 || ::qt_cast<QRadioButton*>(i->button) ) ) i->button->setOn( FALSE ); if ( ( excl_grp || ::qt_cast<QRadioButton*>(i->button) ) && i->button->isToggleButton() && hasTabFocus ) i->button->setFocusPolicy( (FocusPolicy)(i->button->focusPolicy() & ~TabFocus) ); i = buttons->next(); } if ( hasTabFocus ) bt->setFocusPolicy( (FocusPolicy)(bt->focusPolicy() | TabFocus) ); }
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()); bool betterScore = score < bestScore || !candidate; switch( key ) { case Key_Up: if ( p.y() < goal.y() && betterScore ) { if ( QABS( p.x() - goal.x() ) < QABS( p.y() - goal.y() ) ) { candidate = i->button; bestScore = score; } else if ( i->button->x() == f->x() ) { candidate = i->button; bestScore = score/2; } } break; case Key_Down: if ( p.y() > goal.y() && betterScore ) { if ( QABS( p.x() - goal.x() ) < QABS( p.y() - goal.y() ) ) { candidate = i->button; bestScore = score; } else if ( i->button->x() == f->x() ) { candidate = i->button; bestScore = score/2; } } break; case Key_Left: if ( p.x() < goal.x() && betterScore ) { if ( QABS( p.y() - goal.y() ) < QABS( p.x() - goal.x() ) ) { candidate = i->button; bestScore = score; } else if ( i->button->y() == f->y() ) { candidate = i->button; bestScore = score/2; } } break; case Key_Right: if ( p.x() > goal.x() && betterScore ) { if ( QABS( p.y() - goal.y() ) < QABS( p.x() - goal.x() ) ) { candidate = i->button; bestScore = score; } else if ( i->button->y() == f->y() ) { candidate = i->button; bestScore = score/2; } } break; } } i = buttons->next(); } QButton *buttoncand = ::qt_cast<QButton*>(candidate); if ( buttoncand && ::qt_cast<QButton*>(f) && ((QButton*)f)->isOn() && buttoncand->isToggleButton() && ( isExclusive() || ( ::qt_cast<QRadioButton*>(f) && ::qt_cast<QRadioButton*>(candidate)))) { if ( f->focusPolicy() & TabFocus ) { f->setFocusPolicy( (FocusPolicy)(f->focusPolicy() & ~TabFocus) ); candidate->setFocusPolicy( (FocusPolicy)(candidate->focusPolicy()| TabFocus) ); } buttoncand->setOn( TRUE ); buttoncand->animateClick(); buttoncand->animateTimeout(); // ### crude l&f hack } if ( candidate ) { if (key == Key_Up || key == Key_Left) QFocusEvent::setReason(QFocusEvent::Backtab); else QFocusEvent::setReason(QFocusEvent::Tab); candidate->setFocus(); QFocusEvent::resetReason(); } }