1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQRadioButtonGroup.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #include <qradiobutton.h>
21 #include <q3buttongroup.h>
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
25 #include "YQRadioButtonGroup.h"
26 #include "YQRadioButton.h"
29 YQRadioButtonGroup::YQRadioButtonGroup( YWidget * parent )
30 : QWidget( (QWidget *) parent->widgetRep() )
31 , YRadioButtonGroup( parent )
38 YQRadioButtonGroup::~YQRadioButtonGroup()
45 YQRadioButtonGroup::addRadioButton( YRadioButton * button )
47 YRadioButtonGroup::addRadioButton( button );
49 if ( button->value() ) // if this new button is active
51 uncheckOtherButtons( button ); // make it the only active
54 QRadioButton * radio_button = ( ( YQRadioButton * ) button )->getQtButton();
56 connect ( radio_button, SIGNAL ( toggled ( bool ) ),
57 this, SLOT ( radioButtonClicked( bool ) ) );
62 YQRadioButtonGroup::setEnabled( bool enabled )
64 QWidget::setEnabled( enabled );
65 YWidget::setEnabled( enabled );
70 YQRadioButtonGroup::setSize( int newWidth, int newHeight )
72 resize( newWidth, newHeight );
73 YRadioButtonGroup::setSize( newWidth, newHeight );
78 YQRadioButtonGroup::radioButtonClicked( bool newState )
80 // Prevent infinite recursion: YQRadioButton::setValue() might cause Qt
81 // signals that would cause recursion to this place.
88 QRadioButton * senderButton = (QRadioButton *) sender();
90 // Implement radio box behaviour: Uncheck all other radio buttons
92 for ( YRadioButtonListConstIterator it = radioButtonsBegin();
93 it != radioButtonsEnd();
96 YQRadioButton * radioButton = dynamic_cast<YQRadioButton *> (*it);
100 if ( radioButton->getQtButton() == senderButton )
102 // If this button has been clicked, it is to be the RadioBox's
103 // active button - regardless of newState. This is to avoid
104 // RadioBoxes where no single button is active; otherwise the
105 // second click would deactivate the only active button.
107 radioButton->setValue( true );
111 radioButton->setValue( false );
120 #include "YQRadioButtonGroup.moc"