Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / CAF / CAF_Tools.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : CAF_Tools.cxx
23 //  Author : UI team
24 //
25 #include "CAF_Tools.h"
26
27 /*!
28   \class CAF_Tools
29   \brief Prodives a set of helpful static methods.
30 */
31
32 /*!
33   \brief Convert TCollection_ExtendedString \a src to QString.
34   \param src string to be converted
35   \return resulting QString object
36 */
37 QString CAF_Tools::toQString ( const TCollection_ExtendedString& src )
38 {
39   return QString( (const QChar*)src.ToExtString(), src.Length() );
40 }
41
42 /*!
43   \brief Convert TCollection_AsciiString \a src to QString.
44   \param src string to be converted
45   \return resulting QString object
46 */
47 QString CAF_Tools::toQString( const TCollection_AsciiString& src )
48 {
49   return QString( src.ToCString() );
50 }
51
52 /*!
53   \brief Convert QString \a src to TCollection_AsciiString.
54   \param src string to be converted
55   \return resulting TCollection_AsciiString object
56 */
57 TCollection_AsciiString CAF_Tools::toAsciiString( const QString& src )
58 {
59   TCollection_AsciiString res;
60   if ( !src.isEmpty() )
61     res = TCollection_AsciiString( src.toLatin1().data() );
62   return res;
63 }
64
65 /*!
66   \brief Convert QString \a src to TCollection_ExtendedString.
67   \param src string to be converted
68   \return resulting TCollection_ExtendedString object
69 */
70 TCollection_ExtendedString CAF_Tools::toExtString ( const QString& src )
71 {
72   TCollection_ExtendedString result;
73   for ( int i = 0; i < (int)src.length(); i++ )
74     result.Insert( i + 1, src[ i ].unicode() );
75   return result;
76 }
77
78 /*!
79   \brief Convert QColor object to Quantity_Color object.
80   \param c color object in Qt format
81   \return color object in OCC format
82 */
83 Quantity_Color CAF_Tools::color( const QColor& c )
84 {
85   Quantity_Color aColor;
86   if ( c.isValid() )
87     aColor = Quantity_Color( c.red()   / 255., c.green() / 255.,
88                              c.blue()  / 255., Quantity_TOC_RGB );
89   return aColor;
90 }
91
92 /*!
93   \brief Convert Quantity_Color object to QColor object.
94   \param c color object in OCC format
95   \return color object in Qt format
96 */
97 QColor CAF_Tools::color( const Quantity_Color& c )
98 {
99   return QColor ( int( c.Red()   * 255 ),
100                   int( c.Green() * 255 ),
101                   int( c.Blue()  * 255 ) );
102 }