MorphoGraphX
TransferMarkers.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 TRANSFER_MARKERS_HPP
12 #define TRANSFER_MARKERS_HPP
13 
14 #include <Config.hpp>
15 
16 #include <TransferFunction.hpp>
17 
18 #include <QAbstractTableModel>
19 #include <QColor>
20 #include <QFont>
21 #include <QItemDelegate>
22 #include <QModelIndex>
23 
25 class QModelIndex;
26 class QWidget;
27 class QAbstractItemModel;
28 
29 class QItemSelection;
30 class QPushButton;
31 
32 namespace mgx {
33 namespace gui {
34 class mgx_EXPORT MarkerColorDelegate : public QItemDelegate {
35  Q_OBJECT
36 public:
37  MarkerColorDelegate(QObject* parent = 0);
38 
39  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
40  void setEditorData(QWidget* editor, const QModelIndex& index) const;
41  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
42  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
43 
44 protected:
45  QFont _font;
46 };
47 
48 class mgx_EXPORT TransferMarkerModel : public QAbstractTableModel {
49  Q_OBJECT
50 public:
52  TransferMarkerModel(const std::vector<double>& markers, const std::vector<QColor>& colors, Interpolation m,
53  bool showRgba, QObject* parent = 0);
54 
55  int rowCount(const QModelIndex& parent = QModelIndex()) const;
56  int columnCount(const QModelIndex& /*parent*/ = QModelIndex()) const {
57  return 2;
58  }
59 
60  Qt::ItemFlags flags(const QModelIndex& index) const;
61 
62  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
63  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
64  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
65 
66  const std::vector<double>& getMarkers() const {
67  return markers;
68  }
69  const std::vector<QColor>& getColors() const {
70  return colors;
71  }
72 
73 public slots:
74  void addMarker(const QItemSelection& selection);
75  void removeMarker(const QItemSelection& selection);
76  void spreadMarkers(const QItemSelection& selection);
77  void rgbaMode();
78  void hsvaMode();
79 
80 protected:
81  QString colorText(int idx) const;
82  bool setColorText(int idx, QString txt);
83 
84  std::vector<double> markers;
85  std::vector<QColor> colors;
86  Interpolation mode;
87  bool showRgba;
88  QPushButton* spread_button;
89  QFont _font;
90 };
91 } // namespace gui
92 } // namespace mgx
93 #endif // TRANSFER_MARKERS_HPP
Definition: TransferMarkers.hpp:48
Definition: TransferMarkers.hpp:34
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:38