Implement CubeHelix color maps, and reorganize command line and GUI accordingly.
[gencolormap.git] / gui.hpp
1 /*
2  * Copyright (C) 2015, 2016 Computer Graphics Group, University of Siegen
3  * Written by Martin Lambers <martin.lambers@uni-siegen.de>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23
24 #ifndef GUI_HPP
25 #define GUI_HPP
26
27 #include <QVector>
28 #include <QMainWindow>
29
30 class QTabWidget;
31 class QLabel;
32 class QRadioButton;
33 class QSpinBox;
34 class QSlider;
35 class QDoubleSpinBox;
36 class QTabWidget;
37
38
39 class ColorMapCombinedSliderSpinBox : public QObject
40 {
41 Q_OBJECT
42 private:
43     bool _update_lock;
44
45 public:
46     float minval, maxval, step;
47     QSlider* slider;
48     QDoubleSpinBox* spinbox;
49
50     ColorMapCombinedSliderSpinBox(float minval, float maxval, float step);
51     float value() const;
52     void setValue(float v);
53
54 private slots:
55     void sliderChanged();
56     void spinboxChanged();
57
58 signals:
59     void valueChanged(float);
60 };
61
62 class ColorMapWidget : public QWidget
63 {
64 Q_OBJECT
65 protected:
66     QVector<unsigned char> _colormap;
67     virtual void recomputeColorMap() = 0;
68
69 public:
70     ColorMapWidget() {}
71     ~ColorMapWidget() {}
72
73     virtual void reset() = 0;
74
75     const QVector<unsigned char>* colorMap()
76     {
77         recomputeColorMap();
78         return &_colormap;
79     }
80
81 signals:
82     void colorMapChanged();
83 };
84
85 class ColorMapBrewerSequentialWidget : public ColorMapWidget
86 {
87 Q_OBJECT
88 private:
89     bool _update_lock;
90     QSpinBox* _n_spinbox;
91     ColorMapCombinedSliderSpinBox* _hue_changer;
92     ColorMapCombinedSliderSpinBox* _warmth_changer;
93     ColorMapCombinedSliderSpinBox* _contrast_changer;
94     ColorMapCombinedSliderSpinBox* _saturation_changer;
95     ColorMapCombinedSliderSpinBox* _brightness_changer;
96 private slots:
97     void update();
98
99 protected:
100     void recomputeColorMap() override;
101
102 public:
103     ColorMapBrewerSequentialWidget();
104     ~ColorMapBrewerSequentialWidget();
105
106     void reset() override;
107     void parameters(int& n, float& hue,
108             float& contrast, float& saturation, float& brightness, float& warmth);
109 };
110
111 class ColorMapBrewerDivergingWidget : public ColorMapWidget
112 {
113 Q_OBJECT
114 private:
115     bool _update_lock;
116     QSpinBox* _n_spinbox;
117     ColorMapCombinedSliderSpinBox* _hue_changer;
118     ColorMapCombinedSliderSpinBox* _divergence_changer;
119     ColorMapCombinedSliderSpinBox* _warmth_changer;
120     ColorMapCombinedSliderSpinBox* _contrast_changer;
121     ColorMapCombinedSliderSpinBox* _saturation_changer;
122     ColorMapCombinedSliderSpinBox* _brightness_changer;
123 private slots:
124     void update();
125
126 protected:
127     void recomputeColorMap() override;
128
129 public:
130     ColorMapBrewerDivergingWidget();
131     ~ColorMapBrewerDivergingWidget();
132
133     void reset() override;
134     void parameters(int& n, float& hue, float& divergence,
135             float& contrast, float& saturation, float& brightness, float& warmth);
136 };
137
138 class ColorMapBrewerQualitativeWidget : public ColorMapWidget
139 {
140 Q_OBJECT
141 private:
142     bool _update_lock;
143     QSpinBox* _n_spinbox;
144     ColorMapCombinedSliderSpinBox* _hue_changer;
145     ColorMapCombinedSliderSpinBox* _divergence_changer;
146     ColorMapCombinedSliderSpinBox* _contrast_changer;
147     ColorMapCombinedSliderSpinBox* _saturation_changer;
148     ColorMapCombinedSliderSpinBox* _brightness_changer;
149 private slots:
150     void update();
151
152 protected:
153     void recomputeColorMap() override;
154
155 public:
156     ColorMapBrewerQualitativeWidget();
157     ~ColorMapBrewerQualitativeWidget();
158
159     void reset() override;
160     void parameters(int& n, float& hue, float& divergence,
161             float& contrast, float& saturation, float& brightness);
162 };
163
164 class ColorMapCubeHelixWidget : public ColorMapWidget
165 {
166 Q_OBJECT
167 private:
168     bool _update_lock;
169     QSpinBox* _n_spinbox;
170     ColorMapCombinedSliderSpinBox* _hue_changer;
171     ColorMapCombinedSliderSpinBox* _rotations_changer;
172     ColorMapCombinedSliderSpinBox* _saturation_changer;
173     ColorMapCombinedSliderSpinBox* _gamma_changer;
174 private slots:
175     void update();
176
177 protected:
178     void recomputeColorMap() override;
179
180 public:
181     ColorMapCubeHelixWidget();
182     ~ColorMapCubeHelixWidget();
183
184     void reset() override;
185     void parameters(int& n, float& hue, float& rotations,
186             float& saturation, float& gamma);
187 };
188
189 class GUI : public QMainWindow
190 {
191 Q_OBJECT
192
193 public:
194     GUI();
195     ~GUI();
196
197 private:
198     ColorMapBrewerSequentialWidget* _brewerseq_widget;
199     ColorMapBrewerDivergingWidget* _brewerdiv_widget;
200     ColorMapBrewerQualitativeWidget* _brewerqual_widget;
201     ColorMapCubeHelixWidget* _cubehelix_widget;
202     QTabWidget* _tab_widget;
203     QLabel* _colormap_label;
204
205 private slots:
206     void update();
207
208     void file_export_png();
209     void file_export_csv();
210     void edit_reset();
211     void edit_copy_as_img();
212     void edit_copy_as_txt();
213     void help_about();
214 };
215
216 #endif