mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 01:24:46 -07:00
Add a dialog to prompt user to convert to .cod format if trying to apply tags to a .txt deck. (#5514)
* Add a dialog to prompt user to convert to .cod format if trying to apply tags to a .txt deck. * Lint mocks. * Address comments, move dialog to appropriate folder. * Unlint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
4e96157091
commit
ce416df3fb
14 changed files with 229 additions and 6 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "deck_preview_tag_addition_widget.h"
|
||||
|
||||
#include "../../../../../dialogs/dlg_convert_deck_to_cod_format.h"
|
||||
#include "../../../../../settings/cache_settings.h"
|
||||
#include "deck_preview_tag_dialog.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
|
@ -40,11 +42,50 @@ void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event)
|
|||
QStringList knownTags = parent->parent->parent->gatherAllTagsFromFlowWidget();
|
||||
QStringList activeTags = parent->deckLoader->getTags();
|
||||
|
||||
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QStringList updatedTags = dialog.getActiveTags();
|
||||
parent->deckLoader->setTags(updatedTags);
|
||||
parent->deckLoader->saveToFile(parent->parent->filePath, DeckLoader::CockatriceFormat);
|
||||
bool canAddTags = true;
|
||||
|
||||
if (parent->deckLoader->getLastFileFormat() != DeckLoader::CockatriceFormat) {
|
||||
canAddTags = false;
|
||||
// Retrieve saved preference if the prompt is disabled
|
||||
if (!SettingsCache::instance().getVisualDeckStoragePromptForConversion()) {
|
||||
if (SettingsCache::instance().getVisualDeckStorageAlwaysConvert()) {
|
||||
parent->deckLoader->convertToCockatriceFormat(parent->parent->filePath);
|
||||
parent->parent->filePath = parent->deckLoader->getLastFileName();
|
||||
parent->parent->refreshBannerCardText();
|
||||
canAddTags = true;
|
||||
}
|
||||
} else {
|
||||
// Show the dialog to the user
|
||||
DialogConvertDeckToCodFormat conversionDialog(parent);
|
||||
if (conversionDialog.exec() == QDialog::Accepted) {
|
||||
parent->deckLoader->convertToCockatriceFormat(parent->parent->filePath);
|
||||
parent->parent->filePath = parent->deckLoader->getLastFileName();
|
||||
parent->parent->refreshBannerCardText();
|
||||
canAddTags = true;
|
||||
|
||||
if (conversionDialog.dontAskAgain()) {
|
||||
SettingsCache::instance().setVisualDeckStoragePromptForConversion(Qt::CheckState::Unchecked);
|
||||
SettingsCache::instance().setVisualDeckStorageAlwaysConvert(Qt::CheckState::Checked);
|
||||
}
|
||||
} else {
|
||||
SettingsCache::instance().setVisualDeckStorageAlwaysConvert(Qt::CheckState::Unchecked);
|
||||
|
||||
if (conversionDialog.dontAskAgain()) {
|
||||
SettingsCache::instance().setVisualDeckStoragePromptForConversion(Qt::CheckState::Unchecked);
|
||||
} else {
|
||||
SettingsCache::instance().setVisualDeckStoragePromptForConversion(Qt::CheckState::Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canAddTags) {
|
||||
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QStringList updatedTags = dialog.getActiveTags();
|
||||
parent->deckLoader->setTags(updatedTags);
|
||||
parent->deckLoader->saveToFile(parent->parent->filePath, DeckLoader::CockatriceFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ DeckPreviewWidget::DeckPreviewWidget(VisualDeckStorageWidget *_parent, const QSt
|
|||
|
||||
deckLoader = new DeckLoader();
|
||||
connect(deckLoader, &DeckLoader::loadFinished, this, &DeckPreviewWidget::initializeUi);
|
||||
deckLoader->loadFromFileAsync(filePath, DeckLoader::CockatriceFormat, false);
|
||||
deckLoader->loadFromFileAsync(filePath, DeckLoader::getFormatFromName(filePath), false);
|
||||
|
||||
bannerCardDisplayWidget = new DeckPreviewCardPictureWidget(this);
|
||||
|
||||
|
|
@ -88,6 +88,12 @@ void DeckPreviewWidget::setFilePath(const QString &_filePath)
|
|||
filePath = _filePath;
|
||||
}
|
||||
|
||||
void DeckPreviewWidget::refreshBannerCardText()
|
||||
{
|
||||
bannerCardDisplayWidget->setOverlayText(
|
||||
deckLoader->getName().isEmpty() ? QFileInfo(deckLoader->getLastFileName()).fileName() : deckLoader->getName());
|
||||
}
|
||||
|
||||
void DeckPreviewWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
Q_UNUSED(instance);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ signals:
|
|||
|
||||
public slots:
|
||||
void setFilePath(const QString &filePath);
|
||||
void refreshBannerCardText();
|
||||
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void initializeUi(bool deckLoadSuccess);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue