-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistogramWindow.h
246 lines (182 loc) · 5.13 KB
/
HistogramWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef _HistogramWindow_H
#define _HistogramWindow_H
#include <QtWidgets/QWidget>
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QBarCategoryAxis>
#include <QVector>
#include <QHBoxLayout>
#include <QCheckBox>
#include <QGroupBox>
#include "PCX.h"
QT_CHARTS_USE_NAMESPACE
class HistogramWindow : public QWidget
{
Q_OBJECT
public :
HistogramWindow(img::Histogram &&h, QWidget *parent = Q_NULLPTR) : histogram{ std::move(h) }, QWidget(parent)
{
this->setWindowFlag(Qt::FramelessWindowHint);
color_planes_num = histogram.size();
createBarSets();
createBarSeries();
createAxis();
createChart();
createChartView();
createCheckBoxes();
createLayout();
createGroupBox();
}
void resizeEvent(QResizeEvent *ev)
{
group_box->setGeometry(QRect{ 0, height() - check_box_height, width(), check_box_height });
chart_view->setGeometry(0, 0, width(), height() - check_box_height);
}
public slots:
void box0Change_slot(int state)
{
if (state == Qt::CheckState::Checked)
{
sets[0]->setColor(QColor{ color_weight,0,0 });
sets[0]->setBorderColor(QColor{ color_weight,0,0 });
}
else
{
sets[0]->setColor(QColor{ 0,0,0,0 });
sets[0]->setBorderColor(QColor{ 0,0,0,0 });
}
update();
}
void box1Change_slot(int state)
{
if (state == Qt::CheckState::Checked)
{
sets[1]->setColor(QColor{ 0,color_weight,0 });
sets[1]->setBorderColor(QColor{ 0,color_weight,0 });
}
else
{
sets[1]->setColor(QColor{ 0,0,0,0 });
sets[1]->setBorderColor(QColor{ 0,0,0,0 });
}
update();
}
void box2Change_slot(int state)
{
if (state == Qt::CheckState::Checked)
{
sets[2]->setColor(QColor{ 0,0,color_weight });
sets[2]->setBorderColor(QColor{ 0,0,color_weight });
}
else
{
sets[2]->setColor(QColor{ 0,0,0,0 });
sets[2]->setBorderColor(QColor{ 0,0,0,0 });
}
update();
}
private:
const int color_weight{ 220 };
int color_planes_num;
img::Histogram histogram;
QChartView *chart_view;
QChart *chart;
QVector<QBarSet*> sets;
QBarSeries *series;
QBarCategoryAxis *axis;
QGroupBox *group_box;
QHBoxLayout *bottom_layout;
QVector<QCheckBox*> check_boxes;
const int check_box_height = 35;
private:
void createBarSets(void)
{
switch (color_planes_num)
{
case 1:
sets.push_back(new QBarSet{ "Grey Level" ,this });
sets[0]->setColor(QColor{ color_weight,0,0 });
sets[0]->setBorderColor(QColor{ color_weight,0,0 });
break;
case 3:
sets.push_back(new QBarSet{ "R" ,this });
sets.push_back(new QBarSet{ "G" ,this });
sets.push_back(new QBarSet{ "B" ,this });
sets[0]->setColor(QColor{ color_weight,0,0 });
sets[0]->setBorderColor(QColor{ color_weight,0,0 });
sets[1]->setColor(QColor{ 0,color_weight,0 });
sets[1]->setBorderColor(QColor{ 0,color_weight,0 });
sets[2]->setColor(QColor{ 0,0,color_weight });
sets[2]->setBorderColor(QColor{ 0,0,color_weight });
}
for (int c = 0; c < color_planes_num; ++c)
{
auto &set = sets[c];
for (int k = 0; k < 256; ++k)
set->append(histogram[c][k].second);
}
}
void createBarSeries(void)
{
series = new QBarSeries{ this };
for (int i = 0; i < color_planes_num; ++i)
{
series->append(sets[i]);
}
}
void createAxis(void)
{
axis = new QBarCategoryAxis{ this };
}
void createChart(void)
{
chart = new QChart;
chart->setTitle("Histogram");
chart->setAnimationOptions(QChart::SeriesAnimations);
chart->addSeries(series);
chart->createDefaultAxes();
chart->setAxisX(axis, series);
chart->legend()->setVisible(false);
}
void createChartView(void)
{
chart_view = new QChartView{ chart, this };
chart_view->setRenderHint(QPainter::Antialiasing);
}
void createCheckBoxes(void)
{
switch (color_planes_num)
{
case 1:
check_boxes.push_back(new QCheckBox{ "Gray Level",this });
check_boxes[0]->setChecked(true);
QObject::connect(check_boxes[0], SIGNAL(stateChanged(int)), this, SLOT(box0Change_slot(int)));
break;
case 3:
check_boxes.push_back(new QCheckBox{ "R",this });
check_boxes.push_back(new QCheckBox{ "G",this });
check_boxes.push_back(new QCheckBox{ "B",this });
check_boxes[0]->setChecked(true);
check_boxes[1]->setChecked(true);
check_boxes[2]->setChecked(true);
QObject::connect(check_boxes[0], SIGNAL(stateChanged(int)), this, SLOT(box0Change_slot(int)));
QObject::connect(check_boxes[1], SIGNAL(stateChanged(int)), this, SLOT(box1Change_slot(int)));
QObject::connect(check_boxes[2], SIGNAL(stateChanged(int)), this, SLOT(box2Change_slot(int)));
break;
}
}
void createLayout(void)
{
bottom_layout = new QHBoxLayout{ this };
for (int i = 0; i < color_planes_num; ++i)
bottom_layout->addWidget(check_boxes[i]);
}
void createGroupBox(void)
{
group_box = new QGroupBox{ this };
group_box->resize(300, check_box_height);
group_box->setLayout(bottom_layout);
}
};
#endif // end _HistogramWindow_H