mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Merge b51c884cc6 into e05dad4267
This commit is contained in:
commit
3ef15bf030
2 changed files with 52 additions and 6 deletions
|
|
@ -20,14 +20,14 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
||||||
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
||||||
const QString &_filePath)
|
const QString &_filePath)
|
||||||
: QWidget(_parent), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath),
|
: QWidget(_parent), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath),
|
||||||
colorIdentityWidget(nullptr), deckTagsDisplayWidget(nullptr)
|
checkInitializeUiTimer(QTimer(this))
|
||||||
{
|
{
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
deckLoader = new DeckLoader();
|
deckLoader = new DeckLoader();
|
||||||
deckLoader->setParent(this);
|
deckLoader->setParent(this);
|
||||||
connect(deckLoader, &DeckLoader::loadFinished, this, &DeckPreviewWidget::initializeUi);
|
connect(deckLoader, &DeckLoader::loadFinished, this, &DeckPreviewWidget::onDeckLoadFinished);
|
||||||
/* TODO: We shouldn't update the tags on *every* deck load, since it's kinda expensive. We should instead count how
|
/* TODO: We shouldn't update the tags on *every* deck load, since it's kinda expensive. We should instead count how
|
||||||
many deck loads have finished already and if we've loaded all decks and THEN load all the tags at once. */
|
many deck loads have finished already and if we've loaded all decks and THEN load all the tags at once. */
|
||||||
connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget,
|
connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget,
|
||||||
|
|
@ -50,6 +50,10 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
||||||
&DeckPreviewWidget::refreshBannerCardToolTip);
|
&DeckPreviewWidget::refreshBannerCardToolTip);
|
||||||
|
|
||||||
layout->addWidget(bannerCardDisplayWidget);
|
layout->addWidget(bannerCardDisplayWidget);
|
||||||
|
|
||||||
|
checkInitializeUiTimer.setInterval(10);
|
||||||
|
connect(&checkInitializeUiTimer, &QTimer::timeout, this, &DeckPreviewWidget::tryInitializeUi);
|
||||||
|
checkInitializeUiTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::retranslateUi()
|
void DeckPreviewWidget::retranslateUi()
|
||||||
|
|
@ -69,11 +73,46 @@ void DeckPreviewWidget::resizeEvent(QResizeEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
void DeckPreviewWidget::onDeckLoadFinished()
|
||||||
{
|
{
|
||||||
if (!deckLoadSuccess) {
|
deckLoaded = true;
|
||||||
|
tryInitializeUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to initialize the child widgets.
|
||||||
|
* No-ops if the child widgets aren't ready to be created yet or have already been created.
|
||||||
|
*
|
||||||
|
* DeckPreviewWidget delays the creation of its child widgets until it is on screen.
|
||||||
|
* This significantly improves the performance of the VDS.
|
||||||
|
*/
|
||||||
|
void DeckPreviewWidget::tryInitializeUi()
|
||||||
|
{
|
||||||
|
// stop if child widgets are already created from initializeUi
|
||||||
|
if (colorIdentityWidget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop if deck isn't loaded yet
|
||||||
|
if (!deckLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop if this widget is offscreen
|
||||||
|
if (this->visibleRegion().isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the child widgets of the DeckPreviewWidget.
|
||||||
|
*/
|
||||||
|
void DeckPreviewWidget::initializeUi()
|
||||||
|
{
|
||||||
|
checkInitializeUiTimer.stop();
|
||||||
|
|
||||||
auto bannerCard = deckLoader->getBannerCard().first.isEmpty()
|
auto bannerCard = deckLoader->getBannerCard().first.isEmpty()
|
||||||
? CardInfoPtr()
|
? CardInfoPtr()
|
||||||
: CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
: CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ public:
|
||||||
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget = nullptr;
|
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget = nullptr;
|
||||||
QLabel *bannerCardLabel = nullptr;
|
QLabel *bannerCardLabel = nullptr;
|
||||||
QComboBox *bannerCardComboBox = nullptr;
|
QComboBox *bannerCardComboBox = nullptr;
|
||||||
|
QTimer checkInitializeUiTimer;
|
||||||
|
bool deckLoaded = false;
|
||||||
bool filteredBySearch = false;
|
bool filteredBySearch = false;
|
||||||
bool filteredByColor = false;
|
bool filteredByColor = false;
|
||||||
bool filteredByTags = false;
|
bool filteredByTags = false;
|
||||||
|
|
@ -55,20 +57,25 @@ public slots:
|
||||||
void setBannerCard(int);
|
void setBannerCard(int);
|
||||||
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void initializeUi(bool deckLoadSuccess);
|
|
||||||
void updateVisibility();
|
void updateVisibility();
|
||||||
void updateBannerCardComboBoxVisibility(bool visible);
|
void updateBannerCardComboBoxVisibility(bool visible);
|
||||||
void updateTagsVisibility(bool visible);
|
void updateTagsVisibility(bool visible);
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMenu *createRightClickMenu();
|
QMenu *createRightClickMenu();
|
||||||
void addSetBannerCardMenu(QMenu *menu);
|
void addSetBannerCardMenu(QMenu *menu);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onDeckLoadFinished();
|
||||||
|
void tryInitializeUi();
|
||||||
|
void initializeUi();
|
||||||
|
|
||||||
void actRenameDeck();
|
void actRenameDeck();
|
||||||
void actRenameFile();
|
void actRenameFile();
|
||||||
void actDeleteFile();
|
void actDeleteFile();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NoScrollFilter : public QObject
|
class NoScrollFilter : public QObject
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue