MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransferMarkers.hpp
1 #ifndef TRANSFER_MARKERS_HPP
2 #define TRANSFER_MARKERS_HPP
3 
4 #include <Config.hpp>
5 
6 #include <TransferFunction.hpp>
7 
8 #include <QAbstractTableModel>
9 #include <QColor>
10 #include <QFont>
11 #include <QItemDelegate>
12 #include <QModelIndex>
13 
15 class QModelIndex;
16 class QWidget;
17 class QAbstractItemModel;
18 
19 class QItemSelection;
20 class QPushButton;
21 
22 namespace mgx {
23 namespace gui {
24 class mgx_EXPORT MarkerColorDelegate : public QItemDelegate {
25  Q_OBJECT
26 public:
27  MarkerColorDelegate(QObject* parent = 0);
28 
29  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
30  void setEditorData(QWidget* editor, const QModelIndex& index) const;
31  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
32  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
33 
34 protected:
35  QFont _font;
36 };
37 
38 class mgx_EXPORT TransferMarkerModel : public QAbstractTableModel {
39  Q_OBJECT
40 public:
42  TransferMarkerModel(const std::vector<double>& markers, const std::vector<QColor>& colors, Interpolation m,
43  bool showRgba, QObject* parent = 0);
44 
45  int rowCount(const QModelIndex& parent = QModelIndex()) const;
46  int columnCount(const QModelIndex& /*parent*/ = QModelIndex()) const {
47  return 2;
48  }
49 
50  Qt::ItemFlags flags(const QModelIndex& index) const;
51 
52  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
53  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
54  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
55 
56  const std::vector<double>& getMarkers() const {
57  return markers;
58  }
59  const std::vector<QColor>& getColors() const {
60  return colors;
61  }
62 
63 public slots:
64  void addMarker(const QItemSelection& selection);
65  void removeMarker(const QItemSelection& selection);
66  void spreadMarkers(const QItemSelection& selection);
67  void rgbaMode();
68  void hsvaMode();
69 
70 protected:
71  QString colorText(int idx) const;
72  bool setColorText(int idx, QString txt);
73 
74  std::vector<double> markers;
75  std::vector<QColor> colors;
76  Interpolation mode;
77  bool showRgba;
78  QPushButton* spread_button;
79  QFont _font;
80 };
81 } // namespace gui
82 } // namespace mgx
83 #endif // TRANSFER_MARKERS_HPP
Definition: TransferMarkers.hpp:38
Definition: TransferMarkers.hpp:24
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:28