From: vsr Date: Fri, 23 Sep 2011 08:27:53 +0000 (+0000) Subject: 0021285: EDF 1877 SMESH: Color of groups is only visible on one side X-Git-Tag: V6_4_0a1~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=51dd3140f8025375d7e599a64cd2c14fdfd1bc53;p=modules%2Fgui.git 0021285: EDF 1877 SMESH: Color of groups is only visible on one side --- diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 7d86c1c29..5a3954c65 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -38,6 +38,7 @@ salomeinclude_HEADERS = \ QtxActionMgr.h \ QtxActionSet.h \ QtxActionToolMgr.h \ + QtxBiColorTool.h \ QtxColorButton.h \ QtxColorScale.h \ QtxComboBox.h \ @@ -96,6 +97,7 @@ dist_libqtx_la_SOURCES = \ QtxActionMgr.cxx \ QtxActionSet.cxx \ QtxActionToolMgr.cxx \ + QtxBiColorTool.cxx \ QtxColorButton.cxx \ QtxColorScale.cxx \ QtxComboBox.cxx \ @@ -148,6 +150,7 @@ MOC_FILES = \ QtxActionMgr_moc.cxx \ QtxActionSet_moc.cxx \ QtxActionToolMgr_moc.cxx \ + QtxBiColorTool_moc.cxx \ QtxColorButton_moc.cxx \ QtxColorScale_moc.cxx \ QtxComboBox_moc.cxx \ diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 9d0f92e36..3c9f8caa5 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -1112,6 +1112,95 @@ bool Qtx::stringToColor( const QString& str, QColor& color ) return res; } +/*! + \brief Convert bi-color value to the string representation. + + Bi-color value is specified as main color and integer delta + value that is used to calculate secondary color by changing + paremeters of the main color ("saturation" and "value" + components in HSV notation). + + The resulting string consists of two sub-strings separated by + '|' symbol. The first part represents main color + (see colorToString() for more details), the second part is a + delta value. + + Backward conversion can be done with stringToBiColor() method. + + \param color color to be converted + \param delta delta value + \return string representation of the bi-color value + + \sa stringToBiColor(), stringToColor() +*/ +QString Qtx::biColorToString( const QColor& color, const int delta ) +{ + return QString("%1|%2").arg( Qtx::colorToString( color ) ).arg( delta ); +} + +/*! + \brief Restore bi-color value from the string representation. + + Bi-color value is specified as main color and integer delta + value that is used to calculate secondary color by changing + paremeters of the main color ("saturation" and "value" + components in HSV notation). + + The parameter \a str should consist of two sub-strings separated + by '|' symbol. The first part represents main color + (see stringToColor() for more details), the second part is a + delta value. + + Backward conversion can be done with biColorToString() method. + + \param str string representation of the bi-color value + \param color resulting color value + \param delta resulting delta value + \return \c true if the conversion is successful and \c false otherwise + + \sa biColorToString(), stringToColor(), rgbSet() +*/ +bool Qtx::stringToBiColor( const QString& str, QColor& color, int& delta ) +{ + QStringList data = str.split( "|", QString::KeepEmptyParts ); + QColor c; + int d; + bool ok = data.count() > 0 && Qtx::stringToColor( data[0], c ); + bool dok = false; + if ( data.count() > 1 ) d = data[1].toInt( &dok ); + ok = ok && dok; + color = ok ? c : QColor(); + delta = ok ? d : 0; + return ok; +} + +/*! + \brief Compute secondary color value from specified main color + and delta. + + Secondary color is calculated by changing paremeters of the main + color ("saturation" and "value" components in HSV notation) using + specified delta. + + If main color is invalid, result of the function is also invalid color. + + \param color source main color + \param delta delta value + \return resulting secondary color + + \sa biColorToString(), stringToBiColor() +*/ +QColor Qtx::mainColorToSecondary( const QColor& color, int delta ) +{ + QColor cs = color; + if ( cs.isValid() ) { + int val = qMin( 255, qMax( cs.value() + delta, 0 ) ); + int sat = qMin( 255, qMax( cs.saturation() + delta-(val-cs.value()), 0 ) ); + cs.setHsv( cs.hue(), sat, val ); + } + return cs; +} + /*! \brief Dump linear gradient to the string description. \param gradient linear gradient to be converted diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index 2f7fda280..4d1b49efd 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -191,6 +191,9 @@ public: static QString colorToString( const QColor& ); static bool stringToColor( const QString&, QColor& ); + static QString biColorToString( const QColor&, const int ); + static bool stringToBiColor( const QString&, QColor&, int& ); + static QColor mainColorToSecondary( const QColor&, int ); static QString gradientToString( const QLinearGradient& ); static QString gradientToString( const QRadialGradient& ); diff --git a/src/Qtx/QtxBiColorTool.cxx b/src/Qtx/QtxBiColorTool.cxx new file mode 100644 index 000000000..1352ea520 --- /dev/null +++ b/src/Qtx/QtxBiColorTool.cxx @@ -0,0 +1,216 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: QtxBiColorTool.cxx +// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) + +#include "QtxBiColorTool.h" +#include "QtxColorButton.h" + +#include +#include +#include +#include +#include + +const int BICOLOR_MAX_DELTA = 100; + +/*! + \class QtxBiColorTool::ColorLabel + \brief Draw colored label (for secondary color) + \internal +*/ +class QtxBiColorTool::ColorLabel: public QFrame +{ +public: + ColorLabel( QWidget* parent) : QFrame( parent ) + { + setFrameStyle( QFrame::Box | QFrame::Plain ); + setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + } + ~ColorLabel() {} + QSize sizeHint() const + { + return minimumSizeHint(); + } + QSize minimumSizeHint() const + { + int pm = style()->pixelMetric(QStyle::PM_ButtonMargin); + QFontMetrics fm ( font() ); + return QSize( fm.height() + pm, fm.height() + pm ); + } + void paintEvent( QPaintEvent* e ) + { + QPainter p( this ); + drawFrame( &p ); + QRect r = contentsRect(); + if ( myColor.isValid() ) { + p.fillRect( r, QBrush( myColor ) ); + } + else { + p.fillRect( r, QBrush( palette().color( foregroundRole() ), Qt::BDiagPattern ) ); + } + p.end(); + } + void setColor( const QColor& c ) + { + myColor = c; + update(); + } + +private: + QColor myColor; +}; + +/*! + \class QtxBiColorTool + \brief Implementation of the widget managing a couple of colors. + + The main color is specified explicitly. The secondary color is calculated + by changing "value" of the main color in HSV notation to the specified delta. +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +QtxBiColorTool::QtxBiColorTool( QWidget* parent ) + : QWidget( parent ) +{ + QHBoxLayout* l = new QHBoxLayout( this ); + l->setMargin( 0 ); + l->setSpacing( 5 ); + + myMainColor = new QtxColorButton( this ); + myMainColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + myExtraText = new QLabel( this ); + myRuler = new QSlider( Qt::Horizontal, this ); + myRuler->setMinimum( -BICOLOR_MAX_DELTA ); + myRuler->setMaximum( +BICOLOR_MAX_DELTA ); + myRuler->setSingleStep( 1 ); + myRuler->setPageStep( 10 ); + myRuler->setValue( 0 ); + myRuler->setTickPosition( QSlider::NoTicks ); + myDelta = new ColorLabel( this ); + + l->addWidget( myMainColor ); + l->addWidget( myExtraText ); + l->addWidget( myRuler ); + l->addWidget( myDelta ); + + connect( myMainColor, SIGNAL( changed( QColor ) ), this, SLOT( updateState() ) ); + connect( myRuler, SIGNAL( valueChanged( int ) ), this, SLOT( updateState() ) ); + + updateState(); +} + +/*! + \brief Destructor. +*/ +QtxBiColorTool::~QtxBiColorTool() +{ +} + +/*! + \brief Get currently selected main color + + Returns invalid QColor if no color is selected. + + \return selected main color + \sa setMainColor() +*/ +QColor QtxBiColorTool::mainColor() const +{ + return myMainColor->color(); +} + +/*! + \brief Set main color. + \param c color to be set as current main color + \sa mainColor() +*/ +void QtxBiColorTool::setMainColor( const QColor& c ) +{ + myMainColor->setColor( c ); + updateState(); +} + +/*! + \brief Get current value delta for the secondary color + \return curent color value delta + \sa setDelta(), secondaryColor() +*/ +int QtxBiColorTool::delta() const +{ + return myRuler->value(); +} + +/*! + \brief Set value delta for the secondary color + \param d new color value delta + \sa delta(), secondaryColor() +*/ +void QtxBiColorTool::setDelta( int d ) +{ + myRuler->setValue( d ); + updateState(); +} + +/*! + \brief Get secondary color. + + Returns invalid QColor if no main color is selected. + Secondary color is calculated by changing "value" of the main color + in HSV notation to the specified delta. + + \return secondary color + \sa mainColor(), setMainColor(), delta(), setDelta() +*/ +QColor QtxBiColorTool::secondaryColor() const +{ + return Qtx::mainColorToSecondary( mainColor(), delta() ); +} + +/*! + \brief Returns auxiliary text assigned to the widget + \return current widget text + \sa setText() +*/ +QString QtxBiColorTool::text() const +{ + return myExtraText->text(); +} + +/*! + \brief Assign auxiliary text to the widet + \param txt new widget text + \sa text() +*/ +void QtxBiColorTool::setText( const QString& txt ) +{ + myExtraText->setText( txt ); +} + +/*! + \brief Update widget state +*/ +void QtxBiColorTool::updateState() +{ + myDelta->setColor( secondaryColor() ); +} diff --git a/src/Qtx/QtxBiColorTool.h b/src/Qtx/QtxBiColorTool.h new file mode 100644 index 000000000..d0053dbaa --- /dev/null +++ b/src/Qtx/QtxBiColorTool.h @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: QtxBiColorTool.h +// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) + +#ifndef QTXBICOLORTOOL_H +#define QTXBICOLORTOOL_H + +#include "Qtx.h" + +#include +#include + +class QLabel; +class QSlider; +class QtxColorButton; + +class QTX_EXPORT QtxBiColorTool : public QWidget +{ + class ColorLabel; + + Q_OBJECT + +public: + QtxBiColorTool( QWidget* = 0 ); + virtual ~QtxBiColorTool(); + + QColor mainColor() const; + void setMainColor( const QColor& ); + + int delta() const; + void setDelta( int ); + + QColor secondaryColor() const; + + QString text() const; + void setText( const QString& ); + + static QColor mainColorToSecondary( const QColor&, int ); + +private slots: + void updateState(); + +private: + QtxColorButton* myMainColor; + QLabel* myExtraText; + QSlider* myRuler; + ColorLabel* myDelta; +}; + +#endif // QTXBICOLORTOOL_H diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 873ce5d8b..5a768e43c 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -28,6 +28,7 @@ #include "QtxComboBox.h" #include "QtxIntSpinBox.h" #include "QtxColorButton.h" +#include "QtxBiColorTool.h" #include "QtxDoubleSpinBox.h" #include "QtxShortcutEdit.h" #include "QtxResourceMgr.h" @@ -3506,6 +3507,109 @@ void QtxPagePrefColorItem::retrieve() myColor->setColor( getColor() ); } +/*! + \class QtxPagePrefBiColorItem + \brief GUI implementation of the resources item to store a bi-color value. + + The main color is specified explicitly. The secondary color is calculated + by changing "value" and "saturation" parameters of the main color in the + HSV notation using specified delta. +*/ + +/*! + \brief Constructor. + \param title preference item title + \param parent parent preference item + \param sect resource file section associated with the preference item + \param param resource file parameter associated with the preference item +*/ +QtxPagePrefBiColorItem::QtxPagePrefBiColorItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myColors = new QtxBiColorTool( 0 ) ); +} + +/*! + \brief Destructor. +*/ +QtxPagePrefBiColorItem::~QtxPagePrefBiColorItem() +{ +} + +/*! + \bried Get auxiliary text + \return text assigned to the item + \sa setText() +*/ +QString QtxPagePrefBiColorItem::text() const +{ + return myColors->text(); +} + +/*! + \bried Set auxiliary text + \param t text being assigned to the item + \sa text() +*/ +void QtxPagePrefBiColorItem::setText( const QString& t ) +{ + myColors->setText( t ); +} + +/*! + \brief Store preference item to the resource manager. + \sa retrieve() +*/ +void QtxPagePrefBiColorItem::store() +{ + setString( Qtx::biColorToString( myColors->mainColor(), myColors->delta() ) ); +} + +/*! + \brief Retrieve preference item from the resource manager. + \sa store() +*/ +void QtxPagePrefBiColorItem::retrieve() +{ + QColor c; + int d; + Qtx::stringToBiColor( getString(), c, d ); + myColors->setMainColor( c ); + myColors->setDelta( d ); +} + +/*! + \brief Get preference item option value. + \param name option name + \return property value or null QVariant if option is not set + \sa setOptionValue() +*/ +QVariant QtxPagePrefBiColorItem::optionValue( const QString& name ) const +{ + if ( name == "text" ) + return text(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +/*! + \brief Set preference item option value. + \param name option name + \param val new property value + \sa optionValue() +*/ +void QtxPagePrefBiColorItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "text" ) + { + if ( val.canConvert( QVariant::String ) ) + setText( val.toString() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + /*! \class QtxPagePrefFontItem \brief GUI implementation of the resources font item. diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 55c7334d5..db472ada6 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -38,6 +38,7 @@ class QtxFontEdit; class QtxGroupBox; class QtxComboBox; class QtxColorButton; +class QtxBiColorTool; class QtxShortcutEdit; class QtxShortcutTree; @@ -457,7 +458,7 @@ protected: virtual void setOptionValue( const QString&, const QVariant& ); private slots: - void setIcon( int ); + void setIcon( int ); private: void updateSlider(); @@ -587,6 +588,27 @@ private: QtxColorButton* myColor; }; +class QTX_EXPORT QtxPagePrefBiColorItem : public QtxPageNamedPrefItem +{ +public: + QtxPagePrefBiColorItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefBiColorItem(); + + virtual QString text() const; + virtual void setText( const QString& ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + QtxBiColorTool* myColors; +}; + class QTX_EXPORT QtxPagePrefFontItem : public QObject, public QtxPageNamedPrefItem { Q_OBJECT diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx index eaa30e747..bf43e57d6 100644 --- a/src/SUIT/SUIT_PreferenceMgr.cxx +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -157,6 +157,9 @@ int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, case ShortcutTree: item = new QtxPagePrefShortcutTreeItem( title, parent, sect, param ); break; + case BiColor: + item = new QtxPagePrefBiColorItem( title, parent, sect, param ); + break; case UserDefined: item = new QtxUserDefinedItem(parent); break; diff --git a/src/SUIT/SUIT_PreferenceMgr.h b/src/SUIT/SUIT_PreferenceMgr.h index e15319e5e..5a196f7f4 100644 --- a/src/SUIT/SUIT_PreferenceMgr.h +++ b/src/SUIT/SUIT_PreferenceMgr.h @@ -37,7 +37,7 @@ class SUIT_EXPORT SUIT_PreferenceMgr : public QtxPagePrefMgr public: typedef enum { Auto, Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, - GroupBox, Tab, Frame, Font, DirList, File, Slider, Shortcut, ShortcutTree, + GroupBox, Tab, Frame, Font, DirList, File, Slider, Shortcut, ShortcutTree, BiColor, UserDefined = 1000 } PrefItemType; public: