MorphoGraphX
Colors.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 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 
19 #include <QAbstractItemModel>
20 #include <QFont>
21 #include <QModelIndex>
22 #include <QString>
23 #include <QTextStream>
24 #include <vector>
25 
26 namespace mgx {
27 typedef util::Color<float> Colorf;
28 
29 class mgx_EXPORT Colors : public QAbstractItemModel {
30  Q_OBJECT
31 
32 public:
34  enum ColorType {
36  //\name First mesh
39  // Mesh1PointColor,
43  //\name Second mesh
48  // Mesh2PointColor,
52  //\name Others
63  //\name Summary
67  StartMesh1 = Mesh1Color,
68  StartMesh2 = Mesh2Color,
69  StartOthers = BackgroundColor
70  };
72 
73  static const QString colorNames[NbColors];
74  static const QString categoryNames[3];
75  static const int categoryShift[3];
76  static const int categorySize[3];
77 
78  Colors();
79  virtual ~Colors() {
80  }
81 
82  void readParms(util::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  return data(index, Qt::DecorationRole).value<QColor>();
89  }
90  void setColor(const QModelIndex& index, QColor col) {
91  setData(index, col, Qt::DecorationRole);
92  }
93 
94  QColor qcolor(ColorType type) const {
95  return colors[type];
96  }
97  Colorf color(ColorType type) const {
98  return (Colorf)colors[type];
99  }
100 
101  int rowCount(const QModelIndex& parent = QModelIndex()) const;
102  int columnCount(const QModelIndex& parent = QModelIndex()) const;
103 
104  Qt::ItemFlags flags(const QModelIndex& index) const;
105 
106  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
107  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
108  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
109 
110  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
111  QModelIndex parent(const QModelIndex& index) const;
112 
113  static Colors* instance()
114  {
115  if(_instance == 0)
116  _instance = new Colors();
117  return _instance;
118  }
119 
120  static QColor getQColor(ColorType type) {
121  return instance()->qcolor(type);
122  }
123 
124  static Colorf getColor(ColorType type) {
125  return instance()->color(type);
126  }
127 
128 signals:
129  void colorsChanged();
130 
131 public slots:
132  void backupColors();
133  void restoreColors();
134  void resetColors();
135 
136 protected:
137  std::vector<QColor> colors, backup;
138  QFont _font;
139  static Colors* _instance;
140 };
141 } // namespace mgx
142 #endif
Color of the cell ids.
Definition: Colors.hpp:41
Color of the image background.
Definition: Colors.hpp:55
Color of the selected points and edges.
Definition: Colors.hpp:49
Color of the lines.
Definition: Colors.hpp:37
Color of the bounding box.
Definition: Colors.hpp:51
Color of the border.
Definition: Colors.hpp:47
Defines the util::Parms class.
Color of the selected points and edges.
Definition: Colors.hpp:40
Color of the grid of the 3rd clipping planes.
Definition: Colors.hpp:58
Color of the lines.
Definition: Colors.hpp:46
Color of the bounding box.
Definition: Colors.hpp:42
Color of the text and lines in the color bar.
Definition: Colors.hpp:60
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:115
Color of the xircle for the pixel edit tool.
Definition: Colors.hpp:62
Color of the grid of the 1st clipping planes.
Definition: Colors.hpp:56
Total number of colors.
Definition: Colors.hpp:66
ColorType
Mesh1 and 2 must have the same order for their colors.
Definition: Colors.hpp:34
Defines the Color class template.
Color of the cell ids.
Definition: Colors.hpp:50
Definition: Colors.hpp:29
Color of the text and lines in the scale bar.
Definition: Colors.hpp:61
Color of the grid of the cutting surface.
Definition: Colors.hpp:59
Color of the grid of the 2nd clipping planes.
Definition: Colors.hpp:57
Color of the border.
Definition: Colors.hpp:38