libyui  3.0.10
 All Classes Functions Variables Enumerations Friends
YMultiProgressMeter.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: YMultiProgressMeter.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 "YMultiProgressMeter.h"
31 
32 
34 {
35  YMultiProgressMeterPrivate( YUIDimension dim,
36  const std::vector<float> & maxValues )
37  : dim( dim )
38  , maxValues( maxValues )
39  {
40  // Make currentValues as large as maxValues
41  // and initialize each element with 0
42  currentValues = std::vector<float>( maxValues.size(), 0.0 );
43  }
44 
45 
46  YUIDimension dim;
47  std::vector<float> maxValues;
48  std::vector<float> currentValues;
49 };
50 
51 
52 
53 
55  YUIDimension dim,
56  const std::vector<float> & maxValues )
57  : YWidget( parent )
58  , priv( new YMultiProgressMeterPrivate( dim, maxValues ) )
59 {
60  YUI_CHECK_NEW( priv );
61 
62  setDefaultStretchable( YD_HORIZ, dim == YD_HORIZ );
63  setDefaultStretchable( YD_VERT, dim == YD_VERT );
64 }
65 
66 
68 {
69  // NOP
70 }
71 
72 
73 YUIDimension
75 {
76  return priv->dim;
77 }
78 
79 
81 {
82  return priv->dim == YD_HORIZ;
83 }
84 
85 
87 {
88  return priv->dim == YD_VERT;
89 }
90 
91 
93 {
94  return (int) priv->maxValues.size();
95 }
96 
97 
98 float YMultiProgressMeter::maxValue( int segment ) const
99 {
100  YUI_CHECK_INDEX( segment, 0, (int) priv->maxValues.size() );
101 
102  return priv->maxValues[ segment ];
103 }
104 
105 
106 float YMultiProgressMeter::currentValue( int segment ) const
107 {
108  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
109 
110  return priv->currentValues[ segment ];
111 }
112 
113 
114 void YMultiProgressMeter::setCurrentValue( int segment, float value )
115 {
116  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
117 
118  if ( value < 0.0 ) // Allow -1 etc. as marker values
119  value = 0.0;
120 
121  if ( value > maxValue( segment ) ) // Don't complain (beware of rounding errors)
122  value = maxValue( segment );
123 
124  priv->currentValues[ segment ] = value;
125 }
126 
127 
128 void YMultiProgressMeter::setCurrentValues( const std::vector<float> & values )
129 {
130  for ( int i=0; i < (int) values.size(); i++ )
131  {
132  setCurrentValue( i, values[i] );
133  }
134 
135  doUpdate();
136 }
137 
138 
139 const YPropertySet &
141 {
142  static YPropertySet propSet;
143 
144  if ( propSet.isEmpty() )
145  {
146  /*
147  * @property list<integer> Values the current values for all segments
148  */
149  propSet.add( YProperty( YUIProperty_Values, YOtherProperty ) );
150  propSet.add( YWidget::propertySet() );
151  }
152 
153  return propSet;
154 }
155 
156 
157 bool
158 YMultiProgressMeter::setProperty( const std::string & propertyName, const YPropertyValue & val )
159 {
160  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
161 
162  if ( propertyName == YUIProperty_Values ) return false; // need special processing
163  else
164  {
165  YWidget::setProperty( propertyName, val );
166  }
167 
168  return true; // success -- no special handling necessary
169 }
170 
171 
173 YMultiProgressMeter::getProperty( const std::string & propertyName )
174 {
175  propertySet().check( propertyName ); // throws exceptions if not found
176 
177  if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty );
178  else
179  {
180  return YWidget::getProperty( propertyName );
181  }
182 }