1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPartitionSplitter.cc
15 Author: Stefan Hundhammer <sh@suse.de>
21 #define y2log_component "qt-ui"
22 #include <ycp/y2log.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"
34 #include "YQSignalBlocker.h"
37 YQPartitionSplitter::YQPartitionSplitter( YWidget * parent,
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,
63 , _freeSizeSlider( 0 )
68 // Replace children manager so it will accept one single direct child (the outer vbox)
69 setChildrenManager( new YSingleWidgetChildManager( this ) );
72 // Create internal widgets
75 _vbox = YUI::widgetFactory()->createVBox( this );
76 _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
77 YUI_CHECK_PTR( _barGraph );
79 int freeSize = totalFreeSize - newPartSize;
82 YBarGraphMultiUpdate multiUpdate( _barGraph );
84 _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) );
85 _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) );
86 _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
89 _hbox = YUI::widgetFactory()->createHBox( _vbox );
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 );
97 _newPartField = new YQIntField( _hbox, newPartFieldLabel,
98 minNewSize, maxNewPartSize(), newPartSize );
99 YUI_CHECK_PTR( _newPartField );
100 _newPartField->setStretchable( YD_HORIZ, false );
105 connect( _newPartField, SIGNAL( valueChanged (int) ),
106 this, SLOT ( setNewPartSizeSlot(int) ) );
108 connect( _freeSizeSlider, SIGNAL( valueChanged (int) ),
109 this, SLOT ( setFreeSizeSlot(int) ) );
113 YQPartitionSplitter::~YQPartitionSplitter()
119 void YQPartitionSplitter::setEnabled( bool enabled )
121 _freeSizeSlider->setEnabled( enabled );
122 _newPartField->setEnabled ( enabled );
124 YWidget::setEnabled( enabled );
128 int YQPartitionSplitter::preferredWidth()
130 return _vbox->preferredWidth();
134 int YQPartitionSplitter::preferredHeight()
136 return _vbox->preferredHeight();
140 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
142 QWidget::resize( newWidth, newHeight );
143 _vbox->setSize ( newWidth, newHeight );
147 int YQPartitionSplitter::value()
149 YUI_CHECK_PTR( _newPartField );
151 return _newPartField->value();
155 void YQPartitionSplitter::setValue( int newValue )
157 YUI_CHECK_PTR( _barGraph );
158 YUI_CHECK_PTR( _freeSizeSlider );
159 YUI_CHECK_PTR( _newPartField );
161 YQSignalBlocker sigBlocker1( _barGraph );
162 YQSignalBlocker sigBlocker2( _freeSizeSlider );
163 YQSignalBlocker sigBlocker3( _newPartField );
165 _newPartField->setValue( newValue );
167 int freeSize = totalFreeSize() - newValue;
168 _freeSizeSlider->setValue( freeSize );
170 YBarGraphMultiUpdate multiUpdate( _barGraph );
172 _barGraph->setValue( freeSegment, freeSize );
173 _barGraph->setValue( newPartSegment, newValue );
178 void YQPartitionSplitter::setFreeSizeSlot( int newFreeSize )
180 int newPartSize = totalFreeSize() - newFreeSize;
182 setValue( newPartSize );
185 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
189 void YQPartitionSplitter::setNewPartSizeSlot( int newPartSize )
191 setValue( newPartSize );
194 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
198 bool YQPartitionSplitter::setKeyboardFocus()
200 _newPartField->setKeyboardFocus();
206 #include "YQPartitionSplitter.moc"