mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
Refactor CardSizeWidget: don't update setting directly (#5903)
This commit is contained in:
parent
5b9cb4fc8d
commit
c4e42b94f9
4 changed files with 14 additions and 9 deletions
|
|
@ -34,14 +34,7 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *_flowWidget, int def
|
||||||
|
|
||||||
// Debounce setup
|
// Debounce setup
|
||||||
debounceTimer.setSingleShot(true);
|
debounceTimer.setSingleShot(true);
|
||||||
connect(&debounceTimer, &QTimer::timeout, this, [this]() {
|
connect(&debounceTimer, &QTimer::timeout, this, [this] { emit cardSizeSettingUpdated(pendingValue); });
|
||||||
// Check the type of the parent widget
|
|
||||||
if (qobject_cast<PrintingSelector *>(parentWidget())) {
|
|
||||||
SettingsCache::instance().setPrintingSelectorCardSize(pendingValue);
|
|
||||||
} else if (qobject_cast<VisualDeckStorageWidget *>(parentWidget())) {
|
|
||||||
SettingsCache::instance().setVisualDeckStorageCardSize(pendingValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardSizeWidget::updateCardSizeSetting);
|
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardSizeWidget::updateCardSizeSetting);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,17 @@ public:
|
||||||
explicit CardSizeWidget(QWidget *parent, FlowWidget *flowWidget = nullptr, int defaultValue = 100);
|
explicit CardSizeWidget(QWidget *parent, FlowWidget *flowWidget = nullptr, int defaultValue = 100);
|
||||||
[[nodiscard]] QSlider *getSlider() const;
|
[[nodiscard]] QSlider *getSlider() const;
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void updateCardSizeSetting(int newValue);
|
void updateCardSizeSetting(int newValue);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* Emitted when the slider value changes, but on a debounce timer.
|
||||||
|
* Any parents that care about saving the value to settings should use this signal to indicate when to save the new
|
||||||
|
* value to settings.
|
||||||
|
*/
|
||||||
|
void cardSizeSettingUpdated(int newValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *parent;
|
QWidget *parent;
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,8 @@ PrintingSelector::PrintingSelector(QWidget *parent, AbstractTabDeckEditor *_deck
|
||||||
|
|
||||||
cardSizeWidget =
|
cardSizeWidget =
|
||||||
new CardSizeWidget(displayOptionsWidget, flowWidget, SettingsCache::instance().getPrintingSelectorCardSize());
|
new CardSizeWidget(displayOptionsWidget, flowWidget, SettingsCache::instance().getPrintingSelectorCardSize());
|
||||||
|
connect(cardSizeWidget, &CardSizeWidget::cardSizeSettingUpdated, &SettingsCache::instance(),
|
||||||
|
&SettingsCache::setPrintingSelectorCardSize);
|
||||||
|
|
||||||
displayOptionsWidget->addSettingsWidget(sortToolBar);
|
displayOptionsWidget->addSettingsWidget(sortToolBar);
|
||||||
displayOptionsWidget->addSettingsWidget(navigationCheckBox);
|
displayOptionsWidget->addSettingsWidget(navigationCheckBox);
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
||||||
|
|
||||||
// card size slider
|
// card size slider
|
||||||
cardSizeWidget = new CardSizeWidget(this, nullptr, SettingsCache::instance().getVisualDeckStorageCardSize());
|
cardSizeWidget = new CardSizeWidget(this, nullptr, SettingsCache::instance().getVisualDeckStorageCardSize());
|
||||||
|
connect(cardSizeWidget, &CardSizeWidget::cardSizeSettingUpdated, &SettingsCache::instance(),
|
||||||
|
&SettingsCache::setVisualDeckStorageCardSize);
|
||||||
|
|
||||||
quickSettingsWidget = new SettingsButtonWidget(this);
|
quickSettingsWidget = new SettingsButtonWidget(this);
|
||||||
quickSettingsWidget->addSettingsWidget(showFoldersCheckBox);
|
quickSettingsWidget->addSettingsWidget(showFoldersCheckBox);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue