1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : CAF_Tools.cxx
26 #include "CAF_Tools.h"
30 \brief Prodives a set of helpful static methods.
34 \brief Convert TCollection_ExtendedString \a src to QString.
35 \param src string to be converted
36 \return resulting QString object
38 QString CAF_Tools::toQString ( const TCollection_ExtendedString& src )
40 return QString( (const QChar*)src.ToExtString(), src.Length() );
44 \brief Convert TCollection_AsciiString \a src to QString.
45 \param src string to be converted
46 \return resulting QString object
48 QString CAF_Tools::toQString( const TCollection_AsciiString& src )
50 return QString( src.ToCString() );
54 \brief Convert QString \a src to TCollection_AsciiString.
55 \param src string to be converted
56 \return resulting TCollection_AsciiString object
58 TCollection_AsciiString CAF_Tools::toAsciiString( const QString& src )
60 TCollection_AsciiString res;
62 res = TCollection_AsciiString( src.toLatin1().data() );
67 \brief Convert QString \a src to TCollection_ExtendedString.
68 \param src string to be converted
69 \return resulting TCollection_ExtendedString object
71 TCollection_ExtendedString CAF_Tools::toExtString ( const QString& src )
73 TCollection_ExtendedString result;
74 for ( int i = 0; i < (int)src.length(); i++ )
75 result.Insert( i + 1, src[ i ].unicode() );
80 \brief Convert QColor object to Quantity_Color object.
81 \param c color object in Qt format
82 \return color object in OCC format
84 Quantity_Color CAF_Tools::color( const QColor& c )
86 Quantity_Color aColor;
88 aColor = Quantity_Color( c.red() / 255., c.green() / 255.,
89 c.blue() / 255., Quantity_TOC_RGB );
94 \brief Convert Quantity_Color object to QColor object.
95 \param c color object in OCC format
96 \return color object in Qt format
98 QColor CAF_Tools::color( const Quantity_Color& c )
100 return QColor ( int( c.Red() * 255 ),
101 int( c.Green() * 255 ),
102 int( c.Blue() * 255 ) );