mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
Merge 380e16b8cc into 7ca697348b
This commit is contained in:
commit
ee603a8954
2 changed files with 48 additions and 10 deletions
|
|
@ -21,12 +21,14 @@
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QHideEvent>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
|
#include <QShowEvent>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
@ -54,6 +56,9 @@ PrintingSelector::PrintingSelector(QWidget *parent, AbstractTabDeckEditor *_deck
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
widgetLoadingBufferTimer = new QTimer(this);
|
widgetLoadingBufferTimer = new QTimer(this);
|
||||||
|
deckChangeTimer = new QTimer(this);
|
||||||
|
deckChangeTimer->setSingleShot(true);
|
||||||
|
connect(deckChangeTimer, &QTimer::timeout, this, &PrintingSelector::updateDisplay);
|
||||||
|
|
||||||
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||||
|
|
||||||
|
|
@ -122,11 +127,36 @@ void PrintingSelector::retranslateUi()
|
||||||
void PrintingSelector::printingsInDeckChanged()
|
void PrintingSelector::printingsInDeckChanged()
|
||||||
{
|
{
|
||||||
if (SettingsCache::instance().cardsDisplay().getBumpSetsWithCardsInDeckToTop()) {
|
if (SettingsCache::instance().cardsDisplay().getBumpSetsWithCardsInDeckToTop()) {
|
||||||
// Delay the update to avoid race conditions
|
displayDirty = true;
|
||||||
QTimer::singleShot(100, this, &PrintingSelector::updateDisplay);
|
if (isVisible()) {
|
||||||
|
// Coalesce deck changes while the model settles.
|
||||||
|
deckChangeTimer->start(100);
|
||||||
|
} else {
|
||||||
|
widgetLoadingBufferTimer->stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintingSelector::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::showEvent(event);
|
||||||
|
if (displayDirty) {
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintingSelector::hideEvent(QHideEvent *event)
|
||||||
|
{
|
||||||
|
// A partially built batch must be rebuilt on reveal, not resumed with
|
||||||
|
// stale printing data after the selected card or deck changes.
|
||||||
|
if (widgetLoadingBufferTimer->isActive() || deckChangeTimer->isActive()) {
|
||||||
|
widgetLoadingBufferTimer->stop();
|
||||||
|
deckChangeTimer->stop();
|
||||||
|
displayDirty = true;
|
||||||
|
}
|
||||||
|
QWidget::hideEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A map of uuid to amounts (main, side, tokens).
|
* @return A map of uuid to amounts (main, side, tokens).
|
||||||
*/
|
*/
|
||||||
|
|
@ -173,6 +203,8 @@ void PrintingSelector::updateCardAmounts()
|
||||||
*/
|
*/
|
||||||
void PrintingSelector::updateDisplay()
|
void PrintingSelector::updateDisplay()
|
||||||
{
|
{
|
||||||
|
deckChangeTimer->stop();
|
||||||
|
displayDirty = false;
|
||||||
widgetLoadingBufferTimer->stop();
|
widgetLoadingBufferTimer->stop();
|
||||||
widgetLoadingBufferTimer->deleteLater();
|
widgetLoadingBufferTimer->deleteLater();
|
||||||
widgetLoadingBufferTimer = new QTimer(this);
|
widgetLoadingBufferTimer = new QTimer(this);
|
||||||
|
|
@ -199,20 +231,18 @@ void PrintingSelector::updateDisplay()
|
||||||
*/
|
*/
|
||||||
void PrintingSelector::setCard(const CardInfoPtr &newCard)
|
void PrintingSelector::setCard(const CardInfoPtr &newCard)
|
||||||
{
|
{
|
||||||
if (newCard.isNull()) {
|
// Same-name cards may be different database snapshots after a reload.
|
||||||
selectedCard = newCard;
|
if (selectedCard == newCard) {
|
||||||
updateDisplay();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we don't need to redraw the widget if the card is the same
|
|
||||||
if (!selectedCard.isNull() && selectedCard->getName() == newCard->getName()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widgetLoadingBufferTimer->stop();
|
||||||
|
deckChangeTimer->stop();
|
||||||
selectedCard = newCard;
|
selectedCard = newCard;
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
|
} else {
|
||||||
|
displayDirty = true;
|
||||||
}
|
}
|
||||||
flowWidget->setMinimumSizeToMaxSizeHint();
|
flowWidget->setMinimumSizeToMaxSizeHint();
|
||||||
flowWidget->scrollArea->verticalScrollBar()->setValue(0);
|
flowWidget->scrollArea->verticalScrollBar()->setValue(0);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ class QCheckBox;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QString;
|
class QString;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
class QShowEvent;
|
||||||
|
class QHideEvent;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class SettingsButtonWidget;
|
class SettingsButtonWidget;
|
||||||
template <class Key, class T> class QMap;
|
template <class Key, class T> class QMap;
|
||||||
|
|
@ -47,6 +49,10 @@ public:
|
||||||
void setCard(const CardInfoPtr &newCard);
|
void setCard(const CardInfoPtr &newCard);
|
||||||
void getAllSetsForCurrentCard();
|
void getAllSetsForCurrentCard();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
|
void hideEvent(QHideEvent *event) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
|
|
@ -88,6 +94,8 @@ private:
|
||||||
DeckStateManager *deckStateManager;
|
DeckStateManager *deckStateManager;
|
||||||
CardInfoPtr selectedCard;
|
CardInfoPtr selectedCard;
|
||||||
QTimer *widgetLoadingBufferTimer;
|
QTimer *widgetLoadingBufferTimer;
|
||||||
|
QTimer *deckChangeTimer;
|
||||||
|
bool displayDirty = false;
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue