QtxActionMgr.h \
QtxActionSet.h \
QtxActionToolMgr.h \
+ QtxBackgroundTool.h \
QtxBiColorTool.h \
QtxColorButton.h \
QtxColorScale.h \
QtxActionMgr.cxx \
QtxActionSet.cxx \
QtxActionToolMgr.cxx \
+ QtxBackgroundTool.cxx \
QtxBiColorTool.cxx \
QtxColorButton.cxx \
QtxColorScale.cxx \
QtxActionMgr_moc.cxx \
QtxActionSet_moc.cxx \
QtxActionToolMgr_moc.cxx \
+ QtxBackgroundTool_moc.cxx \
QtxBiColorTool_moc.cxx \
QtxColorButton_moc.cxx \
QtxColorScale_moc.cxx \
#include <QCompleter>
#include <QApplication>
#include <QDesktopWidget>
-#include <QLinearGradient>
-#include <QRadialGradient>
-#include <QConicalGradient>
#include <QtDebug>
#include <stdio.h>
#define BICOLOR_CHANGE_HUE
+/*!
+ \brief Auxiliary function converting string \a str to the integer value.
+ Parameter \a defVal specifies default value that is returned if conversion can't be done.
+ Parameters \a minVal and \a maxVal limit the resulting value.
+ \param str string being converted
+ \param defVal default value
+ \param minVal minimum allowed value
+ \param maxVal maximum allowed value
+ \return integer value obtained from the string
+ \internal
+*/
+static int stringToInt( const QString& str, int defVal, int minVal, int maxVal )
+{
+ bool ok;
+ int v = str.toInt( &ok );
+ if ( !ok ) v = defVal;
+ return qMin( qMax( v, minVal ), maxVal );
+}
+
/*!
\class Qtx
\brief A set of helpful utility functions.
{
bool success = false;
QStringList vals = str.split( "|", QString::SkipEmptyParts );
- if ( ( vals.count() > 5 && vals[0] == "radial" ) || vals[0] == "rg" )
+ if ( vals.count() > 5 && ( vals[0] == "radial" || vals[0] == "rg" ) )
{
// center, radius and focal point
double cx, cy, r, fx, fy;
{
bool success = false;
QStringList vals = str.split( "|", QString::SkipEmptyParts );
- if ( ( vals.count() > 3 && vals[0] == "conical" ) || vals[0] == "cg" )
+ if ( vals.count() > 3 && ( vals[0] == "conical" || vals[0] == "cg" ) )
{
// center and angle
double cx, cy, a;
return success;
}
+/*!
+ \brief Convert background data to the string representation.
+ The resulting string consists of several sub-strings separated by ';' symbol.
+ These sub-strings represent:
+ 1. background type (enumerator, see Qtx::BackgroundMode)
+ 2. texture image file name (string)
+ 3. texture mode (enumerator, see Qtx::TextureMode)
+ 4. first color (for simple gradient data) or solid color (for single-colored mode)
+ 5. second color (for simple gradient data)
+ 6. type of simple gradient (some integer identifier)
+ 7. complex gradient data (for custom gradient mode)
+ Each sub-string consists of keyword/value couple, in form of "<keyword>=<value>".
+
+ Backward conversion can be done with stringToBackground() method.
+
+ \param bgData background data
+ \return string representation of the background data
+
+ \sa stringToBackground()
+*/
+QString Qtx::backgroundToString( const Qtx::BackgroundData& bgData )
+{
+ const QString dtSep = ";";
+ const QString kwSep = "=";
+ const QString kwBgType = "bt";
+ const QString kwFileName = "fn";
+ const QString kwTextureMode = "tm";
+ const QString kwFirstColor = "c1";
+ const QString kwSecondColor = "c2";
+ const QString kwGrType = "gt";
+ const QString kwGrData = "gr";
+
+ Qtx::BackgroundMode bgMode = bgData.mode();
+ QString fileName;
+ Qtx::TextureMode textureMode = bgData.texture( fileName );
+ QColor c1, c2;
+ int gradientType = bgData.gradient( c1, c2 );
+ const QGradient* gradient = bgData.gradient();
+ QString grString;
+ if ( gradient ) {
+ switch ( gradient->type() ) {
+ case QGradient::LinearGradient:
+ grString = gradientToString( *(static_cast<const QLinearGradient*>( gradient )) );
+ break;
+ case QGradient::RadialGradient:
+ grString = gradientToString( *(static_cast<const QRadialGradient*>( gradient )) );
+ break;
+ case QGradient::ConicalGradient:
+ grString = gradientToString( *(static_cast<const QConicalGradient*>( gradient )) );
+ break;
+ default:
+ break;
+ }
+ }
+ QStringList data;
+ data << QString( "%1%2%3" ).arg( kwBgType ).arg( kwSep ).arg( (int)bgMode );
+ data << QString( "%1%2%3" ).arg( kwFileName ).arg( kwSep ).arg( fileName );
+ data << QString( "%1%2%3" ).arg( kwTextureMode ).arg( kwSep ).arg( (int)textureMode );
+ data << QString( "%1%2%3" ).arg( kwFirstColor ).arg( kwSep ).arg( Qtx::colorToString( c1 ) );
+ data << QString( "%1%2%3" ).arg( kwSecondColor ).arg( kwSep ).arg( Qtx::colorToString( c2 ) );
+ data << QString( "%1%2%3" ).arg( kwGrType ).arg( kwSep ).arg( gradientType );
+ data << QString( "%1%2%3" ).arg( kwGrData ).arg( kwSep ).arg( grString );
+
+ return data.join( dtSep );
+}
+
+/*!
+ \brief Restore background data from the string representation.
+
+ The string should consist of several sub-strings separated by ';' symbol.
+ Each sub-string consists of keyword/value couple, in form of "<keyword>=<value>".
+ The sub-strings can follow in arbitrary order, some keywords might be missed.
+ The background data is described by the following values:
+ - background type (enumerator, see Qtx::BackgroundMode), keyword "bt"
+ - texture image file name (string), keyword "fn"
+ - texture mode (enumerator, see Qtx::TextureMode), keyword "tm"
+ - first color (for simple gradient data) or solid color (for single-colored mode), keyword "c1"
+ - second color (for simple gradient data), keyword "c2"
+ - name of gradient type (string), keyword "gt"
+ - complex gradient data (for custom gradient mode), keyword "gr"
+
+ Also, for backward compatibility, background data can be represented by
+ single color value, see stringToColor().
+
+ Backward conversion can be done with backgroundToString() method.
+ Returns invalid background if conversion could not be done.
+
+ \code
+ Qtx::BackgroundData bgData = Qtx::stringToBackground( str );
+ if ( bgData.isValid() ) ) doSomething( bgData );
+ \endcode
+
+ \param theString string representation of the background data
+ \return resulting background data (invalid if conversion has failed)
+
+ \sa backgroundToString()
+*/
+
+Qtx::BackgroundData Qtx::stringToBackground( const QString& str )
+{
+ const QString dtSep = ";";
+ const QString kwSep = "=";
+ const QString kwBgType = "bt";
+ const QString kwFileName = "fn";
+ const QString kwTextureMode = "tm";
+ const QString kwFirstColor = "c1";
+ const QString kwSecondColor = "c2";
+ const QString kwGrType = "gt";
+ const QString kwGrData = "gr";
+
+ Qtx::BackgroundData bgData = BackgroundData();
+
+ QStringList data = str.split( dtSep, QString::KeepEmptyParts );
+
+ QColor c;
+ if ( data.count() == 1 && !data.contains( kwSep ) && stringToColor( data[0], c ) ) {
+ // solid color mode, for backward compatibility
+ bgData.setColor( c );
+ }
+ else {
+ QMap<QString, QString> dmap;
+ // background data
+ foreach( QString d, data ) {
+ QStringList items = d.split( kwSep, QString::KeepEmptyParts );
+ if ( items.count() > 0 ) {
+ QString kw = items.takeFirst().trimmed().toLower(); // keyword
+ QString val = items.join( kwSep ).trimmed(); // if value contains "=" symbol, we have to restore it
+ dmap[ kw ] = val;
+ }
+ }
+ QString bgMode = dmap.value( kwBgType, QString() );
+ QString fileName = dmap.value( kwFileName, QString() );
+ QString textureMode = dmap.value( kwTextureMode, QString() );
+ QString color1 = dmap.value( kwFirstColor, QString() );
+ QString color2 = dmap.value( kwSecondColor, QString() );
+ QString gradientType = dmap.value( kwGrType, QString() );
+ QString gradient = dmap.value( kwGrData, QString() );
+
+ // try texture mode
+ if ( !fileName.isEmpty() || !textureMode.isEmpty() ) {
+ Qtx::TextureMode m = (Qtx::TextureMode)( stringToInt( textureMode, Qtx::CenterTexture,
+ Qtx::CenterTexture, Qtx::StretchTexture ) );
+ bgData.setTexture( fileName, m );
+ }
+ QColor c1, c2;
+ // try color mode
+ bool ok = Qtx::stringToColor( color1, c1 );
+ if ( ok ) {
+ bgData.setColor( c1 );
+ }
+ // try simple gradient mode
+ ok = Qtx::stringToColor( color2, c2 );
+ if ( ok || !gradientType.isEmpty() ) {
+ int gt = gradientType.toInt( &ok );
+ bgData.setGradient( ok ? gt : -1, c1, c2 );
+ }
+ // try custom gradient mode
+ QLinearGradient lg;
+ QConicalGradient cg;
+ QRadialGradient rg;
+ ok = Qtx::stringToLinearGradient( gradient, lg );
+ if ( ok ) {
+ bgData.setGradient( lg );
+ }
+ ok = Qtx::stringToRadialGradient( gradient, rg );
+ if ( ok ) {
+ bgData.setGradient( rg );
+ }
+ ok = Qtx::stringToConicalGradient( gradient, cg );
+ if ( ok ) {
+ bgData.setGradient( cg );
+ }
+
+ // finally set backround mode
+ Qtx::BackgroundMode m = (Qtx::BackgroundMode)( stringToInt( bgMode, Qtx::ColorBackground,
+ Qtx::ImageBackground, Qtx::CustomGradientBackground ) );
+ bgData.setMode( m );
+ }
+
+ return bgData;
+}
+
/*!
\class Qtx::Localizer
\brief Localization helper
setlocale( LC_NUMERIC, myCurLocale.toLatin1().constData() );
}
+/*!
+ \class Qtx::BackgroundData
+ \brief Stores background data
+
+ This class is used to store background data. Depending on the mode,
+ the background can be specified by:
+ - image (by assigning the file name to be used as background texture), see setTexture()
+ - single color (by assigning any color), see setColor()
+ - simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& )
+ - complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& )
+ The class stores all the data passed to it, so switching between different modes can be done
+ just by calling setMode() function.
+
+ \note Two-color gradient is specified by two colors and integer identifier. The interpretation of
+ this identifier should be done in the calling code.
+
+ \code
+ Qtx::BackgroundData bg;
+ bg.setTexture( "/data/images/background.png" ); // bg is switched to Qtx::ImageBackground mode
+ bg.setColor( QColor(100, 100, 100) ); // bg is switched to Qtx::ColorBackground mode
+ bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to Qtx::ColorBackground mode
+ QLinearGradient grad( 0,0,1,1 );
+ grad.setColorAt( 0.0, Qt::gray );
+ grad.setColorAt( 0.5, Qt::white );
+ grad.setColorAt( 1.0, Qt::green );
+ grad.setSpread( QGradient::PadSpread );
+ bg.setGradient( grad ); // bg is switched to Qtx::CustomGradientBackground mode
+ bg.setMode( Qtx::ColorBackground ); // bg is switched back to Qtx::ColorBackground mode
+ \endcode
+*/
+
+/*!
+ \brief Default constructor.
+ Creates invalid background data.
+*/
+Qtx::BackgroundData::BackgroundData()
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+{
+ setMode( Qtx::NoBackground );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the specified color
+ \param c color
+*/
+Qtx::BackgroundData::BackgroundData( const QColor& c )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+{
+ setColor( c );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the specified two-color gradient
+ \param type gradient type identifier
+ \param c1 first gradient color
+ \param c2 second gradient color
+ \note the interpretation of the gradient identifier should be done in the calling code
+*/
+Qtx::BackgroundData::BackgroundData( int type, const QColor& c1, const QColor& c2 )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+{
+ setGradient( type, c1, c2 );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the arbirtary gradient data
+ \param grad gradient data
+*/
+Qtx::BackgroundData::BackgroundData( const QGradient& grad )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+{
+ setGradient( grad );
+}
+
+/*!
+ \brief Destructor.
+*/
+Qtx::BackgroundData::~BackgroundData()
+{
+}
+
+/*!
+ \brief Compares two background data objects
+*/
+bool Qtx::BackgroundData::operator==( const Qtx::BackgroundData& other ) const
+{
+ return
+ ( myMode == other.myMode ) &&
+ ( myTextureMode == other.myTextureMode ) &&
+ ( myFileName == other.myFileName ) &&
+ ( myColors == other.myColors ) &&
+ ( myGradientType == other.myGradientType ) &&
+ ( myGradient == other.myGradient );
+}
+
+/*!
+ \brief Returns \c false if background data is not set (invalid)
+ \return \c true if background data is valid or \c false otherwise
+ \sa mode()
+*/
+bool Qtx::BackgroundData::isValid() const
+{
+ return myMode != Qtx::NoBackground;
+}
+
+/*!
+ \brief Get background mode
+ \return current background mode
+ \sa setMode()
+*/
+Qtx::BackgroundMode Qtx::BackgroundData::mode() const
+{
+ return myMode;
+}
+
+/*!
+ \brief Set background mode
+ \param m background mode being set
+ \sa mode()
+*/
+void Qtx::BackgroundData::setMode( const Qtx::BackgroundMode m )
+{
+ myMode = m;
+}
+
+/*!
+ \brief Get file name used as a texture image
+ \return path to the texture image file
+ \sa setTexture(), mode()
+*/
+Qtx::TextureMode Qtx::BackgroundData::texture( QString& fileName ) const
+{
+ fileName = myFileName;
+ return myTextureMode;
+}
+
+/*!
+ \brief Set file name to be used as a texture image and switch to the Qtx::ImageBackground mode
+ \param fileName path to the texture image file name
+ \param m texture mode (Qtx::CenterTexture by default)
+ \sa texture(), mode()
+*/
+void Qtx::BackgroundData::setTexture( const QString& fileName, const Qtx::TextureMode m )
+{
+ myFileName = fileName;
+ myTextureMode = m;
+ setMode( Qtx::ImageBackground );
+}
+
+/*!
+ \brief Get background color. Returns null QColor if color is not set
+ \return solid background color
+ \sa setColor(), mode()
+*/
+QColor Qtx::BackgroundData::color() const
+{
+ return myColors.count() > 0 ? myColors[0] : QColor();
+}
+
+/*!
+ \brief Set background color and switch to the Qtx::ColorBackground mode
+ \param c color
+ \sa color(), mode()
+*/
+void Qtx::BackgroundData::setColor( const QColor& c )
+{
+ myColors.clear();
+ myColors << c;
+ setMode( Qtx::ColorBackground );
+}
+
+/*!
+ \brief Get simple gradient data.
+ Returns -1 and null QColor for \a c1 and \a c2 if gradient data is not set
+ \param c1 first gradient color is returned via this parameter
+ \param c2 second gradient color is returned via this parameter
+ \return current two-colored gradient mode type identifier
+ \note the interpretation of the gradient identifier should be done in the calling code
+ \sa setGradient(int, const QColor&, const QColor&), mode()
+*/
+int Qtx::BackgroundData::gradient( QColor& c1, QColor& c2 ) const
+{
+ c1 = myColors.count() > 0 ? myColors[0] : QColor();
+ c2 = myColors.count() > 1 ? myColors[1] : ( myColors.count() > 0 ? myColors[0] : QColor() );
+ return myGradientType;
+}
+
+/*!
+ \brief Set simple background gradient data and switch to the Qtx::SimpleGradientBackground mode
+ \param type two-colored gradient mode type identifier
+ \param c1 first gradient color is returned via this parameter
+ \param c2 second gradient color is returned via this parameter
+ \note the interpretation of the gradient identifier should be done in the calling code
+ \sa gradient(QColor&, QColor&), mode()
+*/
+void Qtx::BackgroundData::setGradient( int type, const QColor& c1, const QColor& c2 )
+{
+ myColors.clear();
+ myColors << c1 << c2;
+ myGradientType = type;
+ setMode( Qtx::SimpleGradientBackground );
+}
+
+/*!
+ \brief Get complex gradient data.
+ Returns QGradient of QGradient::NoGradient if gradient data is not set
+ \note This function does not transform simple gradient data set with
+ setGradient( const QString&, const QColor&, const QColor& ) to QGradient class
+ \return gradient data
+ \sa setGradient(const QGradient&), mode()
+*/
+const QGradient* Qtx::BackgroundData::gradient() const
+{
+ return &myGradient;
+}
+
+/*!
+ \brief Set complex background gradient data and switch to the Qtx::CustomGradientBackground mode
+ \param grad gradient data (QLinearGradient, QRadialGradient or QConicalGradient)
+ \sa gradient(), mode()
+*/
+void Qtx::BackgroundData::setGradient( const QGradient& grad )
+{
+ myGradient = grad;
+ setMode( Qtx::CustomGradientBackground );
+}
+
+
#ifndef WIN32
#include <X11/Xlib.h>
#include <QColor>
#include <QImage>
#include <QPixmap>
+#include <QGradient>
class QObject;
class QWidget;
class QCompleter;
-class QLinearGradient;
-class QRadialGradient;
-class QConicalGradient;
typedef QList<int> QIntList; //!< list of int values
typedef QList<short> QShortList; //!< list of short int values
ShowAll = ShowText | ShowIcon //!< Show icon and text in the header
} HeaderViewFlags;
- //Type of the custom data
+ //! Type of the custom data (for custom tree model)
typedef enum {
IdType
} CustomDataType;
-
-
+
+ //! Background mode
+ typedef enum {
+ NoBackground, // no (invalid) background data
+ ImageBackground, // image (texture)
+ ColorBackground, // single color
+ SimpleGradientBackground, // simple two-color gradient
+ CustomGradientBackground // custom (complex) gradient
+ } BackgroundMode;
+
+ //! Texture mode
+ typedef enum {
+ CenterTexture, // center texture
+ TileTexture, // tile texture
+ StretchTexture, // stretch texture
+ } TextureMode;
class QTX_EXPORT Localizer
{
QString myCurLocale;
};
+ class QTX_EXPORT BackgroundData
+ {
+ public:
+ BackgroundData();
+ BackgroundData( const QColor& );
+ BackgroundData( int, const QColor&, const QColor& );
+ BackgroundData( const QGradient& );
+ virtual ~BackgroundData();
+
+ bool operator==( const BackgroundData&) const;
+ inline bool operator!=( const BackgroundData& other ) const
+ { return !operator==( other ); }
+
+ bool isValid() const;
+
+ BackgroundMode mode() const;
+ void setMode( const BackgroundMode );
+
+ TextureMode texture( QString& ) const;
+ void setTexture( const QString&, TextureMode = Qtx::CenterTexture );
+
+ QColor color() const;
+ void setColor( const QColor& );
+
+ int gradient( QColor&, QColor& ) const;
+ void setGradient( int, const QColor&, const QColor& );
+
+ const QGradient* gradient() const;
+ void setGradient( const QGradient& );
+
+ private:
+ BackgroundMode myMode;
+ TextureMode myTextureMode;
+ QString myFileName;
+ QColorList myColors;
+ int myGradientType;
+ QGradient myGradient;
+ };
+
static QString toQString( const char*, const int = -1 );
static QString toQString( const short*, const int = -1 );
static QString toQString( const unsigned char*, const int = -1 );
static bool stringToRadialGradient( const QString&, QRadialGradient& );
static bool stringToConicalGradient( const QString&, QConicalGradient& );
+ static QString backgroundToString( const BackgroundData& );
+ static BackgroundData stringToBackground( const QString& );
+
#ifndef WIN32
static void* getDisplay();
static Qt::HANDLE getVisual();
--- /dev/null
+// Copyright (C) 2007-2012 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: QtxBackgroundTool.cxx
+// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+
+#include "QtxBackgroundTool.h"
+
+#include <QComboBox>
+#include <QFileDialog>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QStackedWidget>
+#include <QVBoxLayout>
+#include <QtxColorButton.h>
+
+/*!
+ \class QtxBackgroundTool
+ \brief Implementation of the widget managing background data
+
+ The background data can be specified as:
+ - image (by assigning the file name to be used as background texture)
+ - single color (by assigning any color)
+ - simple two-color gradient (with the gradient type id and two colors)
+ - complex gradient (by assigning arbitrary gradient data) (NOT IMPLEMENTED YET)
+
+ To enable / disable any background type, setModeAllowed() function can be used.
+ Widget's orientation can be specified via the constructor parameter of changed with
+ setOrientation() function.
+
+ To specify two-color gradient modes, use setGradient() function. By default, no gradient modes
+ are provided by the widget.
+
+ Arbitrary gradient mode is not implemented yet, it is remaining for future improvement.
+
+ Typical usage can be as follows:
+ \code
+ // create tool widget
+ QtxBackgroundTool* tool = new QtxBackgroundTool( Qt::Vertical, this );
+ // assign gradients types
+ QStringList sl;
+ sl << "Horizontal" << "Vertical" << "First diagonal" << "Second diagonal";
+ tool->setGradients(sl);
+ // disable image texture and custom gradient modes
+ tool->setModeAllowed(Qtx::ImageBackground, false);
+ tool->setModeAllowed(Qtx::CustomGradientBackground, false);
+ // initialize widget with the some background data
+ tool->setData( bgData );
+ \endcode
+
+ \todo Complete support of custom gradient (QLinearGradient, QRadialGradient, QConicalGradient).
+ \sa Qtx::BackgroundData, QtxBackgroundDialog, Qtx::stringToBackground(), Qtx::backgroundToString()
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent widget
+*/
+QtxBackgroundTool::QtxBackgroundTool( QWidget* parent )
+ : QWidget( parent ), myLastGradient( -1 )
+{
+ init( Qt::Horizontal );
+}
+
+/*!
+ \brief Constructor.
+ \param o widget orientation
+ \param parent parent widget
+*/
+QtxBackgroundTool::QtxBackgroundTool( Qt::Orientation o, QWidget* parent )
+ : QWidget( parent ), myLastGradient( -1 )
+{
+ init( o );
+}
+
+/*!
+ \brief Perform internal initialization
+*/
+void QtxBackgroundTool::init( Qt::Orientation o )
+{
+ // mode combo box
+ myModeCombo = new QComboBox( this );
+ // sub-widgets container
+ myContainer = new QStackedWidget( this );
+
+ QWidget* wrap;
+ QHBoxLayout* wrapLayout;
+
+ // add image controls
+ wrap = new QWidget( this );
+ wrapLayout = new QHBoxLayout( wrap );
+ wrapLayout->setMargin( 0 );
+ wrapLayout->setSpacing( 5 );
+ myFileName = new QLineEdit( wrap );
+ myBrowseBtn = new QPushButton( tr( "Browse..." ), wrap );
+ myTextureMode = new QComboBox( wrap );
+ wrapLayout->addWidget( myFileName );
+ wrapLayout->addWidget( myBrowseBtn );
+ wrapLayout->addWidget( myTextureMode );
+ myContainer->addWidget( wrap ); // Image
+ // add color controls
+ wrap = new QWidget( this );
+ wrapLayout = new QHBoxLayout( wrap );
+ wrapLayout->setMargin( 0 );
+ wrapLayout->setSpacing( 5 );
+ myFirstColor = new QtxColorButton( wrap );
+ mySecondColor = new QtxColorButton( wrap );
+ wrapLayout->addWidget( myFirstColor );
+ wrapLayout->addWidget( mySecondColor );
+ myContainer->addWidget( wrap ); // Color
+ // add gradient controls ... NOT IMPLEMENTED YET
+ wrap = new QWidget( this );
+ wrapLayout = new QHBoxLayout( wrap );
+ wrapLayout->setMargin( 0 );
+ wrapLayout->setSpacing( 5 );
+ QLabel* foo = new QLabel( tr( "Not implemented yet" ), wrap );
+ foo->setAlignment( Qt::AlignCenter );
+ wrapLayout->addWidget( foo );
+ myContainer->addWidget( wrap ); // Gradient
+
+ // initialize widget
+ myFirstColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ mySecondColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ myTextureMode->addItem( tr( "Center" ), Qtx::CenterTexture );
+ myTextureMode->addItem( tr( "Tile" ), Qtx::TileTexture );
+ myTextureMode->addItem( tr( "Stretch" ), Qtx::StretchTexture );
+
+ connect( myModeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateState() ) );
+ connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browse() ) );
+
+ setModeAllowed( Qtx::ImageBackground );
+ setModeAllowed( Qtx::ColorBackground );
+ setModeAllowed( Qtx::SimpleGradientBackground );
+ setModeAllowed( Qtx::CustomGradientBackground );
+ setImageFormats( QString() );
+ setOrientation( o );
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxBackgroundTool::~QtxBackgroundTool()
+{
+}
+
+/*!
+ \brief Get background data from the widget
+ \return background data
+ \sa setData()
+*/
+Qtx::BackgroundData QtxBackgroundTool::data() const
+{
+ Qtx::BackgroundData bgData;
+ int idx = myModeCombo->currentIndex();
+ if ( idx != -1 ) {
+ // get currently selected mode
+ int id = myModeCombo->itemData( idx, TypeRole ).toInt();
+ // texture data
+ if ( isModeAllowed( Qtx::ImageBackground ) ) {
+ bgData.setTexture( myFileName->text().trimmed(),
+ Qtx::TextureMode( myTextureMode->itemData( myTextureMode->currentIndex() ).toInt() ) );
+ }
+ // single-color data
+ if ( isModeAllowed( Qtx::ColorBackground ) ) {
+ bgData.setColor( myFirstColor->color() );
+ }
+ // simple two-color gradient data
+ if ( isModeAllowed( Qtx::SimpleGradientBackground ) ) {
+ bgData.setGradient( myLastGradient, myFirstColor->color(), mySecondColor->color() );
+ }
+ // custom gradient data
+ if ( isModeAllowed( Qtx::CustomGradientBackground ) ) {
+ // bgData.setGradient( ... );
+ // NOT IMPLEMENTED YET
+ }
+
+ // set current mode
+ bgData.setMode( Qtx::BackgroundMode( id ) );
+ }
+ return bgData;
+}
+
+/*!
+ \brief Set background data from the widget
+ \param bgData background data being set to the widget
+ \sa data()
+*/
+void QtxBackgroundTool::setData( const Qtx::BackgroundData& bgData )
+{
+ Qtx::BackgroundMode m = bgData.mode();
+ QColor c1, c2;
+ int gtype = bgData.gradient( c1, c2 );
+ QString fileName;
+ int tmode = bgData.texture( fileName );
+ // texture data
+ myFileName->setText( fileName );
+ myTextureMode->setCurrentIndex( tmode );
+ // color / simple gradient data
+ myFirstColor->setColor( c1 );
+ mySecondColor->setColor( c2 );
+ // gradient data
+ // ... NOT IMPLEMENTED YET
+
+ // set current index
+ int idx = -1;
+ for ( int i = 0; i < myModeCombo->count() && idx == -1; i++ ) {
+ int im = myModeCombo->itemData( i, TypeRole ).toInt();
+ // for simple gradient mode we also check gradient type
+ if ( m == Qtx::SimpleGradientBackground && im == Qtx::SimpleGradientBackground ) {
+ int it = myModeCombo->itemData( i, IdRole ).toInt();
+ if ( it == gtype ) idx = i;
+ }
+ // for other modes we just check mode itself
+ else if ( im == m ) idx = i;
+ }
+ myModeCombo->setCurrentIndex( idx );
+}
+
+/*!
+ \brief Get allowed two-color gradients to the widget
+ \param gradients gradients names are returned via this parameter
+ \param ids gradients identifiers are returned via this parameter (empty list can be returned)
+*/
+void QtxBackgroundTool::gradients( QStringList& gradList, QIntList& idList ) const
+{
+ gradList = myGradients;
+ idList = myGradientsIds;
+}
+
+/*!
+ \brief Set allowed two-color gradients to the widget
+ \param gradients gradients names
+ \param ids optional gradients identifiers; if not specified, gradients are automatically numbered starting from 0
+*/
+void QtxBackgroundTool::setGradients( const QStringList& gradList, const QIntList& idList )
+{
+ myGradients = gradList;
+ myGradientsIds = idList;
+ myLastGradient = -1;
+ Qtx::BackgroundData d = data(); // store current state
+ internalUpdate(); // re-initialize
+ setData( d ); // restore current state (if possible)
+}
+
+/*!
+ \brief Check if specific background mode is allowed
+ \param mode background mode
+ \return \c true if specified background mode is enabled or \c false otherwise
+ \sa setModeAllowed()
+*/
+bool QtxBackgroundTool::isModeAllowed( Qtx::BackgroundMode mode ) const
+{
+ return myTypesAllowed.contains( mode ) ? myTypesAllowed[ mode ] : false;
+}
+
+/*!
+ \brief Enable / disable specific background mode
+ \param mode background mode
+ \param on enable / disable flag
+ \sa isModeAllowed()
+*/
+void QtxBackgroundTool::setModeAllowed( Qtx::BackgroundMode mode, bool on )
+{
+ if ( mode == Qtx::CustomGradientBackground )
+ return; // NOT IMPLEMENTED YET //
+
+ myTypesAllowed[ mode ] = on;
+ Qtx::BackgroundData d = data(); // store current state
+ internalUpdate(); // re-initialize
+ setData( d ); // restore current state (if possible)
+}
+
+/*!
+ \brief Get allowed image formats
+ \return image formats
+ \sa setImageFormats()
+*/
+QString QtxBackgroundTool::imageFormats() const
+{
+ return myImageFormats;
+}
+
+/*!
+ \brief Set allowed image formats
+ \param formats image formats
+ \sa imageFormats()
+*/
+void QtxBackgroundTool::setImageFormats( const QString& formats )
+{
+ myImageFormats = formats.isEmpty() ? tr( "Images Files (*.bmp *.png *.jpg *.jpeg *.gif *.tiff)" ) : formats;
+}
+
+/*!
+ \brief Get widget editor orientation
+ \return orientation
+ \sa setOrientation()
+*/
+Qt::Orientation QtxBackgroundTool::orientation() const
+{
+ return qobject_cast<QVBoxLayout*>( layout() ) ? Qt::Vertical : Qt::Horizontal;
+}
+
+/*!
+ \brief Change widget orientation
+ \param orientation new widget orientation
+ \sa orientation()
+*/
+void QtxBackgroundTool::setOrientation( Qt::Orientation orientation )
+{
+ QBoxLayout* l = (orientation == Qt::Horizontal) ? (QBoxLayout*)(new QHBoxLayout) : (QBoxLayout*)(new QVBoxLayout);
+ l->setMargin( 0 );
+ l->setSpacing( 5 );
+ l->addWidget( myModeCombo );
+ l->addWidget( myContainer );
+ delete layout();
+ setLayout( l );
+}
+
+/*!
+ \brief Initialization: fill in the widget with items according to the
+ available modes
+*/
+void QtxBackgroundTool::internalUpdate()
+{
+ myModeCombo->clear();
+ if ( isModeAllowed( Qtx::ImageBackground ) ) {
+ myModeCombo->addItem( tr( "Image" ) );
+ int idx = myModeCombo->count()-1;
+ myModeCombo->setItemData( idx, (int)Qtx::ImageBackground, TypeRole );
+ }
+ if ( isModeAllowed( Qtx::ColorBackground ) ) {
+ if ( myModeCombo->count() > 0 )
+ myModeCombo->insertSeparator( myModeCombo->count() );
+ myModeCombo->addItem( tr( "Single Color" ) );
+ int idx = myModeCombo->count()-1;
+ myModeCombo->setItemData( idx, (int)Qtx::ColorBackground, TypeRole );
+ }
+ if ( isModeAllowed( Qtx::SimpleGradientBackground ) ) {
+ if ( myGradients.count() > 0 && myModeCombo->count() > 0 )
+ myModeCombo->insertSeparator( myModeCombo->count() );
+ for ( int i = 0; i < myGradients.count(); i++ ) {
+ myModeCombo->addItem( myGradients[i] );
+ int idx = myModeCombo->count()-1;
+ myModeCombo->setItemData( idx, (int)Qtx::SimpleGradientBackground, TypeRole );
+ myModeCombo->setItemData( idx, myGradientsIds.count() > i ? myGradientsIds[i] : i, IdRole );
+ }
+ }
+ if ( isModeAllowed( Qtx::CustomGradientBackground ) ) {
+ if ( myModeCombo->count() > 0 )
+ myModeCombo->insertSeparator( myModeCombo->count() );
+ myModeCombo->addItem( tr( "Custom" ) );
+ int idx = myModeCombo->count()-1;
+ myModeCombo->setItemData( idx, (int)Qtx::CustomGradientBackground, TypeRole );
+ }
+ updateState();
+}
+
+/*!
+ \brief Update widget state
+*/
+void QtxBackgroundTool::updateState()
+{
+ int idx = myModeCombo->currentIndex();
+ int id = -1;
+ if ( idx >= 0 ) {
+ id = myModeCombo->itemData( idx, TypeRole ).toInt();
+ switch( id ) {
+ case Qtx::ImageBackground:
+ myContainer->setCurrentIndex( Image );
+ break;
+ case Qtx::ColorBackground:
+ case Qtx::SimpleGradientBackground:
+ myContainer->setCurrentIndex( Color );
+ myLastGradient = myModeCombo->itemData( idx, IdRole ).toInt();
+ break;
+ case Qtx::CustomGradientBackground:
+ myContainer->setCurrentIndex( Gradient );
+ break;
+ }
+ }
+ myModeCombo->setEnabled( idx >= 0 );
+ myContainer->setEnabled( idx >= 0 );
+ mySecondColor->setEnabled( id == Qtx::SimpleGradientBackground );
+}
+
+/*!
+ \brief Called when "Browse..." button is pressed
+*/
+void QtxBackgroundTool::browse()
+{
+ QString fileName = QFileDialog::getOpenFileName( this, tr( "Select Picture" ), myFileName->text().trimmed(), myImageFormats );
+ if ( !fileName.isEmpty() )
+ myFileName->setText( fileName );
+}
+
+/*!
+ \class QtxBackgroundDialog
+ \brief Dialog box that can be used to set-up the background data
+
+ Usage example:
+ \code
+ // create dialog box
+ QtxBackgroundDialog dlg( this );
+ // assign gradients types
+ QStringList sl;
+ sl << "Horizontal" << "Vertical" << "First diagonal" << "Second diagonal";
+ dlg.setGradients(sl);
+ // disable image texture and custom gradient modes
+ dlg.setModeAllowed(Qtx::ImageBackground, false);
+ dlg.setModeAllowed(Qtx::CustomGradientBackground, false);
+ // initialize dialog box with the some background data
+ dlg.setData(backgroundData);
+ // execute dialog box and obtain result background data
+ if ( dlg.exec() ) {
+ Qtx::BackgroundData bgData = dlg.getBackgroundData();
+ }
+ \endcode
+
+ Also it is possible to use static function:
+ \code
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( this );
+ if ( bgData.isValid() )
+ doSomething( bgData );
+ \endcode
+*/
+
+/*!
+ \brief Constructor
+ \param parent parent widget
+*/
+QtxBackgroundDialog::QtxBackgroundDialog( QWidget* parent )
+ : QtxDialog( parent, true, true, OK | Cancel )
+{
+ init();
+}
+
+/*!
+ \brief Constructor
+ \param bgData initial background data
+ \param parent parent widget
+*/
+QtxBackgroundDialog::QtxBackgroundDialog( const Qtx::BackgroundData& bgData, QWidget* parent )
+ : QtxDialog( parent, true, true, OK | Cancel )
+{
+ init();
+}
+
+/*!
+ \brief Destructor
+*/
+QtxBackgroundDialog::~QtxBackgroundDialog()
+{
+}
+
+/*!
+ \brief Perform internal initialization
+*/
+void QtxBackgroundDialog::init()
+{
+ // title
+ setWindowTitle( tr( "Change background" ) );
+ // flags
+ setDialogFlags( SetFocus );
+ // move "Cancel" button to the right
+ setButtonPosition( Right, Cancel );
+
+ // main layout
+ QVBoxLayout* main = new QVBoxLayout( mainFrame() );
+ main->setMargin( 0 );
+ main->setSpacing( 5 );
+
+ // background widget
+ myTool = new QtxBackgroundTool( Qt::Vertical, mainFrame() );
+ main->addWidget( myTool );
+}
+
+/*!
+ \brief Set background data
+ \param bgData background data
+*/
+void QtxBackgroundDialog::setData( const Qtx::BackgroundData& bgData )
+{
+ myTool->setData( bgData );
+}
+
+/*!
+ \brief Get background data
+ \return background data
+*/
+Qtx::BackgroundData QtxBackgroundDialog::data() const
+{
+ return myTool->data();
+}
+
+/*!
+ \brief Set allowed two-color gradients to the widget
+ \param gradients gradients names
+ \param ids optional gradients identifiers; if not specified, gradients are automatically numbered starting from 0
+*/
+void QtxBackgroundDialog::setGradients( const QStringList& gradList, const QIntList& idList )
+{
+ myTool->setGradients( gradList, idList );
+}
+
+/*!
+ \brief Enable / disable specific background mode
+ \param mode background mode
+ \param on enable / disable flag
+*/
+void QtxBackgroundDialog::setModeAllowed( Qtx::BackgroundMode mode, bool on )
+{
+ myTool->setModeAllowed( mode, on );
+}
+
+/*!
+ \brief Set allowed image formats
+ \param formats image formats
+*/
+void QtxBackgroundDialog::setImageFormats( const QString& formats )
+{
+ myTool->setImageFormats( formats );
+}
+
+/*!
+ \brief This is a convenience static function that returns an background data selected by the user.
+ If the user presses Cancel, it returns an invalid background data.
+*/
+Qtx::BackgroundData QtxBackgroundDialog::getBackground( QWidget* parent,
+ const Qtx::BackgroundData& bgData,
+ bool enableSolidColor,
+ bool enableTexture,
+ bool enableGradient,
+ bool enableCustom,
+ const QStringList& gradList,
+ const QIntList& idList,
+ const QString& formats )
+{
+ QtxBackgroundDialog dlg( parent );
+ dlg.setModeAllowed( Qtx::ImageBackground, enableTexture );
+ dlg.setModeAllowed( Qtx::ColorBackground, enableSolidColor );
+ dlg.setModeAllowed( Qtx::SimpleGradientBackground, enableGradient );
+ dlg.setModeAllowed( Qtx::CustomGradientBackground, enableCustom );
+ dlg.setGradients( gradList, idList );
+ dlg.setImageFormats( formats );
+ dlg.setData( bgData );
+ Qtx::BackgroundData res;
+ int rc = dlg.exec();
+ if ( rc ) res = dlg.data();
+ return res;
+}
--- /dev/null
+// Copyright (C) 2007-2012 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: QtxBackgroundTool.h
+// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+
+#ifndef QTXBACKGROUNDTOOL_H
+#define QTXBACKGROUNDTOOL_H
+
+#include "Qtx.h"
+#include "QtxDialog.h"
+
+#include <QWidget>
+#include <QMap>
+
+class QComboBox;
+class QStackedWidget;
+class QLineEdit;
+class QPushButton;
+class QtxColorButton;
+
+class QTX_EXPORT QtxBackgroundTool : public QWidget
+{
+ enum { Image, Color, Gradient };
+ enum { TypeRole = Qt::UserRole, IdRole };
+
+ Q_OBJECT
+
+public:
+ QtxBackgroundTool( QWidget* = 0 );
+ QtxBackgroundTool( Qt::Orientation, QWidget* = 0 );
+ virtual ~QtxBackgroundTool();
+
+ Qtx::BackgroundData data() const;
+ void setData( const Qtx::BackgroundData& );
+
+ void gradients( QStringList&, QIntList& ) const;
+ void setGradients( const QStringList&, const QIntList& = QIntList() );
+
+ bool isModeAllowed( Qtx::BackgroundMode ) const;
+ void setModeAllowed( Qtx::BackgroundMode, bool = true );
+
+ QString imageFormats() const;
+ void setImageFormats( const QString& );
+
+ Qt::Orientation orientation() const;
+ void setOrientation( Qt::Orientation );
+
+private:
+ void init( Qt::Orientation );
+ void internalUpdate();
+
+private slots:
+ void updateState();
+ void browse();
+
+private:
+ QComboBox* myModeCombo;
+ QStackedWidget* myContainer;
+ QLineEdit* myFileName;
+ QPushButton* myBrowseBtn;
+ QComboBox* myTextureMode;
+ QtxColorButton* myFirstColor;
+ QtxColorButton* mySecondColor;
+ QStringList myGradients;
+ QIntList myGradientsIds;
+ QMap<int, bool> myTypesAllowed;
+ QString myImageFormats;
+ int myLastGradient;
+};
+
+class QTX_EXPORT QtxBackgroundDialog : public QtxDialog
+{
+ Q_OBJECT
+
+public:
+ QtxBackgroundDialog( QWidget* = 0 );
+ QtxBackgroundDialog( const Qtx::BackgroundData&, QWidget* = 0 );
+ virtual ~QtxBackgroundDialog();
+
+ void setData( const Qtx::BackgroundData& );
+ Qtx::BackgroundData data() const;
+
+ static Qtx::BackgroundData getBackground( QWidget* = 0,
+ const Qtx::BackgroundData& = Qtx::BackgroundData(),
+ bool = true, bool = true, bool = true, bool = true,
+ const QStringList& = QStringList(),
+ const QIntList& = QIntList(),
+ const QString& = QString() );
+
+ void setGradients( const QStringList&, const QIntList& = QIntList() );
+ void setModeAllowed( Qtx::BackgroundMode, bool = true );
+ void setImageFormats( const QString& );
+
+private:
+ void init();
+
+private:
+ QtxBackgroundTool* myTool;
+};
+
+#endif // QTXBACKGROUNDTOOL_H
#include "QtxBiColorTool.h"
#include "QtxDoubleSpinBox.h"
#include "QtxShortcutEdit.h"
+#include "QtxBackgroundTool.h"
#include "QtxResourceMgr.h"
#include <QEvent>
}
}
+/*!
+ \class QtxPagePrefBackgroundItem
+ \brief GUI implementation of the resources item to store background data.
+
+ Preference item allows specifying background data in different ways:
+ - solid color
+ - texture image file
+ - simple two-color gradient
+ - complex custom gradient (NOT IMPLEMENTED YET)
+
+ Allows background modes can be specified using setModeAllowed() method.
+ Verical or horizontal orientation of the widget can be chosen via setOrientation()
+ method (default orientation is horizontal).
+
+ Simple gradient types can be specified using setGradients() method.
+ \sa Qtx::BackgroundData, QtxBackgroundTool
+*/
+
+/*!
+ \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
+*/
+QtxPagePrefBackgroundItem::QtxPagePrefBackgroundItem( const QString& title, QtxPreferenceItem* parent,
+ const QString& sect, const QString& param )
+: QtxPageNamedPrefItem( title, parent, sect, param )
+{
+ setControl( myBgTool = new QtxBackgroundTool( 0 ) );
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxPagePrefBackgroundItem::~QtxPagePrefBackgroundItem()
+{
+}
+
+/*!
+ \brief Get allowed two-color gradients to the widget
+ \param gradients gradients names are returned via this parameter
+ \param ids gradients identifiers are returned via this parameter (empty list can be returned)
+*/
+void QtxPagePrefBackgroundItem::gradients( QStringList& gradList, QIntList& idList ) const
+{
+ myBgTool->gradients( gradList, idList );
+}
+
+/*!
+ \brief Set allowed two-color gradients to the widget
+ \param gradients gradients names
+ \param ids optional gradients identifiers; if not specified, gradients are automatically numbered starting from 0
+*/
+void QtxPagePrefBackgroundItem::setGradients( const QStringList& gradients, const QIntList& ids )
+{
+ myBgTool->setGradients( gradients, ids );
+}
+
+/*!
+ \brief Check if specific background mode is allowed
+ \param mode background mode
+ \return \c true if specified background mode is enabled or \c false otherwise
+ \sa setModeAllowed()
+*/
+bool QtxPagePrefBackgroundItem::isModeAllowed( Qtx::BackgroundMode mode ) const
+{
+ return myBgTool->isModeAllowed( mode );
+}
+
+/*!
+ \brief Enable / disable specific background mode
+ \param mode background mode
+ \param on enable / disable flag
+ \sa isModeAllowed()
+*/
+void QtxPagePrefBackgroundItem::setModeAllowed( Qtx::BackgroundMode mode, bool on )
+{
+ myBgTool->setModeAllowed( mode, on );
+}
+
+/*!
+ \brief Get allowed image formats
+ \return image formats
+*/
+QString QtxPagePrefBackgroundItem::imageFormats() const
+{
+ return myBgTool->imageFormats();
+}
+
+/*!
+ \brief Set allowed image formats
+ \param formats image formats
+*/
+void QtxPagePrefBackgroundItem::setImageFormats( const QString& formats )
+{
+ myBgTool->setImageFormats( formats );
+}
+
+/*!
+ \brief Get widget editor orientation
+ \return orientation
+*/
+Qt::Orientation QtxPagePrefBackgroundItem::orientation() const
+{
+ return myBgTool->orientation();
+}
+
+/*!
+ \brief Set widget editor orientation
+ \param o orientation
+*/
+void QtxPagePrefBackgroundItem::setOrientation( Qt::Orientation o )
+{
+ myBgTool->setOrientation( o );
+}
+
+/*!
+ \brief Store preference item to the resource manager.
+ \sa retrieve()
+*/
+void QtxPagePrefBackgroundItem::store()
+{
+ setString( Qtx::backgroundToString( myBgTool->data() ) );
+}
+
+/*!
+ \brief Retrieve preference item from the resource manager.
+ \sa store()
+*/
+void QtxPagePrefBackgroundItem::retrieve()
+{
+ myBgTool->setData( Qtx::stringToBackground( getString() ) );
+}
+
+/*!
+ \brief Get preference item option value.
+ \param name option name
+ \return property value or null QVariant if option is not set
+ \sa setOptionValue()
+*/
+QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const
+{
+ if ( name == "texture_enabled" )
+ return isModeAllowed( Qtx::ImageBackground );
+ else if ( name == "color_enabled" )
+ return isModeAllowed( Qtx::ColorBackground );
+ else if ( name == "gradient_enabled" )
+ return isModeAllowed( Qtx::SimpleGradientBackground );
+ else if ( name == "custom_enabled" )
+ return isModeAllowed( Qtx::CustomGradientBackground );
+ else if ( name == "orientation" )
+ return orientation();
+ else if ( name == "image_formats" )
+ return imageFormats();
+ else if ( name == "gradient_names" ) {
+ QStringList grList;
+ QIntList idList;
+ gradients( grList, idList );
+ return grList;
+ }
+ else if ( name == "gradient_ids" ) {
+ QStringList grList;
+ QIntList idList;
+ gradients( grList, idList );
+ QList<QVariant> lst;
+ for ( QIntList::const_iterator it = idList.begin(); it != idList.end(); ++it )
+ lst.append( *it );
+ return lst;
+ }
+ else
+ return QtxPageNamedPrefItem::optionValue( name );
+}
+
+/*!
+ \brief Set preference item option value.
+ \param name option name
+ \param val new property value
+ \sa optionValue()
+*/
+void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVariant& val )
+{
+ if ( name == "texture_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setModeAllowed( Qtx::ImageBackground, val.toBool() );
+ }
+ else if ( name == "color_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setModeAllowed( Qtx::ColorBackground, val.toBool() );
+ }
+ else if ( name == "gradient_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setModeAllowed( Qtx::SimpleGradientBackground, val.toBool() );
+ }
+ else if ( name == "custom_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setModeAllowed( Qtx::CustomGradientBackground, val.toBool() );
+ }
+ else if ( name == "orientation" ) {
+ if ( val.canConvert( QVariant::Int ) )
+ setOrientation( (Qt::Orientation)val.toInt() );
+ }
+ else if ( name == "image_formats" ) {
+ if ( val.canConvert( QVariant::String ) )
+ setImageFormats( val.toString() );
+ }
+ else if ( name == "gradient_names" ) {
+ if ( val.canConvert( QVariant::StringList ) )
+ setGradients( val.toStringList() );
+ }
+ else if ( name == "gradient_ids" ) {
+ if ( val.canConvert( QVariant::List ) ) {
+ QStringList grList;
+ QIntList idList;
+ gradients( grList, idList );
+ idList.clear();
+ QList<QVariant> varList = val.toList();
+ for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it ) {
+ if ( (*it).canConvert( QVariant::Int ) )
+ idList.append( (*it).toInt() );
+ }
+ setGradients( grList, idList );
+ }
+ }
+ else
+ QtxPageNamedPrefItem::setOptionValue( name, val );
+}
+
/*!
\brief Constructor.
class QtxBiColorTool;
class QtxShortcutEdit;
class QtxShortcutTree;
+class QtxBackgroundTool;
class QToolBox;
class QLineEdit;
QString mySection;
};
+class QTX_EXPORT QtxPagePrefBackgroundItem : public QObject, public QtxPageNamedPrefItem
+{
+ Q_OBJECT
+
+public:
+ QtxPagePrefBackgroundItem( const QString&, QtxPreferenceItem* = 0,
+ const QString& = QString(), const QString& = QString() );
+ virtual ~QtxPagePrefBackgroundItem();
+
+ void gradients( QStringList&, QIntList& ) const;
+ void setGradients( const QStringList&, const QIntList& = QIntList() );
+
+ bool isModeAllowed( Qtx::BackgroundMode ) const;
+ void setModeAllowed( Qtx::BackgroundMode, bool = true );
+
+ QString imageFormats() const;
+ void setImageFormats( const QString& );
+
+ Qt::Orientation orientation() const;
+ void setOrientation( Qt::Orientation );
+
+ virtual void store();
+ virtual void retrieve();
+
+protected:
+ virtual QVariant optionValue( const QString& ) const;
+ virtual void setOptionValue( const QString&, const QVariant& );
+
+private:
+ QtxBackgroundTool* myBgTool;
+};
+
class QtxUserDefinedContent: public QWidget
{
public:
\brief Get linear gradient parameter value.
\param sect section name
\param name parameter name
- \param gVal parameter to return resulting linear gradient value value
+ \param gVal parameter to return resulting linear gradient value
\return \c true if parameter is found and \c false if parameter is not found
(in this case \a gVal value is undefined)
*/
\brief Get radial gradient parameter value.
\param sect section name
\param name parameter name
- \param gVal parameter to return resulting radial gradient value value
+ \param gVal parameter to return resulting radial gradient value
\return \c true if parameter is found and \c false if parameter is not found
(in this case \a gVal value is undefined)
*/
\brief Get conical gradient parameter value.
\param sect section name
\param name parameter name
- \param gVal parameter to return resulting conical gradient value value
+ \param gVal parameter to return resulting conical gradient value
\return \c true if parameter is found and \c false if parameter is not found
(in this case \a gVal value is undefined)
*/
return Qtx::stringToConicalGradient( val, gVal );
}
+/*!
+ \brief Get background parameter value.
+ \param sect section name
+ \param name parameter name
+ \param bgVal parameter to return resulting background value
+ \return \c true if parameter is found and \c false if parameter is not found
+ (in this case \a bgVal value is undefined)
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, Qtx::BackgroundData& bgVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ bgVal = Qtx::stringToBackground( val );
+ return bgVal.isValid();
+}
+
/*!
\brief Get string parameter value (native format).
\param sect section name
return val;
}
+/*!
+ \brief Get background parameter value.
+
+ If the specified parameter is not found, the specified default value is returned instead.
+
+ \param sect section name
+ \param name parameter name
+ \param def default value
+ \return parameter value (or default value if parameter is not found)
+*/
+Qtx::BackgroundData QtxResourceMgr::backgroundValue( const QString& sect, const QString& name, const Qtx::BackgroundData& def ) const
+{
+ Qtx::BackgroundData val;
+ if ( !value( sect, name, val ) )
+ val = def;
+ return val;
+}
+
/*!
\brief Check parameter existence.
\param sect section name
setResource( sect, name, Qtx::gradientToString( val ) );
}
+/*!
+ \brief Set background parameter value.
+ \param sect section name
+ \param name parameter name
+ \param val parameter value
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const Qtx::BackgroundData& val )
+{
+ Qtx::BackgroundData res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ setResource( sect, name, Qtx::backgroundToString( val ) );
+}
+
/*!
\brief Remove resources section.
\param sect section name
bool value( const QString&, const QString&, QLinearGradient& ) const;
bool value( const QString&, const QString&, QRadialGradient& ) const;
bool value( const QString&, const QString&, QConicalGradient& ) const;
+ bool value( const QString&, const QString&, Qtx::BackgroundData& ) const;
bool value( const QString&, const QString&, QString&, const bool = true ) const;
int integerValue( const QString&, const QString&, const int = 0 ) const;
QLinearGradient linearGradientValue( const QString&, const QString&, const QLinearGradient& = QLinearGradient() ) const;
QRadialGradient radialGradientValue( const QString&, const QString&, const QRadialGradient& = QRadialGradient() ) const;
QConicalGradient conicalGradientValue( const QString&, const QString&, const QConicalGradient& = QConicalGradient() ) const;
+ Qtx::BackgroundData backgroundValue( const QString&, const QString&, const Qtx::BackgroundData& = Qtx::BackgroundData() ) const;
bool hasSection( const QString& ) const;
bool hasValue( const QString&, const QString& ) const;
void setValue( const QString&, const QString&, const QLinearGradient& );
void setValue( const QString&, const QString&, const QRadialGradient& );
void setValue( const QString&, const QString&, const QConicalGradient& );
+ void setValue( const QString&, const QString&, const Qtx::BackgroundData& );
void remove( const QString& );
void remove( const QString&, const QString& );
<translation>Echelle de couleurs</translation>
</message>
</context>
+<context>
+ <name>QtxBackgroundTool</name>
+ <message>
+ <source>Browse...</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Not implemented yet</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Center</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Tile</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Stretch</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Images Files (*.bmp *.png *.jpg *.jpeg *.gif *.tiff)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Image</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Single Color</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Custom</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Select Picture</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>QtxBackgroundDialog</name>
+ <message>
+ <source>Change background</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
</TS>
case BiColor:
item = new QtxPagePrefBiColorItem( title, parent, sect, param );
break;
+ case Background:
+ item = new QtxPagePrefBackgroundItem( 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, BiColor,
+ GroupBox, Tab, Frame, Font, DirList, File,
+ Slider, Shortcut, ShortcutTree, BiColor, Background,
UserDefined = 1000 } PrefItemType;
public: