MorphoGraphX
TransferFunctionViewer.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 QTRANSFERFUNCTIONVIEWER_HPP
12 #define QTRANSFERFUNCTIONVIEWER_HPP
13 
14 #include "Config.hpp"
15 #include <QLinearGradient>
16 #include <QWidget>
17 #include <QColor>
18 #include <QPainterPath>
19 #include "TransferFunction.hpp"
20 
21 #include <vector>
22 
23 class QMouseEvent;
24 class QPixmap;
25 class QAction;
26 class QPaintEvent;
27 
28 class mgxBase_EXPORT QTransferFunctionViewer : public QWidget
29 {
30  Q_OBJECT
31 public:
32  typedef TransferFunction::Colorf Colorf;
33  enum BackgroundType
34  {
35  BG_CHECKS,
36  BG_WHITE,
37  BG_BLACK
38  };
39 
40  QTransferFunctionViewer(QWidget *parent = 0, Qt::WindowFlags f = 0);
41  virtual ~QTransferFunctionViewer() {}
42 
43  size_t nbValues() const;
44 
45  const TransferFunction& transferFunction() const { return transfer_fct; }
46 
47 public slots:
48  void changeNbValues(int n);
49  void reverseFunction();
50  void changeTransferFunction(const TransferFunction& fct);
51  void setupGradient();
52  void setHistogram(const std::vector<double>& h);
53  void setBounds(double min, double max);
54  void setStickers(const std::vector<double>& s);
55  void setMarkerSize(int s);
56  void setCheckSize(int s);
57  void setBackgroundType(BackgroundType type);
58  void setInterpolation(TransferFunction::Interpolation i);
59  void setSelectionColor(QColor col);
60  void editMarkers();
61  void autoAdjust();
62 
63 signals:
64  void changedTransferFunction(const TransferFunction& fct);
65 
66 protected:
67  void paintEvent(QPaintEvent *event);
71  void mouseMoveEvent(QMouseEvent *e);
72  void resetMouseInteraction();
73 
74  void prepareHistogram();
75 
76  void createBackground();
77  QPixmap createChecks();
78 
79  TransferFunction transfer_fct;
80  std::vector<double> histogram, hist_values;
81  double minValue, maxValue;
82  QPainterPath hist_shape;
83  bool use_histogram;
84  std::vector<double> stickers;
85  bool sticking;
86  int marker_size;
87  bool select_pos;
88  double current_pos;
89  int bg_size;
90  double bg_bright;
91  double bg_dark;
92  QColor activ_pos_color;
93  Colorf saved_color;
94  double saved_pos;
95  QAction *reverse_act, *edit_markers;
96  QLinearGradient gradient;
97  BackgroundType bg_type;
98  size_t _nb_values;
99 };
100 
101 #endif
102 
mouseReleaseEvent(QMouseEvent *event)
paintEvent(QPaintEvent *event)
mousePressEvent(QMouseEvent *event)
mouseMoveEvent(QMouseEvent *event)
mouseDoubleClickEvent(QMouseEvent *event)
Definition: TransferFunctionViewer.hpp:28