mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -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);
|
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);
|
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardSizeWidget::updateCardSizeSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,12 +53,8 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defa
|
||||||
*/
|
*/
|
||||||
void CardSizeWidget::updateCardSizeSetting(int newValue)
|
void CardSizeWidget::updateCardSizeSetting(int newValue)
|
||||||
{
|
{
|
||||||
// Check the type of the parent widget
|
pendingValue = newValue;
|
||||||
if ((parent = qobject_cast<PrintingSelector *>(parentWidget()))) {
|
debounceTimer.start(300); // 300ms debounce time
|
||||||
SettingsCache::instance().setPrintingSelectorCardSize(newValue);
|
|
||||||
} else if ((parent = qobject_cast<VisualDeckStorageWidget *>(parentWidget()))) {
|
|
||||||
SettingsCache::instance().setVisualDeckStorageCardSize(newValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
#include <QTimer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class CardSizeWidget : public QWidget
|
class CardSizeWidget : public QWidget
|
||||||
|
|
@ -15,15 +16,18 @@ class CardSizeWidget : public QWidget
|
||||||
public:
|
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;
|
||||||
QWidget *parent;
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateCardSizeSetting(int newValue);
|
void updateCardSizeSetting(int newValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QWidget *parent;
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
QHBoxLayout *cardSizeLayout;
|
QHBoxLayout *cardSizeLayout;
|
||||||
QLabel *cardSizeLabel;
|
QLabel *cardSizeLabel;
|
||||||
QSlider *cardSizeSlider;
|
QSlider *cardSizeSlider;
|
||||||
|
QTimer debounceTimer; // Debounce timer
|
||||||
|
int pendingValue; // Stores the latest slider value
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARD_SIZE_WIDGET_H
|
#endif // CARD_SIZE_WIDGET_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue