libyui-qt  2.53.0
YQPartitionSplitter.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQPartitionSplitter.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "qt-ui"
26 #include <yui/YUILog.h>
27 
28 #include "utf8.h"
29 #include "YQUI.h"
30 #include <yui/YEvent.h>
31 #include "YQWidgetFactory.h"
32 #include "YQOptionalWidgetFactory.h"
33 #include "YQPartitionSplitter.h"
34 #include "YQLayoutBox.h"
35 #include "YQBarGraph.h"
36 #include "YQIntField.h"
37 #include "YQSlider.h"
38 #include "YQSignalBlocker.h"
39 
40 using std::string;
41 
42 
44  int usedSize,
45  int totalFreeSize,
46  int newPartSize,
47  int minNewSize,
48  int minFreeSize,
49  const string & usedLabel,
50  const string & freeLabel,
51  const string & newPartLabel,
52  const string & freeFieldLabel,
53  const string & newPartFieldLabel )
54  : QWidget( (QWidget *) parent->widgetRep() )
55  , YPartitionSplitter( parent,
56  usedSize,
57  totalFreeSize,
58  newPartSize,
59  minNewSize,
60  minFreeSize,
61  usedLabel,
62  freeLabel,
63  newPartLabel,
64  freeFieldLabel,
65  newPartFieldLabel )
66  , _vbox( 0 )
67  , _barGraph( 0 )
68  , _hbox( 0 )
69  , _freeSizeSlider( 0 )
70  , _newPartField( 0 )
71 {
72  setWidgetRep( this );
73 
74  // Replace children manager so it will accept one single direct child (the outer vbox)
75  setChildrenManager( new YSingleWidgetChildManager( this ) );
76 
77  //
78  // Create internal widgets
79  //
80 
81  _vbox = YUI::widgetFactory()->createVBox( this );
82  _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
83  YUI_CHECK_PTR( _barGraph );
84 
85  int freeSize = totalFreeSize - newPartSize;
86 
87  {
88  YBarGraphMultiUpdate multiUpdate( _barGraph );
89 
90  _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) );
91  _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) );
92  _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
93  }
94 
95  _hbox = YUI::widgetFactory()->createHBox( _vbox );
96 
97  _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel,
98  minFreeSize, maxFreeSize(), freeSize,
99  true ); // reverseLayout (put QSpinBox left of QSlider)
100  YUI_CHECK_PTR( _freeSizeSlider );
101  _freeSizeSlider->setStretchable( YD_HORIZ, true );
102 
103  _newPartField = new YQIntField( _hbox, newPartFieldLabel,
104  minNewSize, maxNewPartSize(), newPartSize );
105  YUI_CHECK_PTR( _newPartField );
106  _newPartField->setStretchable( YD_HORIZ, false );
107 
108 
109  // Connect signals
110 
111  connect( _newPartField, &pclass(_newPartField)::valueChanged,
112  this, &pclass(this)::setNewPartSizeSlot );
113 
114  connect( _freeSizeSlider, &pclass(_freeSizeSlider)::valueChanged,
115  this, &pclass(this)::setFreeSizeSlot );
116 }
117 
118 
120 {
121  // NOP
122 }
123 
124 
126 {
127  _freeSizeSlider->setEnabled( enabled );
128  _newPartField->setEnabled ( enabled );
129 
130  YWidget::setEnabled( enabled );
131 }
132 
133 
135 {
136  return _vbox->preferredWidth();
137 }
138 
139 
141 {
142  return _vbox->preferredHeight();
143 }
144 
145 
146 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
147 {
148  QWidget::resize( newWidth, newHeight );
149  _vbox->setSize ( newWidth, newHeight );
150 }
151 
152 
154 {
155  YUI_CHECK_PTR( _newPartField );
156 
157  return _newPartField->value();
158 }
159 
160 
161 void YQPartitionSplitter::setValue( int newValue )
162 {
163  YUI_CHECK_PTR( _barGraph );
164  YUI_CHECK_PTR( _freeSizeSlider );
165  YUI_CHECK_PTR( _newPartField );
166 
167  YQSignalBlocker sigBlocker1( _barGraph );
168  YQSignalBlocker sigBlocker2( _freeSizeSlider );
169  YQSignalBlocker sigBlocker3( _newPartField );
170 
171  _newPartField->setValue( newValue );
172 
173  int freeSize = totalFreeSize() - newValue;
174  _freeSizeSlider->setValue( freeSize );
175 
176  YBarGraphMultiUpdate multiUpdate( _barGraph );
177  {
178  _barGraph->setValue( freeSegment, freeSize );
179  _barGraph->setValue( newPartSegment, newValue );
180  }
181 }
182 
183 
185 {
186  int newPartSize = totalFreeSize() - newFreeSize;
187 
188  setValue( newPartSize );
189 
190  if ( notify() )
191  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
192 }
193 
194 
196 {
197  setValue( newPartSize );
198 
199  if ( notify() )
200  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
201 }
202 
203 
205 {
206  _newPartField->setKeyboardFocus();
207 
208  return true;
209 }
210 
211 
212 
YQIntField
Definition: YQIntField.h:40
YQSignalBlocker
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
Definition: YQSignalBlocker.h:37
YQPartitionSplitter::YQPartitionSplitter
YQPartitionSplitter(YWidget *parent, int usedSize, int freeSize, int newPartSize, int minNewPartSize, int minFreeSize, const std::string &usedLabel, const std::string &freeLabel, const std::string &newPartLabel, const std::string &freeFieldLabel, const std::string &newPartFieldLabel)
Constructor.
Definition: YQPartitionSplitter.cc:43
YQUI::sendEvent
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:480
YQPartitionSplitter::setKeyboardFocus
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQPartitionSplitter.cc:204
YQIntField::setEnabled
virtual void setEnabled(bool enabled)
Sets the widget's enabled state.
Definition: YQIntField.cc:121
YQSlider::setEnabled
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQSlider.cc:156
YQPartitionSplitter::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQPartitionSplitter.cc:140
YQPartitionSplitter::setEnabled
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQPartitionSplitter.cc:125
YQPartitionSplitter::setNewPartSizeSlot
void setNewPartSizeSlot(int newNewSize)
Slot for setting the new size.
Definition: YQPartitionSplitter.cc:195
YQUI::ui
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:83
YQPartitionSplitter::~YQPartitionSplitter
~YQPartitionSplitter()
Destructor.
Definition: YQPartitionSplitter.cc:119
YQSlider
Definition: YQSlider.h:37
YQIntField::setKeyboardFocus
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQIntField.cc:151
YQPartitionSplitter::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQPartitionSplitter.cc:134
YQPartitionSplitter::setValue
virtual void setValue(int newValue)
Set the value (the size of the new partition).
Definition: YQPartitionSplitter.cc:161
YQPartitionSplitter::value
virtual int value()
Return the value (the size of the new partition).
Definition: YQPartitionSplitter.cc:153
YQPartitionSplitter::setFreeSizeSlot
void setFreeSizeSlot(int newFreeSize)
Slot for setting the free size.
Definition: YQPartitionSplitter.cc:184
YQPartitionSplitter::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQPartitionSplitter.cc:146
YQIntField::value
virtual int value()
Get the current value (the number entered by the user or set from the outside) of this IntField.
Definition: YQIntField.cc:89
YQBarGraph
Definition: YQBarGraph.h:40