From: stv Date: Tue, 10 Jan 2006 14:13:29 +0000 (+0000) Subject: Color conversion methods. X-Git-Tag: T_Before_Join_BR-D5-38-2003~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d7d04faee7288d2dddb0225e99975cbe85eef2c9;p=modules%2Fgui.git Color conversion methods. --- diff --git a/src/CAF/CAF_Tools.cxx b/src/CAF/CAF_Tools.cxx index 41b56f6e1..c32d4a27e 100755 --- a/src/CAF/CAF_Tools.cxx +++ b/src/CAF/CAF_Tools.cxx @@ -29,7 +29,26 @@ */ QString CAF_Tools::toQString ( const TCollection_ExtendedString& src ) { - return QString( (const QChar*)src.ToExtString(), src.Length() ); + return QString( (const QChar*)src.ToExtString(), src.Length() ); +} + +/*! + Converts TCollection_AsciiString'src' to Qt string. [ static ] +*/ +QString CAF_Tools::toQString( const TCollection_AsciiString& src ) +{ + return QString( src.ToCString() ); +} + +/*! + Converts Qt string to TCollection_AsciiString. [ static ] +*/ +TCollection_AsciiString CAF_Tools::toAsciiString( const QString& src ) +{ + TCollection_AsciiString res; + if ( !src.isEmpty() ) + res = TCollection_AsciiString( (char*)src.latin1() ); + return res; } /*! @@ -37,8 +56,24 @@ QString CAF_Tools::toQString ( const TCollection_ExtendedString& src ) */ TCollection_ExtendedString CAF_Tools::toExtString ( const QString& src ) { - TCollection_ExtendedString result; - for ( int i = 0; i < (int)src.length(); i++ ) - result.Insert( i + 1, src[ i ].unicode() ); - return result; + TCollection_ExtendedString result; + for ( int i = 0; i < (int)src.length(); i++ ) + result.Insert( i + 1, src[ i ].unicode() ); + return result; +} + +Quantity_Color CAF_Tools::color( const QColor& c ) +{ + Quantity_Color aColor; + if ( c.isValid() ) + aColor = Quantity_Color( c.red() / 255., c.green() / 255., + c.blue() / 255., Quantity_TOC_RGB ); + return aColor; +} + +QColor CAF_Tools::color( const Quantity_Color& c ) +{ + return QColor ( int( c.Red() * 255 ), + int( c.Green() * 255 ), + int( c.Blue() * 255 ) ); } diff --git a/src/CAF/CAF_Tools.h b/src/CAF/CAF_Tools.h index 8af84f9fe..e04d1c9d8 100755 --- a/src/CAF/CAF_Tools.h +++ b/src/CAF/CAF_Tools.h @@ -26,13 +26,24 @@ #include +#include + +#include + +#include #include class CAF_EXPORT CAF_Tools : public SUIT_Tools { public: + static QString toQString( const TCollection_AsciiString& ); static QString toQString( const TCollection_ExtendedString& ); + static TCollection_ExtendedString toExtString( const QString& ); + static TCollection_AsciiString toAsciiString( const QString& ); + + static Quantity_Color color( const QColor& ); + static QColor color( const Quantity_Color& ); }; #endif