]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQPartitionSplitter.cc
YQMultiSelectionBoxItem compiles
[duncan/yast2-qt4.git] / src / YQPartitionSplitter.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPartitionSplitter.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19 #define QT3_SUPPORT
20
21 #define y2log_component "qt-ui"
22 #include <ycp/y2log.h>
23
24 #include "utf8.h"
25 #include "YQUI.h"
26 #include "YEvent.h"
27 #include "YQWidgetFactory.h"
28 #include "YQOptionalWidgetFactory.h"
29 #include "YQPartitionSplitter.h"
30 #include "YQLayoutBox.h"
31 #include "YQBarGraph.h"
32 #include "YQIntField.h"
33 #include "YQSlider.h"
34 #include "YQSignalBlocker.h"
35
36
37 YQPartitionSplitter::YQPartitionSplitter( YWidget *             parent,
38                                           int                   usedSize,
39                                           int                   totalFreeSize,
40                                           int                   newPartSize,
41                                           int                   minNewSize,
42                                           int                   minFreeSize,
43                                           const string &        usedLabel,
44                                           const string &        freeLabel,
45                                           const string &        newPartLabel,
46                                           const string &        freeFieldLabel,
47                                           const string &        newPartFieldLabel )
48     : QWidget( (QWidget *) parent->widgetRep() )
49     , YPartitionSplitter( parent,
50                           usedSize,
51                           totalFreeSize,
52                           newPartSize,
53                           minNewSize,
54                           minFreeSize,
55                           usedLabel,
56                           freeLabel,
57                           newPartLabel,
58                           freeFieldLabel,
59                           newPartFieldLabel )
60       , _vbox( 0 )
61       , _barGraph( 0 )
62       , _hbox( 0 )
63       , _freeSizeSlider( 0 )
64       , _newPartField( 0 )
65 {
66     setWidgetRep( this );
67
68     // Replace children manager so it will accept one single direct child (the outer vbox)
69     setChildrenManager( new YSingleWidgetChildManager( this ) );
70
71     //
72     // Create internal widgets
73     //
74     
75     _vbox       = YUI::widgetFactory()->createVBox( this );
76     _barGraph   = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
77     YUI_CHECK_PTR( _barGraph );
78
79     int freeSize = totalFreeSize - newPartSize;
80     
81     {
82         YBarGraphMultiUpdate multiUpdate( _barGraph );
83
84         _barGraph->addSegment( YBarGraphSegment( usedSize,    usedLabel ) );
85         _barGraph->addSegment( YBarGraphSegment( freeSize,    freeLabel ) );
86         _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
87     }
88
89     _hbox          = YUI::widgetFactory()->createHBox( _vbox );
90
91     _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel,
92                                     minFreeSize, maxFreeSize(), freeSize,
93                                     true ); // reverseLayout (put QSpinBox left of QSlider)
94     YUI_CHECK_PTR( _freeSizeSlider );
95     _freeSizeSlider->setStretchable( YD_HORIZ, true );
96
97     _newPartField = new YQIntField( _hbox, newPartFieldLabel,
98                                     minNewSize, maxNewPartSize(), newPartSize );
99     YUI_CHECK_PTR( _newPartField );
100     _newPartField->setStretchable( YD_HORIZ, false );
101
102
103     // Connect signals
104
105     connect( _newPartField,     SIGNAL( valueChanged      (int) ),
106              this,              SLOT  ( setNewPartSizeSlot(int) ) );
107
108     connect( _freeSizeSlider,   SIGNAL( valueChanged   (int) ),
109              this,              SLOT  ( setFreeSizeSlot(int) ) );
110 }
111
112
113 YQPartitionSplitter::~YQPartitionSplitter()
114 {
115     // NOP
116 }
117
118
119 void YQPartitionSplitter::setEnabled( bool enabled )
120 {
121     _freeSizeSlider->setEnabled( enabled );
122     _newPartField->setEnabled  ( enabled );
123
124     YWidget::setEnabled( enabled );
125 }
126
127
128 int YQPartitionSplitter::preferredWidth()
129 {
130     return _vbox->preferredWidth();
131 }
132
133
134 int YQPartitionSplitter::preferredHeight()
135 {
136     return _vbox->preferredHeight();
137 }
138
139
140 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
141 {
142     QWidget::resize( newWidth, newHeight );
143     _vbox->setSize ( newWidth, newHeight );
144 }
145
146
147 int YQPartitionSplitter::value()
148 {
149     YUI_CHECK_PTR( _newPartField );
150     
151     return _newPartField->value();
152 }
153
154
155 void YQPartitionSplitter::setValue( int newValue )
156 {
157     YUI_CHECK_PTR( _barGraph       );
158     YUI_CHECK_PTR( _freeSizeSlider );
159     YUI_CHECK_PTR( _newPartField   );
160                   
161     YQSignalBlocker sigBlocker1( _barGraph       );
162     YQSignalBlocker sigBlocker2( _freeSizeSlider );
163     YQSignalBlocker sigBlocker3( _newPartField   );
164
165     _newPartField->setValue( newValue );
166
167     int freeSize = totalFreeSize() - newValue;
168     _freeSizeSlider->setValue( freeSize );
169
170     YBarGraphMultiUpdate multiUpdate( _barGraph );
171     {
172         _barGraph->setValue( freeSegment,    freeSize );
173         _barGraph->setValue( newPartSegment, newValue );
174     }
175 }
176
177
178 void YQPartitionSplitter::setFreeSizeSlot( int newFreeSize )
179 {
180     int newPartSize = totalFreeSize() - newFreeSize;
181
182     setValue( newPartSize );
183
184     if ( notify() )
185         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
186 }
187
188
189 void YQPartitionSplitter::setNewPartSizeSlot( int newPartSize )
190 {
191     setValue( newPartSize );
192
193     if ( notify() )
194         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
195 }
196
197
198 bool YQPartitionSplitter::setKeyboardFocus()
199 {
200     _newPartField->setKeyboardFocus();
201
202     return true;
203 }
204
205
206 #include "YQPartitionSplitter.moc"