Salome HOME
updated copyright message
[modules/gui.git] / src / CAF / CAF_Tools.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
23 //  File   : CAF_Tools.cxx
24 //  Author : UI team
25 //
26 #include "CAF_Tools.h"
27
28 /*!
29   \class CAF_Tools
30   \brief Prodives a set of helpful static methods.
31 */
32
33 /*!
34   \brief Convert TCollection_ExtendedString \a src to QString.
35   \param src string to be converted
36   \return resulting QString object
37 */
38 QString CAF_Tools::toQString ( const TCollection_ExtendedString& src )
39 {
40   return QString( (const QChar*)src.ToExtString(), src.Length() );
41 }
42
43 /*!
44   \brief Convert TCollection_AsciiString \a src to QString.
45   \param src string to be converted
46   \return resulting QString object
47 */
48 QString CAF_Tools::toQString( const TCollection_AsciiString& src )
49 {
50   return QString( src.ToCString() );
51 }
52
53 /*!
54   \brief Convert QString \a src to TCollection_AsciiString.
55   \param src string to be converted
56   \return resulting TCollection_AsciiString object
57 */
58 TCollection_AsciiString CAF_Tools::toAsciiString( const QString& src )
59 {
60   TCollection_AsciiString res;
61   if ( !src.isEmpty() )
62     res = TCollection_AsciiString( src.toLatin1().data() );
63   return res;
64 }
65
66 /*!
67   \brief Convert QString \a src to TCollection_ExtendedString.
68   \param src string to be converted
69   \return resulting TCollection_ExtendedString object
70 */
71 TCollection_ExtendedString CAF_Tools::toExtString ( const QString& src )
72 {
73   TCollection_ExtendedString result;
74   for ( int i = 0; i < (int)src.length(); i++ )
75     result.Insert( i + 1, src[ i ].unicode() );
76   return result;
77 }
78
79 /*!
80   \brief Convert QColor object to Quantity_Color object.
81   \param c color object in Qt format
82   \return color object in OCC format
83 */
84 Quantity_Color CAF_Tools::color( const QColor& c )
85 {
86   Quantity_Color aColor;
87   if ( c.isValid() )
88     aColor = Quantity_Color( c.red()   / 255., c.green() / 255.,
89                              c.blue()  / 255., Quantity_TOC_RGB );
90   return aColor;
91 }
92
93 /*!
94   \brief Convert Quantity_Color object to QColor object.
95   \param c color object in OCC format
96   \return color object in Qt format
97 */
98 QColor CAF_Tools::color( const Quantity_Color& c )
99 {
100   return QColor ( int( c.Red()   * 255 ),
101                   int( c.Green() * 255 ),
102                   int( c.Blue()  * 255 ) );
103 }