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