MorphoGraphX  2.0-1-227
Colors.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2016 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef COLORS_HPP
12 #define COLORS_HPP
13 
14 #include <Config.hpp>
15 
16 #include <Color.hpp>
17 #include <Parms.hpp>
18 #include <Util.hpp>
19 
20 #include <QAbstractItemModel>
21 #include <QFont>
22 #include <QModelIndex>
23 #include <QString>
24 #include <QTextStream>
25 #include <vector>
26 
27 namespace mgx
28 {
29  class mgx_EXPORT Colors : public QAbstractItemModel
30  {
31  Q_OBJECT
32 
33  public:
35  enum ColorType {
37  //\name First mesh
40  // Mesh1PointColor,
44  //\name Second mesh
49  // Mesh2PointColor,
53  //\name Others
64  //\name Summary
68  StartMesh1 = Mesh1Color,
69  StartMesh2 = Mesh2Color,
70  StartOthers = BackgroundColor
71  };
73 
74  static const QString colorNames[NbColors];
75  static const QString categoryNames[3];
76  static const int categoryShift[3];
77  static const int categorySize[3];
78 
79  Colors();
80  virtual ~Colors() {}
81 
82  void readParms(Parms& parms, QString section);
83  void writeParms(QTextStream& pout, QString section);
84 
85  bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
86 
87  QColor color(const QModelIndex& index) const
88  {
89  return data(index, Qt::DecorationRole).value<QColor>();
90  }
91  void setColor(const QModelIndex& index, QColor col)
92  {
93  setData(index, col, Qt::DecorationRole);
94  }
95 
96  QColor qcolor(ColorType type) const { return colors[type]; }
97  Colorf color(ColorType type) const { return (Colorf)colors[type]; }
98 
99  int rowCount(const QModelIndex& parent = QModelIndex()) const;
100  int columnCount(const QModelIndex& parent = QModelIndex()) const;
101 
102  Qt::ItemFlags flags(const QModelIndex& index) const;
103 
104  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
105  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
106  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
107 
108  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
109  QModelIndex parent(const QModelIndex& index) const;
110 
111  static Colors* instance()
112  {
113  if(_instance == 0)
114  _instance = new Colors();
115  return _instance;
116  }
117 
118  static QColor getQColor(ColorType type) {
119  return instance()->qcolor(type);
120  }
121 
122  static Colorf getColor(ColorType type) {
123  return instance()->color(type);
124  }
125 
126  signals:
127  void colorsChanged();
128 
129  public slots:
130  void backupColors();
131  void restoreColors();
132  void resetColors();
133 
134  protected:
135  std::vector<QColor> colors, backup;
136  QFont _font;
137  static Colors* _instance;
138  };
139 }
140 #endif
mgx::Colors::Stack2BBoxColor
@ Stack2BBoxColor
Color of the bounding box.
Definition: Colors.hpp:52
mgx::Colors::color
Colorf color(ColorType type) const
Definition: Colors.hpp:97
mgx::Colors::getColor
static Colorf getColor(ColorType type)
Definition: Colors.hpp:122
mgx::Colors::CuttingPlaneGridColor
@ CuttingPlaneGridColor
Color of the grid of the cutting surface.
Definition: Colors.hpp:60
mgx::Colors::Mesh1SelectColor
@ Mesh1SelectColor
Color of the selected points and edges.
Definition: Colors.hpp:41
mgx::Colors::Stack1BBoxColor
@ Stack1BBoxColor
Color of the bounding box.
Definition: Colors.hpp:43
mgx::Colors::VoxelEditColor
@ VoxelEditColor
Color of the xircle for the pixel edit tool.
Definition: Colors.hpp:63
mgx::Colors::NbColors
@ NbColors
Definition: Colors.hpp:67
mgx::Colors::Clip1GridColor
@ Clip1GridColor
Color of the grid of the 1st clipping planes.
Definition: Colors.hpp:57
mgx::Colors::color
QColor color(const QModelIndex &index) const
Definition: Colors.hpp:87
mgx::Colors::LegendColor
@ LegendColor
Color of the text and lines in the color bar.
Definition: Colors.hpp:61
mgx::Colors::ColorType
ColorType
Mesh1 and 2 must have the same order for their colors.
Definition: Colors.hpp:35
mgx::Colors::colors
std::vector< QColor > colors
Definition: Colors.hpp:135
mgx::Colors::setColor
void setColor(const QModelIndex &index, QColor col)
Definition: Colors.hpp:91
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::Colors::Clip3GridColor
@ Clip3GridColor
Color of the grid of the 3rd clipping planes.
Definition: Colors.hpp:59
mgx::Colors::Mesh2Color
@ Mesh2Color
Definition: Colors.hpp:47
Parms.hpp
mgx::Colors::getQColor
static QColor getQColor(ColorType type)
Definition: Colors.hpp:118
mgx::Colors::instance
static Colors * instance()
Definition: Colors.hpp:111
mgx::Colors::BackgroundColor
@ BackgroundColor
Definition: Colors.hpp:56
mgx::Colors
Definition: Colors.hpp:29
Util.hpp
mgx::Colors::_font
QFont _font
Definition: Colors.hpp:136
mgx::Colors::qcolor
QColor qcolor(ColorType type) const
Definition: Colors.hpp:96
Color.hpp
mgx::Colors::Mesh1BorderColor
@ Mesh1BorderColor
Color of the border.
Definition: Colors.hpp:39
mgx::Color< float >
mgx::Colors::Mesh2CellsColor
@ Mesh2CellsColor
Color of the cell ids.
Definition: Colors.hpp:51
mgx::Colors::Mesh2SelectColor
@ Mesh2SelectColor
Color of the selected points and edges.
Definition: Colors.hpp:50
mgx::Colors::ScaleBarColor
@ ScaleBarColor
Color of the text and lines in the scale bar.
Definition: Colors.hpp:62
mgx::Colors::Mesh2BorderColor
@ Mesh2BorderColor
Color of the border.
Definition: Colors.hpp:48
mgx::Colors::~Colors
virtual ~Colors()
Definition: Colors.hpp:80
mgx::Colors::_instance
static Colors * _instance
Definition: Colors.hpp:137
mgx::Parms
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:116
mgx::Colors::Mesh1CellsColor
@ Mesh1CellsColor
Color of the cell ids.
Definition: Colors.hpp:42
mgx::Colors::Mesh1Color
@ Mesh1Color
Color of the lines.
Definition: Colors.hpp:38
mgx::Colors::Clip2GridColor
@ Clip2GridColor
Color of the grid of the 2nd clipping planes.
Definition: Colors.hpp:58