1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPartitionSplitter.cc
15 Author: Stefan Hundhammer <sh@suse.de>
19 #define y2log_component "qt-ui"
20 #include <ycp/y2log.h>
25 #include "YQWidgetFactory.h"
26 #include "YQOptionalWidgetFactory.h"
27 #include "YQPartitionSplitter.h"
28 #include "YQLayoutBox.h"
29 #include "YQBarGraph.h"
30 #include "YQIntField.h"
32 #include "YQSignalBlocker.h"
35 YQPartitionSplitter::YQPartitionSplitter( YWidget * parent,
41 const string & usedLabel,
42 const string & freeLabel,
43 const string & newPartLabel,
44 const string & freeFieldLabel,
45 const string & newPartFieldLabel )
46 : QWidget( (QWidget *) parent->widgetRep() )
47 , YPartitionSplitter( parent,
61 , _freeSizeSlider( 0 )
66 // Replace children manager so it will accept one single direct child (the outer vbox)
67 setChildrenManager( new YSingleWidgetChildManager( this ) );
70 // Create internal widgets
73 _vbox = YUI::widgetFactory()->createVBox( this );
74 _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
75 YUI_CHECK_PTR( _barGraph );
77 int freeSize = totalFreeSize - newPartSize;
80 YBarGraphMultiUpdate multiUpdate( _barGraph );
82 _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) );
83 _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) );
84 _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
87 _hbox = YUI::widgetFactory()->createHBox( _vbox );
89 _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel,
90 minFreeSize, maxFreeSize(), freeSize,
91 true ); // reverseLayout (put QSpinBox left of QSlider)
92 YUI_CHECK_PTR( _freeSizeSlider );
93 _freeSizeSlider->setStretchable( YD_HORIZ, true );
95 _newPartField = new YQIntField( _hbox, newPartFieldLabel,
96 minNewSize, maxNewPartSize(), newPartSize );
97 YUI_CHECK_PTR( _newPartField );
98 _newPartField->setStretchable( YD_HORIZ, false );
103 connect( _newPartField, SIGNAL( valueChanged (int) ),
104 this, SLOT ( setNewPartSizeSlot(int) ) );
106 connect( _freeSizeSlider, SIGNAL( valueChanged (int) ),
107 this, SLOT ( setFreeSizeSlot(int) ) );
111 YQPartitionSplitter::~YQPartitionSplitter()
117 void YQPartitionSplitter::setEnabled( bool enabled )
119 _freeSizeSlider->setEnabled( enabled );
120 _newPartField->setEnabled ( enabled );
122 YWidget::setEnabled( enabled );
126 int YQPartitionSplitter::preferredWidth()
128 return _vbox->preferredWidth();
132 int YQPartitionSplitter::preferredHeight()
134 return _vbox->preferredHeight();
138 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
140 QWidget::resize( newWidth, newHeight );
141 _vbox->setSize ( newWidth, newHeight );
145 int YQPartitionSplitter::value()
147 YUI_CHECK_PTR( _newPartField );
149 return _newPartField->value();
153 void YQPartitionSplitter::setValue( int newValue )
155 YUI_CHECK_PTR( _barGraph );
156 YUI_CHECK_PTR( _freeSizeSlider );
157 YUI_CHECK_PTR( _newPartField );
159 YQSignalBlocker sigBlocker1( _barGraph );
160 YQSignalBlocker sigBlocker2( _freeSizeSlider );
161 YQSignalBlocker sigBlocker3( _newPartField );
163 _newPartField->setValue( newValue );
165 int freeSize = totalFreeSize() - newValue;
166 _freeSizeSlider->setValue( freeSize );
168 YBarGraphMultiUpdate multiUpdate( _barGraph );
170 _barGraph->setValue( freeSegment, freeSize );
171 _barGraph->setValue( newPartSegment, newValue );
176 void YQPartitionSplitter::setFreeSizeSlot( int newFreeSize )
178 int newPartSize = totalFreeSize() - newFreeSize;
180 setValue( newPartSize );
183 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
187 void YQPartitionSplitter::setNewPartSizeSlot( int newPartSize )
189 setValue( newPartSize );
192 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
196 bool YQPartitionSplitter::setKeyboardFocus()
198 _newPartField->setKeyboardFocus();
204 #include "YQPartitionSplitter.moc"