anatomist  5.1.2
3D neuroimaging data viewer
gradwidget.h
Go to the documentation of this file.
1 /**************************************************************************
2  * This file is part of the Fraqtive program.
3  * Copyright (C) 2005 Michal Mecinski.
4  * This program is licensed under the GNU General Public License.
5  **************************************************************************/
6 
7 #ifndef GRADCONTROL_H
8 #define GRADCONTROL_H
9 
10 #include "gradient.h"
11 
12 #include <sstream>
13 #include <qstring.h>
14 #include <qwidget.h>
15 #include <qrect.h>
16 
20 #define noDragMode 0
21 #define dragNodeMode 1
22 #define dragSegmentMode 2
23 
24 class GradientWidget : public QWidget
25 {
26  Q_OBJECT
27  public:
31  GradientWidget(QWidget* parent = 0, const char* name = 0,
32  const QString& gradString = "", double vMin = 0,
33  double vMax = 1.);
34  //GradientWidget(QWidget* parent=0, const char* name=0);
35 
40 
41  public:
45  QSize minimumSizeHint() const;
46 
50  QSize sizeHint() const;
51 
57  const Gradient& getGradient() const
58  {
59  return _gradient;
60  }
61 
62  QString getGradientString() const;
63  void setGradient(const QString& s);
64 
65  bool hasAlpha() const
66  { return _hasAlpha; }
67  void setHasAlpha( bool x );
68  void setBounds( double vMin = 0, double vMax = 1. );
69  double minBound() const { return _minVal; }
70  double maxBound() const { return _maxVal; }
71 
72  signals:
73  void gradientChanged(QString s);
74 
75  public slots:
81  void setGradient(const Gradient& gradient);
82 
86  void newRgb();
87 
91  void newHsv();
92 
96  void invert();
97 
98  private:
99  // process events
100  void paintEvent(QPaintEvent* e);
101  void resizeEvent(QResizeEvent* e);
102  void mousePressEvent(QMouseEvent* e);
103  void mouseReleaseEvent(QMouseEvent* e);
104  void mouseMoveEvent(QMouseEvent* e);
105 
106  // layout the area rectangles
107  void calcRects();
108 
109  // Make mapping between real value and x position:
110  int realValToWidgetX(double v);
111 
112  // Retrieve colormap data compatible with matplotlib
113  QString getRGBnodes();
114 
115  private:
116  Gradient _gradient;
117 
118  // area rectangles
119  QRect _gradRect;
120  QRect _splineRect[4];
121 
122  // node dragging
123  int _dragMode; // either noDragMode, dragNodeMode or dragSegmentMode
124  int _dragSpline;
125  int _dragSegLeft;
126  int _dragSegRight;
127  QPoint _prevMousePos;
128  int _dragNode;
129  bool _dragRemove;
130 
131  // real value mapping
132  double _minVal;
133  double _maxVal;
134  QPoint _pointerPos;
135  QString _posText;
136  bool _hasAlpha;
137 };
138 
139 #endif
#define slots
double maxBound() const
Definition: gradwidget.h:70
QSize minimumSizeHint() const
Return the minimum size of the widget.
const Gradient & getGradient() const
Get the current gradient.
Definition: gradwidget.h:57
void setBounds(double vMin=0, double vMax=1.)
void invert()
Invert the current gradient.
bool hasAlpha() const
Definition: gradwidget.h:65
~GradientWidget()
Destructor.
void gradientChanged(QString s)
QString getGradientString() const
void setGradient(const QString &s)
QSize sizeHint() const
Return the recommended size of the widget.
void newHsv()
Set a default HSV gradient.
void setHasAlpha(bool x)
GradientWidget(QWidget *parent=0, const char *name=0, const QString &gradString="", double vMin=0, double vMax=1.)
Constructor.
void setGradient(const Gradient &gradient)
Set the gradient to edit.
double minBound() const
Definition: gradwidget.h:69
void newRgb()
Set a default RGB gradient.
The gradient of colors.
Definition: gradient.h:24