From ab94d2c91d12c614b375162857631f22d08b237f Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Tue, 25 Apr 2017 06:29:57 +0200 Subject: [PATCH] Token Dialog Revamp (#2639) --- cockatrice/src/dlg_create_token.cpp | 39 ++++++++++++++++++++--------- cockatrice/src/dlg_create_token.h | 6 +++++ cockatrice/src/settingscache.cpp | 7 ++++++ cockatrice/src/settingscache.h | 3 +++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/dlg_create_token.cpp b/cockatrice/src/dlg_create_token.cpp index cc0a97d5..604e2675 100644 --- a/cockatrice/src/dlg_create_token.cpp +++ b/cockatrice/src/dlg_create_token.cpp @@ -10,18 +10,20 @@ #include #include #include +#include #include "decklist.h" #include "dlg_create_token.h" #include "carddatabasemodel.h" #include "main.h" #include "settingscache.h" +#include "cardinfopicture.h" DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent) : QDialog(parent), predefinedTokens(_predefinedTokens) { - this->setMinimumSize(200,200); - this->adjustSize(); + pic = new CardInfoPicture(); + pic->setObjectName("pic"); nameLabel = new QLabel(tr("&Name:")); nameEdit = new QLineEdit(tr("Token")); @@ -105,19 +107,16 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list")); tokenChooseGroupBox->setLayout(tokenChooseLayout); - - QVBoxLayout *leftVBox = new QVBoxLayout; - leftVBox->addWidget(tokenDataGroupBox); - leftVBox->addStretch(); QGridLayout *hbox = new QGridLayout; - hbox->addLayout(leftVBox, 0, 0); - hbox->addWidget(tokenChooseGroupBox, 0, 1); + hbox->addWidget(pic, 0, 0, 1, 1); + hbox->addWidget(tokenDataGroupBox, 1, 0, 1, 1); + hbox->addWidget(tokenChooseGroupBox, 0, 1, 2, 1); hbox->setColumnStretch(1, 1); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(actReject())); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(hbox); @@ -125,14 +124,21 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa setLayout(mainLayout); setWindowTitle(tr("Create token")); - setFixedHeight(sizeHint().height()); - setFixedWidth(width()); + + resize(600, 500); + restoreGeometry(settingsCache->getTokenDialogGeometry()); +} + +void DlgCreateToken::closeEvent(QCloseEvent *event) +{ + event->accept(); + settingsCache->setTokenDialogGeometry(saveGeometry()); } void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/) { const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current); - const CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : 0; + CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : 0; if(cardInfo) { @@ -148,6 +154,8 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QMo ptEdit->setText(""); annotationEdit->setText(""); } + + pic->setCard(cardInfo); } void DlgCreateToken::updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const { @@ -175,9 +183,16 @@ void DlgCreateToken::actChooseTokenFromDeck(bool checked) void DlgCreateToken::actOk() { + settingsCache->setTokenDialogGeometry(saveGeometry()); accept(); } +void DlgCreateToken::actReject() +{ + settingsCache->setTokenDialogGeometry(saveGeometry()); + reject(); +} + QString DlgCreateToken::getName() const { return nameEdit->text(); diff --git a/cockatrice/src/dlg_create_token.h b/cockatrice/src/dlg_create_token.h index ec212471..fa5c3159 100644 --- a/cockatrice/src/dlg_create_token.h +++ b/cockatrice/src/dlg_create_token.h @@ -10,9 +10,11 @@ class QComboBox; class QCheckBox; class QPushButton; class QRadioButton; +class QCloseEvent; class DeckList; class CardDatabaseModel; class TokenDisplayModel; +class CardInfoPicture; class DlgCreateToken : public QDialog { Q_OBJECT @@ -23,12 +25,15 @@ public: QString getPT() const; QString getAnnotation() const; bool getDestroy() const; +protected: + void closeEvent(QCloseEvent *event); private slots: void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); void updateSearch(const QString &search); void actChooseTokenFromAll(bool checked); void actChooseTokenFromDeck(bool checked); void actOk(); + void actReject(); private: CardDatabaseModel *cardDatabaseModel; TokenDisplayModel *cardDatabaseDisplayModel; @@ -38,6 +43,7 @@ private: QLineEdit *nameEdit, *ptEdit, *annotationEdit; QCheckBox *destroyCheckBox; QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton; + CardInfoPicture *pic; void updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const; }; diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index bf7f9dea..b1fae89d 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -208,6 +208,7 @@ SettingsCache::SettingsCache() picUrlFallback = settings->value("personal/picUrlFallback", PIC_URL_FALLBACK).toString(); mainWindowGeometry = settings->value("interface/main_window_geometry").toByteArray(); + tokenDialogGeometry = settings->value("interface/token_dialog_geometry").toByteArray(); notificationsEnabled = settings->value("interface/notificationsenabled", true).toBool(); spectatorNotificationsEnabled = settings->value("interface/specnotificationsenabled", false).toBool(); doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool(); @@ -544,6 +545,12 @@ void SettingsCache::setMainWindowGeometry(const QByteArray &_mainWindowGeometry) settings->setValue("interface/main_window_geometry", mainWindowGeometry); } +void SettingsCache::setTokenDialogGeometry(const QByteArray &_tokenDialogGeometry) +{ + tokenDialogGeometry = _tokenDialogGeometry; + settings->setValue("interface/token_dialog_geometry", tokenDialogGeometry); +} + void SettingsCache::setPixmapCacheSize(const int _pixmapCacheSize) { pixmapCacheSize = _pixmapCacheSize; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index d5fe4e9a..818e357b 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -59,6 +59,7 @@ private: LayoutsSettings *layoutsSettings; QByteArray mainWindowGeometry; + QByteArray tokenDialogGeometry; QString lang; QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, tokenDatabasePath, themeName; bool notifyAboutUpdates; @@ -123,6 +124,7 @@ public: QString getDataPath(); QString getSettingsPath(); const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; } + const QByteArray &getTokenDialogGeometry() const { return tokenDialogGeometry; } QString getLang() const { return lang; } QString getDeckPath() const { return deckPath; } QString getReplaysPath() const { return replaysPath; } @@ -203,6 +205,7 @@ public: LayoutsSettings& layouts() const { return *layoutsSettings; } public slots: void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); + void setTokenDialogGeometry(const QByteArray &_tokenDialog); void setLang(const QString &_lang); void setDeckPath(const QString &_deckPath); void setReplaysPath(const QString &_replaysPath);