]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQCheckBoxFrame.cc
give checkboxframe examples some love. The 3rd example
[duncan/yast2-qt4.git] / src / YQCheckBoxFrame.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQCheckBoxFrame.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
22 #include <qcheckbox.h>
23 #include <QDebug>
24 #include <QVBoxLayout>
25 #include <qevent.h>
26 #include "YQUI.h"
27 #include "YEvent.h"
28 #include "utf8.h"
29
30 using std::max;
31
32 #include "YQCheckBoxFrame.h"
33
34 #define TOP_MARGIN 6
35
36
37 YQCheckBoxFrame::YQCheckBoxFrame( YWidget *             parent,
38                                   const string &        label,
39                                   bool                  checked )
40     : QGroupBox( (QWidget *) parent->widgetRep() )
41     , YCheckBoxFrame( parent, label, checked)
42 {
43     setWidgetRep ( this );
44     QGroupBox::setTitle( fromUTF8( label ) );
45     QGroupBox::setCheckable( true );
46
47     setValue( checked );
48 }
49
50
51 void YQCheckBoxFrame::setLabel( const string & newLabel )
52 {
53     YCheckBoxFrame::setLabel( newLabel );
54     QGroupBox::setTitle( fromUTF8( label() ) );
55 }
56
57
58 bool YQCheckBoxFrame::value()
59 {
60     return _checkBox ? _checkBox->isChecked() : QGroupBox::isChecked();
61 }
62
63
64 void YQCheckBoxFrame::setValue( bool newValue )
65 {
66     if ( _checkBox )
67         _checkBox->setChecked( newValue );
68     else
69         setChecked( newValue );
70 }
71
72 void YQCheckBoxFrame::setEnabled( bool enabled )
73 {
74     if ( enabled )
75     {
76         QGroupBox::setEnabled( true );
77         handleChildrenEnablement( value() );
78     }
79     else
80     {
81         QGroupBox::setEnabled( true );
82         YWidget::setChildrenEnabled( false );
83     }
84
85     YWidget::setEnabled( enabled );
86 }
87
88
89 void YQCheckBoxFrame::stateChanged( bool newState )
90 {
91     y2debug( "new state: %d", newState );
92     handleChildrenEnablement( newState );
93
94     if ( notify() )
95         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
96 }
97
98
99 void YQCheckBoxFrame::childEvent( QChildEvent * )
100 {
101     // Reimplemented to prevent the parent class disabling child widgets
102     // according to its default policy.
103
104     // y2debug( "ChildEvent" );
105 }
106
107
108 void
109 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
110 {
111     resize ( newWidth, newHeight );
112
113     if ( hasChildren() )
114     {
115         int left, top, right, bottom;
116         getContentsMargins( &left, &top, &right, &bottom );
117         int newChildWidth  = newWidth - left - right;
118         int newChildHeight = newHeight - bottom - top;
119
120         firstChild()->setSize( newChildWidth, newChildHeight );
121
122         QWidget * qChild = (QWidget *) firstChild()->widgetRep();
123         qChild->move( left, top );
124     }
125 }
126
127
128 int YQCheckBoxFrame::preferredWidth()
129 {
130     int preferredWidth;
131     int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
132
133     preferredWidth = max( childPreferredWidth,
134                           (10 + fontMetrics().width( title() ) ) );
135     int left, top, right, bottom;
136     getContentsMargins( &left, &top, &right, &bottom );
137
138     preferredWidth += left + right;
139
140     return preferredWidth;
141 }
142
143
144 int YQCheckBoxFrame::preferredHeight()
145 {
146     int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
147     int left, top, right, bottom;
148     getContentsMargins( &left, &top, &right, &bottom );
149
150     preferredHeight += top + left;
151
152     return preferredHeight;
153 }
154
155
156 bool YQCheckBoxFrame::setKeyboardFocus()
157 {
158     setFocus();
159
160     return true;
161 }
162
163
164
165
166 #include "YQCheckBoxFrame.moc"