1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQRadioButton.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #include <qradiobutton.h>
21 #include <QMouseEvent>
22 #include <q3boxlayout.h>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
28 #include "YQApplication.h"
30 #include "YQRadioButton.h"
31 #include "YRadioButtonGroup.h"
32 #include "YQSignalBlocker.h"
38 // +----+----------------------------------+----+
39 // | |(o) RadioButtonlabel | |
40 // +----+----------------------------------+----+
41 // <----> SPACING <---->
45 YQRadioButton::YQRadioButton( YWidget * parent,
48 : Q3GroupBox( (QWidget *) (parent->widgetRep() ) )
49 , YRadioButton( parent, label )
52 setFrameStyle( NoFrame );
54 QBoxLayout * layout = new QBoxLayout( this, QBoxLayout::LeftToRight );
56 _qt_radioButton = new QRadioButton( fromUTF8( label ), this );
58 layout->addSpacing( SPACING );
59 layout->addWidget( _qt_radioButton );
60 layout->addSpacing( SPACING );
61 _qt_radioButton->setChecked( checked );
63 installEventFilter(this);
65 connect ( _qt_radioButton, SIGNAL( toggled ( bool ) ),
66 this, SLOT ( changed ( bool ) ) );
71 YQRadioButton::setUseBoldFont( bool useBold )
73 _qt_radioButton->setFont( useBold ?
74 YQUI::yqApp()->boldFont() :
75 YQUI::yqApp()->currentFont() );
77 YRadioButton::setUseBoldFont( useBold );
81 int YQRadioButton::preferredWidth()
83 return 2 * SPACING + _qt_radioButton->sizeHint().width();
87 int YQRadioButton::preferredHeight()
89 return _qt_radioButton->sizeHint().height();
93 void YQRadioButton::setSize( int newWidth, int newHeight )
95 _qt_radioButton->resize( newWidth - 2*SPACING, newHeight );
96 resize( newWidth, newHeight );
100 bool YQRadioButton::value()
102 return _qt_radioButton->isChecked();
106 void YQRadioButton::setValue( bool newValue )
108 YQSignalBlocker sigBlocker( _qt_radioButton );
110 _qt_radioButton->setChecked( newValue );
114 YRadioButtonGroup * group = buttonGroup();
117 group->uncheckOtherButtons( this );
122 void YQRadioButton::setLabel( const string & label )
124 _qt_radioButton->setText( fromUTF8( label ) );
125 YRadioButton::setLabel( label );
129 void YQRadioButton::setEnabled( bool enabled )
131 _qt_radioButton->setEnabled( enabled );
132 YWidget::setEnabled( enabled );
136 QRadioButton * YQRadioButton::getQtButton()
138 return _qt_radioButton;
142 bool YQRadioButton::setKeyboardFocus()
144 _qt_radioButton->setFocus();
152 void YQRadioButton::changed( bool newState )
154 if ( notify() && newState )
155 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
159 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
161 if ( event && event->type() == QEvent::MouseButtonRelease )
163 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
165 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
167 y2milestone( "Right click on button detected" );
168 YQUI::ui()->maybeLeftHandedUser();
172 return QObject::eventFilter( obj, event );
176 #include "YQRadioButton.moc"