SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utility.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9  License for the specific language governing rights and limitations under
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 #ifndef UTILITY_H
30 #define UTILITY_H
31 
32 #include <sstream>
33 
34 namespace SCIRun {
35 
36 template <class Point>
37 std::string to_string(const Point& p)
38 {
39  std::ostringstream ostr;
40  ostr << "QPoint(" << p.x() << "," << p.y() << ")";
41  return ostr.str();
42 }
43 
44 namespace Gui
45 {
46  //TODO un-inline
47 
48  inline QColor to_color(const std::string& str)
49  {
50  if (str == "red")
51  return Qt::red;
52  if (str == "blue")
53  return Qt::blue;
54  if (str == "darkBlue")
55  return Qt::darkBlue;
56  if (str == "cyan")
57  return Qt::cyan;
58  if (str == "darkCyan")
59  return Qt::darkCyan;
60  if (str == "darkGreen")
61  return Qt::darkGreen;
62  if (str == "cyan")
63  return Qt::cyan;
64  if (str == "magenta")
65  return Qt::magenta;
66  if (str == "white")
67  return Qt::white;
68  if (str == "yellow")
69  return Qt::yellow;
70  if (str == "darkYellow")
71  return Qt::darkYellow;
72  if (str == "lightGray")
73  return Qt::lightGray;
74  if (str == "darkGray")
75  return Qt::darkGray;
76  if (str == "black")
77  return Qt::black;
78  if (str == "purple")
79  return Qt::darkMagenta;
80  if (str == "orange")
81  return QColor(255, 165, 0);
82  else
83  return Qt::black;
84  }
85 
86  inline QAction* separatorAction(QWidget* parent)
87  {
88  auto sep = new QAction(parent);
89  sep->setSeparator(true);
90  return sep;
91  }
92 
93  inline QAction* disabled(QAction* action)
94  {
95  action->setEnabled(false);
96  return action;
97  }
98 
99 
100  inline std::ostream& operator<<(std::ostream& o, const QPointF& p)
101  {
102  return o << "[" << p.x() << "," << p.y() << "]";
103  }
104 }
105 
106 }
107 
108 #endif
std::string to_string(const MatrixHandle &mat)
Definition: Matrix.h:213
void y(const double)
Definition: Point.h:135
Definition: Point.h:49
QColor to_color(const std::string &str)
Definition: Utility.h:48
void x(const double)
Definition: Point.h:125
QAction * disabled(QAction *action)
Definition: Utility.h:93
std::ostream & operator<<(std::ostream &o, const QPointF &p)
Definition: Utility.h:100
QAction * separatorAction(QWidget *parent)
Definition: Utility.h:86