1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQRadioButtonGroup.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #include <QRadioButton>
21 #define y2log_component "qt-ui"
22 #include <ycp/y2log.h>
24 #include "YQRadioButtonGroup.h"
25 #include "YQRadioButton.h"
28 YQRadioButtonGroup::YQRadioButtonGroup( YWidget * parent )
29 : QWidget( (QWidget *) parent->widgetRep() )
30 , YRadioButtonGroup( parent )
37 YQRadioButtonGroup::~YQRadioButtonGroup()
44 YQRadioButtonGroup::addRadioButton( YRadioButton * button )
46 YRadioButtonGroup::addRadioButton( button );
48 if ( button->value() ) // if this new button is active
50 uncheckOtherButtons( button ); // make it the only active
53 QRadioButton * radio_button = dynamic_cast<YQRadioButton *>( button );
55 connect ( radio_button, SIGNAL ( toggled ( bool ) ),
56 this, SLOT ( radioButtonClicked( bool ) ) );
61 YQRadioButtonGroup::setEnabled( bool enabled )
63 QWidget::setEnabled( enabled );
64 YWidget::setEnabled( enabled );
69 YQRadioButtonGroup::setSize( int newWidth, int newHeight )
71 resize( newWidth, newHeight );
72 YRadioButtonGroup::setSize( newWidth, newHeight );
77 YQRadioButtonGroup::radioButtonClicked( bool newState )
79 // Prevent infinite recursion: YQRadioButton::setValue() might cause Qt
80 // signals that would cause recursion to this place.
87 QRadioButton * senderButton = (QRadioButton *) sender();
89 // Implement radio box behaviour: Uncheck all other radio buttons
91 for ( YRadioButtonListConstIterator it = radioButtonsBegin();
92 it != radioButtonsEnd();
95 YQRadioButton * radioButton = dynamic_cast<YQRadioButton *> (*it);
99 if ( radioButton == senderButton )
101 // If this button has been clicked, it is to be the RadioBox's
102 // active button - regardless of newState. This is to avoid
103 // RadioBoxes where no single button is active; otherwise the
104 // second click would deactivate the only active button.
106 radioButton->setValue( true );
110 radioButton->setValue( false );
119 #include "YQRadioButtonGroup.moc"