]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQRadioButton.cc
compile some 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 #define QT3_SUPPORT
20
21 #include <qradiobutton.h>
22 #include <QMouseEvent>
23 #include <q3boxlayout.h>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
26
27 #include "utf8.h"
28 #include "YQUI.h"
29 #include "YQApplication.h"
30 #include "YEvent.h"
31 #include "YQRadioButton.h"
32 #include "YRadioButtonGroup.h"
33 #include "YQSignalBlocker.h"
34
35 using std::string;
36
37 #define SPACING 8
38
39 // +----+----------------------------------+----+
40 // |    |(o) RadioButtonlabel              |    |
41 // +----+----------------------------------+----+
42 // <----> SPACING                          <---->
43
44
45
46 YQRadioButton::YQRadioButton( YWidget *         parent,
47                               const string &    label,
48                               bool              checked )
49     : Q3GroupBox( (QWidget *) (parent->widgetRep() ) )
50     , YRadioButton( parent, label )
51 {
52     setWidgetRep( this );
53     setFrameStyle( NoFrame );
54
55     QBoxLayout * layout = new QBoxLayout( this, QBoxLayout::LeftToRight );
56
57     _qt_radioButton = new QRadioButton( fromUTF8( label ), this );
58
59     layout->addSpacing( SPACING );
60     layout->addWidget( _qt_radioButton );
61     layout->addSpacing( SPACING );
62     _qt_radioButton->setChecked( checked );
63
64     installEventFilter(this);
65
66     connect ( _qt_radioButton,  SIGNAL( toggled ( bool ) ),
67               this,             SLOT  ( changed ( bool ) ) );
68 }
69
70
71 void
72 YQRadioButton::setUseBoldFont( bool useBold )
73 {
74     _qt_radioButton->setFont( useBold ?
75                               YQUI::yqApp()->boldFont() :
76                               YQUI::yqApp()->currentFont() );
77
78     YRadioButton::setUseBoldFont( useBold );
79 }
80
81
82 int YQRadioButton::preferredWidth()
83 {
84     return 2 * SPACING + _qt_radioButton->sizeHint().width();
85 }
86
87
88 int YQRadioButton::preferredHeight()
89 {
90     return _qt_radioButton->sizeHint().height();
91 }
92
93
94 void YQRadioButton::setSize( int newWidth, int newHeight )
95 {
96     _qt_radioButton->resize( newWidth - 2*SPACING, newHeight );
97     resize( newWidth, newHeight );
98 }
99
100
101 bool YQRadioButton::value()
102 {
103     return _qt_radioButton->isChecked();
104 }
105
106
107 void YQRadioButton::setValue( bool newValue )
108 {
109     YQSignalBlocker sigBlocker( _qt_radioButton );
110
111     _qt_radioButton->setChecked( newValue );
112
113     if ( newValue )
114     {
115         YRadioButtonGroup * group = buttonGroup();
116
117         if ( group )
118             group->uncheckOtherButtons( this );
119     }
120 }
121
122
123 void YQRadioButton::setLabel( const string & label )
124 {
125     _qt_radioButton->setText( fromUTF8( label ) );
126     YRadioButton::setLabel( label );
127 }
128
129
130 void YQRadioButton::setEnabled( bool enabled )
131 {
132     _qt_radioButton->setEnabled( enabled );
133     YWidget::setEnabled( enabled );
134 }
135
136
137 QRadioButton * YQRadioButton::getQtButton()
138 {
139     return _qt_radioButton;
140 }
141
142
143 bool YQRadioButton::setKeyboardFocus()
144 {
145     _qt_radioButton->setFocus();
146
147     return true;
148 }
149
150
151 // slots
152
153 void YQRadioButton::changed( bool newState )
154 {
155     if ( notify() && newState )
156         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
157 }
158
159
160 bool YQRadioButton::eventFilter( QObject * obj, QEvent * event )
161 {
162     if ( event && event->type() == QEvent::MouseButtonRelease )
163     {
164         QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
165
166         if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
167         {
168              y2milestone( "Right click on button detected" );
169              YQUI::ui()->maybeLeftHandedUser();
170         }
171     }
172
173     return QObject::eventFilter( obj, event );
174 }
175
176
177 #include "YQRadioButton.moc"