[yast-commit] r39150 - in /branches/tmp/sh/mod-ui: core/libyui/src/ qt/src/
Author: sh-sh-sh Date: Tue Jul 3 17:50:06 2007 New Revision: 39150 URL: http://svn.opensuse.org/viewcvs/yast?rev=39150&view=rev Log: ported ProgressBar Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.h branches/tmp/sh/mod-ui/core/libyui/src/YUI.h branches/tmp/sh/mod-ui/qt/src/YQInputField.cc branches/tmp/sh/mod-ui/qt/src/YQProgressBar.cc branches/tmp/sh/mod-ui/qt/src/YQProgressBar.h branches/tmp/sh/mod-ui/qt/src/YQUI.h branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Tue Jul 3 17:50:06 2007 @@ -324,4 +324,7 @@ * Ported YMultiLineEdit - renamed text() -> value() - renamed setText() -> setValue() - - new: YMultiLineEdit::defaultVisibleLines() (use this in preferredHeight() ) \ No newline at end of file + - new: YMultiLineEdit::defaultVisibleLines() (use this in preferredHeight() ) + +* Ported YProgressBar + - renamed setProgress() -> setValue() Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc Tue Jul 3 17:50:06 2007 @@ -53,9 +53,10 @@ #include "YLabel.h" #include "YLayoutBox.h" #include "YMenuButton.h" -#include "YMultiSelectionBox.h" #include "YMultiLineEdit.h" +#include "YMultiSelectionBox.h" #include "YPackageSelector.h" +#include "YProgressBar.h" #include "YPushButton.h" #include "YRadioButton.h" #include "YRadioButtonGroup.h" @@ -2217,23 +2218,21 @@ return 0; } - YCPString label = term->value( argnr )->asString(); - YCPInteger maxprogress( 100 ); - if ( s >= 2 ) maxprogress = term->value( argnr+1 )->asInteger(); - YCPInteger progress( 0LL ); - if ( s >= 3 ) progress = term->value( argnr+2 )->asInteger(); - - if ( maxprogress->value() < 0 - || progress->value() < 0 - || progress->value() > maxprogress->value()) - { - y2error( "Invalid maxprogress/progress value for the ProgressBar widget: %s", - term->toString().c_str() ); - return 0; - } - rejectAllOptions( term,optList ); - return YUI::ui()->createProgressBar( parent, opt, label, maxprogress, progress ); + + string label = term->value( argnr )->asString()->value(); + int maxValue = 100; + int initialValue = 0; + + if ( s >= 2 ) maxValue = term->value( argnr+1 )->asInteger()->value(); + if ( s >= 3 ) initialValue = term->value( argnr+2 )->asInteger()->value(); + + YProgressBar * progressBar = YUI::widgetFactory()->createProgressBar( parent, label, maxValue ); + + if ( initialValue > 0 ) + progressBar->setValue( initialValue ); + + return progressBar; } Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc Tue Jul 3 17:50:06 2007 @@ -17,115 +17,133 @@ /-*/ -#include <ycp/YCPSymbol.h> -#include <ycp/YCPBoolean.h> #define y2log_component "ui" #include <ycp/y2log.h> #include "YUISymbols.h" #include "YProgressBar.h" +struct YProgressBarPrivate +{ + YProgressBarPrivate( const string & label, + int maxValue ) + : label( label ) + , maxValue( maxValue ) + , value( 0 ) + { + if ( maxValue < 1 ) + maxValue = 1; + } + + string label; + int maxValue; + int value; +}; + -YProgressBar::YProgressBar( const YWidgetOpt & opt, - const YCPString & label, - const YCPInteger & maxProgress, - const YCPInteger & progress ) - : YWidget( opt ) - , label( label ) - , maxProgress( maxProgress ) - , progress( progress ) + + +YProgressBar::YProgressBar( YWidget * parent, + const string & label, + int maxValue ) + : YWidget( parent ) + , priv( new YProgressBarPrivate( label, maxValue ) ) { + YUI_CHECK_NEW( priv ); + setDefaultStretchable( YD_HORIZ, true ); setStretchable( YD_VERT, false ); } -void YProgressBar::setLabel( const YCPString & label ) +YProgressBar::~YProgressBar() +{ + // NOP +} + + +string YProgressBar::label() +{ + return priv->label; +} + + +void YProgressBar::setLabel( const string & label ) { - this->label = label; + priv->label = label; } -void YProgressBar::setProgress( const YCPInteger & progress ) +int YProgressBar::maxValue() const { - this->progress = progress; + return priv->maxValue; } -YCPString YProgressBar::getLabel() +int YProgressBar::value() const { - return label; + return priv->value; } -YCPInteger YProgressBar::getProgress() +void YProgressBar::setValue( int newValue ) { - return progress; + if ( newValue < 0 ) + newValue = 0; + + if ( newValue > priv->maxValue ) + newValue = priv->maxValue; + + priv->value = newValue; } -YCPValue YProgressBar::changeWidget( const YCPSymbol & property, const YCPValue & newvalue ) +const YPropertySet & +YProgressBar::propertySet() { - string s = property->symbol(); + static YPropertySet propSet; - /** - * @property integer Value the current progress - */ - if ( s == YUIProperty_Value ) + if ( propSet.isEmpty() ) { - if ( newvalue->isInteger() ) - { - YCPInteger p = newvalue->asInteger(); - if ( p->value() < 0 ) - { - y2warning( "Negative value %s for progress bar", p->toString().c_str() ); - p = YCPInteger( 0LL ); - } - else if ( p->value() > maxProgress->value() ) - { - y2warning( "Too big value %s for progress bar ( max is %s )", - p->toString().c_str(), maxProgress->toString().c_str() ); - p = maxProgress; - } - setProgress(p); - this->progress = p; - return YCPBoolean( true ); - } - else - { - y2error( "ProgressBar: Invalid parameter %s for Value property. Must be integer", - newvalue->toString().c_str() ); - return YCPBoolean( false ); - } + /* + * @property integer Value the current progress + * @property string Label caption above the input field + */ + propSet.add( YProperty( YUIProperty_Value, YIntegerProperty ) ); + propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); + propSet.add( YWidget::propertySet() ); } - /** - * @property string Label the label above the progress bar - */ - else if ( s == YUIProperty_Label ) + return propSet; +} + + +bool +YProgressBar::setProperty( const string & propertyName, const YPropertyValue & val ) +{ + propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch + + if ( propertyName == YUIProperty_Value ) setValue( val.integerVal() ); + else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); + else { - if ( newvalue->isString() ) - { - setLabel( newvalue->asString() ); - return YCPBoolean( true ); - } - else - { - y2error( "ProgressBar: Invalid parameter %s for Label property. Must be string", - newvalue->toString().c_str() ); - return YCPBoolean( false ); - } + YWidget::setProperty( propertyName, val ); } - else return YWidget::changeWidget( property, newvalue ); -} + return true; // success -- no special processing necessary +} -YCPValue YProgressBar::queryWidget( const YCPSymbol & property ) +YPropertyValue +YProgressBar::getProperty( const string & propertyName ) { - string s = property->symbol(); - if ( s == YUIProperty_Value ) return getProgress(); - else if ( s == YUIProperty_Label ) return getLabel(); - else return YWidget::queryWidget( property ); + propertySet().check( propertyName ); // throws exceptions if not found + + if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); + else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); + else + { + return YWidget::getProperty( propertyName ); + } } Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.h Tue Jul 3 17:50:06 2007 @@ -20,8 +20,8 @@ #define YProgressBar_h #include "YWidget.h" -#include <ycp/YCPString.h> -#include <ycp/YCPInteger.h> + +class YProgressBarPrivate; class YProgressBar : public YWidget @@ -30,73 +30,87 @@ /** * Constructor. **/ - YProgressBar( const YWidgetOpt & opt, - const YCPString & label, - const YCPInteger & maxProgress, - const YCPInteger & initialProgress ); + YProgressBar( YWidget * parent, + const string & label, + int maxValue = 100 ); public: /** + * Destructor. + **/ + virtual ~YProgressBar(); + + /** * Returns a descriptive name of this widget class for logging, * debugging etc. **/ virtual const char * widgetClass() { return "YProgressBar"; } /** - * Implements the ui command changeWidget. + * Get the label (the caption above the progress bar). **/ - YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue ); + string label(); /** - * Implements the ui command queryWidget + * Set the label (the caption above the progress bar). + * + * Derived classes are free to reimplement this, but they should call this + * base class method at the end of the overloaded function. **/ - YCPValue queryWidget( const YCPSymbol & property ); + virtual void setLabel( const string & label ); /** - * Change the ProgressBar label. Overload this, but call - * YProgressBar::setLabel at the end of your own function. + * Return the maximum progress value. + * Notice that this value can only be set in the constructor. **/ - virtual void setLabel( const YCPString & label ); + int maxValue() const; /** - * Get the current label. This method cannot be overidden. The label of the - * ProgressBar cannot be changed other than by calling setProgress, i.e. not - * by the ui. Therefore setProgress stores the current ProgressBar in - * #ProgressBar. + * Return the current progress value. **/ - YCPString getLabel(); + int value() const; /** - * Change the progress. Overload this, but call - * YProgressBar::setProgress at the end of your own function. + * Set the current progress value ( <= maxValue() ). + * + * Derived classes should reimplement this, but they should call this + * base class method at the end of the overloaded function. **/ - virtual void setProgress( const YCPInteger & progress ); + virtual void setValue( int newValue ); /** - * Get the current progress. This method cannot be overidden. The progress - * of the cannot be changed other than by calling setProgress, i.e. not by - * the ui. Therefore setProgress stores the current ProgressBar in - * #ProgressBar. + * Set a property. + * Reimplemented from YWidget. + * + * This function may throw YUIPropertyExceptions. + * + * This function returns 'true' if the value was successfully set and + * 'false' if that value requires special handling (not in error cases: + * those are covered by exceptions). **/ - YCPInteger getProgress(); + virtual bool setProperty( const string & propertyName, + const YPropertyValue & val ); - -protected: /** - * Current label of the ProgressBar + * Get a property. + * Reimplemented from YWidget. + * + * This method may throw YUIPropertyExceptions. **/ - YCPString label; + virtual YPropertyValue getProperty( const string & propertyName ); /** - * Maximum progress value of the progress bar. - * The progress can go from 0 to maxprogress. + * Return this class's property set. + * This also initializes the property upon the first call. + * + * Reimplemented from YWidget. **/ - YCPInteger maxProgress; + virtual const YPropertySet & propertySet(); - /** - * current progress value of the ProgressBar. - **/ - YCPInteger progress; + +private: + + ImplPtr<YProgressBarPrivate> priv; }; Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/... ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Tue Jul 3 17:50:06 2007 @@ -450,7 +450,6 @@ virtual YWidget *createMenuButton( YWidget *parent, YWidgetOpt & opt, const YCPString & label ) = 0; virtual YWidget *createTree( YWidget *parent, YWidgetOpt & opt, const YCPString & label ) = 0; virtual YWidget *createTable( YWidget *parent, YWidgetOpt & opt, vector<string> header ) = 0; - virtual YWidget *createProgressBar( YWidget *parent, YWidgetOpt & opt, const YCPString & label, const YCPInteger & maxprogress, const YCPInteger & progress ) = 0; virtual YWidget *createIntField( YWidget *parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue ) = 0; // FIXME: Obsolete // FIXME: Obsolete Modified: branches/tmp/sh/mod-ui/qt/src/YQInputField.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQInputFi... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQInputField.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQInputField.cc Tue Jul 3 17:50:06 2007 @@ -119,7 +119,7 @@ int minSize = shrinkable() ? 20 : 200; int hintWidth = _qt_label->sizeHint().width(); - if ( _qt_label->text().isEmpty() ) + if ( ! _qt_label->isVisible() ) hintWidth = 0; return max( minSize, hintWidth ); Modified: branches/tmp/sh/mod-ui/qt/src/YQProgressBar.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQProgres... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQProgressBar.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQProgressBar.cc Tue Jul 3 17:50:06 2007 @@ -31,33 +31,59 @@ #define MAX_PROGRESS 10000 -YQProgressBar::YQProgressBar( QWidget * parent, - const YWidgetOpt & opt, - const YCPString & label, - const YCPInteger & maxProgress, - const YCPInteger & progress ) - : QVBox( parent ) - , YProgressBar( opt, label, maxProgress, progress ) +YQProgressBar::YQProgressBar( YWidget * parent, + const string & label, + int maxValue ) + : QVBox( (QWidget *) parent->widgetRep() ) + , YProgressBar( parent, label, maxValue ) { setWidgetRep( this ); setSpacing( YQWidgetSpacing ); - setMargin( YQWidgetMargin ); + setMargin ( YQWidgetMargin ); - _qt_label = new QLabel( fromUTF8(label->value() ), this ); + _qt_label = new QLabel( fromUTF8( label ), this ); _qt_label->setTextFormat( QLabel::PlainText ); - if ( label->value() == "" ) + if ( label.empty() ) _qt_label->hide(); - _qt_progressbar = new QProgressBar( this ); - _qt_progressbar->setTotalSteps( MAX_PROGRESS ); + _qt_progressbar = new QProgressBar( maxValue, this ); _qt_label->setBuddy( _qt_progressbar ); +} + + +YQProgressBar::~YQProgressBar() +{ + // NOP +} + + +void YQProgressBar::setLabel( const string & label ) +{ + _qt_label->setText( fromUTF8( label ) ); + + if ( label.empty() ) + { + if ( _qt_label->isVisible() ) + _qt_label->hide(); + } + else + { + if ( _qt_label->isHidden() ) + _qt_label->show(); + } +} + - setProgress( progress ); +void YQProgressBar::setValue( int newValue ) +{ + YProgressBar::setValue( newValue ); + _qt_progressbar->setProgress( value() ); } + void YQProgressBar::setEnabled( bool enabled ) { _qt_label->setEnabled( enabled ); @@ -70,7 +96,7 @@ { int hintWidth = _qt_label->sizeHint().width() + margin(); - if ( _qt_label->text().isEmpty() ) + if ( ! _qt_label->isVisible() ) hintWidth = 0; return max( 200, hintWidth ); @@ -89,40 +115,6 @@ } -void YQProgressBar::setLabel( const YCPString & text ) -{ - _qt_label->setText( fromUTF8(text->value() ) ); - - if ( _qt_label->text().isEmpty() ) - { - if ( _qt_label->isVisible() ) - _qt_label->hide(); - } - else - { - if ( _qt_label->isHidden() ) - _qt_label->show(); - } -} - - -void YQProgressBar::setProgress( const YCPInteger & newProgress ) -{ - int progress = 0; - - if ( maxProgress->value() != 0 ) - { - progress = (int) ( MAX_PROGRESS * - ( (float) newProgress->value() ) / - ( (float) maxProgress->value() ) ); - - } - - _qt_progressbar->setProgress( progress ); - YProgressBar::setProgress( newProgress ); -} - - bool YQProgressBar::setKeyboardFocus() { _qt_progressbar->setFocus(); Modified: branches/tmp/sh/mod-ui/qt/src/YQProgressBar.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQProgres... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQProgressBar.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQProgressBar.h Tue Jul 3 17:50:06 2007 @@ -21,8 +21,6 @@ #define YQProgressBar_h #include <qvbox.h> -#include <ycp/YCPString.h> - #include "YProgressBar.h" @@ -38,17 +36,34 @@ /** * Constructor. **/ - YQProgressBar( QWidget * parent, - const YWidgetOpt & opt, - const YCPString & label, - const YCPInteger & maxProgress, - const YCPInteger & initialProgress ); + YQProgressBar( YWidget * parent, + const string & label, + int maxValue = 100 ); + /** + * Destructor. + **/ + virtual ~YQProgressBar(); + + /** + * Set the label (the caption above the progress bar). + * + * Reimplemented from YProgressBar. + **/ + virtual void setLabel( const string & label ); /** - * Inherited from YWidget: Sets the enabled state of the - * widget. Disabling a progress bar makes it grey + * Set the current progress value ( <= maxValue() ). + * + * Reimplemented from YProgressBar. **/ - void setEnabled( bool enabled ); + virtual void setValue( int newValue ); + + /** + * Set enabled/disabled state. + * + * Reimplemented from YWidget. + **/ + virtual void setEnabled( bool enabled ); /** * Preferred width of the widget. @@ -72,18 +87,6 @@ virtual void setSize( int newWidth, int newHeight ); /** - * Change the ProgressBar label. Calls - * YProgressBar::setLabel at the end. - **/ - void setLabel( const YCPString & label ); - - /** - * Change the progress. Calls - * YProgressBar::setProgress at the end. - **/ - void setProgress( const YCPInteger & progress ); - - /** * Accept the keyboard focus. **/ virtual bool setKeyboardFocus(); Modified: branches/tmp/sh/mod-ui/qt/src/YQUI.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI.h?re... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI.h Tue Jul 3 17:50:06 2007 @@ -452,7 +452,6 @@ YWidget * createIntField ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue); YWidget * createLogView ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines ); - YWidget * createProgressBar ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, const YCPInteger & maxProgress, const YCPInteger & currentProgress ); YWidget * createMenuButton ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); YWidget * createTable ( YWidget * parent, YWidgetOpt & opt, vector<string> header); YWidget * createTree ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); Modified: branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI_widg... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc Tue Jul 3 17:50:06 2007 @@ -35,7 +35,6 @@ #include "YQPartitionSplitter.h" #include "YQPatternSelector.h" #include "YQSimplePatchSelector.h" -#include "YQProgressBar.h" #include "YQSlider.h" #include "YQTable.h" #include "YQTime.h" @@ -123,15 +122,6 @@ return new YQTable( (QWidget *) ( parent->widgetRep() ), opt, header); } -YWidget * YQUI::createProgressBar ( YWidget * parent, - YWidgetOpt & opt, - const YCPString & label, - const YCPInteger & maxProgress, - const YCPInteger & progress ) -{ - return new YQProgressBar( (QWidget *) ( parent->widgetRep() ), opt, label, maxProgress, progress ); -} - YWidget * YQUI::createIntField ( YWidget * parent, YWidgetOpt & opt, Modified: branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWidgetF... ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Tue Jul 3 17:50:06 2007 @@ -188,7 +188,10 @@ YQProgressBar * YQWidgetFactory::createProgressBar( YWidget * parent, const string & label, int maxValue ) { - return 0; // FIXME: TO DO + YQProgressBar * progressBar = new YQProgressBar( parent, label, maxValue ); + YUI_CHECK_NEW( progressBar ); + + return progressBar; } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org