-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.cpp
More file actions
174 lines (143 loc) · 4.96 KB
/
node.cpp
File metadata and controls
174 lines (143 loc) · 4.96 KB
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
#include "node.h"
#include <QDebug>
Node::Node(QWidget *parent)
: QWidget(parent)
{
// Create layouts
mainLayout = new QVBoxLayout(this);
titleLayout = new QHBoxLayout();
// Create title label
titleLabel = new QLabel("Node", this);
// Create delete button
deleteButton = new QPushButton("X", this);
deleteButton->setFixedSize(20, 20);
// Add to title layout
titleLayout->addWidget(titleLabel);
titleLayout->addWidget(deleteButton);
// Create function selection combo
functionCombo = new QComboBox(this);
for (int i = 0; i < FUNCTION_COUNT; i++) {
functionCombo->addItem(functionName(static_cast<FunctionType>(i)));
}
// Create parameter stack
parameterStack = new QStackedWidget(this);
// Setup parameter UIs for each function
setupBrightnessContrastUI();
setupGaussianBlurUI();
setupThresholdUI();
setupGaussianNoiseUI();
// Add widgets to main layout
mainLayout->addLayout(titleLayout);
mainLayout->addWidget(functionCombo);
mainLayout->addWidget(parameterStack);
// Connections
connect(deleteButton, &QPushButton::clicked, [this]() {
emit deleteRequested(this);
});
connect(functionCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &Node::updateFunctionUI);
// Set initial function
functionCombo->setCurrentIndex(0);
}
QString Node::functionName(FunctionType type) {
switch(type) {
case BrightnessContrast: return "Brightness/Contrast";
case GaussianBlur: return "Gaussian Blur";
case Threshold: return "Threshold";
case GaussianNoise: return "Gaussian Noise";
default: return "Unknown";
}
}
Node::FunctionType Node::currentFunction() const {
return static_cast<FunctionType>(functionCombo->currentIndex());
}
QVariantList Node::getParameters() const {
QVariantList params;
switch(currentFunction()) {
case BrightnessContrast:
params << alphaSpin->value() << betaSlider->value();
break;
case GaussianBlur:
params << kernelSizeSlider->value();
break;
case Threshold:
params << thresholdSlider->value();
break;
case GaussianNoise:
params << stddevSpin->value();
break;
default:
break;
}
return params;
}
void Node::setTitle(const QString &title) {
titleLabel->setText(title);
}
void Node::updateFunctionUI(int index) {
parameterStack->setCurrentIndex(index);
emit functionChanged();
}
void Node::setupBrightnessContrastUI() {
brightnessContrastWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(brightnessContrastWidget);
// Alpha parameter (Contrast)
QHBoxLayout *alphaLayout = new QHBoxLayout();
alphaLayout->addWidget(new QLabel("Contrast:"));
alphaSpin = new QDoubleSpinBox();
alphaSpin->setRange(0.0, 3.0);
alphaSpin->setSingleStep(0.1);
alphaSpin->setValue(1.0);
alphaLayout->addWidget(alphaSpin);
layout->addLayout(alphaLayout);
// Beta parameter (Brightness)
QHBoxLayout *betaLayout = new QHBoxLayout();
betaLayout->addWidget(new QLabel("Brightness:"));
betaSlider = new QSlider(Qt::Horizontal);
betaSlider->setRange(-100, 100);
betaSlider->setValue(0);
betaLayout->addWidget(betaSlider);
layout->addLayout(betaLayout);
parameterStack->addWidget(brightnessContrastWidget);
}
void Node::setupGaussianBlurUI() {
gaussianBlurWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(gaussianBlurWidget);
// Kernel size parameter
QHBoxLayout *kernelLayout = new QHBoxLayout();
kernelLayout->addWidget(new QLabel("Kernel Size:"));
kernelSizeSlider = new QSlider(Qt::Horizontal);
kernelSizeSlider->setRange(1, 31);
kernelSizeSlider->setSingleStep(2);
kernelSizeSlider->setValue(3);
kernelLayout->addWidget(kernelSizeSlider);
layout->addLayout(kernelLayout);
parameterStack->addWidget(gaussianBlurWidget);
}
void Node::setupThresholdUI() {
thresholdWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(thresholdWidget);
// Threshold value
QHBoxLayout *threshLayout = new QHBoxLayout();
threshLayout->addWidget(new QLabel("Threshold:"));
thresholdSlider = new QSlider(Qt::Horizontal);
thresholdSlider->setRange(0, 255);
thresholdSlider->setValue(127);
threshLayout->addWidget(thresholdSlider);
layout->addLayout(threshLayout);
parameterStack->addWidget(thresholdWidget);
}
void Node::setupGaussianNoiseUI() {
gaussianNoiseWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(gaussianNoiseWidget);
// Standard deviation
QHBoxLayout *stddevLayout = new QHBoxLayout();
stddevLayout->addWidget(new QLabel("Noise StdDev:"));
stddevSpin = new QDoubleSpinBox();
stddevSpin->setRange(0.0, 100.0);
stddevSpin->setSingleStep(1.0);
stddevSpin->setValue(10.0);
stddevLayout->addWidget(stddevSpin);
layout->addLayout(stddevLayout);
parameterStack->addWidget(gaussianNoiseWidget);
}