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 : QRadioButton( fromUTF8( label ), ( QWidget *) (parent->widgetRep() ) )
48 , YRadioButton( parent, label )
52 setChecked( checked );
54 installEventFilter(this);
56 connect ( this, SIGNAL( toggled ( bool ) ),
57 this, SLOT ( changed ( bool ) ) );
62 YQRadioButton::setUseBoldFont( bool useBold )
65 YQUI::yqApp()->boldFont() :
66 YQUI::yqApp()->currentFont() );
68 YRadioButton::setUseBoldFont( useBold );
72 int YQRadioButton::preferredWidth()
74 return sizeHint().width();
78 int YQRadioButton::preferredHeight()
80 return sizeHint().height();
84 void YQRadioButton::setSize( int newWidth, int newHeight )
86 resize( newWidth, newHeight );
90 bool YQRadioButton::value()
96 void YQRadioButton::setValue( bool newValue )
98 YQSignalBlocker sigBlocker( this );
100 setChecked( newValue );
104 YRadioButtonGroup * group = buttonGroup();
107 group->uncheckOtherButtons( this );
112 void YQRadioButton::setLabel( const string & label )
114 setText( fromUTF8( label ) );
115 YRadioButton::setLabel( label );
119 void YQRadioButton::setEnabled( bool enabled )
121 setEnabled( enabled );
122 YWidget::setEnabled( enabled );
126 bool YQRadioButton::setKeyboardFocus()
136 void YQRadioButton::changed( bool newState )
138 if ( notify() && newState )
139 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
143 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
145 if ( event && event->type() == QEvent::MouseButtonRelease )
147 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
149 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
151 y2milestone( "Right click on button detected" );
152 YQUI::ui()->maybeLeftHandedUser();
156 return QObject::eventFilter( obj, event );
160 #include "YQRadioButton.moc"