Token Dialog Revamp (#2639)

This commit is contained in:
ctrlaltca 2017-04-25 06:29:57 +02:00 committed by Zach H
parent 8ad448a23c
commit ab94d2c91d
4 changed files with 43 additions and 12 deletions

View file

@ -10,18 +10,20 @@
#include <QTreeView>
#include <QRadioButton>
#include <QHeaderView>
#include <QCloseEvent>
#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 &current, 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 &current, 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();

View file

@ -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 &current, 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;
};

View file

@ -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;

View file

@ -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);