MorphoGraphX  2.0-1-227
TransferMarkers.hpp
Go to the documentation of this file.
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 
24 class QStyleOptionViewItem;
25 class QModelIndex;
26 class QWidget;
27 class QAbstractItemModel;
28 
29 class QItemSelection;
30 class QPushButton;
31 
32 namespace mgx
33 {
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;
87  bool showRgba;
88  QPushButton* spread_button;
89  QFont _font;
90  };
91 }
92 #endif // TRANSFER_MARKERS_HPP
mgx::TransferMarkerModel::showRgba
bool showRgba
Definition: TransferMarkers.hpp:87
mgx::MarkerColorDelegate::_font
QFont _font
Definition: TransferMarkers.hpp:45
TransferFunction.hpp
mgx::TransferMarkerModel::mode
Interpolation mode
Definition: TransferMarkers.hpp:86
mgx::TransferMarkerModel::spread_button
QPushButton * spread_button
Definition: TransferMarkers.hpp:88
mgx::TransferMarkerModel::colors
std::vector< QColor > colors
Definition: TransferMarkers.hpp:85
mgx::TransferMarkerModel::Interpolation
TransferFunction::Interpolation Interpolation
Definition: TransferMarkers.hpp:51
mgx::TransferMarkerModel::columnCount
int columnCount(const QModelIndex &=QModelIndex()) const
Definition: TransferMarkers.hpp:56
mgx::TransferMarkerModel::markers
std::vector< double > markers
Definition: TransferMarkers.hpp:84
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::TransferFunction::Interpolation
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:40
mgx::TransferMarkerModel::getMarkers
const std::vector< double > & getMarkers() const
Definition: TransferMarkers.hpp:66
mgx::TransferMarkerModel::getColors
const std::vector< QColor > & getColors() const
Definition: TransferMarkers.hpp:69
mgx::TransferMarkerModel::_font
QFont _font
Definition: TransferMarkers.hpp:89
mgx::TransferMarkerModel
Definition: TransferMarkers.hpp:48
mgx::MarkerColorDelegate
Definition: TransferMarkers.hpp:34