libyui  3.3.2
YPartitionSplitter.h
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: YPartitionSplitter.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YPartitionSplitter_h
26 #define YPartitionSplitter_h
27 
28 #include "YWidget.h"
29 
30 
32 
33 
34 /**
35  * PartitionSplitter: A (very custom) widget for easily splitting one existing
36  * partition into two.
37  *
38  * Layout:
39  *
40  * +--------------------+---------------+--------------------------+
41  * | Old Partition | Old Partition | New Partition |
42  * | used | free | |
43  * +--------------------+---------------+--------------------------+
44  *
45  * Old Partition free New Partition
46  * [ 123 ] ================O================================ [ 123 ]
47  *
48  *
49  * At the top, there is a BarGraph that dynamicylla displays the sizes in
50  * graphical form. Below are an IntField to the left and an IntField to the
51  * right, each with its respective label. Between the two IntFields there is a
52  * Slider.
53  *
54  * The user can enter a value in either IntField or drag the slider. The other
55  * sub-widgets (including the BarGraph) will automatically be
56  * adjusted. Visually (in the BarGraph), the border between "old partition
57  * free" and "new partition" will move left and right. The border between "old
58  * partition used" and "old partition free" is static.
59  *
60  * There are built-in (configurable) limits for the minimum sizes of "old
61  * partition free" and "new partition".
62  **/
64 {
65 protected:
66  /**
67  * Constructor.
68  *
69  * usedSize: Used size of the old partition (constant)
70  *
71  * totalFreeSize: Total free size of the old partition before the split:
72  * OldPartitionFree + NewPartition
73  *
74  * newPartSize': Initial size of the new partition
75  *
76  * minNewPartSize: Miminum size of the new partition
77  *
78  * minFreeSize: Minimum free size of the old partition
79  *
80  * usedLabel: BarGraph label for the used part of the old partition
81  *
82  * freeLabel: BarGraph label for the free part of the old partition
83  *
84  * newPartLabel: BarGraph label for the new partition
85  *
86  * freeFieldLabel: IntField label for the free part of the old partition
87  *
88  * newPartFieldLabel: IntField label for the size of the new partition
89  **/
91  int usedSize,
92  int totalFreeSize,
93  int newPartSize,
94  int minNewPartSize,
95  int minFreeSize,
96  const std::string & usedLabel,
97  const std::string & freeLabel,
98  const std::string & newPartLabel,
99  const std::string & freeFieldLabel,
100  const std::string & newPartFieldLabel );
101 
102 public:
103 
104  /**
105  * Destructor.
106  **/
107  virtual ~YPartitionSplitter();
108 
109  /**
110  * Returns a descriptive name of this widget class for logging,
111  * debugging etc.
112  **/
113  virtual const char * widgetClass() const { return "YPartitionSplitter"; }
114 
115  /**
116  * The value of this PartitionSplitter: The size of the new partition.
117  *
118  * Derived classes are required to implement this.
119  **/
120  virtual int value() = 0;
121 
122  /**
123  * Set the value (the size of the new partition).
124  *
125  * Derived classes are required to implement this.
126  **/
127  virtual void setValue( int newValue ) = 0;
128 
129 
130  // Access methods
131 
132  int usedSize() const;
133  int totalFreeSize() const;
134  int minFreeSize() const;
135  int maxFreeSize() const { return totalFreeSize() - minNewPartSize(); }
136  int freeSize() { return totalFreeSize() - newPartSize(); }
137  int newPartSize() { return value(); }
138  int minNewPartSize() const;
139  int maxNewPartSize() const { return totalFreeSize() - minFreeSize(); }
140 
141  std::string usedLabel() const;
142  std::string freeLabel() const;
143  std::string newPartLabel() const;
144  std::string freeFieldLabel() const;
145  std::string newPartFieldLabel() const;
146 
147  /**
148  * Set a property.
149  * Reimplemented from YWidget.
150  *
151  * This function may throw YUIPropertyExceptions.
152  *
153  * This function returns 'true' if the value was successfully set and
154  * 'false' if that value requires special handling (not in error cases:
155  * those are covered by exceptions).
156  **/
157  virtual bool setProperty( const std::string & propertyName,
158  const YPropertyValue & val );
159 
160  /**
161  * Get a property.
162  * Reimplemented from YWidget.
163  *
164  * This method may throw YUIPropertyExceptions.
165  **/
166  virtual YPropertyValue getProperty( const std::string & propertyName );
167 
168  /**
169  * Return this class's property set.
170  * This also initializes the property upon the first call.
171  *
172  * Reimplemented from YWidget.
173  **/
174  virtual const YPropertySet & propertySet();
175 
176 
177  /**
178  * The name of the widget property that will return user input.
179  * Inherited from YWidget.
180  **/
181  const char * userInputProperty() { return YUIProperty_Value; }
182 
183 
184 private:
185 
187 };
188 
189 
190 #endif // YPartitionSplitter_h
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
PartitionSplitter: A (very custom) widget for easily splitting one existing partition into two...
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
A set of properties to check names and types against.
Definition: YProperty.h:197
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
const char * userInputProperty()
The name of the widget property that will return user input.
YPartitionSplitter(YWidget *parent, int usedSize, int totalFreeSize, 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 const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual void setValue(int newValue)=0
Set the value (the size of the new partition).
virtual int value()=0
The value of this PartitionSplitter: The size of the new partition.
Abstract base class of all UI widgets.
Definition: YWidget.h:54
virtual ~YPartitionSplitter()
Destructor.