]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQRadioButton.cc
drawContent is no more
[duncan/yast2-qt4.git] / src / YQRadioButton.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQRadioButton.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19 #include <qradiobutton.h>
20 #include <QMouseEvent>
21 #include <QBoxLayout>
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
24
25 #include "utf8.h"
26 #include "YQUI.h"
27 #include "YQApplication.h"
28 #include "YEvent.h"
29 #include "YQRadioButton.h"
30 #include "YRadioButtonGroup.h"
31 #include "YQSignalBlocker.h"
32
33 using std::string;
34
35 #define SPACING 8
36
37 // +----+----------------------------------+----+
38 // |    |(o) RadioButtonlabel              |    |
39 // +----+----------------------------------+----+
40 // <----> SPACING                          <---->
41
42
43
44 YQRadioButton::YQRadioButton( YWidget *         parent,
45                               const string &    label,
46                               bool              checked )
47     : QRadioButton( fromUTF8( label ), ( QWidget *) (parent->widgetRep() ) )
48     , YRadioButton( parent, label )
49 {
50     setWidgetRep( this );
51
52     setChecked( checked );
53
54     installEventFilter(this);
55
56     connect ( this,     SIGNAL( toggled ( bool ) ),
57               this,     SLOT  ( changed ( bool ) ) );
58 }
59
60
61 void
62 YQRadioButton::setUseBoldFont( bool useBold )
63 {
64     setFont( useBold ?
65              YQUI::yqApp()->boldFont() :
66              YQUI::yqApp()->currentFont() );
67
68     YRadioButton::setUseBoldFont( useBold );
69 }
70
71
72 int YQRadioButton::preferredWidth()
73 {
74     return sizeHint().width();
75 }
76
77
78 int YQRadioButton::preferredHeight()
79 {
80     return sizeHint().height();
81 }
82
83
84 void YQRadioButton::setSize( int newWidth, int newHeight )
85 {
86     resize( newWidth, newHeight );
87 }
88
89
90 bool YQRadioButton::value()
91 {
92     return isChecked();
93 }
94
95
96 void YQRadioButton::setValue( bool newValue )
97 {
98     YQSignalBlocker sigBlocker( this );
99
100     setChecked( newValue );
101
102     if ( newValue )
103     {
104         YRadioButtonGroup * group = buttonGroup();
105
106         if ( group )
107             group->uncheckOtherButtons( this );
108     }
109 }
110
111
112 void YQRadioButton::setLabel( const string & label )
113 {
114     setText( fromUTF8( label ) );
115     YRadioButton::setLabel( label );
116 }
117
118
119 void YQRadioButton::setEnabled( bool enabled )
120 {
121     setEnabled( enabled );
122     YWidget::setEnabled( enabled );
123 }
124
125
126 bool YQRadioButton::setKeyboardFocus()
127 {
128     setFocus();
129
130     return true;
131 }
132
133
134 // slots
135
136 void YQRadioButton::changed( bool newState )
137 {
138     if ( notify() && newState )
139         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
140 }
141
142
143 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
144 {
145     if ( event && event->type() == QEvent::MouseButtonRelease )
146     {
147         QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
148
149         if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
150         {
151              y2milestone( "Right click on button detected" );
152              YQUI::ui()->maybeLeftHandedUser();
153         }
154     }
155
156     return QObject::eventFilter( obj, event );
157 }
158
159
160 #include "YQRadioButton.moc"