1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQRadioButton.cc
15 Author: Stefan Hundhammer <sh@suse.de>
21 #include <qradiobutton.h>
22 #include <QMouseEvent>
23 #include <q3boxlayout.h>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
29 #include "YQApplication.h"
31 #include "YQRadioButton.h"
32 #include "YRadioButtonGroup.h"
33 #include "YQSignalBlocker.h"
39 // +----+----------------------------------+----+
40 // | |(o) RadioButtonlabel | |
41 // +----+----------------------------------+----+
42 // <----> SPACING <---->
46 YQRadioButton::YQRadioButton( YWidget * parent,
49 : Q3GroupBox( (QWidget *) (parent->widgetRep() ) )
50 , YRadioButton( parent, label )
53 setFrameStyle( NoFrame );
55 QBoxLayout * layout = new QBoxLayout( this, QBoxLayout::LeftToRight );
57 _qt_radioButton = new QRadioButton( fromUTF8( label ), this );
59 layout->addSpacing( SPACING );
60 layout->addWidget( _qt_radioButton );
61 layout->addSpacing( SPACING );
62 _qt_radioButton->setChecked( checked );
64 installEventFilter(this);
66 connect ( _qt_radioButton, SIGNAL( toggled ( bool ) ),
67 this, SLOT ( changed ( bool ) ) );
72 YQRadioButton::setUseBoldFont( bool useBold )
74 _qt_radioButton->setFont( useBold ?
75 YQUI::yqApp()->boldFont() :
76 YQUI::yqApp()->currentFont() );
78 YRadioButton::setUseBoldFont( useBold );
82 int YQRadioButton::preferredWidth()
84 return 2 * SPACING + _qt_radioButton->sizeHint().width();
88 int YQRadioButton::preferredHeight()
90 return _qt_radioButton->sizeHint().height();
94 void YQRadioButton::setSize( int newWidth, int newHeight )
96 _qt_radioButton->resize( newWidth - 2*SPACING, newHeight );
97 resize( newWidth, newHeight );
101 bool YQRadioButton::value()
103 return _qt_radioButton->isChecked();
107 void YQRadioButton::setValue( bool newValue )
109 YQSignalBlocker sigBlocker( _qt_radioButton );
111 _qt_radioButton->setChecked( newValue );
115 YRadioButtonGroup * group = buttonGroup();
118 group->uncheckOtherButtons( this );
123 void YQRadioButton::setLabel( const string & label )
125 _qt_radioButton->setText( fromUTF8( label ) );
126 YRadioButton::setLabel( label );
130 void YQRadioButton::setEnabled( bool enabled )
132 _qt_radioButton->setEnabled( enabled );
133 YWidget::setEnabled( enabled );
137 QRadioButton * YQRadioButton::getQtButton()
139 return _qt_radioButton;
143 bool YQRadioButton::setKeyboardFocus()
145 _qt_radioButton->setFocus();
153 void YQRadioButton::changed( bool newState )
155 if ( notify() && newState )
156 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
160 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
162 if ( event && event->type() == QEvent::MouseButtonRelease )
164 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
166 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
168 y2milestone( "Right click on button detected" );
169 YQUI::ui()->maybeLeftHandedUser();
173 return QObject::eventFilter( obj, event );
177 #include "YQRadioButton.moc"