1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQRadioButton.cc
15 Author: Stefan Hundhammer <sh@suse.de>
19 #include <qradiobutton.h>
20 #include <QMouseEvent>
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
27 #include "YQApplication.h"
29 #include "YQRadioButton.h"
30 #include "YRadioButtonGroup.h"
31 #include "YQSignalBlocker.h"
37 // +----+----------------------------------+----+
38 // | |(o) RadioButtonlabel | |
39 // +----+----------------------------------+----+
40 // <----> SPACING <---->
44 YQRadioButton::YQRadioButton( YWidget * parent,
47 : Q3GroupBox( (QWidget *) (parent->widgetRep() ) )
48 , YRadioButton( parent, label )
51 setFrameStyle( NoFrame );
53 QBoxLayout * layout = new QBoxLayout( QBoxLayout::LeftToRight, this );
55 _qt_radioButton = new QRadioButton( fromUTF8( label ), this );
57 layout->addSpacing( SPACING );
58 layout->addWidget( _qt_radioButton );
59 layout->addSpacing( SPACING );
60 _qt_radioButton->setChecked( checked );
62 installEventFilter(this);
64 connect ( _qt_radioButton, SIGNAL( toggled ( bool ) ),
65 this, SLOT ( changed ( bool ) ) );
70 YQRadioButton::setUseBoldFont( bool useBold )
72 _qt_radioButton->setFont( useBold ?
73 YQUI::yqApp()->boldFont() :
74 YQUI::yqApp()->currentFont() );
76 YRadioButton::setUseBoldFont( useBold );
80 int YQRadioButton::preferredWidth()
82 return 2 * SPACING + _qt_radioButton->sizeHint().width();
86 int YQRadioButton::preferredHeight()
88 return _qt_radioButton->sizeHint().height();
92 void YQRadioButton::setSize( int newWidth, int newHeight )
94 _qt_radioButton->resize( newWidth - 2*SPACING, newHeight );
95 resize( newWidth, newHeight );
99 bool YQRadioButton::value()
101 return _qt_radioButton->isChecked();
105 void YQRadioButton::setValue( bool newValue )
107 YQSignalBlocker sigBlocker( _qt_radioButton );
109 _qt_radioButton->setChecked( newValue );
113 YRadioButtonGroup * group = buttonGroup();
116 group->uncheckOtherButtons( this );
121 void YQRadioButton::setLabel( const string & label )
123 _qt_radioButton->setText( fromUTF8( label ) );
124 YRadioButton::setLabel( label );
128 void YQRadioButton::setEnabled( bool enabled )
130 _qt_radioButton->setEnabled( enabled );
131 YWidget::setEnabled( enabled );
135 QRadioButton * YQRadioButton::getQtButton()
137 return _qt_radioButton;
141 bool YQRadioButton::setKeyboardFocus()
143 _qt_radioButton->setFocus();
151 void YQRadioButton::changed( bool newState )
153 if ( notify() && newState )
154 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
158 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
160 if ( event && event->type() == QEvent::MouseButtonRelease )
162 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
164 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
166 y2milestone( "Right click on button detected" );
167 YQUI::ui()->maybeLeftHandedUser();
171 return QObject::eventFilter( obj, event );
175 #include "YQRadioButton.moc"