libyui
YBarGraph.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: YBarGraph.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YBarGraph_h
26 #define YBarGraph_h
27 
28 #include "YWidget.h"
29 #include "YColor.h"
30 
31 
32 class YBarGraphPrivate;
33 class YBarGraphSegment;
34 
40 class YBarGraph : public YWidget
41 {
42  friend class YBarGraphMultiUpdate;
43 
44 protected:
49 
50 public:
54  virtual ~YBarGraph();
55 
60  virtual const char * widgetClass() const { return "YBarGraph"; }
61 
73  void addSegment( const YBarGraphSegment & segment );
74 
78  void deleteAllSegments();
79 
83  int segments();
84 
90  const YBarGraphSegment & segment( int segmentIndex ) const;
91 
100  void setValue( int segmentIndex, int newValue );
101 
111  void setLabel( int segmentIndex, const std::string & newLabel );
112 
120  void setSegmentColor( int segmentIndex, const YColor & color );
121 
129  void setTextColor( int segmentIndex, const YColor & color );
130 
141  virtual bool setProperty( const std::string & propertyName,
142  const YPropertyValue & val );
143 
150  virtual YPropertyValue getProperty( const std::string & propertyName );
151 
158  virtual const YPropertySet & propertySet();
159 
160 
161 protected:
167  virtual void doUpdate() = 0;
168 
169 
170 private:
174  void updateDisplay();
175 
177 };
178 
179 
180 
181 
187 {
188 public:
205  const std::string & label = std::string(),
206  const YColor & segmentColor = YColor(),
207  const YColor & textColor = YColor() )
208  : _value( value )
209  , _label( label )
210  , _segmentColor( segmentColor )
211  , _textColor( textColor )
212  {}
213 
217  int value() const { return _value; }
218 
222  void setValue( int newValue ) { _value = newValue; }
223 
228  std::string label() const { return _label; }
229 
234  void setLabel( const std::string & newLabel ) { _label = newLabel; }
235 
239  YColor segmentColor() const { return _segmentColor; }
240 
246  bool hasSegmentColor() const { return _segmentColor.isDefined(); }
247 
251  void setSegmentColor( const YColor & color ) { _segmentColor = color; }
252 
256  YColor textColor() const { return _textColor; }
257 
263  bool hasTextColor() const { return _textColor.isDefined(); }
264 
268  void setTextColor( const YColor & color ) { _textColor = color; }
269 
270 
271 private:
272 
273  int _value;
274  std::string _label;
275  YColor _segmentColor;
276  YColor _textColor;
277 };
278 
279 
280 
286 {
287 public:
309  YBarGraphMultiUpdate( YBarGraph * barGraph );
310 
318 
319 private:
320 
321  YBarGraph * _barGraph;
322 };
323 
324 
325 #endif // YBarGraph_h
Definition: YBarGraph.h:186
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Definition: YBarGraph.cc:196
virtual YPropertyValue getProperty(const std::string &propertyName)
Definition: YBarGraph.cc:212
YBarGraphSegment(int value=0, const std::string &label=std::string(), const YColor &segmentColor=YColor(), const YColor &textColor=YColor())
Definition: YBarGraph.h:204
YColor textColor() const
Definition: YBarGraph.h:256
Definition: YProperty.h:104
bool isDefined() const
Definition: YColor.h:78
virtual const YPropertySet & propertySet()
Definition: YBarGraph.cc:175
Definition: YProperty.h:197
Definition: YBarGraph.h:40
YWidget * parent() const
Definition: YWidget.cc:271
void setLabel(int segmentIndex, const std::string &newLabel)
Definition: YBarGraph.cc:139
Definition: YColor.h:34
void setLabel(const std::string &newLabel)
Definition: YBarGraph.h:234
Definition: YBarGraph.cc:53
void setSegmentColor(int segmentIndex, const YColor &color)
Definition: YBarGraph.cc:149
void deleteAllSegments()
Definition: YBarGraph.cc:105
void setTextColor(int segmentIndex, const YColor &color)
Definition: YBarGraph.cc:162
std::string label() const
Definition: YBarGraph.h:228
bool hasSegmentColor() const
Definition: YBarGraph.h:246
void setTextColor(const YColor &color)
Definition: YBarGraph.h:268
YColor segmentColor() const
Definition: YBarGraph.h:239
virtual ~YBarGraph()
Definition: YBarGraph.cc:77
int value() const
Definition: YBarGraph.h:217
void setValue(int segmentIndex, int newValue)
Definition: YBarGraph.cc:129
YBarGraph(YWidget *parent)
Definition: YBarGraph.cc:68
void addSegment(const YBarGraphSegment &segment)
Definition: YBarGraph.cc:97
~YBarGraphMultiUpdate()
Definition: YBarGraph.cc:236
int segments()
Definition: YBarGraph.cc:122
void setSegmentColor(const YColor &color)
Definition: YBarGraph.h:251
bool hasTextColor() const
Definition: YBarGraph.h:263
Definition: YWidget.h:54
virtual const char * widgetClass() const
Definition: YBarGraph.h:60
const YBarGraphSegment & segment(int segmentIndex) const
Definition: YBarGraph.cc:113
virtual void doUpdate()=0
YBarGraphMultiUpdate(YBarGraph *barGraph)
Definition: YBarGraph.cc:227
Definition: YBarGraph.h:285
void setValue(int newValue)
Definition: YBarGraph.h:222