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