Add editor spinboxes again

Took 4 minutes
This commit is contained in:
Lukas Brübach 2026-08-23 20:31:18 +02:00
parent b664050ac3
commit b17f72802a
2 changed files with 89 additions and 3 deletions

View file

@ -7,9 +7,11 @@
#include "card_database_model.h"
#include "playmat_preview_widget.h"
#include <QCheckBox>
#include <QComboBox>
#include <QCompleter>
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
@ -61,6 +63,16 @@ PlaymatParams PlaymatSettingsDialog::params() const
return currentParams;
}
QDoubleSpinBox *PlaymatSettingsDialog::makeSpinBox(double min, double max, double value, double step)
{
auto *spin = new QDoubleSpinBox;
spin->setRange(min, max);
spin->setSingleStep(step);
spin->setDecimals(3);
spin->setValue(value);
return spin;
}
void PlaymatSettingsDialog::initializeSearchBar()
{
searchBar = new QLineEdit;
@ -105,6 +117,32 @@ void PlaymatSettingsDialog::setupUi()
form->addRow(cardNameLabel, searchBar);
form->addRow(printingLabel, providerComboBox);
// Numerical editors expose the raw PlaymatParams for precise input. They
// stay hidden until requested since the crop surface is the primary control.
marginLSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctL, 0.01);
marginRSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctR, 0.01);
verticalOffsetSpin = makeSpinBox(0.0, 1.0, currentParams.verticalOffset, 0.01);
zoomSpin = makeSpinBox(0.1, 4.0, currentParams.zoom, 0.05);
leftMarginLabel = new QLabel;
rightMarginLabel = new QLabel;
verticalOffsetLabel = 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;
form->addRow(showNumericEditorsCheck);
form->addRow(numericEditors);
controlsGroup = new QGroupBox;
controlsGroup->setLayout(form);
@ -133,8 +171,25 @@ void PlaymatSettingsDialog::setupUi()
// The crop surface is the primary control: dragging pans, wheel/keys zoom
//, editing exactly the same stored parameters the old numeric fields did.
connect(preview, &PlaymatPreviewWidget::paramsEdited, this,
[this](const PlaymatParams &edited) { currentParams = edited; });
connect(preview, &PlaymatPreviewWidget::paramsEdited, this, [this](const PlaymatParams &edited) {
currentParams = edited;
QSignalBlocker blockMarginL(marginLSpin);
QSignalBlocker blockMarginR(marginRSpin);
QSignalBlocker blockOffset(verticalOffsetSpin);
QSignalBlocker blockZoom(zoomSpin);
marginLSpin->setValue(edited.marginPctL);
marginRSpin->setValue(edited.marginPctR);
verticalOffsetSpin->setValue(edited.verticalOffset);
zoomSpin->setValue(edited.zoom);
});
connect(showNumericEditorsCheck, &QCheckBox::toggled, numericEditors, &QWidget::setVisible);
connect(marginLSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
connect(marginRSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
connect(verticalOffsetSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
connect(zoomSpin, &QDoubleSpinBox::valueChanged, this, &PlaymatSettingsDialog::onParamChanged);
// The crop surface leads visually, card selection supports it below.
auto *root = new QVBoxLayout;
@ -229,12 +284,26 @@ void PlaymatSettingsDialog::reloadPreview()
preview->setAttribution(buildArtAttribution(card));
}
void PlaymatSettingsDialog::onParamChanged()
{
currentParams.marginPctL = marginLSpin->value();
currentParams.marginPctR = marginRSpin->value();
currentParams.verticalOffset = verticalOffsetSpin->value();
currentParams.zoom = zoomSpin->value();
preview->setParams(currentParams);
}
void PlaymatSettingsDialog::retranslateUi()
{
setWindowTitle(tr("Playmat Settings"));
searchBar->setPlaceholderText(tr("Type a card name..."));
cardNameLabel->setText(tr("Card name:"));
printingLabel->setText(tr("Printing:"));
showNumericEditorsCheck->setText(tr("Show numerical editors"));
leftMarginLabel->setText(tr("Left margin (%):"));
rightMarginLabel->setText(tr("Right margin (%):"));
verticalOffsetLabel->setText(tr("Vertical offset:"));
zoomLabel->setText(tr("Zoom:"));
controlsGroup->setTitle(tr("Card"));
previewGroup->setTitle(tr("Crop"));
previewCaptionLabel->setText(

View file

@ -5,12 +5,15 @@
#include <QPixmap>
#include <libcockatrice/deck_list/deck_list.h>
class QCheckBox;
class QComboBox;
class QCompleter;
class QDoubleSpinBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QWidget;
class CardDatabaseModel;
class CardDatabaseDisplayModel;
class CardSearchModel;
@ -22,7 +25,8 @@ class PlaymatPreviewWidget;
*
* The crop surface is the primary control: drag to pan the visible art,
* scroll (or +/- keys) to zoom, arrow keys to nudge. Card name and printing
* are selected below. These gestures edit the same stored PlaymatParams that
* are selected below. A checkbox reveals optional numerical editors for the
* raw PlaymatParams. These controls edit the same stored PlaymatParams that
* ship in deck files and player properties.
*/
class PlaymatSettingsDialog : public QDialog
@ -39,6 +43,7 @@ public:
private slots:
void onCardNameChanged(const QString &name);
void onParamChanged();
void reloadPreview();
private:
@ -46,6 +51,7 @@ private:
void populateProviderCombo(const QString &cardName);
void initializeSearchBar();
void retranslateUi();
QDoubleSpinBox *makeSpinBox(double min, double max, double value, double step);
QLineEdit *searchBar;
QCompleter *completer;
@ -61,10 +67,21 @@ private:
QLabel *cardNameLabel;
QLabel *printingLabel;
QLabel *previewCaptionLabel;
QCheckBox *showNumericEditorsCheck;
QWidget *numericEditors;
QLabel *leftMarginLabel;
QLabel *rightMarginLabel;
QLabel *verticalOffsetLabel;
QLabel *zoomLabel;
QGroupBox *controlsGroup;
QGroupBox *previewGroup;
QPushButton *removeButton;
QDoubleSpinBox *marginLSpin;
QDoubleSpinBox *marginRSpin;
QDoubleSpinBox *verticalOffsetSpin;
QDoubleSpinBox *zoomSpin;
PlaymatPreviewWidget *preview;
QPixmap currentPixmap;