#include <QCompleter>
#include <QApplication>
#include <QDesktopWidget>
+#include <QLinearGradient>
+#include <QRadialGradient>
+#include <QConicalGradient>
#include <stdio.h>
#include <stdlib.h>
lst.append( scaleColor( i, 0, num - 1 ) );
}
+/*!
+ \brief Scale the pixmap to the required size.
+
+ If \h is 0 (default) the value of \a w is used instead (to create
+ square pixmap).
+
+ \param icon pixmap to be resized
+ \param w required pixmap width
+ \param h required pixmap height
+ \return scaled pixmap
+*/
+QPixmap Qtx::scaleIcon( const QPixmap& icon, const unsigned w, const unsigned h )
+{
+ QPixmap p;
+ int aw = w, ah = h <= 0 ? w : h;
+ if ( icon.isNull() || aw <= 0 || ah <= 0 || aw == icon.width() && ah == icon.height() )
+ p = icon;
+ else
+ p = icon.fromImage( icon.toImage().scaled( aw, ah, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
+ return p;
+}
+
/*!
\brief Convert given image to the grayscale format.
\param img initial image
return res;
}
+
+/*!
+ \brief Convert color to the string representation.
+
+ The resulting string is in the one of two possible formats
+ (\c RR, \c GG, \c BB and \c AA value represent red, green, blue
+ and alpha components of the color):
+ - if color has alpha channel : "#RR,#GG,#BB,#AA"
+ - if color does not have alpha channel : "#RRGGBB"
+
+ If color is invalid, null string is returned.
+
+ Backward conversion can be done with stringToColor() method.
+
+ \param color color to be converted
+ \return string representation of the color
+
+ \sa stringToColor()
+*/
+QString Qtx::colorToString( const QColor& color )
+{
+ QString str;
+ if ( color.isValid() )
+ {
+ if ( color.alpha() != 255 )
+ {
+ QStringList vals;
+ vals << QString( "#%1" ).arg( color.red(), 0, 16 );
+ vals << QString( "#%1" ).arg( color.green(), 0, 16 );
+ vals << QString( "#%1" ).arg( color.blue(), 0, 16 );
+ vals << QString( "#%1" ).arg( color.alpha(), 0, 16 );
+ str = vals.join( "," );
+ }
+ else
+ {
+ str = color.name();
+ }
+ }
+ return str;
+}
+
+/*!
+ \brief Create color from the string representation.
+
+ The parameter \a str must be in the one of following formats
+ (\c RR, \c GG, \c BB and \c AA value represent red, green, blue
+ and alpha components of the color):
+ - "#RR,#GG,#BB[,#AA]" or "#RR #GG #BB[ #AA]" (\c RR, \c GG, \c BB
+ and optional \c AA values represent red, green, blue and alpha
+ components of the color in hexadecimal form)
+ - "RR,GG,BB[,AA]" or "RR GG BB[ AA]" (\c RR, \c GG, \c BB
+ and optional \c AA values represent red, green, blue and alpha
+ components of the color in decimal form)
+ - #RRGGBB" - (\c RR, \c GG and \c BB values represent red, green and blue
+ components of the color in hexadecimal form)
+ - an integer value representing packed color components (see rgbSet())
+ - a name from the list of colors defined in the list of SVG color keyword names
+ provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro".
+
+ Backward conversion can be done with colorToString() method.
+
+ \param str string representation of the color
+ \param color resulting color value
+ \return \c true if the conversion is successful and \c false otherwise
+
+ \sa colorToString(), rgbSet()
+*/
+bool Qtx::stringToColor( const QString& str, QColor& color )
+{
+ bool res = true;
+ QStringList vals = str.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts );
+
+ QIntList nums;
+ for ( QStringList::const_iterator it = vals.begin(); it != vals.end() && res; ++it )
+ {
+ int num = 0;
+ if ( (*it).startsWith( "#" ) )
+ num = (*it).mid( 1 ).toInt( &res, 16 );
+ else
+ num = (*it).toInt( &res, 10 );
+ if ( res )
+ nums.append( num );
+ }
+
+ res = res && nums.count() >= 3;
+ if ( res )
+ color.setRgb( nums[0], nums[1], nums[2] );
+
+ if ( !res )
+ {
+ int pack = str.toInt( &res );
+ if ( res )
+ color = Qtx::rgbSet( pack );
+ }
+
+ if ( !res )
+ {
+ color = QColor( str );
+ res = color.isValid();
+ }
+
+ return res;
+}
+
+/*!
+ \brief Dump linear gradient to the string description.
+ \param gradient linear gradient to be converted
+ \return string representation of the linear gradient
+ \sa stringToLinearGradient()
+*/
+QString Qtx::gradientToString( const QLinearGradient& gradient )
+{
+ QStringList data;
+ data << "linear";
+ data << QString::number( gradient.start().x() );
+ data << QString::number( gradient.start().y() );
+ data << QString::number( gradient.finalStop().x() );
+ data << QString::number( gradient.finalStop().y() );
+ switch( gradient.spread() )
+ {
+ case QGradient::PadSpread:
+ data << "pad";
+ break;
+ case QGradient::RepeatSpread:
+ data << "repeat";
+ break;
+ case QGradient::ReflectSpread:
+ data << "reflect";
+ break;
+ default:
+ break;
+ }
+ QGradientStops stops = gradient.stops();
+ QGradientStop stop;
+ foreach ( stop, stops )
+ {
+ data << QString::number( stop.first );
+ data << colorToString( stop.second );
+ }
+ return data.join( "|" );
+}
+
+/*!
+ \brief Dump radial gradient to the string description.
+ \param gradient radial gradient to be converted
+ \return string representation of the radial gradient
+ \sa stringToRadialGradient()
+*/
+QString Qtx::gradientToString( const QRadialGradient& gradient )
+{
+ QStringList data;
+ data << "radial";
+ data << QString::number( gradient.center().x() );
+ data << QString::number( gradient.center().y() );
+ data << QString::number( gradient.radius() );
+ data << QString::number( gradient.focalPoint().x() );
+ data << QString::number( gradient.focalPoint().y() );
+ switch( gradient.spread() )
+ {
+ case QGradient::PadSpread:
+ data << "pad";
+ break;
+ case QGradient::RepeatSpread:
+ data << "repeat";
+ break;
+ case QGradient::ReflectSpread:
+ data << "reflect";
+ break;
+ default:
+ break;
+ }
+ QGradientStops stops = gradient.stops();
+ QGradientStop stop;
+ foreach ( stop, stops )
+ {
+ data << QString::number( stop.first );
+ data << colorToString( stop.second );
+ }
+ return data.join( "|" );
+}
+
+/*!
+ \brief Dump conical gradient to the string description.
+ \param gradient conical gradient to be converted
+ \return string representation of the conical gradient
+ \sa stringToConicalGradient()
+*/
+QString Qtx::gradientToString( const QConicalGradient& gradient )
+{
+ QStringList data;
+ data << "conical";
+ data << QString::number( gradient.center().x() );
+ data << QString::number( gradient.center().y() );
+ data << QString::number( gradient.angle() );
+ switch( gradient.spread() )
+ {
+ case QGradient::PadSpread:
+ data << "pad";
+ break;
+ case QGradient::RepeatSpread:
+ data << "repeat";
+ break;
+ case QGradient::ReflectSpread:
+ data << "reflect";
+ break;
+ default:
+ break;
+ }
+ QGradientStops stops = gradient.stops();
+ QGradientStop stop;
+ foreach ( stop, stops )
+ {
+ data << QString::number( stop.first );
+ data << colorToString( stop.second );
+ }
+ return data.join( "|" );
+}
+
+/*!
+ \brief Create linear gradient from its string representation.
+ \param str string representation of the linear gradient
+ \param gradient resulting linear gradient object
+ \return \c true if the conversion is successful and \c false otherwise
+ \sa gradientToString()
+*/
+bool Qtx::stringToLinearGradient( const QString& str, QLinearGradient& gradient )
+{
+ bool success = false;
+ QStringList vals = str.split( "|", QString::SkipEmptyParts );
+ if ( vals.count() > 4 && ( vals[0] == "linear" || vals[0] == "lg" ) )
+ {
+ // start and end points
+ double x1, y1, x2, y2;
+ bool bOk1, bOk2, bOk3, bOk4;
+ x1 = vals[1].toDouble( &bOk1 );
+ y1 = vals[2].toDouble( &bOk2 );
+ x2 = vals[3].toDouble( &bOk3 );
+ y2 = vals[4].toDouble( &bOk4 );
+ if ( bOk1 && bOk2 && bOk3 && bOk4 )
+ {
+ gradient = QLinearGradient( x1, y1, x2, y2 );
+ // spread type
+ if ( vals.count() > 5 )
+ {
+ QString spread = vals[ 5 ].trimmed().toLower();
+ if ( spread == "pad" || spread == "0" )
+ gradient.setSpread( QGradient::PadSpread );
+ else if ( spread == "repeat" || spread == "2" )
+ gradient.setSpread( QGradient::RepeatSpread );
+ else if ( spread == "reflect" || spread == "1" )
+ gradient.setSpread( QGradient::ReflectSpread );
+ }
+ // stop points
+ QGradientStops stops;
+ for ( int i = 6; i < vals.count(); i+=2 )
+ {
+ bool bOk5, bOk6 = false;
+ QColor c;
+ double stop = vals[i].toDouble( &bOk5 );
+ if ( i+1 < vals.count() )
+ bOk6 = stringToColor( vals[ i+1 ], c );
+ if ( bOk5 && stop >= 0.0 && stop <= 1.0 && bOk6 && c.isValid() )
+ stops.append( QGradientStop( stop, c ) );
+ }
+ gradient.setStops( stops );
+ success = true;
+ }
+ }
+ return success;
+}
+
+/*!
+ \brief Create radial gradient from its string representation.
+ \param str string representation of the radial gradient
+ \param gradient resulting radial gradient object
+ \return \c true if the conversion is successful and \c false otherwise
+ \sa gradientToString()
+*/
+bool Qtx::stringToRadialGradient( const QString& str, QRadialGradient& gradient )
+{
+ bool success = false;
+ QStringList vals = str.split( "|", QString::SkipEmptyParts );
+ if ( vals.count() > 5 && vals[0] == "radial" || vals[0] == "rg" )
+ {
+ // center, radius and focal point
+ double cx, cy, r, fx, fy;
+ bool bOk1, bOk2, bOk3, bOk4, bOk5;
+ cx = vals[1].toDouble( &bOk1 );
+ cy = vals[2].toDouble( &bOk2 );
+ r = vals[3].toDouble( &bOk3 );
+ fx = vals[4].toDouble( &bOk4 );
+ fy = vals[5].toDouble( &bOk5 );
+ if ( bOk1 && bOk2 && bOk3 && bOk4 && bOk5 )
+ {
+ gradient = QRadialGradient( cx, cy, r, fx, fy );
+ // spread type
+ if ( vals.count() > 6 )
+ {
+ QString spread = vals[ 6 ].trimmed().toLower();
+ if ( spread == "pad" || spread == "0" )
+ gradient.setSpread( QGradient::PadSpread );
+ else if ( spread == "repeat" || spread == "2" )
+ gradient.setSpread( QGradient::RepeatSpread );
+ else if ( spread == "reflect" || spread == "1" )
+ gradient.setSpread( QGradient::ReflectSpread );
+ }
+ // stop points
+ QGradientStops stops;
+ for ( int i = 7; i < vals.count(); i+=2 )
+ {
+ bool bOk7, bOk8 = false;
+ QColor c;
+ double stop = vals[i].toDouble( &bOk7 );
+ if ( i+1 < vals.count() )
+ bOk8 = stringToColor( vals[ i+1 ], c );
+ if ( bOk7 && stop >= 0.0 && stop <= 1.0 && bOk8 && c.isValid() )
+ stops.append( QGradientStop( stop, c ) );
+ }
+ gradient.setStops( stops );
+ success = true;
+ }
+ }
+ return success;
+}
+
+/*!
+ \brief Create conical gradient from its string representation.
+ \param str string representation of the conical gradient
+ \param gradient resulting conical gradient object
+ \return \c true if the conversion is successful and \c false otherwise
+ \sa gradientToString()
+*/
+bool Qtx::stringToConicalGradient( const QString& str, QConicalGradient& gradient )
+{
+ bool success = false;
+ QStringList vals = str.split( "|", QString::SkipEmptyParts );
+ if ( vals.count() > 3 && vals[0] == "conical" || vals[0] == "cg" )
+ {
+ // center and angle
+ double cx, cy, a;
+ bool bOk1, bOk2, bOk3;
+ cx = vals[1].toDouble( &bOk1 );
+ cy = vals[2].toDouble( &bOk2 );
+ a = vals[3].toDouble( &bOk3 );
+ if ( bOk1 && bOk2 && bOk3 )
+ {
+ gradient = QConicalGradient( cx, cy, a );
+ // spread type
+ if ( vals.count() > 4 )
+ {
+ QString spread = vals[ 4 ].trimmed().toLower();
+ if ( spread == "pad" || spread == "0" )
+ gradient.setSpread( QGradient::PadSpread );
+ else if ( spread == "repeat" || spread == "2" )
+ gradient.setSpread( QGradient::RepeatSpread );
+ else if ( spread == "reflect" || spread == "1" )
+ gradient.setSpread( QGradient::ReflectSpread );
+ }
+ // stop points
+ QGradientStops stops;
+ for ( int i = 5; i < vals.count(); i+=2 )
+ {
+ bool bOk4, bOk5 = false;
+ QColor c;
+ double stop = vals[i].toDouble( &bOk4 );
+ if ( i+1 < vals.count() )
+ bOk5 = stringToColor( vals[ i+1 ], c );
+ if ( bOk4 && stop >= 0.0 && stop <= 1.0 && bOk5 && c.isValid() )
+ stops.append( QGradientStop( stop, c ) );
+ }
+ gradient.setStops( stops );
+ success = true;
+ }
+ }
+ return success;
+}
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
PT_Directory //!< the directory path is required
} PathType;
+ //! Custom data roles
+ enum {
+ AppropriateRole = Qt::UserRole + 100 //!< can be used to return \c true if data is appropriate
+ };
+
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 QColor scaleColor( const int, const int, const int );
static void scaleColors( const int, QColorList& );
+ static QPixmap scaleIcon( const QPixmap&, const unsigned, const unsigned = 0 );
static QImage grayscale( const QImage& );
static QPixmap grayscale( const QPixmap& );
static QImage transparentImage( const int, const int, const int = -1 );
static QPixmap transparentPixmap( const int, const int, const int = -1 );
static QPixmap composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() );
+
+ static QString colorToString( const QColor& );
+ static bool stringToColor( const QString&, QColor& );
+
+ static QString gradientToString( const QLinearGradient& );
+ static QString gradientToString( const QRadialGradient& );
+ static QString gradientToString( const QConicalGradient& );
+ static bool stringToLinearGradient( const QString&, QLinearGradient& );
+ static bool stringToRadialGradient( const QString&, QRadialGradient& );
+ static bool stringToConicalGradient( const QString&, QConicalGradient& );
};
#endif
if ( !filePath.isEmpty() )
{
if ( !QFileInfo( filePath ).exists() )
- filePath = QString::null;
+ filePath = QString();
}
return filePath;
}
*/
QString QtxResourceMgr::Resources::environmentVariable( const QString& str, int& start, int& len ) const
{
- QString varName = QString::null;
+ QString varName;
len = 0;
QRegExp rx( "(^\\$\\{|[^\\$]\\$\\{)([a-zA-Z]+[a-zA-Z0-9_]*)(\\})|(^\\$\\(|[^\\$]\\$\\()([a-zA-Z]+[a-zA-Z0-9_]*)(\\))|(^\\$|[^\\$]\\$)([a-zA-Z]+[a-zA-Z0-9_]*)|(^%|[^%]%)([a-zA-Z]+[a-zA-Z0-9_]*)(%[^%]|%$)" );
if ( !value( sect, name, val, true ) )
return false;
- bool res = true;
- QStringList vals = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts );
-
- QIntList nums;
- for ( QStringList::const_iterator it = vals.begin(); it != vals.end() && res; ++it )
- {
- int num = 0;
- if ( (*it).startsWith( "#" ) )
- num = (*it).mid( 1 ).toInt( &res, 16 );
- else
- num = (*it).toInt( &res, 10 );
- if ( res )
- nums.append( num );
- }
-
- res = res && nums.count() >= 3;
- if ( res )
- cVal.setRgb( nums[0], nums[1], nums[2] );
-
- if ( !res )
- {
- int pack = val.toInt( &res );
- if ( res )
- cVal = Qtx::rgbSet( pack );
- }
-
- if ( !res )
- {
- cVal = QColor( val );
- res = cVal.isValid();
- }
-
- return res;
+ return Qtx::stringToColor( val, cVal );
}
/*!
return !baVal.isEmpty();
}
+/*!
+ \brief Get linear gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param gVal parameter to return resulting linear gradient value value
+ \return \c true if parameter is found and \c false if parameter is not found
+ (in this case \a gVal value is undefined)
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, QLinearGradient& gVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ return Qtx::stringToLinearGradient( val, gVal );
+}
+
+/*!
+ \brief Get radial gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param gVal parameter to return resulting radial gradient value value
+ \return \c true if parameter is found and \c false if parameter is not found
+ (in this case \a gVal value is undefined)
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, QRadialGradient& gVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ return Qtx::stringToRadialGradient( val, gVal );
+}
+
+/*!
+ \brief Get conical gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param gVal parameter to return resulting conical gradient value value
+ \return \c true if parameter is found and \c false if parameter is not found
+ (in this case \a gVal value is undefined)
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, QConicalGradient& gVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ return Qtx::stringToConicalGradient( val, gVal );
+}
+
/*!
\brief Get string parameter value (native format).
\param sect section name
return val;
}
+/*!
+ \brief Get linear gradient 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)
+*/
+QLinearGradient QtxResourceMgr::linearGradientValue( const QString& sect, const QString& name, const QLinearGradient& def ) const
+{
+ QLinearGradient val;
+ if ( !value( sect, name, val ) )
+ val = def;
+ return val;
+}
+
+/*!
+ \brief Get radial gradient 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)
+*/
+QRadialGradient QtxResourceMgr::radialGradientValue( const QString& sect, const QString& name, const QRadialGradient& def ) const
+{
+ QRadialGradient val;
+ if ( !value( sect, name, val ) )
+ val = def;
+ return val;
+}
+
+/*!
+ \brief Get conical gradient 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)
+*/
+QConicalGradient QtxResourceMgr::conicalGradientValue( const QString& sect, const QString& name, const QConicalGradient& def ) const
+{
+ QConicalGradient val;
+ if ( !value( sect, name, val ) )
+ val = def;
+ return val;
+}
+
/*!
\brief Check parameter existence.
\param sect section name
if ( checkExisting() && value( sect, name, res ) && res == val )
return;
- setResource( sect, name, val.isValid() ? val.name() : QString() );
+ setResource( sect, name, Qtx::colorToString( val ) );
}
/*!
setResource( sect, name, lst.join( " " ) );
}
+/*!
+ \brief Set linear gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param val parameter value
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QLinearGradient& val )
+{
+ QLinearGradient res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ setResource( sect, name, Qtx::gradientToString( val ) );
+}
+
+/*!
+ \brief Set radial gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param val parameter value
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QRadialGradient& val )
+{
+ QRadialGradient res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ setResource( sect, name, Qtx::gradientToString( val ) );
+}
+
+/*!
+ \brief Set conical gradient parameter value.
+ \param sect section name
+ \param name parameter name
+ \param val parameter value
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QConicalGradient& val )
+{
+ QConicalGradient res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ setResource( sect, name, Qtx::gradientToString( val ) );
+}
+
/*!
\brief Remove resources section.
\param sect section name
#include <QPixmap>
#include <QByteArray>
#include <QStringList>
+#include <QLinearGradient>
+#include <QRadialGradient>
+#include <QConicalGradient>
class QTranslator;
#endif
public:
- QtxResourceMgr( const QString&, const QString& = QString::null );
+ QtxResourceMgr( const QString&, const QString& = QString() );
virtual ~QtxResourceMgr();
- QString appName() const;
- QStringList dirList() const;
-
- bool checkExisting() const;
- virtual void setCheckExisting( const bool );
-
- bool isPixmapCached() const;
- void setIsPixmapCached( const bool );
-
- void clear();
-
- void setIgnoreUserValues( const bool = true );
- bool ignoreUserValues() const;
-
- bool value( const QString&, const QString&, int& ) const;
- bool value( const QString&, const QString&, double& ) const;
- bool value( const QString&, const QString&, bool& ) const;
- bool value( const QString&, const QString&, QColor& ) const;
- bool value( const QString&, const QString&, QFont& ) const;
- bool value( const QString&, const QString&, QByteArray& ) const;
- bool value( const QString&, const QString&, QString&, const bool = true ) const;
-
- int integerValue( const QString&, const QString&, const int = 0 ) const;
- double doubleValue( const QString&, const QString&, const double = 0 ) const;
- bool booleanValue( const QString&, const QString&, const bool = false ) const;
- QFont fontValue( const QString&, const QString&, const QFont& = QFont() ) const;
- QColor colorValue( const QString&, const QString&, const QColor& = QColor() ) const;
- QString stringValue( const QString&, const QString&, const QString& = QString::null ) const;
- QByteArray byteArrayValue( const QString&, const QString&, const QByteArray& = QByteArray() ) const;
-
- bool hasSection( const QString& ) const;
- bool hasValue( const QString&, const QString& ) const;
-
- void setValue( const QString&, const QString&, const int );
- void setValue( const QString&, const QString&, const double );
- void setValue( const QString&, const QString&, const bool );
- void setValue( const QString&, const QString&, const QFont& );
- void setValue( const QString&, const QString&, const QColor& );
- void setValue( const QString&, const QString&, const QString& );
- void setValue( const QString&, const QString&, const QByteArray& );
-
- void remove( const QString& );
- void remove( const QString&, const QString& );
-
- QString currentFormat() const;
- void setCurrentFormat( const QString& );
-
- Format* format( const QString& ) const;
- void installFormat( Format* );
- void removeFormat( Format* );
-
- QStringList options() const;
- QString option( const QString& ) const;
- void setOption( const QString&, const QString& );
-
- QPixmap defaultPixmap() const;
- virtual void setDefaultPixmap( const QPixmap& );
-
- QString resSection() const;
- QString langSection() const;
-
- QPixmap loadPixmap( const QString&, const QString& ) const;
- QPixmap loadPixmap( const QString&, const QString&, const bool ) const;
- QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const;
- void loadLanguage( const QString& = QString::null, const QString& = QString::null );
-
- void raiseTranslators( const QString& );
- void removeTranslators( const QString& );
- void loadTranslator( const QString&, const QString& );
- void loadTranslators( const QString&, const QStringList& );
-
- QString path( const QString&, const QString&, const QString& ) const;
-
- bool load();
- bool import( const QString& );
- bool save();
-
- QStringList sections() const;
- QStringList parameters( const QString& ) const;
-
- void refresh();
+ QString appName() const;
+ QStringList dirList() const;
+
+ bool checkExisting() const;
+ virtual void setCheckExisting( const bool );
+
+ bool isPixmapCached() const;
+ void setIsPixmapCached( const bool );
+
+ void clear();
+
+ void setIgnoreUserValues( const bool = true );
+ bool ignoreUserValues() const;
+
+ bool value( const QString&, const QString&, int& ) const;
+ bool value( const QString&, const QString&, double& ) const;
+ bool value( const QString&, const QString&, bool& ) const;
+ bool value( const QString&, const QString&, QColor& ) const;
+ bool value( const QString&, const QString&, QFont& ) const;
+ bool value( const QString&, const QString&, QByteArray& ) const;
+ 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&, QString&, const bool = true ) const;
+
+ int integerValue( const QString&, const QString&, const int = 0 ) const;
+ double doubleValue( const QString&, const QString&, const double = 0 ) const;
+ bool booleanValue( const QString&, const QString&, const bool = false ) const;
+ QFont fontValue( const QString&, const QString&, const QFont& = QFont() ) const;
+ QColor colorValue( const QString&, const QString&, const QColor& = QColor() ) const;
+ QString stringValue( const QString&, const QString&, const QString& = QString() ) const;
+ QByteArray byteArrayValue( const QString&, const QString&, const QByteArray& = QByteArray() ) 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;
+
+ bool hasSection( const QString& ) const;
+ bool hasValue( const QString&, const QString& ) const;
+
+ void setValue( const QString&, const QString&, const int );
+ void setValue( const QString&, const QString&, const double );
+ void setValue( const QString&, const QString&, const bool );
+ void setValue( const QString&, const QString&, const QFont& );
+ void setValue( const QString&, const QString&, const QColor& );
+ void setValue( const QString&, const QString&, const QString& );
+ void setValue( const QString&, const QString&, const QByteArray& );
+ 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 remove( const QString& );
+ void remove( const QString&, const QString& );
+
+ QString currentFormat() const;
+ void setCurrentFormat( const QString& );
+
+ Format* format( const QString& ) const;
+ void installFormat( Format* );
+ void removeFormat( Format* );
+
+ QStringList options() const;
+ QString option( const QString& ) const;
+ void setOption( const QString&, const QString& );
+
+ QPixmap defaultPixmap() const;
+ virtual void setDefaultPixmap( const QPixmap& );
+
+ QString resSection() const;
+ QString langSection() const;
+
+ QPixmap loadPixmap( const QString&, const QString& ) const;
+ QPixmap loadPixmap( const QString&, const QString&, const bool ) const;
+ QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const;
+ void loadLanguage( const QString& = QString(), const QString& = QString() );
+
+ void raiseTranslators( const QString& );
+ void removeTranslators( const QString& );
+ void loadTranslator( const QString&, const QString& );
+ void loadTranslators( const QString&, const QStringList& );
+
+ QString path( const QString&, const QString&, const QString& ) const;
+
+ bool load();
+ bool import( const QString& );
+ bool save();
+
+ QStringList sections() const;
+ QStringList parameters( const QString& ) const;
+
+ void refresh();
protected:
- virtual void setDirList( const QStringList& );
- virtual void setResource( const QString&, const QString&, const QString& );
+ virtual void setDirList( const QStringList& );
+ virtual void setResource( const QString&, const QString&, const QString& );
- virtual QString userFileName( const QString&, const bool = true ) const;
- virtual QString globalFileName( const QString& ) const;
+ virtual QString userFileName( const QString&, const bool = true ) const;
+ virtual QString globalFileName( const QString& ) const;
private:
- void initialize( const bool = true ) const;
- QString substMacro( const QString&, const QMap<QChar, QString>& ) const;
+ void initialize( const bool = true ) const;
+ QString substMacro( const QString&, const QMap<QChar, QString>& ) const;
private:
typedef QList<Resources*> ResList;
typedef QMap<QString, TransList> TransListMap;
private:
- QString myAppName; //!< application name
- QStringList myDirList; //!< list of resources directories
- FormatList myFormats; //!< list of formats
- OptionsMap myOptions; //!< options map
- ResList myResources; //!< resources list
- bool myCheckExist; //!< "check existance" flag
- TransListMap myTranslator; //!< map of loaded translators
- QPixmap* myDefaultPix; //!< default icon
- bool myIsPixmapCached; //!< "cached pixmaps" flag
-
- bool myIsIgnoreUserValues; //!< "ignore user values" flag
+ QString myAppName; //!< application name
+ QStringList myDirList; //!< list of resources directories
+ FormatList myFormats; //!< list of formats
+ OptionsMap myOptions; //!< options map
+ ResList myResources; //!< resources list
+ bool myCheckExist; //!< "check existance" flag
+ TransListMap myTranslator; //!< map of loaded translators
+ QPixmap* myDefaultPix; //!< default icon
+ bool myIsPixmapCached; //!< "cached pixmaps" flag
+
+ bool myIsIgnoreUserValues; //!< "ignore user values" flag
friend class QtxResourceMgr::Format;
};
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File: QtxSplash.cxx
-// Author: Vadim SANDLER
+// File : QtxSplash.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
#include "QtxSplash.h"
+#include "QtxResourceMgr.h"
#include <QApplication>
#include <QPainter>
\param msg progress message
\param progress current progress (for example, in %)
*/
- ProgressEvent( const QString& msg, const int progress = 0 )
+ ProgressEvent( const QString& msg, const int progress )
: QEvent( (QEvent::Type)id() ),
myMessage( msg ),
myProgress( progress )
splash->show();
app.processEvents();
// doing first step
- splash->message("Step 1");
+ splash->setMessage("Step 1");
splash->ress(1);
qApp->processEvents();
// ... perform some actions
// doing second step
- splash->message("Step 2");
+ splash->setMessage("Step 2");
splash->setProgress(2);
qApp->processEvents();
// ... perform some actions
\endcode
There is a static function QtxSplash::setStatus() which allows to put next status message
- and progress with one call. It can substitue two calls: message() and setProgress().
+ and progress with one call. It can substitue two calls: setMessage() and setProgress().
QtxSplash class provides alos a lot of functions to set-up its behavior. Set progress
bar width with setProgressWidth() method, its position and direction with setProgressFlags().
To change the progress bar and status message transparency, use setOpacity() function.
The methods setTextAlignment(), setTextColor() and setTextColors() can be used to change
the attributes of the status message.
+
+ The displayed message text includes constant info and status message. The constant info
+ is set by setConstantInfo() method and status message is set by setMessage().
+
+ Sometimes it is useful to splay an error message above the splash screen window.
+ For example, it can be necessary if an error occurs when loading the application.
+ Method setError() can be used to show the error message and set the error code which
+ can be then retrieved with the error() function.
*/
//! The only one instance of splash screen
\brief Send the status message and (optionally) current progress
to the splash screen.
- This function can be used, for example, from an external thread
- which checks the application loading progress.
+ If the second parameter is less than 0 (default) than it is ignored
+ and only the status message is changed. If you want to modify progress
+ also, pass positive value to the \a progress parameter explicitly.
\param msg progress status message
\param progress current progress
- \sa message(), setProgress()
+ \sa setMessage(), setProgress()
*/
void QtxSplash::setStatus( const QString& msg, const int progress )
{
\param error error message
\param title message box title
\param code error code
+ \sa error()
*/
-void QtxSplash::error( const QString& error, const QString& title, const int code )
+void QtxSplash::setError( const QString& error, const QString& title, const int code )
{
if ( mySplash ) {
mySplash->setError( code );
shadow = myShadowColor;
}
+/*!
+ \brief Set constant info text to be displayed on the splash screen.
+
+ The displayed text includes constant info and status message.
+ The constant message is set by setConstantInfo() method and status
+ message is set by setMessage().
+
+ \param info constant info text
+ \sa constantInfo(), message(), setMessage()
+*/
+void QtxSplash::setConstantInfo( const QString& info )
+{
+ myInfo = info;
+ repaint();
+}
+
+/*!
+ \brief Get constant info text.
+ \return constant info text
+ \sa setConstantInfo(), message(), setMessage()
+*/
+QString QtxSplash::constantInfo() const
+{
+ return myInfo;
+}
+
+/*!
+ \brief Set constant information option value.
+
+ The option is a part of the constant information text,
+ which is replaced at the time of the displaying.
+
+ The following options are supported:
+ - %A - could be used as application name
+ - %V - could be used as application version
+ - %L - could be used as application license information
+ - %C - could be used as application copyright information
+
+ \param name option name
+ \param option value
+ \sa option()
+*/
+void QtxSplash::setOption( const QString& name, const QString& value )
+{
+ myOptions[ name ] = value;
+ repaint();
+}
+
+/*!
+ \brief Get constant information option value.
+ \param name option name
+ \return option value or empty string if option is not set
+ \sa setOption()
+*/
+QString QtxSplash::option( const QString& name ) const
+{
+ QString val;
+ if ( myOptions.contains( name ) )
+ val = myOptions[ name ];
+ return val;
+}
+
/*!
\brief Get current status message.
\return status message
+ \sa setMessage(), constantInfo(), setConstantInfo()
*/
QString QtxSplash::message() const
{
If no error code has been set, 0 is returned.
\return last error code
+ \sa setError()
*/
int QtxSplash::error() const
{
QApplication::flush();
}
+/*!
+ \brief Read splash settings from the resources manager.
+ \param resMgr resources manager
+ \param section resources file section name (if empty, the default name is used).
+*/
+void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section )
+{
+ QString resSection = section.isEmpty() ? "splash" : section;
+
+ // pixmap
+ QString pxname;
+ if ( resMgr->value( resSection, "image", pxname ) ) {
+ QPixmap px( pxname );
+ if ( !px.isNull() )
+ setPixmap( px );
+ }
+
+ // hide-on-click
+#ifdef _DEBUG_
+ setHideOnClick( true );
+#else
+ bool bHide;
+ if ( resMgr->value( resSection, "hide_on_click", bHide ) ) {
+ setHideOnClick( bHide );
+ }
+#endif
+
+ // margin
+ int m;
+ if ( resMgr->value( resSection, "margin", m ) ) {
+ setMargin( m );
+ }
+
+ // progress bar width
+ int pw;
+ if ( resMgr->value( resSection, "progress_width", pw ) ) {
+ setProgressWidth( pw );
+ }
+
+ // progress bar position and direction
+ QString pf;
+ if ( resMgr->value( resSection, "progress_flags", pf ) ) {
+ bool bOk;
+ int fl = pf.toInt( &bOk );
+ if ( !bOk ) {
+ fl = 0;
+ QStringList opts = pf.split( QRegExp( "," ), QString::SkipEmptyParts );
+ for ( int i = 0; i < opts.count(); i++ ) {
+ QString opt = opts[i].trimmed().toLower();
+ if ( opt == "left" )
+ fl = fl | LeftSide;
+ else if ( opt == "right" )
+ fl = fl | RightSide;
+ else if ( opt == "top" )
+ fl = fl | TopSide;
+ else if ( opt == "bottom" )
+ fl = fl | BottomSide;
+ else if ( opt == "left_to_right" )
+ fl = fl | LeftToRight;
+ else if ( opt == "right_to_left" )
+ fl = fl | RightToLeft;
+ }
+ }
+ setProgressFlags( fl );
+ }
+
+ // opacity
+ double op;
+ if ( resMgr->value( resSection, "opacity", op ) ) {
+ setOpacity( op );
+ }
+
+ // font
+ QFont f;
+ if ( resMgr->value( resSection, "font", f ) ) {
+ setFont( f );
+ }
+
+ // text alignment
+ QString al;
+ if ( resMgr->value( resSection, "alignment", al ) ) {
+ bool bOk;
+ int fl = al.toInt( &bOk );
+ if ( !bOk ) {
+ fl = 0;
+ QStringList opts = al.split( QRegExp( "," ), QString::SkipEmptyParts );
+ for ( int i = 0; i < opts.count(); i++ ) {
+ QString opt = opts[i].trimmed().toLower();
+ if ( opt == "left" )
+ fl = fl | Qt::AlignLeft;
+ else if ( opt == "right" )
+ fl = fl | Qt::AlignRight;
+ else if ( opt == "top" )
+ fl = fl | Qt::AlignTop;
+ else if ( opt == "bottom" )
+ fl = fl | Qt::AlignBottom;
+ else if ( opt == "hcenter" )
+ fl = fl | Qt::AlignHCenter;
+ else if ( opt == "vcenter" )
+ fl = fl | Qt::AlignVCenter;
+ else if ( opt == "justify" )
+ fl = fl | Qt::AlignJustify;
+ else if ( opt == "center" )
+ fl = fl | Qt::AlignCenter;
+ }
+ }
+ setTextAlignment( fl );
+ }
+
+ // progress color(s)
+ QString pc;
+ QLinearGradient grad;
+ if ( resMgr->value( resSection, "progress_gradient", grad ) ) {
+ // gradient-colored progress bar
+ setProgressGradient( grad );
+ }
+ else if ( resMgr->value( resSection, "progress_color", pc ) ||
+ resMgr->value( resSection, "progress_colors", pc ) ) {
+ // one/two-colored progress bar
+ QStringList colors = pc.split( "|", QString::SkipEmptyParts );
+ QColor c1, c2;
+ QtxSplash::GradientType gradType = QtxSplash::Vertical;
+ if ( colors.count() > 0 ) c1 = QColor( colors[0] );
+ if ( colors.count() > 1 ) c2 = QColor( colors[1] );
+ int gt;
+ if ( colors.count() > 2 ) {
+ bool bOk;
+ gt = colors[2].toInt( &bOk );
+ if ( bOk ) {
+ if ( gt >= QtxSplash::Horizontal && gt <= QtxSplash::Vertical )
+ gradType = (QtxSplash::GradientType)gt;
+ }
+ else {
+ if ( colors[2].toLower() == "horizontal" )
+ gradType = QtxSplash::Horizontal;
+ else if ( colors[2].toLower() == "vertical" )
+ gradType = QtxSplash::Vertical;
+ }
+ }
+ setProgressColors( c1, c2, gradType );
+ }
+
+ // text color(s)
+ QString tc;
+ if ( resMgr->value( resSection, "text_color", tc ) ||
+ resMgr->value( resSection, "text_colors", tc ) ) {
+ QStringList colors = tc.split( "|", QString::SkipEmptyParts );
+ QColor c1, c2;
+ if ( colors.count() > 0 )
+ c1 = QColor( colors[0] );
+ if ( colors.count() > 1 )
+ c2 = QColor( colors[1] );
+ setTextColors( c1, c2 );
+ }
+
+ // const info
+ QString cinfo;
+ if ( resMgr->value( resSection, "constant_info", cinfo, false ) ||
+ resMgr->value( resSection, "info", cinfo, false ) ) {
+ setConstantInfo( cinfo.split( "|", QString::KeepEmptyParts ).join( "\n" ) );
+ }
+}
+
/*!
\brief Set status message for the splash screen and define its color
and aligment flags.
\param msg status message
\param alignment message text alignment flags (Qt::Alignment)
\param color message text color
+ \sa message(), constantInfo(), setConstantInfo()
*/
-void QtxSplash::message( const QString& msg,
- int alignment,
- const QColor& color )
+void QtxSplash::setMessage( const QString& msg,
+ int alignment,
+ const QColor& color )
{
myMessage = msg;
myAlignment = alignment;
\overload
\brief Set status message for the splash screen.
\param msg status message
+ \sa message(), constantInfo(), setConstantInfo()
*/
-void QtxSplash::message( const QString& msg )
+void QtxSplash::setMessage( const QString& msg )
{
myMessage = msg;
repaint();
*/
void QtxSplash::clear()
{
- myMessage = QString::null;
+ myMessage.clear();
repaint();
}
}
// draw status message
- if ( !myMessage.isEmpty() ) {
+ if ( !fullMessage().isEmpty() ) {
p->save();
drawMessage( p );
p->restore();
{
if ( ce->type() == ProgressEvent::id() ) {
ProgressEvent* pe = (ProgressEvent*)ce;
- pe->message().isEmpty() ? clear() : message( pe->message() );
- setProgress( pe->progress() );
+ pe->message().isEmpty() ? clear() : setMessage( pe->message() );
+ if ( pe->progress() >= 0 )
+ setProgress( pe->progress() );
QApplication::instance()->processEvents();
}
}
// ... take into account trailing '\n' symbols
int shift = 0;
- int i = myMessage.length() - 1;
- while( i >= 0 && myMessage[ i-- ] == '\n' )
+ QString msg = fullMessage();
+ int i = msg.length() - 1;
+ while( i >= 0 && msg[ i-- ] == '\n' )
shift += spacing;
r1.setHeight( r1.height() - shift );
if ( myAlignment & Qt::AlignRight ) r2.setRight ( r2.right() + 1 );
if ( myAlignment & Qt::AlignBottom ) r2.setBottom( r2.bottom() + 1 );
p->setPen( myShadowColor );
- p->drawText( r2, myAlignment, myMessage );
+ p->drawText( r2, myAlignment, msg );
}
// draw foreground status text
p->setPen( myColor );
- p->drawText( r1, myAlignment, myMessage );
+ p->drawText( r1, myAlignment, msg );
}
/*!
myError = code;
}
+/*!
+ \brief Get full message which includes constant info and status message.
+ \return get fill message text
+ \sa constantInfo(), setConstantInfo(), message(), setMessage()
+*/
+QString QtxSplash::fullMessage() const
+{
+ QStringList info;
+
+ QString cinfo = myInfo;
+ cinfo = cinfo.replace( QRegExp( "%A" ), option( "%A" ) );
+ cinfo = cinfo.replace( QRegExp( "%V" ), option( "%V" ) );
+ cinfo = cinfo.replace( QRegExp( "%L" ), option( "%L" ) );
+ cinfo = cinfo.replace( QRegExp( "%C" ), option( "%C" ) );
+
+ if ( !cinfo.isEmpty() )
+ info << cinfo;
+ if ( !myMessage.isEmpty() )
+ info << myMessage;
+ return info.join( "\n" );
+}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File: QtxSplash.h
-// Author: Vadim SANDLER
+// File : QtxSplash.h
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
#ifndef QTXSPLASH_H
#define QTXSPLASH_H
#include <QWidget>
#include <QPixmap>
#include <QLinearGradient>
+#include <QMap>
#ifdef WIN32
#pragma warning( disable:4251 )
#endif
+class QtxResourceMgr;
+
class QTX_EXPORT QtxSplash : public QWidget
{
Q_OBJECT
static QtxSplash* splash( const QPixmap& = QPixmap() );
- static void setStatus( const QString&, const int = 0 );
- static void error( const QString&, const QString& = QString::null, const int = -1 );
+ static void setStatus( const QString&, const int = -1 );
+ static void setError( const QString&, const QString& = QString(), const int = -1 );
void setPixmap( const QPixmap& );
QPixmap pixmap() const;
void setTextColors( const QColor&, const QColor& = QColor() );
void textColors( QColor&, QColor& ) const;
+ void setConstantInfo( const QString& info );
+ QString constantInfo() const;
+
+ void setOption( const QString&, const QString& );
+ QString option( const QString& ) const;
+
QString message() const;
int error() const;
void finish( QWidget* );
void repaint();
+ void readSettings( QtxResourceMgr*, const QString& = QString() );
+
public slots:
- void message( const QString&,
- const int,
- const QColor& = QColor() );
- void message( const QString& );
+ void setMessage( const QString&,
+ const int,
+ const QColor& = QColor() );
+ void setMessage( const QString& );
void clear();
protected:
private:
void drawContents();
void setError( const int );
+ QString fullMessage() const;
+private:
+ typedef QMap<QString, QString> OptMap;
+
private:
static QtxSplash* mySplash;
QPixmap myPixmap; //!< splash pixmap
+ QString myInfo; //!< constant info
QString myMessage; //!< current status message
int myAlignment; //!< text alignment flags (Qt::Alignment)
QColor myColor; //!< text color
double myOpacity; //!< progress bar / status message opacity
int myError; //!< error code
bool myGradientUsed; //!< 'use custom gradient color scale' flag
+ OptMap myOptions; //!< constant info options
};
#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// 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: QtxTreeView.cxx
+// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
+
+#include "QtxTreeView.h"
+
+#include <QHeaderView>
+#include <QMenu>
+#include <QMouseEvent>
+
+/*!
+ \class QtxTreeView::Header
+ \brief Custom tree view header class.
+ \internal
+*/
+
+class QtxTreeView::Header : public QHeaderView
+{
+public:
+ Header( const bool, QWidget* = 0 );
+ ~Header();
+
+ void setSortMenuEnabled( const bool );
+ bool sortMenuEnabled() const;
+
+protected:
+ void contextMenuEvent( QContextMenuEvent* );
+
+private:
+ bool myEnableSortMenu;
+};
+
+/*!
+ \brief Constructor
+ \param enableSortMenu show "Sorting" menu if \c true
+ \param parent parent widget
+ \internal
+*/
+QtxTreeView::Header::Header( const bool enableSortMenu, QWidget* parent )
+: QHeaderView( Qt::Horizontal, parent ),
+ myEnableSortMenu( enableSortMenu )
+{
+}
+
+/*!
+ \brief Destructor
+ \internal
+*/
+QtxTreeView::Header::~Header()
+{
+}
+
+/*
+ \brief Enable/disable "Sorting" popup menu command for the header.
+ \param enableSortMenu if \c true, enable "Sorting" menu command
+ \internal
+*/
+void QtxTreeView::Header::setSortMenuEnabled( const bool enableSortMenu )
+{
+ myEnableSortMenu = enableSortMenu;
+}
+
+/*
+ \brief Check if "Sorting" popup menu command for the header is enabled.
+ \return \c true if "Sorting" menu command is enabled
+ \internal
+*/
+bool QtxTreeView::Header::sortMenuEnabled() const
+{
+ return myEnableSortMenu;
+}
+
+/*!
+ \brief Customize context menu event.
+ \internal
+
+ Shows popup menu with the list of the available columns allowing the user to
+ show/hide the specified column.
+
+ \param e context menu event
+*/
+void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e )
+{
+ QMenu menu;
+ QMap<QAction*, int> actionMap;
+ for ( int i = 0; i < count(); i++ ) {
+ QString lab = model()->headerData( i, orientation(), Qt::DisplayRole ).toString();
+ QVariant iconData = model()->headerData( i, orientation(), Qt::DecorationRole );
+ QVariant appropriate = model()->headerData( i, orientation(), Qtx::AppropriateRole );
+ QIcon icon;
+ if ( iconData.isValid() ) {
+ if ( qVariantCanConvert<QIcon>( iconData ) )
+ icon = qVariantValue<QIcon>( iconData );
+ else if ( qVariantCanConvert<QPixmap>( iconData ) )
+ icon = qVariantValue<QPixmap>( iconData );
+ }
+ if ( ( !lab.isEmpty() || !icon.isNull() ) &&
+ appropriate.isValid() ? appropriate.toBool() : true ) {
+ QAction* a = menu.addAction( icon, lab );
+ a->setCheckable( true );
+ a->setChecked( !isSectionHidden( i ) );
+ actionMap.insert( a, i );
+ }
+ }
+ QAction* sortAction = 0;
+ if ( count() > 0 && myEnableSortMenu ) {
+ menu.addSeparator();
+ sortAction = menu.addAction( tr( "Enable sorting" ) );
+ sortAction->setCheckable( true );
+ sortAction->setChecked( isSortIndicatorShown() );
+ }
+ if ( !menu.isEmpty() ) {
+ Qtx::simplifySeparators( &menu );
+ QAction* a = menu.exec( e->globalPos() );
+ if ( a && actionMap.contains( a ) ) {
+ setSectionHidden( actionMap[ a ], !isSectionHidden( actionMap[ a ] ) );
+ }
+ else if ( a && a == sortAction ) {
+ setSortIndicatorShown( a->isChecked() );
+ setClickable( a->isChecked() );
+ QtxTreeView* view = qobject_cast<QtxTreeView*>( parent() );
+ if ( view ) {
+ view->emitSortingEnabled( a->isChecked() );
+ if ( a->isChecked() ) {
+ connect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
+ view->sortByColumn( sortIndicatorSection(), sortIndicatorOrder() );
+ }
+ else {
+ disconnect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
+ view->sortByColumn( 0, Qt::AscendingOrder );
+ }
+ }
+ }
+ }
+ e->accept();
+}
+
+/*!
+ \class QtxTreeView
+ \brief Tree view class with possibility to display columns popup menu.
+
+ The QtxTreeView class represents a customized tree view class. In addition to the
+ base functionality inherited from the QTreeView class, clicking at the tree view
+ header with the right mouse button displays the popup menu allowing the user
+ to show/hide specified columns.
+
+ By default the popup menu contains items corresponding to all the tree view columns.
+ In order to disable some columns from being shown in the popup menu one may customize
+ the data model (see QAbstractItemModel class). The custom model should implement
+ headerData() method and return \c true for the Qtx::AppropriateRole role for
+ those columns which should be available in the popup menu and \c false for the columns
+ which should not be added to it.
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent widget
+*/
+QtxTreeView::QtxTreeView( QWidget* parent )
+: QTreeView( parent )
+{
+ setHeader( new Header( false, this ) );
+}
+
+/*!
+ \brief Constructor.
+ \param enableSortMenu show "Sorting" header menu command if \c true
+ \param parent parent widget
+*/
+QtxTreeView::QtxTreeView( const bool enableSortMenu, QWidget* parent )
+: QTreeView( parent )
+{
+ setHeader( new Header( enableSortMenu, this ) );
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxTreeView::~QtxTreeView()
+{
+}
+
+/*!
+ \brief Expand all branches for specified number of levels.
+
+ If \c levels < 0, all branches are expanded (the same results can
+ be achieved with expandAll() method).
+
+ \param levels number of levels to be opened
+ \sa collapseLevels(), setOpened()
+*/
+void QtxTreeView::expandLevels( const int levels )
+{
+ setOpened( rootIndex(), levels+1, true );
+}
+
+/*!
+ \brief Collapse all branches for specified number of levels.
+
+ If \c levels < 0, all branches are collapsed (the same results can
+ be achieved with collapseAll() method).
+
+ \param levels number of levels to be collapsed
+ \sa expandLevels(), setOpened()
+*/
+void QtxTreeView::collapseLevels( const int levels )
+{
+ setOpened( rootIndex(), levels+1, false );
+}
+
+/*!
+ \brief Expand the branch specifed by the \index and all its
+ children recursively.
+ \param index model index to be expanded
+ \sa collapseAll()
+*/
+void QtxTreeView::expandAll( const QModelIndex& index )
+{
+ setOpened( index, -1, true );
+}
+
+/*!
+ \brief Collapse the branch specifed by the \index and all its
+ children recursively.
+ \param index model index to be collapsed
+ \sa expandAll()
+*/
+void QtxTreeView::collapseAll( const QModelIndex& index )
+{
+ setOpened( index, -1, false );
+}
+
+/*
+ \brief Enable/disable "Sorting" popup menu command for the header.
+ \param enableSortMenu if \c true, enable "Sorting" menu command
+ \sa sortMenuEnabled()
+*/
+void QtxTreeView::setSortMenuEnabled( const bool enableSortMenu )
+{
+ Header* h = dynamic_cast<Header*>( header() );
+ if ( h )
+ h->setSortMenuEnabled( enableSortMenu );
+}
+
+/*
+ \brief Check if "Sorting" popup menu command for the header is enabled.
+ \return \c true if "Sorting" menu command is enabled
+ \sa setSortMenuEnabled()
+*/
+bool QtxTreeView::sortMenuEnabled() const
+{
+ Header* h = dynamic_cast<Header*>( header() );
+ return h ? h->sortMenuEnabled() : false;
+}
+
+/*
+ \brief Called when the header section is clicked.
+ \param column header column index
+*/
+void QtxTreeView::onHeaderClicked( int column )
+{
+ sortByColumn( column, header()->sortIndicatorOrder() );
+}
+
+/*!
+ \brief Called when the selection is changed.
+
+ Emits selectionChanged() signal.
+
+ \param selected new selection
+ \param deselected previous selection
+*/
+void QtxTreeView::selectionChanged( const QItemSelection& selected,
+ const QItemSelection& deselected )
+{
+ QTreeView::selectionChanged( selected, deselected );
+ emit( selectionChanged() );
+}
+
+/*!
+ \brief Expand/collapse the specified item (recursively).
+ \param index model index
+ \param levels number of levels to be expanded/collapsed
+ \param open if \c true, item is expanded, otherwise it is collapsed
+ \sa expandLevels(), collapseLevels()
+*/
+void QtxTreeView::setOpened( const QModelIndex& index, const int levels, bool open )
+{
+ if ( !levels )
+ return;
+
+ if ( !index.isValid() && index != rootIndex() )
+ return;
+
+ setExpanded( index, open );
+
+ for ( int i = 0; i < model()->rowCount( index ); i++ ) {
+ QModelIndex child = model()->index( i, 0, index );
+ setOpened( child, levels-1, open );
+ }
+}
+
+/*!
+ \fn QtxTreeView::sortingEnabled( bool on );
+ \brief Emitted when "Sorting" commans is enabled/disabled from the popup menu.
+ \param on \c true if sorting is enabled and \c false otherwise
+*/
+
+/*!
+ \fn QtxTreeView::selectionChanged();
+ \brief Emitted when selection is changed in the tree view.
+*/
+
+/*!
+ \brief Emit sortingEnabled(bool) signal.
+ \param enabled "enable sorting" flag state
+*/
+void QtxTreeView::emitSortingEnabled( bool enabled )
+{
+ emit( sortingEnabled( enabled ) );
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// 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: QtxTreeView.h
+// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
+
+#ifndef QTXTREEVIEW_H
+#define QTXTREEVIEW_H
+
+#include "Qtx.h"
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+#include <QTreeView>
+
+class QTX_EXPORT QtxTreeView : public QTreeView
+{
+ Q_OBJECT
+
+ class Header;
+
+public:
+ QtxTreeView( QWidget* = 0 );
+ QtxTreeView( const bool, QWidget* = 0 );
+ virtual ~QtxTreeView();
+
+ void expandLevels( const int );
+ void collapseLevels( const int );
+
+ void expandAll( const QModelIndex& );
+ void collapseAll( const QModelIndex& );
+
+ void setSortMenuEnabled( const bool );
+ bool sortMenuEnabled() const;
+
+protected slots:
+ void onHeaderClicked( int );
+ void selectionChanged( const QItemSelection&, const QItemSelection& );
+
+protected:
+ void setOpened( const QModelIndex&, const int, bool );
+
+signals:
+ void sortingEnabled( bool );
+ void selectionChanged();
+
+private:
+ void emitSortingEnabled( bool );
+
+ friend class QtxTreeView::Header;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif // QTXTREEVIEW_H
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
-
-// TODO
-//#include <QtxSplash.h>
+#include <Style_Salome.h>
+#include <Style_Model.h>
+#include <QtxSplash.h>
#ifdef SUIT_ENABLE_PYTHON
#include <Python.h>
#endif
-#include <QtCore/qdir.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qregexp.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
+#include <QDir>
+#include <QFile>
+#include <QRegExp>
+#include <QString>
+#include <QStringList>
#include <stdlib.h>
-QString salomeVersion()
+static QString salomeVersion()
{
QString path( ::getenv( "GUI_ROOT_DIR" ) );
if ( !path.isEmpty() )
QFile vf( path );
if ( !vf.open( QFile::ReadOnly ) )
- return QString::null;
+ return QString();
QString line = vf.readLine( 1024 );
vf.close();
if ( line.isEmpty() )
- return QString::null;
+ return QString();
while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
line.remove( line.length() - 1, 1 );
return ver;
}
+static void MessageOutput( QtMsgType type, const char* msg )
+{
+ switch ( type )
+ {
+ case QtDebugMsg:
+#ifdef _DEBUG_
+ printf( "Debug: %s\n", msg );
+#endif
+ break;
+ case QtWarningMsg:
+#ifdef _DEBUG_
+ printf( "Warning: %s\n", msg );
+#endif
+ break;
+ case QtFatalMsg:
+#ifdef _DEBUG_
+ printf( "Fatal: %s\n", msg );
+#endif
+ break;
+ default:
+ break;
+ }
+}
/* XPM */
static const char* pixmap_not_found_xpm[] = {
PySys_SetArgv( args, argv );
#endif
+ qInstallMsgHandler( MessageOutput );
+
QStringList argList;
bool noExceptHandling = false;
bool iniFormat = false;
if ( !argList.isEmpty() )
{
SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
- // TODO
-/*
QtxSplash* splash = 0;
- if ( !noSplash )
+ if ( !noSplash )
{
SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
if ( resMgr )
{
- resMgr->loadLanguage();
- QString splashIcon, splashInfo, splashTextColors;
- resMgr->value( "splash", "image", splashIcon );
- resMgr->value( "splash", "info", splashInfo, false );
- resMgr->value( "splash", "text_colors", splashTextColors );
- QString appName = QObject::tr( "APP_NAME" ).stripWhiteSpace();
- QString appVersion = QObject::tr( "APP_VERSION" ).stripWhiteSpace();
- if ( appVersion == "APP_VERSION" )
- {
- if ( appName == "APP_NAME" || appName.toLower() == "salome" )
- appVersion = salomeVersion();
- else
- appVersion = "";
- }
- QPixmap px( splashIcon );
- if ( !px.isNull() )
- {
- splash = QtxSplash::splash( px );
- if ( !splashTextColors.isEmpty() )
- {
- QStringList colors = QStringList::split( "|", splashTextColors );
- QColor c1, c2;
- if ( colors.count() > 0 )
- c1 = QColor( colors[0] );
- if ( colors.count() > 1 )
- c2 = QColor( colors[1] );
- splash->setTextColors( c1, c2 );
- }
- else
- {
- splash->setTextColors( Qt::white, Qt::black );
- }
-#ifdef _DEBUG_
- splash->setHideOnClick( true );
-#endif
- QFont f = splash->font();
- f.setBold( true );
- splash->setFont( f );
- if ( !splashInfo.isEmpty() )
- {
- splashInfo.replace( QRegExp( "%A" ), appName );
- splashInfo.replace( QRegExp( "%V" ), QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
- splashInfo.replace( QRegExp( "%L" ), QObject::tr( "ABOUT_LICENSE" ) );
- splashInfo.replace( QRegExp( "%C" ), QObject::tr( "ABOUT_COPYRIGHT" ) );
- splashInfo.replace( QRegExp( "\\\\n" ), "\n" );
- splash->message( splashInfo );
- }
- splash->show();
- QApplication::instance()->processEvents();
- }
+ resMgr->loadLanguage();
+
+ splash = QtxSplash::splash( QPixmap() );
+ splash->readSettings( resMgr );
+ if ( splash->pixmap().isNull() ) {
+ delete splash;
+ splash = 0;
+ }
+ else {
+ QString appName = QObject::tr( "APP_NAME" ).trimmed();
+ QString appVersion = QObject::tr( "APP_VERSION" ).trimmed();
+ if ( appVersion == "APP_VERSION" )
+ {
+ if ( appName == "APP_NAME" || appName.toLower() == "salome" )
+ appVersion = salomeVersion();
+ else
+ appVersion = "";
+ }
+ splash->setOption( "%A", appName );
+ splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
+ splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
+ splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
+ splash->show();
+ QApplication::instance()->processEvents();
+ }
}
}
-*/
+
SUIT_Application* theApp = aSession->startApplication( argList.first() );
if ( theApp )
{
+ Style_Salome* aStyle = new Style_Salome();
+ aStyle->getModel()->initFromResource( theApp->resourceMgr() );
+ app.setStyle( aStyle );
+
if ( !noExceptHandling )
app.setHandler( aSession->handler() );
-// TODO
-// if ( splash )
-// splash->finish( theApp->desktop() );
+ if ( splash )
+ splash->finish( theApp->desktop() );
result = app.exec();
-// TODO
-// delete splash;
+ delete splash;
}
delete aSession;
}
OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET
INCLUDEPATH = ../../include
-LIBS += -L../../$(CONFIG_ID)/lib -lSUIT -lQtx
+LIBS += -L../../$(CONFIG_ID)/lib -lSUIT -lQtx -lStyle
CONFIG -= debug release debug_and_release
CONFIG += qt thread debug dll shared
#include "SUITApp_Application.h"
#include <SUIT_Tools.h>
-#include <SUIT_MessageBox.h>
#include <SUIT_ExceptionHandler.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qfileinfo.h>
-#include <QtCore/qtranslator.h>
+#include <QDir>
+#include <QTranslator>
#ifdef WIN32
#include <windows.h>
#ifndef SUITAPP_APPLICATION_H
#define SUITAPP_APPLICATION_H
-#include <QtGui/qapplication.h>
+#include <QApplication>
class SUIT_ExceptionHandler;