-
Notifications
You must be signed in to change notification settings - Fork 0
/
filterdialog.cpp
172 lines (152 loc) · 5.85 KB
/
filterdialog.cpp
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
#include "filterdialog.h"
#include <QtWidgets>
FilterDialog::FilterDialog()
{
QRadioButton *meanFilter = new QRadioButton;
meanFilter->setText(tr("Mean Filter"));
meanFilter->setChecked(true);
QRadioButton *medianFilter = new QRadioButton;
medianFilter->setText(tr("Median Filter"));
QRadioButton *gaussianFilter = new QRadioButton;
gaussianFilter->setText(tr("Gaussian Filter"));
btnGroup = new QButtonGroup;
btnGroup->setExclusive(true);
btnGroup->addButton(meanFilter, 0);
btnGroup->addButton(medianFilter, 1);
btnGroup->addButton(gaussianFilter, 2);
QHBoxLayout *filterTypeGroupLayout = new QHBoxLayout;
filterTypeGroupLayout->addWidget(meanFilter);
filterTypeGroupLayout->addWidget(medianFilter);
filterTypeGroupLayout->addWidget(gaussianFilter);
filterTypeGroupLayout->setSpacing(10);
filterTypeGroupLayout->setContentsMargins(10, 10, 10, 10);
QGroupBox *filterTypeGroup = new QGroupBox(tr("Filter Type"));
filterTypeGroup->setLayout(filterTypeGroupLayout);
QLabel *sizeLabel = new QLabel;
sizeLabel->setText(tr("Size: "));
QLabel *leftParenthesisLabel = new QLabel;
leftParenthesisLabel->setAlignment(Qt::AlignRight);
leftParenthesisLabel->setMaximumWidth(10);
leftParenthesisLabel->setText("(");
colEdit = new QLineEdit;
colEdit->setText("3");
colEdit->setMaximumWidth(50);
QLabel *commaLabel = new QLabel;
commaLabel->setMaximumWidth(10);
commaLabel->setText(",");
rowEdit = new QLineEdit;
rowEdit->setText("3");
rowEdit->setMaximumWidth(50);
QLabel *rightParenthesisLabel = new QLabel;
rightParenthesisLabel->setMaximumWidth(10);
rightParenthesisLabel->setText(")");
QIntValidator *sizeValidator = new QIntValidator;
sizeValidator->setRange(2, 50);
colEdit->setValidator(sizeValidator);
rowEdit->setValidator(sizeValidator);
QHBoxLayout *sizeLayout = new QHBoxLayout;
sizeLayout->addWidget(sizeLabel);
sizeLayout->addWidget(leftParenthesisLabel);
sizeLayout->addWidget(colEdit);
sizeLayout->addWidget(commaLabel);
sizeLayout->addWidget(rowEdit);
sizeLayout->addWidget(rightParenthesisLabel);
sizeLayout->setContentsMargins(10, 10, 10, 10);
QLabel *anchorLabel = new QLabel;
anchorLabel->setText(tr("Anchor: "));
QLabel *lpLabel = new QLabel;
lpLabel->setAlignment(Qt::AlignRight);
lpLabel->setMaximumWidth(10);
lpLabel->setText("(");
anchorXEdit = new QLineEdit;
anchorXEdit->setText("-1");
anchorXEdit->setMaximumWidth(50);
QLabel *cmLabel = new QLabel;
cmLabel->setMaximumWidth(10);
cmLabel->setText(",");
anchorYEdit = new QLineEdit;
anchorYEdit->setText("-1");
anchorYEdit->setMaximumWidth(50);
QLabel *rpLabel = new QLabel;
rpLabel->setMaximumWidth(10);
rpLabel->setText(")");
QIntValidator *anchorValidator = new QIntValidator;
anchorValidator->setRange(-1, 50);
anchorXEdit->setValidator(anchorValidator);
anchorYEdit->setValidator(anchorValidator);
QHBoxLayout *anchorLayout = new QHBoxLayout;
anchorLayout->addWidget(anchorLabel);
anchorLayout->addWidget(lpLabel);
anchorLayout->addWidget(anchorXEdit);
anchorLayout->addWidget(cmLabel);
anchorLayout->addWidget(anchorYEdit);
anchorLayout->addWidget(rpLabel);
anchorLayout->setContentsMargins(10, 10, 10, 10);
QLabel *sigmaXLabel = new QLabel;
sigmaXLabel->setText(tr("Sigma: "));
sigmaXEdit = new QLineEdit;
sigmaXEdit->setText("0.5");
sigmaXEdit->setMaximumWidth(50);
QHBoxLayout *sigmaXLayout = new QHBoxLayout;
sigmaXLayout->addWidget(sigmaXLabel);
sigmaXLayout->addWidget(sigmaXEdit);
sigmaXLayout->setContentsMargins(10, 10, 10, 10);
QDoubleValidator *sigmaValidator = new QDoubleValidator;
sigmaValidator->setRange(0, 10, 1);
sigmaXEdit->setValidator(sigmaValidator);
sigmaXEdit->setEnabled(false);
QVBoxLayout *settingLayout = new QVBoxLayout;
settingLayout->addLayout(sizeLayout);
settingLayout->addLayout(anchorLayout);
settingLayout->addLayout(sigmaXLayout);
QGroupBox *settingGroup = new QGroupBox(tr("Filter Kernel Setting"));
settingGroup->setLayout(settingLayout);
QPushButton *applyButton = new QPushButton(tr("Apply"));
QPushButton *closeButton = new QPushButton(tr("Close"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch(1);
btnLayout->addWidget(applyButton);
btnLayout->addWidget(closeButton);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(filterTypeGroup);
mainLayout->addWidget(settingGroup);
mainLayout->addStretch(1);
mainLayout->addSpacing(12);
mainLayout->addLayout(btnLayout);
setLayout(mainLayout);
connect(closeButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(applyButton, &QAbstractButton::clicked, this, &FilterDialog::apply);
connect(btnGroup, SIGNAL(buttonClicked(int)), this, SLOT(buttonGroupChanged(int)));
setWindowTitle(tr("Filter Dialog"));
}
void FilterDialog::apply(){
QJsonObject obj;
int type = btnGroup->checkedId();
obj.insert("type", type);
int col = colEdit->text().toInt();
obj.insert("col", col);
int row = rowEdit->text().toInt();
obj.insert("row", row);
int anchorX = anchorXEdit->text().toInt();
int anchorY = anchorYEdit->text().toInt();
if(anchorX >= col || anchorY >= row){
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Illegal anchor."));
msgBox.exec();
return;
}
obj.insert("x", anchorX);
obj.insert("y", anchorY);
if(type == 2){
double sigma = sigmaXEdit->text().toDouble();
obj.insert("sigma", sigma);
}
emit sendApplyFilter(obj);
close();
}
void FilterDialog::buttonGroupChanged(int id){
if(id == 2){
sigmaXEdit->setEnabled(true);
} else {
sigmaXEdit->setEnabled(false);
}
}