libyui-qt  2.49.2
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 
42  int usedSize,
43  int totalFreeSize,
44  int newPartSize,
45  int minNewSize,
46  int minFreeSize,
47  const std::string & usedLabel,
48  const std::string & freeLabel,
49  const std::string & newPartLabel,
50  const std::string & freeFieldLabel,
51  const std::string & newPartFieldLabel )
52  : QWidget( (QWidget *) parent->widgetRep() )
53  , YPartitionSplitter( parent,
54  usedSize,
55  totalFreeSize,
56  newPartSize,
57  minNewSize,
58  minFreeSize,
59  usedLabel,
60  freeLabel,
61  newPartLabel,
62  freeFieldLabel,
63  newPartFieldLabel )
64  , _vbox( 0 )
65  , _barGraph( 0 )
66  , _hbox( 0 )
67  , _freeSizeSlider( 0 )
68  , _newPartField( 0 )
69 {
70  setWidgetRep( this );
71 
72  // Replace children manager so it will accept one single direct child (the outer vbox)
73  setChildrenManager( new YSingleWidgetChildManager( this ) );
74 
75  //
76  // Create internal widgets
77  //
78 
79  _vbox = YUI::widgetFactory()->createVBox( this );
80  _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) );
81  YUI_CHECK_PTR( _barGraph );
82 
83  int freeSize = totalFreeSize - newPartSize;
84 
85  {
86  YBarGraphMultiUpdate multiUpdate( _barGraph );
87 
88  _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) );
89  _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) );
90  _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) );
91  }
92 
93  _hbox = YUI::widgetFactory()->createHBox( _vbox );
94 
95  _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel,
96  minFreeSize, maxFreeSize(), freeSize,
97  true ); // reverseLayout (put QSpinBox left of QSlider)
98  YUI_CHECK_PTR( _freeSizeSlider );
99  _freeSizeSlider->setStretchable( YD_HORIZ, true );
100 
101  _newPartField = new YQIntField( _hbox, newPartFieldLabel,
102  minNewSize, maxNewPartSize(), newPartSize );
103  YUI_CHECK_PTR( _newPartField );
104  _newPartField->setStretchable( YD_HORIZ, false );
105 
106 
107  // Connect signals
108 
109  connect( _newPartField, &pclass(_newPartField)::valueChanged,
110  this, &pclass(this)::setNewPartSizeSlot );
111 
112  connect( _freeSizeSlider, &pclass(_freeSizeSlider)::valueChanged,
113  this, &pclass(this)::setFreeSizeSlot );
114 }
115 
116 
118 {
119  // NOP
120 }
121 
122 
124 {
125  _freeSizeSlider->setEnabled( enabled );
126  _newPartField->setEnabled ( enabled );
127 
128  YWidget::setEnabled( enabled );
129 }
130 
131 
133 {
134  return _vbox->preferredWidth();
135 }
136 
137 
139 {
140  return _vbox->preferredHeight();
141 }
142 
143 
144 void YQPartitionSplitter::setSize( int newWidth, int newHeight )
145 {
146  QWidget::resize( newWidth, newHeight );
147  _vbox->setSize ( newWidth, newHeight );
148 }
149 
150 
152 {
153  YUI_CHECK_PTR( _newPartField );
154 
155  return _newPartField->value();
156 }
157 
158 
159 void YQPartitionSplitter::setValue( int newValue )
160 {
161  YUI_CHECK_PTR( _barGraph );
162  YUI_CHECK_PTR( _freeSizeSlider );
163  YUI_CHECK_PTR( _newPartField );
164 
165  YQSignalBlocker sigBlocker1( _barGraph );
166  YQSignalBlocker sigBlocker2( _freeSizeSlider );
167  YQSignalBlocker sigBlocker3( _newPartField );
168 
169  _newPartField->setValue( newValue );
170 
171  int freeSize = totalFreeSize() - newValue;
172  _freeSizeSlider->setValue( freeSize );
173 
174  YBarGraphMultiUpdate multiUpdate( _barGraph );
175  {
176  _barGraph->setValue( freeSegment, freeSize );
177  _barGraph->setValue( newPartSegment, newValue );
178  }
179 }
180 
181 
183 {
184  int newPartSize = totalFreeSize() - newFreeSize;
185 
186  setValue( newPartSize );
187 
188  if ( notify() )
189  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
190 }
191 
192 
194 {
195  setValue( newPartSize );
196 
197  if ( notify() )
198  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
199 }
200 
201 
203 {
204  _newPartField->setKeyboardFocus();
205 
206  return true;
207 }
208 
209 
210 #include "YQPartitionSplitter.moc"
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
void setNewPartSizeSlot(int newNewSize)
Slot for setting the new size.
virtual int value()
Return the value (the size of the new partition).
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQIntField.cc:147
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
~YQPartitionSplitter()
Destructor.
virtual int value()
Get the current value (the number entered by the user or set from the outside) of this IntField...
Definition: YQIntField.cc:85
virtual void setValue(int newValue)
Set the value (the size of the new partition).
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:468
virtual void setEnabled(bool enabled)
Sets the widget&#39;s enabled state.
Definition: YQIntField.cc:117
void setFreeSizeSlot(int newFreeSize)
Slot for setting the free size.
virtual int preferredHeight()
Preferred height of the widget.
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.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQSlider.cc:154
virtual int preferredWidth()
Preferred width of the widget.
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:80