75 setWindowTitle(tr(
"Custom Uniforms"));
79 auto *mainLayout =
new QVBoxLayout(
this);
80 auto *addLayout =
new QHBoxLayout();
83 nameEdit->setPlaceholderText(tr(
"GLSL uniform name"));
95 addLayout->addWidget(
new QLabel(tr(
"Name"),
this));
97 addLayout->addWidget(
new QLabel(tr(
"Minimum"),
this));
99 addLayout->addWidget(
new QLabel(tr(
"Maximum"),
this));
101 addLayout->addWidget(
new QLabel(tr(
"Step"),
this));
103 auto *addButton =
new QPushButton(tr(
"Add Slider"),
this);
104 disableDefaultButton(addButton);
105 addLayout->addWidget(addButton);
106 mainLayout->addLayout(addLayout);
108 auto *hint =
new QLabel(tr(
"Names become GLSL float uniforms. Values and slots are saved in "
109 "library.json and sent live to the active engine."),
111 hint->setWordWrap(
true);
112 mainLayout->addWidget(hint);
122 auto *buttons =
new QDialogButtonBox(QDialogButtonBox::Close,
this);
123 for (QAbstractButton *button : buttons->buttons()) {
124 if (
auto *pushButton = qobject_cast<QPushButton *>(button))
125 disableDefaultButton(pushButton);
127 mainLayout->addWidget(buttons);
135 connect(buttons, &QDialogButtonBox::rejected,
this, &CustomUniformDialog::hide);
264 while (QLayoutItem *item =
rowsLayout->takeAt(0)) {
265 if (QWidget *widget = item->widget())
266 widget->deleteLater();
271 auto *emptyLabel =
new QLabel(tr(
"No custom uniforms are defined for this library."),
rowsWidget);
272 emptyLabel->setAlignment(Qt::AlignCenter);
280 auto *layout =
new QGridLayout(row);
281 layout->setContentsMargins(4, 4, 4, 4);
283 auto *nameLabel =
new QLabel(uniform.name, row);
284 nameLabel->setMinimumWidth(140);
285 auto *slider =
new QSlider(Qt::Horizontal, row);
286 slider->setRange(0, sliderStepCount(uniform));
287 slider->setValue(sliderPosition(uniform, uniform.value));
288 auto *valueSpin =
new QDoubleSpinBox(row);
289 valueSpin->setDecimals(decimalsForStep(uniform.step));
290 valueSpin->setRange(uniform.minimum, uniform.maximum);
291 valueSpin->setSingleStep(uniform.step);
292 valueSpin->setValue(uniform.value);
293 valueSpin->setKeyboardTracking(
false);
294 valueSpin->setMinimumWidth(130);
295 auto *rangeLabel =
new QLabel(tr(
"%1 to %2, step %3").arg(uniform.minimum, 0,
'g', 8).arg(uniform.maximum, 0,
'g', 8).arg(uniform.step, 0,
'g', 8), row);
296 const QString location = uniformLocation(uniform);
298 locationLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
299 auto *copyButton =
new QPushButton(tr(
"Copy"), row);
300 copyButton->setToolTip(tr(
"Copy the source declaration:\n%1").arg(uniformSourceDefinition(uniform,
activeBackend)));
301 auto *deleteButton =
new QPushButton(tr(
"Delete"), row);
302 disableDefaultButton(copyButton);
303 disableDefaultButton(deleteButton);
305 layout->addWidget(nameLabel, 0, 0);
306 layout->addWidget(slider, 0, 1);
307 layout->addWidget(valueSpin, 0, 2);
308 layout->addWidget(copyButton, 0, 3);
309 layout->addWidget(deleteButton, 0, 4);
310 layout->addWidget(rangeLabel, 1, 1, 1, 2);
311 layout->addWidget(locationLabel, 1, 3, 1, 2);
312 layout->setColumnStretch(1, 1);
315 connect(slider, &QSlider::valueChanged,
this, [
this, name = uniform.name, valueSpin](
int position) {
316 const int index = uniformIndex(name);
319 auto &definition = uniformDefinitions[index];
320 definition.value = sliderValue(definition, position);
321 const QSignalBlocker blocker(valueSpin);
322 valueSpin->setValue(definition.value);
324 emit uniformsChanged();
326 connect(valueSpin,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
this, [
this, name = uniform.name, slider, valueSpin](
double value) {
327 const int index = uniformIndex(name);
330 auto &definition = uniformDefinitions[index];
331 const int position = sliderPosition(definition, value);
332 definition.value = sliderValue(definition, position);
333 const QSignalBlocker sliderBlocker(slider);
334 const QSignalBlocker spinBlocker(valueSpin);
335 slider->setValue(position);
336 valueSpin->setValue(definition.value);
338 emit uniformsChanged();
340 connect(deleteButton, &QPushButton::clicked,
this, [
this, name = uniform.name]() { removeUniform(name); });
341 connect(copyButton, &QPushButton::clicked,
this, [uniform, backend =
activeBackend]() { QGuiApplication::clipboard()->setText(uniformSourceDefinition(uniform, backend)); });