QtxActionMgr.h \
QtxActionSet.h \
QtxActionToolMgr.h \
+ QtxBiColorTool.h \
QtxColorButton.h \
QtxColorScale.h \
QtxComboBox.h \
QtxActionMgr.cxx \
QtxActionSet.cxx \
QtxActionToolMgr.cxx \
+ QtxBiColorTool.cxx \
QtxColorButton.cxx \
QtxColorScale.cxx \
QtxComboBox.cxx \
QtxActionMgr_moc.cxx \
QtxActionSet_moc.cxx \
QtxActionToolMgr_moc.cxx \
+ QtxBiColorTool_moc.cxx \
QtxColorButton_moc.cxx \
QtxColorScale_moc.cxx \
QtxComboBox_moc.cxx \
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
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& );
--- /dev/null
+// 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 <QHBoxLayout>
+#include <QLabel>
+#include <QPainter>
+#include <QSlider>
+#include <QStyle>
+
+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() );
+}
--- /dev/null
+// 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 <QColor>
+#include <QWidget>
+
+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
#include "QtxComboBox.h"
#include "QtxIntSpinBox.h"
#include "QtxColorButton.h"
+#include "QtxBiColorTool.h"
#include "QtxDoubleSpinBox.h"
#include "QtxShortcutEdit.h"
#include "QtxResourceMgr.h"
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.
class QtxGroupBox;
class QtxComboBox;
class QtxColorButton;
+class QtxBiColorTool;
class QtxShortcutEdit;
class QtxShortcutTree;
virtual void setOptionValue( const QString&, const QVariant& );
private slots:
- void setIcon( int );
+ void setIcon( int );
private:
void updateSlider();
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
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;
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: