libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YMultiProgressMeter.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 00026 #define YUILogComponent "ui" 00027 #include "YUILog.h" 00028 00029 #include "YUISymbols.h" 00030 #include "YMultiProgressMeter.h" 00031 00032 00033 struct YMultiProgressMeterPrivate 00034 { 00035 YMultiProgressMeterPrivate( YUIDimension dim, 00036 const std::vector<float> & maxValues ) 00037 : dim( dim ) 00038 , maxValues( maxValues ) 00039 { 00040 // Make currentValues as large as maxValues 00041 // and initialize each element with 0 00042 currentValues = std::vector<float>( maxValues.size(), 0.0 ); 00043 } 00044 00045 00046 YUIDimension dim; 00047 std::vector<float> maxValues; 00048 std::vector<float> currentValues; 00049 }; 00050 00051 00052 00053 00054 YMultiProgressMeter::YMultiProgressMeter( YWidget * parent, 00055 YUIDimension dim, 00056 const std::vector<float> & maxValues ) 00057 : YWidget( parent ) 00058 , priv( new YMultiProgressMeterPrivate( dim, maxValues ) ) 00059 { 00060 YUI_CHECK_NEW( priv ); 00061 00062 setDefaultStretchable( YD_HORIZ, dim == YD_HORIZ ); 00063 setDefaultStretchable( YD_VERT, dim == YD_VERT ); 00064 } 00065 00066 00067 YMultiProgressMeter::~YMultiProgressMeter() 00068 { 00069 // NOP 00070 } 00071 00072 00073 YUIDimension 00074 YMultiProgressMeter::dimension() const 00075 { 00076 return priv->dim; 00077 } 00078 00079 00080 bool YMultiProgressMeter::horizontal() const 00081 { 00082 return priv->dim == YD_HORIZ; 00083 } 00084 00085 00086 bool YMultiProgressMeter::vertical() const 00087 { 00088 return priv->dim == YD_VERT; 00089 } 00090 00091 00092 int YMultiProgressMeter::segments() const 00093 { 00094 return (int) priv->maxValues.size(); 00095 } 00096 00097 00098 float YMultiProgressMeter::maxValue( int segment ) const 00099 { 00100 YUI_CHECK_INDEX( segment, 0, (int) priv->maxValues.size() ); 00101 00102 return priv->maxValues[ segment ]; 00103 } 00104 00105 00106 float YMultiProgressMeter::currentValue( int segment ) const 00107 { 00108 YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() ); 00109 00110 return priv->currentValues[ segment ]; 00111 } 00112 00113 00114 void YMultiProgressMeter::setCurrentValue( int segment, float value ) 00115 { 00116 YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() ); 00117 00118 if ( value < 0.0 ) // Allow -1 etc. as marker values 00119 value = 0.0; 00120 00121 if ( value > maxValue( segment ) ) // Don't complain (beware of rounding errors) 00122 value = maxValue( segment ); 00123 00124 priv->currentValues[ segment ] = value; 00125 } 00126 00127 00128 void YMultiProgressMeter::setCurrentValues( const std::vector<float> & values ) 00129 { 00130 for ( int i=0; i < (int) values.size(); i++ ) 00131 { 00132 setCurrentValue( i, values[i] ); 00133 } 00134 00135 doUpdate(); 00136 } 00137 00138 00139 const YPropertySet & 00140 YMultiProgressMeter::propertySet() 00141 { 00142 static YPropertySet propSet; 00143 00144 if ( propSet.isEmpty() ) 00145 { 00146 /* 00147 * @property list<integer> Values the current values for all segments 00148 */ 00149 propSet.add( YProperty( YUIProperty_Values, YOtherProperty ) ); 00150 propSet.add( YWidget::propertySet() ); 00151 } 00152 00153 return propSet; 00154 } 00155 00156 00157 bool 00158 YMultiProgressMeter::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00159 { 00160 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00161 00162 if ( propertyName == YUIProperty_Values ) return false; // need special processing 00163 else 00164 { 00165 YWidget::setProperty( propertyName, val ); 00166 } 00167 00168 return true; // success -- no special handling necessary 00169 } 00170 00171 00172 YPropertyValue 00173 YMultiProgressMeter::getProperty( const std::string & propertyName ) 00174 { 00175 propertySet().check( propertyName ); // throws exceptions if not found 00176 00177 if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty ); 00178 else 00179 { 00180 return YWidget::getProperty( propertyName ); 00181 } 00182 }