libyui  3.3.2
YProgressBar.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: YProgressBar.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YProgressBar.h"
31 
33 {
34  YProgressBarPrivate( const std::string & label,
35  int maxValue )
36  : label( label )
37  , maxValue( maxValue )
38  , value( 0 )
39  {
40  if ( maxValue < 1 )
41  maxValue = 1;
42  }
43 
44  std::string label;
45  int maxValue;
46  int value;
47 };
48 
49 
50 
51 
53  const std::string & label,
54  int maxValue )
55  : YWidget( parent )
56  , priv( new YProgressBarPrivate( label, maxValue ) )
57 {
58  YUI_CHECK_NEW( priv );
59 
60  setDefaultStretchable( YD_HORIZ, true );
61  setStretchable( YD_VERT, false );
62 }
63 
64 
66 {
67  // NOP
68 }
69 
70 
71 std::string YProgressBar::label()
72 {
73  return priv->label;
74 }
75 
76 
77 void YProgressBar::setLabel( const std::string & label )
78 {
79  priv->label = label;
80 }
81 
82 
84 {
85  return priv->maxValue;
86 }
87 
88 
90 {
91  return priv->value;
92 }
93 
94 
95 void YProgressBar::setValue( int newValue )
96 {
97  if ( newValue < 0 )
98  newValue = 0;
99 
100  if ( newValue > priv->maxValue )
101  newValue = priv->maxValue;
102 
103  priv->value = newValue;
104 }
105 
106 
107 const YPropertySet &
109 {
110  static YPropertySet propSet;
111 
112  if ( propSet.isEmpty() )
113  {
114  /*
115  * @property integer Value the current progress
116  * @property std::string Label caption above the progress bar
117  */
118  propSet.add( YProperty( YUIProperty_Value, YIntegerProperty ) );
119  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
120  propSet.add( YWidget::propertySet() );
121  }
122 
123  return propSet;
124 }
125 
126 
127 bool
128 YProgressBar::setProperty( const std::string & propertyName, const YPropertyValue & val )
129 {
130  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
131 
132  if ( propertyName == YUIProperty_Value ) setValue( val.integerVal() );
133  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
134  else
135  {
136  return YWidget::setProperty( propertyName, val );
137  }
138 
139  return true; // success -- no special processing necessary
140 }
141 
142 
144 YProgressBar::getProperty( const std::string & propertyName )
145 {
146  propertySet().check( propertyName ); // throws exceptions if not found
147 
148  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
149  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
150  else
151  {
152  return YWidget::getProperty( propertyName );
153  }
154 }
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
YProgressBar(YWidget *parent, const std::string &label, int maxValue=100)
Constructor.
Definition: YProgressBar.cc:52
int maxValue() const
Return the maximum progress value.
Definition: YProgressBar.cc:83
virtual ~YProgressBar()
Destructor.
Definition: YProgressBar.cc:65
Transport class for the value of simple properties.
Definition: YProperty.h:104
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:428
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:453
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:561
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
Definition: YProgressBar.cc:77
Class for widget properties.
Definition: YProperty.h:51
std::string label()
Get the label (the caption above the progress bar).
Definition: YProgressBar.cc:71
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual void setValue(int newValue)
Set the current progress value ( <= maxValue() ).
Definition: YProgressBar.cc:95
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
void setStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
Definition: YWidget.cc:555
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
Abstract base class of all UI widgets.
Definition: YWidget.h:54
int value() const
Return the current progress value.
Definition: YProgressBar.cc:89
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.