Resize on show

Took 7 minutes
This commit is contained in:
Lukas Brübach 2026-08-24 18:20:38 +02:00
parent b17f72802a
commit 73c8f6a2c0
2 changed files with 28 additions and 15 deletions

View file

@ -112,13 +112,16 @@ void PlaymatSettingsDialog::setupUi()
}); });
auto *form = new QFormLayout; auto *form = new QFormLayout;
controlsForm = form;
cardNameLabel = new QLabel; cardNameLabel = new QLabel;
printingLabel = new QLabel; printingLabel = new QLabel;
form->addRow(cardNameLabel, searchBar); form->addRow(cardNameLabel, searchBar);
form->addRow(printingLabel, providerComboBox); form->addRow(printingLabel, providerComboBox);
// Numerical editors expose the raw PlaymatParams for precise input. They // Numerical editors expose the raw PlaymatParams for precise input. They
// stay hidden until requested since the crop surface is the primary control. // share the same form as the rows above so every field lines up on one
// label column. They stay hidden until requested since the crop surface
// is the primary control.
marginLSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctL, 0.01); marginLSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctL, 0.01);
marginRSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctR, 0.01); marginRSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctR, 0.01);
verticalOffsetSpin = makeSpinBox(0.0, 1.0, currentParams.verticalOffset, 0.01); verticalOffsetSpin = makeSpinBox(0.0, 1.0, currentParams.verticalOffset, 0.01);
@ -129,19 +132,13 @@ void PlaymatSettingsDialog::setupUi()
verticalOffsetLabel = new QLabel; verticalOffsetLabel = new QLabel;
zoomLabel = new QLabel; zoomLabel = new QLabel;
auto *numericForm = new QFormLayout;
numericForm->addRow(leftMarginLabel, marginLSpin);
numericForm->addRow(rightMarginLabel, marginRSpin);
numericForm->addRow(verticalOffsetLabel, verticalOffsetSpin);
numericForm->addRow(zoomLabel, zoomSpin);
numericEditors = new QWidget;
numericEditors->setLayout(numericForm);
numericEditors->setVisible(false);
showNumericEditorsCheck = new QCheckBox; showNumericEditorsCheck = new QCheckBox;
form->addRow(showNumericEditorsCheck); form->addRow(showNumericEditorsCheck);
form->addRow(numericEditors); form->addRow(leftMarginLabel, marginLSpin);
form->addRow(rightMarginLabel, marginRSpin);
form->addRow(verticalOffsetLabel, verticalOffsetSpin);
form->addRow(zoomLabel, zoomSpin);
controlsGroup = new QGroupBox; controlsGroup = new QGroupBox;
controlsGroup->setLayout(form); controlsGroup->setLayout(form);
@ -169,8 +166,8 @@ void PlaymatSettingsDialog::setupUi()
accept(); accept();
}); });
// The crop surface is the primary control: dragging pans, wheel/keys zoom // The crop surface is the primary control: dragging pans, wheel/keys zoom,
//, editing exactly the same stored parameters the old numeric fields did. // editing exactly the same stored parameters the numeric fields do.
connect(preview, &PlaymatPreviewWidget::paramsEdited, this, [this](const PlaymatParams &edited) { connect(preview, &PlaymatPreviewWidget::paramsEdited, this, [this](const PlaymatParams &edited) {
currentParams = edited; currentParams = edited;
@ -184,7 +181,8 @@ void PlaymatSettingsDialog::setupUi()
zoomSpin->setValue(edited.zoom); zoomSpin->setValue(edited.zoom);
}); });
connect(showNumericEditorsCheck, &QCheckBox::toggled, numericEditors, &QWidget::setVisible); connect(showNumericEditorsCheck, &QCheckBox::toggled, this, &PlaymatSettingsDialog::setNumericEditorsVisible);
setNumericEditorsVisible(false);
connect(marginLSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged); connect(marginLSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
connect(marginRSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged); connect(marginRSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
@ -293,6 +291,19 @@ void PlaymatSettingsDialog::onParamChanged()
preview->setParams(currentParams); preview->setParams(currentParams);
} }
void PlaymatSettingsDialog::setNumericEditorsVisible(bool visible)
{
controlsForm->setRowVisible(leftMarginLabel, visible);
controlsForm->setRowVisible(rightMarginLabel, visible);
controlsForm->setRowVisible(verticalOffsetLabel, visible);
controlsForm->setRowVisible(zoomLabel, visible);
// A QDialog never resizes itself when its content requirements change,
// so revealing the editors would squeeze the crop group until the info
// caption ran into the preview. Re-fit the dialog to the new size hint.
adjustSize();
}
void PlaymatSettingsDialog::retranslateUi() void PlaymatSettingsDialog::retranslateUi()
{ {
setWindowTitle(tr("Playmat Settings")); setWindowTitle(tr("Playmat Settings"));

View file

@ -9,6 +9,7 @@ class QCheckBox;
class QComboBox; class QComboBox;
class QCompleter; class QCompleter;
class QDoubleSpinBox; class QDoubleSpinBox;
class QFormLayout;
class QGroupBox; class QGroupBox;
class QLabel; class QLabel;
class QLineEdit; class QLineEdit;
@ -51,6 +52,7 @@ private:
void populateProviderCombo(const QString &cardName); void populateProviderCombo(const QString &cardName);
void initializeSearchBar(); void initializeSearchBar();
void retranslateUi(); void retranslateUi();
void setNumericEditorsVisible(bool visible);
QDoubleSpinBox *makeSpinBox(double min, double max, double value, double step); QDoubleSpinBox *makeSpinBox(double min, double max, double value, double step);
QLineEdit *searchBar; QLineEdit *searchBar;
@ -68,7 +70,7 @@ private:
QLabel *printingLabel; QLabel *printingLabel;
QLabel *previewCaptionLabel; QLabel *previewCaptionLabel;
QCheckBox *showNumericEditorsCheck; QCheckBox *showNumericEditorsCheck;
QWidget *numericEditors; QFormLayout *controlsForm;
QLabel *leftMarginLabel; QLabel *leftMarginLabel;
QLabel *rightMarginLabel; QLabel *rightMarginLabel;
QLabel *verticalOffsetLabel; QLabel *verticalOffsetLabel;