parse_color.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
31 
32 namespace rviz
33 {
34 
35 static int limit( int i )
36 {
37  if( i < 0 )
38  return 0;
39  if( i > 255 )
40  return 255;
41  return i;
42 }
43 
44 QColor parseColor( const QString& color_string )
45 {
46  if( color_string.indexOf( ';' ) != -1 )
47  {
48  QStringList strings = color_string.split( ';' );
49  if( strings.size() >= 3 )
50  {
51  bool r_ok = true;
52  int r = strings[ 0 ].toInt( &r_ok );
53  bool g_ok = true;
54  int g = strings[ 1 ].toInt( &g_ok );
55  bool b_ok = true;
56  int b = strings[ 2 ].toInt( &b_ok );
57  if( r_ok && g_ok && b_ok )
58  {
59  return QColor( limit( r ), limit( g ), limit( b ));
60  }
61  }
62  return QColor();
63  }
64 
65  QColor new_color;
66  if( QColor::colorNames().contains( color_string, Qt::CaseInsensitive ) ||
67  (color_string.size() > 0 && color_string[ 0 ] == '#' ))
68  {
69  new_color.setNamedColor( color_string.toLower() );
70  }
71  return new_color;
72 }
73 
74 QString printColor( const QColor& color )
75 {
76  return QString( "%1; %2; %3" )
77  .arg( color.red() )
78  .arg( color.green() )
79  .arg( color.blue() );
80 }
81 
82 QColor ogreToQt( const Ogre::ColourValue& c )
83 {
84  return QColor::fromRgbF( c.r, c.g, c.b, c.a );
85 }
86 
87 Ogre::ColourValue qtToOgre( const QColor& c )
88 {
89  return Ogre::ColourValue( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
90 }
91 
92 } // end namespace rviz
static int limit(int i)
Definition: parse_color.cpp:35
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:87
QColor ogreToQt(const Ogre::ColourValue &c)
Definition: parse_color.cpp:82
QColor parseColor(const QString &color_string)
Definition: parse_color.cpp:44
QString printColor(const QColor &color)
Definition: parse_color.cpp:74
r


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41