1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPartitionSplitter.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
26 #include "YQWidgetFactory.h"
27 #include "YQOptionalWidgetFactory.h"
28 #include "YQPartitionSplitter.h"
29 #include "YQLayoutBox.h"
30 #include "YQBarGraph.h"
31 #include "YQIntField.h"
33 #include "YQSignalBlocker.h"
36 YQPartitionSplitter::YQPartitionSplitter( YWidget * parent,
42 const string & usedLabel,
43 const string & freeLabel,
44 const string & newPartLabel,
45 const string & freeFieldLabel,
46 const string & newPartFieldLabel )
47 : QWidget( (QWidget *) parent->widgetRep() )
48 , YPartitionSplitter( parent,
62 , _freeSizeSlider( 0 )
67 // Replace children manager so it will accept one single direct child (the outer vbox)
68 setChildrenManager( new YSingleWidgetChildManager( this ) );
71 // Create internal widgets
74 _vbox = YUI::widgetFactory()->createVBox( this );
75 _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
76 YUI_CHECK_PTR( _barGraph );
78 int freeSize = totalFreeSize - newPartSize;
81 YBarGraphMultiUpdate multiUpdate( _barGraph );
83 _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) );
84 _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) );
85 _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
88 _hbox = YUI::widgetFactory()->createHBox( _vbox );
90 _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel,
91 minFreeSize, maxFreeSize(), freeSize,
92 true ); // reverseLayout (put QSpinBox left of QSlider)
93 YUI_CHECK_PTR( _freeSizeSlider );
94 _freeSizeSlider->setStretchable( YD_HORIZ, true );
96 _newPartField = new YQIntField( _hbox, newPartFieldLabel,
97 minNewSize, maxNewPartSize(), newPartSize );
98 YUI_CHECK_PTR( _newPartField );
99 _newPartField->setStretchable( YD_HORIZ, false );
104 connect( _newPartField, SIGNAL( valueChanged (int) ),
105 this, SLOT ( setNewPartSizeSlot(int) ) );
107 connect( _freeSizeSlider, SIGNAL( valueChanged (int) ),
108 this, SLOT ( setFreeSizeSlot(int) ) );
112 YQPartitionSplitter::~YQPartitionSplitter()
118 void YQPartitionSplitter::setEnabled( bool enabled )
120 _freeSizeSlider->setEnabled( enabled );
121 _newPartField->setEnabled ( enabled );
123 YWidget::setEnabled( enabled );
127 int YQPartitionSplitter::preferredWidth()
129 return _vbox->preferredWidth();
133 int YQPartitionSplitter::preferredHeight()
135 return _vbox->preferredHeight();
139 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
141 QWidget::resize( newWidth, newHeight );
142 _vbox->setSize ( newWidth, newHeight );
146 int YQPartitionSplitter::value()
148 YUI_CHECK_PTR( _newPartField );
150 return _newPartField->value();
154 void YQPartitionSplitter::setValue( int newValue )
156 YUI_CHECK_PTR( _barGraph );
157 YUI_CHECK_PTR( _freeSizeSlider );
158 YUI_CHECK_PTR( _newPartField );
160 YQSignalBlocker sigBlocker1( _barGraph );
161 YQSignalBlocker sigBlocker2( _freeSizeSlider );
162 YQSignalBlocker sigBlocker3( _newPartField );
164 _newPartField->setValue( newValue );
166 int freeSize = totalFreeSize() - newValue;
167 _freeSizeSlider->setValue( freeSize );
169 YBarGraphMultiUpdate multiUpdate( _barGraph );
171 _barGraph->setValue( freeSegment, freeSize );
172 _barGraph->setValue( newPartSegment, newValue );
177 void YQPartitionSplitter::setFreeSizeSlot( int newFreeSize )
179 int newPartSize = totalFreeSize() - newFreeSize;
181 setValue( newPartSize );
184 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
188 void YQPartitionSplitter::setNewPartSizeSlot( int newPartSize )
190 setValue( newPartSize );
193 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
197 bool YQPartitionSplitter::setKeyboardFocus()
199 _newPartField->setKeyboardFocus();
205 #include "YQPartitionSplitter.moc"