Commit 31cf3b20 authored by unknown's avatar unknown
Browse files
parents 1bc05562 87addd12
...@@ -5,7 +5,7 @@ INCLUDEPATH += . src ../common ...@@ -5,7 +5,7 @@ INCLUDEPATH += . src ../common
MOC_DIR = build MOC_DIR = build
OBJECTS_DIR = build OBJECTS_DIR = build
RESOURCES = cockatrice.qrc RESOURCES = cockatrice.qrc
QT += network svg multimedia QT += network script svg multimedia
HEADERS += src/abstractcounter.h \ HEADERS += src/abstractcounter.h \
src/counter_general.h \ src/counter_general.h \
...@@ -71,6 +71,7 @@ HEADERS += src/abstractcounter.h \ ...@@ -71,6 +71,7 @@ HEADERS += src/abstractcounter.h \
src/localserverinterface.h \ src/localserverinterface.h \
src/localclient.h \ src/localclient.h \
src/translation.h \ src/translation.h \
src/priceupdater.h \
src/soundengine.h \ src/soundengine.h \
../common/color.h \ ../common/color.h \
../common/serializable_item.h \ ../common/serializable_item.h \
...@@ -154,6 +155,7 @@ SOURCES += src/abstractcounter.cpp \ ...@@ -154,6 +155,7 @@ SOURCES += src/abstractcounter.cpp \
src/localserver.cpp \ src/localserver.cpp \
src/localserverinterface.cpp \ src/localserverinterface.cpp \
src/localclient.cpp \ src/localclient.cpp \
src/priceupdater.cpp \
src/soundengine.cpp \ src/soundengine.cpp \
../common/serializable_item.cpp \ ../common/serializable_item.cpp \
../common/decklist.cpp \ ../common/decklist.cpp \
...@@ -179,7 +181,10 @@ TRANSLATIONS += \ ...@@ -179,7 +181,10 @@ TRANSLATIONS += \
translations/cockatrice_pt-br.ts \ translations/cockatrice_pt-br.ts \
translations/cockatrice_fr.ts \ translations/cockatrice_fr.ts \
translations/cockatrice_ja.ts \ translations/cockatrice_ja.ts \
translations/cockatrice_ru.ts translations/cockatrice_ru.ts \
translations/cockatrice_cz.ts \
translations/cockatrice_pl.ts
win32 { win32 {
RC_FILE = cockatrice.rc RC_FILE = cockatrice.rc
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<file>resources/pencil.svg</file> <file>resources/pencil.svg</file>
<file>resources/icon_search.svg</file> <file>resources/icon_search.svg</file>
<file>resources/icon_clearsearch.svg</file> <file>resources/icon_clearsearch.svg</file>
<file>resources/icon_update.png</file>
<file>resources/hr.jpg</file> <file>resources/hr.jpg</file>
<file>resources/appicon.svg</file> <file>resources/appicon.svg</file>
<file>resources/add_to_sideboard.svg</file> <file>resources/add_to_sideboard.svg</file>
...@@ -45,6 +46,8 @@ ...@@ -45,6 +46,8 @@
<file>translations/cockatrice_fr.qm</file> <file>translations/cockatrice_fr.qm</file>
<file>translations/cockatrice_ja.qm</file> <file>translations/cockatrice_ja.qm</file>
<file>translations/cockatrice_ru.qm</file> <file>translations/cockatrice_ru.qm</file>
<file>translations/cockatrice_cz.qm</file>
<file>translations/cockatrice_pl.qm</file>
<file>resources/countries/at.svg</file> <file>resources/countries/at.svg</file>
<file>resources/countries/au.svg</file> <file>resources/countries/au.svg</file>
......
...@@ -11,8 +11,24 @@ ...@@ -11,8 +11,24 @@
#include "settingscache.h" #include "settingscache.h"
CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags) CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags), pixmapWidth(160), aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH), minimized(false), mode(_mode), info(0) : QFrame(parent, flags)
, pixmapWidth(160)
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
, mode(_mode)
, info(0)
{ {
if (mode == ModeGameTab) {
// Create indexed list of status views for card.
const QStringList cardInfoStatus = QStringList() << tr("Hide card info") << tr("Show card only") << tr("Show text only") << tr("Show full info");
// Create droplist for cardinfo view selection, and set right current index.
dropList = new QComboBox();
dropList->addItems(cardInfoStatus);
dropList->setCurrentIndex(minimized);
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
}
cardPicture = new QLabel; cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter); cardPicture->setAlignment(Qt::AlignCenter);
...@@ -33,6 +49,8 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag ...@@ -33,6 +49,8 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
QGridLayout *grid = new QGridLayout(this); QGridLayout *grid = new QGridLayout(this);
int row = 0; int row = 0;
if (mode == ModeGameTab)
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
grid->addWidget(cardPicture, row++, 0, 1, 2); grid->addWidget(cardPicture, row++, 0, 1, 2);
grid->addWidget(nameLabel1, row, 0); grid->addWidget(nameLabel1, row, 0);
grid->addWidget(nameLabel2, row++, 1); grid->addWidget(nameLabel2, row++, 1);
...@@ -51,15 +69,51 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag ...@@ -51,15 +69,51 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
retranslateUi(); retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised); setFrameStyle(QFrame::Panel | QFrame::Raised);
setMinimumHeight(350);
if (mode == ModeGameTab) { if (mode == ModeGameTab) {
textLabel->setFixedHeight(100); textLabel->setFixedHeight(100);
setFixedWidth(sizeHint().width()); setFixedWidth(sizeHint().width());
setMaximumHeight(580); setMinimized(settingsCache->getCardInfoMinimized());
} else if (mode == ModePopUp) } else if (mode == ModePopUp)
setFixedWidth(350); setFixedWidth(350);
else else
setFixedWidth(250); setFixedWidth(250);
if (mode != ModeDeckEditor)
setFixedHeight(sizeHint().height());
}
void CardInfoWidget::minimizeClicked(int newMinimized)
{
// Set new status, and store it in the settings cache.
setMinimized(newMinimized);
settingsCache->setCardInfoMinimized(newMinimized);
}
void CardInfoWidget::setMinimized(int _minimized)
{
minimized = _minimized;
// Set the picture to be shown only at "card only" (1) and "full info" (3)
if (minimized == 1 || minimized == 3) {
cardPicture->setVisible(true);
} else {
cardPicture->setVisible(false);
}
// Set the rest of the fields to be shown only at "full info" (3) and "oracle only" (2)
bool showAll = (minimized == 2 || minimized == 3) ? true : false;
// Toggle oracle fields as according to selected view.
nameLabel2->setVisible(showAll);
nameLabel1->setVisible(showAll);
manacostLabel1->setVisible(showAll);
manacostLabel2->setVisible(showAll);
cardtypeLabel1->setVisible(showAll);
cardtypeLabel2->setVisible(showAll);
powtoughLabel1->setVisible(showAll);
powtoughLabel2->setVisible(showAll);
textLabel->setVisible(showAll);
setFixedHeight(sizeHint().height());
} }
void CardInfoWidget::setCard(CardInfo *card) void CardInfoWidget::setCard(CardInfo *card)
...@@ -112,7 +166,7 @@ void CardInfoWidget::retranslateUi() ...@@ -112,7 +166,7 @@ void CardInfoWidget::retranslateUi()
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/) void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
{ {
if ((mode == ModeDeckEditor) || (mode == ModeGameTab)) { if (mode == ModeDeckEditor) {
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio); pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
updatePixmap(); updatePixmap();
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#define CARDINFOWIDGET_H #define CARDINFOWIDGET_H
#include <QFrame> #include <QFrame>
#include <QStringList>
#include <QComboBox>
class QLabel; class QLabel;
class QTextEdit; class QTextEdit;
...@@ -13,34 +15,44 @@ class QMouseEvent; ...@@ -13,34 +15,44 @@ class QMouseEvent;
class CardInfoWidget : public QFrame { class CardInfoWidget : public QFrame {
Q_OBJECT Q_OBJECT
public: public:
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp }; enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
private: private:
int pixmapWidth; int pixmapWidth;
qreal aspectRatio; qreal aspectRatio;
bool minimized; int minimized; // 0 - minimized, 1 - card, 2 - oracle only, 3 - full
ResizeMode mode; ResizeMode mode;
QComboBox *dropList;
QLabel *cardPicture; QLabel *cardPicture;
QLabel *nameLabel1, *nameLabel2; QLabel *nameLabel1, *nameLabel2;
QLabel *manacostLabel1, *manacostLabel2; QLabel *manacostLabel1, *manacostLabel2;
QLabel *cardtypeLabel1, *cardtypeLabel2; QLabel *cardtypeLabel1, *cardtypeLabel2;
QLabel *powtoughLabel1, *powtoughLabel2; QLabel *powtoughLabel1, *powtoughLabel2;
QTextEdit *textLabel; QTextEdit *textLabel;
CardInfo *info; CardInfo *info;
void setMinimized(int _minimized);
public: public:
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0); CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
void retranslateUi(); void retranslateUi();
public slots: public slots:
void setCard(CardInfo *card); void setCard(CardInfo *card);
void setCard(const QString &cardName); void setCard(const QString &cardName);
void setCard(AbstractCardItem *card); void setCard(AbstractCardItem *card);
private slots: private slots:
void clear(); void clear();
void updatePixmap(); void updatePixmap();
void minimizeClicked(int newMinimized);
signals: signals:
void mouseReleased(); void mouseReleased();
protected: protected:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
......
...@@ -32,7 +32,7 @@ void ChatView::appendMessage(QString sender, const QString &message) ...@@ -32,7 +32,7 @@ void ChatView::appendMessage(QString sender, const QString &message)
senderFormat.setForeground(Qt::blue); senderFormat.setForeground(Qt::blue);
cursor.setCharFormat(senderFormat); cursor.setCharFormat(senderFormat);
if (!sender.isEmpty()) if (!sender.isEmpty())
sender.append(" "); sender.append(": ");
cursor.insertText(sender); cursor.insertText(sender);
QTextCharFormat messageFormat; QTextCharFormat messageFormat;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "main.h" #include "main.h"
#include "decklistmodel.h" #include "decklistmodel.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "settingscache.h"
DeckListModel::DeckListModel(QObject *parent) DeckListModel::DeckListModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
...@@ -65,12 +66,20 @@ int DeckListModel::rowCount(const QModelIndex &parent) const ...@@ -65,12 +66,20 @@ int DeckListModel::rowCount(const QModelIndex &parent) const
return 0; return 0;
} }
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
{
if (settingsCache->getPriceTagFeature())
return 3;
else
return 2;
}
QVariant DeckListModel::data(const QModelIndex &index, int role) const QVariant DeckListModel::data(const QModelIndex &index, int role) const
{ {
// debugIndexInfo("data", index); // debugIndexInfo("data", index);
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (index.column() >= 2) if (index.column() >= columnCount())
return QVariant(); return QVariant();
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer()); AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
...@@ -86,8 +95,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const ...@@ -86,8 +95,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: case Qt::EditRole:
switch (index.column()) { switch (index.column()) {
case 0: return node->recursiveCount(true); case 0: return node->recursiveCount(true);
case 1: return node->getVisibleName(); case 1: return node->getVisibleName();
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
default: return QVariant(); default: return QVariant();
} }
case Qt::BackgroundRole: { case Qt::BackgroundRole: {
...@@ -101,8 +111,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const ...@@ -101,8 +111,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: { case Qt::EditRole: {
switch (index.column()) { switch (index.column()) {
case 0: return card->getNumber(); case 0: return card->getNumber();
case 1: return card->getName(); case 1: return card->getName();
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
default: return QVariant(); default: return QVariant();
} }
} }
...@@ -119,9 +130,12 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int ...@@ -119,9 +130,12 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
{ {
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
return QVariant(); return QVariant();
if (section >= columnCount())
return QVariant();
switch (section) { switch (section) {
case 0: return tr("Number"); case 0: return tr("Number");
case 1: return tr("Card"); case 1: return tr("Card");
case 2: return tr("Price");
default: return QVariant(); default: return QVariant();
} }
} }
...@@ -174,8 +188,9 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int ...@@ -174,8 +188,9 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
return false; return false;
switch (index.column()) { switch (index.column()) {
case 0: node->setNumber(value.toInt()); break; case 0: node->setNumber(value.toInt()); break;
case 1: node->setName(value.toString()); break; case 1: node->setName(value.toString()); break;
case 2: node->setPrice(value.toFloat()); break;
default: return false; default: return false;
} }
emitRecursiveUpdates(index); emitRecursiveUpdates(index);
...@@ -300,7 +315,7 @@ void DeckListModel::setDeckList(DeckList *_deck) ...@@ -300,7 +315,7 @@ void DeckListModel::setDeckList(DeckList *_deck)
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node) void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{ {
static const int totalColumns = 3; const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
if (node->height() == 1) { if (node->height() == 1) {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
...@@ -308,13 +323,16 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no ...@@ -308,13 +323,16 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
charFormat.setFontPointSize(11); charFormat.setFontPointSize(11);
charFormat.setFontWeight(QFont::Bold); charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat); cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QString priceStr;
if (settingsCache->getPriceTagFeature())
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
QTextTableFormat tableFormat; QTextTableFormat tableFormat;
tableFormat.setCellPadding(0); tableFormat.setCellPadding(0);
tableFormat.setCellSpacing(0); tableFormat.setCellSpacing(0);
tableFormat.setBorder(0); tableFormat.setBorder(0);
QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat); QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
for (int i = 0; i < node->size(); i++) { for (int i = 0; i < node->size(); i++) {
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i)); AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
...@@ -330,6 +348,13 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no ...@@ -330,6 +348,13 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
cell.setFormat(cellCharFormat); cell.setFormat(cellCharFormat);
cellCursor = cell.firstCursorPosition(); cellCursor = cell.firstCursorPosition();
cellCursor.insertText(card->getName()); cellCursor.insertText(card->getName());
if (settingsCache->getPriceTagFeature()) {
cell = table->cellAt(i, 2);
cell.setFormat(cellCharFormat);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
}
} }
} else if (node->height() == 2) { } else if (node->height() == 2) {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
...@@ -338,7 +363,10 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no ...@@ -338,7 +363,10 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
charFormat.setFontWeight(QFont::Bold); charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat); cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QString priceStr;
if (settingsCache->getPriceTagFeature())
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
QTextTableFormat tableFormat; QTextTableFormat tableFormat;
tableFormat.setCellPadding(10); tableFormat.setCellPadding(10);
...@@ -391,3 +419,14 @@ void DeckListModel::printDeckList(QPrinter *printer) ...@@ -391,3 +419,14 @@ void DeckListModel::printDeckList(QPrinter *printer)
doc.print(printer); doc.print(printer);
} }
void DeckListModel::pricesUpdated(InnerDecklistNode *node)
{
if (!node)
node = root;
if (node->isEmpty())
return;
emit dataChanged(createIndex(0, 2, node->at(0)), createIndex(node->size() - 1, 2, node->last()));
}
...@@ -17,6 +17,8 @@ public: ...@@ -17,6 +17,8 @@ public:
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { } DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
int getNumber() const { return dataNode->getNumber(); } int getNumber() const { return dataNode->getNumber(); }
void setNumber(int _number) { dataNode->setNumber(_number); } void setNumber(int _number) { dataNode->setNumber(_number); }
float getPrice() const { return dataNode->getPrice(); }
void setPrice(float _price) { dataNode->setPrice(_price); }
QString getName() const { return dataNode->getName(); } QString getName() const { return dataNode->getName(); }
void setName(const QString &_name) { dataNode->setName(_name); } void setName(const QString &_name) { dataNode->setName(_name); }
DecklistCardNode *getDataNode() const { return dataNode; } DecklistCardNode *getDataNode() const { return dataNode; }
...@@ -32,7 +34,7 @@ public: ...@@ -32,7 +34,7 @@ public:
DeckListModel(QObject *parent = 0); DeckListModel(QObject *parent = 0);
~DeckListModel(); ~DeckListModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 2; } int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
...@@ -45,6 +47,7 @@ public: ...@@ -45,6 +47,7 @@ public:
void cleanList(); void cleanList();
DeckList *getDeckList() const { return deckList; } DeckList *getDeckList() const { return deckList; }
void setDeckList(DeckList *_deck); void setDeckList(DeckList *_deck);
void pricesUpdated(InnerDecklistNode *node = 0);
private: private:
DeckList *deckList; DeckList *deckList;
InnerDecklistNode *root; InnerDecklistNode *root;
......
...@@ -455,6 +455,30 @@ void UserInterfaceSettingsPage::soundPathButtonClicked() ...@@ -455,6 +455,30 @@ void UserInterfaceSettingsPage::soundPathButtonClicked()
settingsCache->setSoundPath(path); settingsCache->setSoundPath(path);
} }
DeckEditorSettingsPage::DeckEditorSettingsPage()
{
priceTagsCheckBox = new QCheckBox;
priceTagsCheckBox->setChecked(settingsCache->getPriceTagFeature());
connect(priceTagsCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPriceTagFeature(int)));
QGridLayout *generalGrid = new QGridLayout;
generalGrid->addWidget(priceTagsCheckBox, 0, 0);
generalGroupBox = new QGroupBox;
generalGroupBox->setLayout(generalGrid);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(generalGroupBox);
setLayout(mainLayout);
}
void DeckEditorSettingsPage::retranslateUi()
{
priceTagsCheckBox->setText(tr("Enable &price tag feature (using data from blacklotusproject.com)"));
generalGroupBox->setTitle(tr("General"));
}
MessagesSettingsPage::MessagesSettingsPage() MessagesSettingsPage::MessagesSettingsPage()
{ {
aAdd = new QAction(this); aAdd = new QAction(this);
...@@ -533,6 +557,7 @@ DlgSettings::DlgSettings(QWidget *parent) ...@@ -533,6 +557,7 @@ DlgSettings::DlgSettings(QWidget *parent)
pagesWidget->addWidget(new GeneralSettingsPage); pagesWidget->addWidget(new GeneralSettingsPage);
pagesWidget->addWidget(new AppearanceSettingsPage); pagesWidget->addWidget(new AppearanceSettingsPage);
pagesWidget->addWidget(new UserInterfaceSettingsPage); pagesWidget->addWidget(new UserInterfaceSettingsPage);
pagesWidget->addWidget(new DeckEditorSettingsPage);
pagesWidget->addWidget(new MessagesSettingsPage); pagesWidget->addWidget(new MessagesSettingsPage);
closeButton = new QPushButton; closeButton = new QPushButton;
...@@ -577,6 +602,11 @@ void DlgSettings::createIcons() ...@@ -577,6 +602,11 @@ void DlgSettings::createIcons()
userInterfaceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); userInterfaceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
userInterfaceButton->setIcon(QIcon(":/resources/icon_config_interface.svg")); userInterfaceButton->setIcon(QIcon(":/resources/icon_config_interface.svg"));
deckEditorButton = new QListWidgetItem(contentsWidget);
deckEditorButton->setTextAlignment(Qt::AlignHCenter);
deckEditorButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
deckEditorButton->setIcon(QIcon(":/resources/icon_deckeditor.svg"));
messagesButton = new QListWidgetItem(contentsWidget); messagesButton = new QListWidgetItem(contentsWidget);
messagesButton->setTextAlignment(Qt::AlignHCenter); messagesButton->setTextAlignment(Qt::AlignHCenter);
messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
...@@ -633,6 +663,7 @@ void DlgSettings::retranslateUi() ...@@ -633,6 +663,7 @@ void DlgSettings::retranslateUi()
generalButton->setText(tr("General")); generalButton->setText(tr("General"));
appearanceButton->setText(tr("Appearance")); appearanceButton->setText(tr("Appearance"));
userInterfaceButton->setText(tr("User interface")); userInterfaceButton->setText(tr("User interface"));
deckEditorButton->setText(tr("Deck editor"));
messagesButton->setText(tr("Messages")); messagesButton->setText(tr("Messages"));
closeButton->setText(tr("&Close")); closeButton->setText(tr("&Close"));
......
...@@ -93,6 +93,16 @@ public: ...@@ -93,6 +93,16 @@ public:
void retranslateUi(); void retranslateUi();
}; };
class DeckEditorSettingsPage : public AbstractSettingsPage {
Q_OBJECT
public:
DeckEditorSettingsPage();
void retranslateUi();
private:
QCheckBox *priceTagsCheckBox;
QGroupBox *generalGroupBox;
};
class MessagesSettingsPage : public AbstractSettingsPage { class MessagesSettingsPage : public AbstractSettingsPage {
Q_OBJECT Q_OBJECT
public: public:
...@@ -118,7 +128,7 @@ private slots: ...@@ -118,7 +128,7 @@ private slots:
private: private:
QListWidget *contentsWidget; QListWidget *contentsWidget;
QStackedWidget *pagesWidget; QStackedWidget *pagesWidget;
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *messagesButton; QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *deckEditorButton, *messagesButton;
QPushButton *closeButton; QPushButton *closeButton;
void createIcons(); void createIcons();
void retranslateUi(); void retranslateUi();
......
/**
* @author Marcio Ribeiro <mmr@b1n.org>
* @version 1.0
*/
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QScriptEngine>
#include <QScriptValueIterator>
#include "priceupdater.h"
/**
* Constructor.
*
* @param _deck deck.
*/
PriceUpdater::PriceUpdater(const DeckList *_deck)
{
nam = new QNetworkAccessManager(this);
deck = _deck;
}
/**
* Update the prices of the cards in deckList.
*/
void PriceUpdater::updatePrices()
{
QString q = "http://blacklotusproject.com/json/?cards=";
QStringList cards = deck->getCardList();
for (int i = 0; i < cards.size(); ++i) {
q += cards[i] + "|";
}
QUrl url(q.replace(' ', '+'));
QNetworkReply *reply = nam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
/**
* Called when the download of the json file with the prices is finished.
*/
void PriceUpdater::downloadFinished()
{
QMap<QString, DecklistCardNode *> cmap;
InnerDecklistNode *listRoot = deck->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
cmap.insert(currentCard->getName().toLower(), currentCard);
currentCard->setPrice(0);
}
}
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
QByteArray result = reply->readAll();
QScriptValue sc;
QScriptEngine engine;
sc = engine.evaluate("value = " + result);
if (sc.property("cards").isArray()) {
QScriptValueIterator it(sc.property("cards"));
while (it.hasNext()) {
it.next();
QString name = it.value().property("name").toString().toLower();
float price = it.value().property("average").toString().toFloat();
DecklistCardNode *c = cmap[name];
if (!c)
continue;
if (c->getPrice() == 0 || c->getPrice() > price) {
c->setPrice(price);
}
}
}
reply->deleteLater();
deleteLater();
emit finishedUpdate();
}
#ifndef PRICEUPDATER_H
#define PRICEUPDATER_H
#include <QNetworkReply>
#include "decklist.h"
class QNetworkAccessManager;
/**
* Price Updater.
*
* @author Marcio Ribeiro <mmr@b1n.org>
*/
class PriceUpdater : public QObject
{
Q_OBJECT
private:
const DeckList *deck;
QNetworkAccessManager *nam;
signals:
void finishedUpdate();
private slots:
void downloadFinished();
public:
PriceUpdater(const DeckList *deck);
void updatePrices();
};
#endif
...@@ -19,6 +19,7 @@ SettingsCache::SettingsCache() ...@@ -19,6 +19,7 @@ SettingsCache::SettingsCache()
picDownload = settings->value("personal/picturedownload", true).toBool(); picDownload = settings->value("personal/picturedownload", true).toBool();
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool(); doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
cardInfoMinimized = settings->value("interface/cardinfominimized", 0).toInt();
tabGameSplitterSizes = settings->value("interface/tabgame_splittersizes").toByteArray(); tabGameSplitterSizes = settings->value("interface/tabgame_splittersizes").toByteArray();
displayCardNames = settings->value("cards/displaycardnames", true).toBool(); displayCardNames = settings->value("cards/displaycardnames", true).toBool();
horizontalHand = settings->value("hand/horizontal", true).toBool(); horizontalHand = settings->value("hand/horizontal", true).toBool();
...@@ -30,6 +31,8 @@ SettingsCache::SettingsCache() ...@@ -30,6 +31,8 @@ SettingsCache::SettingsCache()
soundEnabled = settings->value("sound/enabled", false).toBool(); soundEnabled = settings->value("sound/enabled", false).toBool();
soundPath = settings->value("sound/path").toString(); soundPath = settings->value("sound/path").toString();
priceTagFeature = settings->value("deckeditor/pricetags", false).toBool();
} }
void SettingsCache::setLang(const QString &_lang) void SettingsCache::setLang(const QString &_lang)
...@@ -107,6 +110,12 @@ void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay) ...@@ -107,6 +110,12 @@ void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay)
settings->setValue("interface/doubleclicktoplay", doubleClickToPlay); settings->setValue("interface/doubleclicktoplay", doubleClickToPlay);
} }
void SettingsCache::setCardInfoMinimized(int _cardInfoMinimized)
{
cardInfoMinimized = _cardInfoMinimized;
settings->setValue("interface/cardinfominimized", cardInfoMinimized);
}
void SettingsCache::setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes) void SettingsCache::setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes)
{ {
tabGameSplitterSizes = _tabGameSplitterSizes; tabGameSplitterSizes = _tabGameSplitterSizes;
...@@ -164,3 +173,9 @@ void SettingsCache::setSoundPath(const QString &_soundPath) ...@@ -164,3 +173,9 @@ void SettingsCache::setSoundPath(const QString &_soundPath)
settings->setValue("sound/path", soundPath); settings->setValue("sound/path", soundPath);
emit soundPathChanged(); emit soundPathChanged();
} }
void SettingsCache::setPriceTagFeature(int _priceTagFeature)
{
priceTagFeature = _priceTagFeature;
settings->setValue("deckeditor/pricetags", priceTagFeature);
}
...@@ -29,6 +29,7 @@ private: ...@@ -29,6 +29,7 @@ private:
QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath; QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath;
bool picDownload; bool picDownload;
bool doubleClickToPlay; bool doubleClickToPlay;
int cardInfoMinimized;
QByteArray tabGameSplitterSizes; QByteArray tabGameSplitterSizes;
bool displayCardNames; bool displayCardNames;
bool horizontalHand; bool horizontalHand;
...@@ -37,6 +38,7 @@ private: ...@@ -37,6 +38,7 @@ private:
bool zoneViewSortByName, zoneViewSortByType; bool zoneViewSortByName, zoneViewSortByType;
bool soundEnabled; bool soundEnabled;
QString soundPath; QString soundPath;
bool priceTagFeature;
public: public:
SettingsCache(); SettingsCache();
QString getLang() const { return lang; } QString getLang() const { return lang; }
...@@ -50,6 +52,7 @@ public: ...@@ -50,6 +52,7 @@ public:
QString getCardBackPicturePath() const { return cardBackPicturePath; } QString getCardBackPicturePath() const { return cardBackPicturePath; }
bool getPicDownload() const { return picDownload; } bool getPicDownload() const { return picDownload; }
bool getDoubleClickToPlay() const { return doubleClickToPlay; } bool getDoubleClickToPlay() const { return doubleClickToPlay; }
int getCardInfoMinimized() const { return cardInfoMinimized; }
QByteArray getTabGameSplitterSizes() const { return tabGameSplitterSizes; } QByteArray getTabGameSplitterSizes() const { return tabGameSplitterSizes; }
bool getDisplayCardNames() const { return displayCardNames; } bool getDisplayCardNames() const { return displayCardNames; }
bool getHorizontalHand() const { return horizontalHand; } bool getHorizontalHand() const { return horizontalHand; }
...@@ -59,6 +62,7 @@ public: ...@@ -59,6 +62,7 @@ public:
bool getZoneViewSortByType() const { return zoneViewSortByType; } bool getZoneViewSortByType() const { return zoneViewSortByType; }
bool getSoundEnabled() const { return soundEnabled; } bool getSoundEnabled() const { return soundEnabled; }
QString getSoundPath() const { return soundPath; } QString getSoundPath() const { return soundPath; }
bool getPriceTagFeature() const { return priceTagFeature; }
public slots: public slots:
void setLang(const QString &_lang); void setLang(const QString &_lang);
void setDeckPath(const QString &_deckPath); void setDeckPath(const QString &_deckPath);
...@@ -71,6 +75,7 @@ public slots: ...@@ -71,6 +75,7 @@ public slots:
void setCardBackPicturePath(const QString &_cardBackPicturePath); void setCardBackPicturePath(const QString &_cardBackPicturePath);
void setPicDownload(int _picDownload); void setPicDownload(int _picDownload);
void setDoubleClickToPlay(int _doubleClickToPlay); void setDoubleClickToPlay(int _doubleClickToPlay);
void setCardInfoMinimized(int _cardInfoMinimized);
void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes); void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes);
void setDisplayCardNames(int _displayCardNames); void setDisplayCardNames(int _displayCardNames);
void setHorizontalHand(int _horizontalHand); void setHorizontalHand(int _horizontalHand);
...@@ -80,6 +85,7 @@ public slots: ...@@ -80,6 +85,7 @@ public slots:
void setZoneViewSortByType(int _zoneViewSortByType); void setZoneViewSortByType(int _zoneViewSortByType);
void setSoundEnabled(int _soundEnabled); void setSoundEnabled(int _soundEnabled);
void setSoundPath(const QString &_soundPath); void setSoundPath(const QString &_soundPath);
void setPriceTagFeature(int _priceTagFeature);
}; };
extern SettingsCache *settingsCache; extern SettingsCache *settingsCache;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QInputDialog> #include <QInputDialog>
#include <QLabel> #include <QLabel>
#include <QSplitter>
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "tab_supervisor.h" #include "tab_supervisor.h"
#include "tab_room.h" #include "tab_room.h"
...@@ -153,12 +154,12 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q ...@@ -153,12 +154,12 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
chatGroupBox = new QGroupBox; chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatVbox); chatGroupBox->setLayout(chatVbox);
QVBoxLayout *vbox = new QVBoxLayout; QSplitter *splitter = new QSplitter(Qt::Vertical);
vbox->addWidget(gameSelector); splitter->addWidget(gameSelector);
vbox->addWidget(chatGroupBox); splitter->addWidget(chatGroupBox);
QHBoxLayout *hbox = new QHBoxLayout; QHBoxLayout *hbox = new QHBoxLayout;
hbox->addLayout(vbox, 3); hbox->addWidget(splitter, 3);
hbox->addWidget(userList, 1); hbox->addWidget(userList, 1);
aLeaveRoom = new QAction(this); aLeaveRoom = new QAction(this);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "dlg_load_deck_from_clipboard.h" #include "dlg_load_deck_from_clipboard.h"
#include "main.h" #include "main.h"
#include "settingscache.h" #include "settingscache.h"
#include "priceupdater.h"
void SearchLineEdit::keyPressEvent(QKeyEvent *event) void SearchLineEdit::keyPressEvent(QKeyEvent *event)
{ {
...@@ -113,15 +114,37 @@ WndDeckEditor::WndDeckEditor(QWidget *parent) ...@@ -113,15 +114,37 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
commentsEdit->setMaximumHeight(70); commentsEdit->setMaximumHeight(70);
commentsLabel->setBuddy(commentsEdit); commentsLabel->setBuddy(commentsEdit);
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments())); connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
QGridLayout *grid = new QGridLayout; QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0); grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1); grid->addWidget(nameEdit, 0, 1);
grid->addWidget(commentsLabel, 1, 0); grid->addWidget(commentsLabel, 1, 0);
grid->addWidget(commentsEdit, 1, 1); grid->addWidget(commentsEdit, 1, 1);
// Update price
aUpdatePrices = new QAction(tr("&Update prices"), this);
aUpdatePrices->setShortcut(tr("Ctrl+U"));
aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png"));
connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
if (!settingsCache->getPriceTagFeature())
aUpdatePrices->setVisible(false);
QToolBar *deckToolBar = new QToolBar;
deckToolBar->setOrientation(Qt::Vertical);
deckToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
deckToolBar->setIconSize(QSize(24, 24));
deckToolBar->addAction(aUpdatePrices);
QHBoxLayout *deckToolbarLayout = new QHBoxLayout;
deckToolbarLayout->addStretch();
deckToolbarLayout->addWidget(deckToolBar);
deckToolbarLayout->addStretch();
QVBoxLayout *rightFrame = new QVBoxLayout; QVBoxLayout *rightFrame = new QVBoxLayout;
rightFrame->addLayout(grid); rightFrame->addLayout(grid);
rightFrame->addWidget(deckView); rightFrame->addWidget(deckView);
rightFrame->addLayout(deckToolbarLayout);
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftFrame, 10); mainLayout->addLayout(leftFrame, 10);
...@@ -456,6 +479,21 @@ void WndDeckEditor::actDecrement() ...@@ -456,6 +479,21 @@ void WndDeckEditor::actDecrement()
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actUpdatePrices()
{
aUpdatePrices->setDisabled(true);
PriceUpdater *up = new PriceUpdater(deckModel->getDeckList());
connect(up, SIGNAL(finishedUpdate()), this, SLOT(finishedUpdatingPrices()));
up->updatePrices();
}
void WndDeckEditor::finishedUpdatingPrices()
{
deckModel->pricesUpdated();
setWindowModified(true);
aUpdatePrices->setDisabled(false);
}
void WndDeckEditor::setDeck(DeckList *_deck, const QString &_lastFileName, DeckList::FileFormat _lastFileFormat) void WndDeckEditor::setDeck(DeckList *_deck, const QString &_lastFileName, DeckList::FileFormat _lastFileFormat)
{ {
deckModel->setDeckList(_deck); deckModel->setDeckList(_deck);
......
...@@ -52,6 +52,9 @@ private slots: ...@@ -52,6 +52,9 @@ private slots:
void actRemoveCard(); void actRemoveCard();
void actIncrement(); void actIncrement();
void actDecrement(); void actDecrement();
void actUpdatePrices();
void finishedUpdatingPrices();
private: private:
void addCardHelper(const QString &zoneName); void addCardHelper(const QString &zoneName);
void recursiveExpand(const QModelIndex &index); void recursiveExpand(const QModelIndex &index);
...@@ -74,7 +77,7 @@ private: ...@@ -74,7 +77,7 @@ private:
QMenu *deckMenu, *dbMenu; QMenu *deckMenu, *dbMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aClose; QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aClose;
QAction *aEditSets, *aSearch, *aClearSearch; QAction *aEditSets, *aSearch, *aClearSearch;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
public: public:
WndDeckEditor(QWidget *parent = 0); WndDeckEditor(QWidget *parent = 0);
~WndDeckEditor(); ~WndDeckEditor();
......
...@@ -178,6 +178,7 @@ void MainWindow::actAbout() ...@@ -178,6 +178,7 @@ void MainWindow::actAbout()
+ tr("French:") + " Yannick Hammer, Arnaud Faes<br>" + tr("French:") + " Yannick Hammer, Arnaud Faes<br>"
+ tr("Japanese:") + " Nagase Task<br>" + tr("Japanese:") + " Nagase Task<br>"
+ tr("Russian:") + " Alexander Davidov<br>" + tr("Russian:") + " Alexander Davidov<br>"
+ tr("Czech:") + " Ondřej Trhoň<br>"
)); ));
} }
......
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment