mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Debounce writing the setting to cache when adjusting card sizes. (#5550)
* Debounce writing the setting to cache when adjusting card sizes. * Lint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
f0adafb275
commit
6c1b7c83ec
2 changed files with 18 additions and 7 deletions
|
|
@ -32,6 +32,17 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defa
|
|||
connect(cardSizeSlider, &QSlider::valueChanged, flowWidget, &FlowWidget::setMinimumSizeToMaxSizeHint);
|
||||
}
|
||||
|
||||
// Debounce setup
|
||||
debounceTimer.setSingleShot(true);
|
||||
connect(&debounceTimer, &QTimer::timeout, this, [this]() {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
@ -42,12 +53,8 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defa
|
|||
*/
|
||||
void CardSizeWidget::updateCardSizeSetting(int newValue)
|
||||
{
|
||||
// Check the type of the parent widget
|
||||
if ((parent = qobject_cast<PrintingSelector *>(parentWidget()))) {
|
||||
SettingsCache::instance().setPrintingSelectorCardSize(newValue);
|
||||
} else if ((parent = qobject_cast<VisualDeckStorageWidget *>(parentWidget()))) {
|
||||
SettingsCache::instance().setVisualDeckStorageCardSize(newValue);
|
||||
}
|
||||
pendingValue = newValue;
|
||||
debounceTimer.start(300); // 300ms debounce time
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
class CardSizeWidget : public QWidget
|
||||
|
|
@ -15,15 +16,18 @@ class CardSizeWidget : public QWidget
|
|||
public:
|
||||
explicit CardSizeWidget(QWidget *parent, FlowWidget *flowWidget = nullptr, int defaultValue = 100);
|
||||
[[nodiscard]] QSlider *getSlider() const;
|
||||
QWidget *parent;
|
||||
|
||||
public slots:
|
||||
void updateCardSizeSetting(int newValue);
|
||||
|
||||
private:
|
||||
QWidget *parent;
|
||||
FlowWidget *flowWidget;
|
||||
QHBoxLayout *cardSizeLayout;
|
||||
QLabel *cardSizeLabel;
|
||||
QSlider *cardSizeSlider;
|
||||
QTimer debounceTimer; // Debounce timer
|
||||
int pendingValue; // Stores the latest slider value
|
||||
};
|
||||
|
||||
#endif // CARD_SIZE_WIDGET_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue