MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Colors.hpp
1 #ifndef COLORS_HPP
2 #define COLORS_HPP
3 
4 #include <Config.hpp>
5 
6 #include <Color.hpp>
7 #include <Parms.hpp>
8 
9 #include <QAbstractItemModel>
10 #include <QFont>
11 #include <QModelIndex>
12 #include <QString>
13 #include <QTextStream>
14 #include <vector>
15 
16 namespace mgx {
17 typedef util::Color<float> Colorf;
18 
19 class mgx_EXPORT Colors : public QAbstractItemModel {
20  Q_OBJECT
21 
22 public:
24  enum ColorType {
26  //\name First mesh
29  // Mesh1PointColor,
33  //\name Second mesh
38  // Mesh2PointColor,
42  //\name Others
53  //\name Summary
57  StartMesh1 = Mesh1Color,
58  StartMesh2 = Mesh2Color,
59  StartOthers = BackgroundColor
60  };
62 
63  static const QString colorNames[NbColors];
64  static const QString categoryNames[3];
65  static const int categoryShift[3];
66  static const int categorySize[3];
67 
68  Colors();
69  virtual ~Colors() {
70  }
71 
72  void readParms(util::Parms& parms, QString section);
73  void writeParms(QTextStream& pout, QString section);
74 
75  bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
76 
77  QColor color(const QModelIndex& index) const {
78  return data(index, Qt::DecorationRole).value<QColor>();
79  }
80  void setColor(const QModelIndex& index, QColor col) {
81  setData(index, col, Qt::DecorationRole);
82  }
83 
84  QColor qcolor(ColorType type) const {
85  return colors[type];
86  }
87  Colorf color(ColorType type) const {
88  return (Colorf)colors[type];
89  }
90 
91  int rowCount(const QModelIndex& parent = QModelIndex()) const;
92  int columnCount(const QModelIndex& parent = QModelIndex()) const;
93 
94  Qt::ItemFlags flags(const QModelIndex& index) const;
95 
96  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
97  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
98  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
99 
100  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
101  QModelIndex parent(const QModelIndex& index) const;
102 
103  static Colors* instance()
104  {
105  if(_instance == 0)
106  _instance = new Colors();
107  return _instance;
108  }
109 
110  static QColor getQColor(ColorType type) {
111  return instance()->qcolor(type);
112  }
113 
114  static Colorf getColor(ColorType type) {
115  return instance()->color(type);
116  }
117 
118 signals:
119  void colorsChanged();
120 
121 public slots:
122  void backupColors();
123  void restoreColors();
124  void resetColors();
125 
126 protected:
127  std::vector<QColor> colors, backup;
128  QFont _font;
129  static Colors* _instance;
130 };
131 } // namespace mgx
132 #endif
Color of the cell ids.
Definition: Colors.hpp:31
Definition: Colors.hpp:45
Color of the selected points and edges.
Definition: Colors.hpp:39
Color of the lines.
Definition: Colors.hpp:27
Color of the bounding box.
Definition: Colors.hpp:41
Color of the border.
Definition: Colors.hpp:37
Defines the util::Parms class.
Color of the selected points and edges.
Definition: Colors.hpp:30
Color of the grid of the 3rd clipping planes.
Definition: Colors.hpp:48
Definition: Colors.hpp:36
Color of the bounding box.
Definition: Colors.hpp:32
Color of the text and lines in the color bar.
Definition: Colors.hpp:50
Color of the xircle for the pixel edit tool.
Definition: Colors.hpp:52
Color of the grid of the 1st clipping planes.
Definition: Colors.hpp:46
Definition: Colors.hpp:56
ColorType
Mesh1 and 2 must have the same order for their colors.
Definition: Colors.hpp:24
Defines the Color class template.
Color of the cell ids.
Definition: Colors.hpp:40
Definition: Colors.hpp:19
Color of the text and lines in the scale bar.
Definition: Colors.hpp:51
Color of the grid of the cutting surface.
Definition: Colors.hpp:49
Color of the grid of the 2nd clipping planes.
Definition: Colors.hpp:47
Color of the border.
Definition: Colors.hpp:28