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: YProgressBar.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 "YProgressBar.h" 00031 00032 struct YProgressBarPrivate 00033 { 00034 YProgressBarPrivate( const std::string & label, 00035 int maxValue ) 00036 : label( label ) 00037 , maxValue( maxValue ) 00038 , value( 0 ) 00039 { 00040 if ( maxValue < 1 ) 00041 maxValue = 1; 00042 } 00043 00044 std::string label; 00045 int maxValue; 00046 int value; 00047 }; 00048 00049 00050 00051 00052 YProgressBar::YProgressBar( YWidget * parent, 00053 const std::string & label, 00054 int maxValue ) 00055 : YWidget( parent ) 00056 , priv( new YProgressBarPrivate( label, maxValue ) ) 00057 { 00058 YUI_CHECK_NEW( priv ); 00059 00060 setDefaultStretchable( YD_HORIZ, true ); 00061 setStretchable( YD_VERT, false ); 00062 } 00063 00064 00065 YProgressBar::~YProgressBar() 00066 { 00067 // NOP 00068 } 00069 00070 00071 std::string YProgressBar::label() 00072 { 00073 return priv->label; 00074 } 00075 00076 00077 void YProgressBar::setLabel( const std::string & label ) 00078 { 00079 priv->label = label; 00080 } 00081 00082 00083 int YProgressBar::maxValue() const 00084 { 00085 return priv->maxValue; 00086 } 00087 00088 00089 int YProgressBar::value() const 00090 { 00091 return priv->value; 00092 } 00093 00094 00095 void YProgressBar::setValue( int newValue ) 00096 { 00097 if ( newValue < 0 ) 00098 newValue = 0; 00099 00100 if ( newValue > priv->maxValue ) 00101 newValue = priv->maxValue; 00102 00103 priv->value = newValue; 00104 } 00105 00106 00107 const YPropertySet & 00108 YProgressBar::propertySet() 00109 { 00110 static YPropertySet propSet; 00111 00112 if ( propSet.isEmpty() ) 00113 { 00114 /* 00115 * @property integer Value the current progress 00116 * @property std::string Label caption above the progress bar 00117 */ 00118 propSet.add( YProperty( YUIProperty_Value, YIntegerProperty ) ); 00119 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00120 propSet.add( YWidget::propertySet() ); 00121 } 00122 00123 return propSet; 00124 } 00125 00126 00127 bool 00128 YProgressBar::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00129 { 00130 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00131 00132 if ( propertyName == YUIProperty_Value ) setValue( val.integerVal() ); 00133 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00134 else 00135 { 00136 return YWidget::setProperty( propertyName, val ); 00137 } 00138 00139 return true; // success -- no special processing necessary 00140 } 00141 00142 00143 YPropertyValue 00144 YProgressBar::getProperty( const std::string & propertyName ) 00145 { 00146 propertySet().check( propertyName ); // throws exceptions if not found 00147 00148 if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); 00149 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00150 else 00151 { 00152 return YWidget::getProperty( propertyName ); 00153 } 00154 }