mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-26 08:33:54 -07:00
Merge branch 'experimental' of git://cockatrice.git.sourceforge.net/gitroot/cockatrice/cockatrice
This commit is contained in:
commit
31cf3b20be
30 changed files with 7938 additions and 915 deletions
|
|
@ -11,8 +11,24 @@
|
|||
#include "settingscache.h"
|
||||
|
||||
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->setAlignment(Qt::AlignCenter);
|
||||
|
||||
|
|
@ -33,6 +49,8 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
|
|||
|
||||
QGridLayout *grid = new QGridLayout(this);
|
||||
int row = 0;
|
||||
if (mode == ModeGameTab)
|
||||
grid->addWidget(dropList, row++, 1, 1, 1, Qt::AlignRight);
|
||||
grid->addWidget(cardPicture, row++, 0, 1, 2);
|
||||
grid->addWidget(nameLabel1, row, 0);
|
||||
grid->addWidget(nameLabel2, row++, 1);
|
||||
|
|
@ -51,15 +69,51 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
|
|||
|
||||
retranslateUi();
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
setMinimumHeight(350);
|
||||
if (mode == ModeGameTab) {
|
||||
textLabel->setFixedHeight(100);
|
||||
setFixedWidth(sizeHint().width());
|
||||
setMaximumHeight(580);
|
||||
setMinimized(settingsCache->getCardInfoMinimized());
|
||||
} else if (mode == ModePopUp)
|
||||
setFixedWidth(350);
|
||||
else
|
||||
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)
|
||||
|
|
@ -112,7 +166,7 @@ void CardInfoWidget::retranslateUi()
|
|||
|
||||
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
||||
{
|
||||
if ((mode == ModeDeckEditor) || (mode == ModeGameTab)) {
|
||||
if (mode == ModeDeckEditor) {
|
||||
pixmapWidth = qMin(width() * 0.95, (height() - 200) / aspectRatio);
|
||||
updatePixmap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#define CARDINFOWIDGET_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QStringList>
|
||||
#include <QComboBox>
|
||||
|
||||
class QLabel;
|
||||
class QTextEdit;
|
||||
|
|
@ -13,34 +15,44 @@ class QMouseEvent;
|
|||
|
||||
class CardInfoWidget : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
||||
|
||||
private:
|
||||
int pixmapWidth;
|
||||
qreal aspectRatio;
|
||||
bool minimized;
|
||||
int minimized; // 0 - minimized, 1 - card, 2 - oracle only, 3 - full
|
||||
ResizeMode mode;
|
||||
|
||||
QComboBox *dropList;
|
||||
QLabel *cardPicture;
|
||||
QLabel *nameLabel1, *nameLabel2;
|
||||
QLabel *manacostLabel1, *manacostLabel2;
|
||||
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
||||
QLabel *powtoughLabel1, *powtoughLabel2;
|
||||
QTextEdit *textLabel;
|
||||
|
||||
|
||||
CardInfo *info;
|
||||
void setMinimized(int _minimized);
|
||||
|
||||
public:
|
||||
CardInfoWidget(ResizeMode _mode, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
void retranslateUi();
|
||||
|
||||
public slots:
|
||||
void setCard(CardInfo *card);
|
||||
void setCard(const QString &cardName);
|
||||
void setCard(AbstractCardItem *card);
|
||||
|
||||
private slots:
|
||||
void clear();
|
||||
void updatePixmap();
|
||||
void minimizeClicked(int newMinimized);
|
||||
|
||||
signals:
|
||||
void mouseReleased();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ void ChatView::appendMessage(QString sender, const QString &message)
|
|||
senderFormat.setForeground(Qt::blue);
|
||||
cursor.setCharFormat(senderFormat);
|
||||
if (!sender.isEmpty())
|
||||
sender.append(" ");
|
||||
sender.append(": ");
|
||||
cursor.insertText(sender);
|
||||
|
||||
QTextCharFormat messageFormat;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "main.h"
|
||||
#include "decklistmodel.h"
|
||||
#include "carddatabase.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
DeckListModel::DeckListModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
|
|
@ -65,12 +66,20 @@ int DeckListModel::rowCount(const QModelIndex &parent) const
|
|||
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
|
||||
{
|
||||
// debugIndexInfo("data", index);
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
if (index.column() >= 2)
|
||||
if (index.column() >= columnCount())
|
||||
return QVariant();
|
||||
|
||||
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
||||
|
|
@ -86,8 +95,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
switch (index.column()) {
|
||||
case 0: return node->recursiveCount(true);
|
||||
case 1: return node->getVisibleName();
|
||||
case 0: return node->recursiveCount(true);
|
||||
case 1: return node->getVisibleName();
|
||||
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
|
||||
default: return QVariant();
|
||||
}
|
||||
case Qt::BackgroundRole: {
|
||||
|
|
@ -101,8 +111,9 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case Qt::EditRole: {
|
||||
switch (index.column()) {
|
||||
case 0: return card->getNumber();
|
||||
case 1: return card->getName();
|
||||
case 0: return card->getNumber();
|
||||
case 1: return card->getName();
|
||||
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
@ -119,9 +130,12 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
|
|||
{
|
||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||
return QVariant();
|
||||
if (section >= columnCount())
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0: return tr("Number");
|
||||
case 1: return tr("Card");
|
||||
case 0: return tr("Number");
|
||||
case 1: return tr("Card");
|
||||
case 2: return tr("Price");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
@ -174,8 +188,9 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
return false;
|
||||
|
||||
switch (index.column()) {
|
||||
case 0: node->setNumber(value.toInt()); break;
|
||||
case 1: node->setName(value.toString()); break;
|
||||
case 0: node->setNumber(value.toInt()); break;
|
||||
case 1: node->setName(value.toString()); break;
|
||||
case 2: node->setPrice(value.toFloat()); break;
|
||||
default: return false;
|
||||
}
|
||||
emitRecursiveUpdates(index);
|
||||
|
|
@ -300,7 +315,7 @@ void DeckListModel::setDeckList(DeckList *_deck)
|
|||
|
||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||
{
|
||||
static const int totalColumns = 3;
|
||||
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
|
||||
|
||||
if (node->height() == 1) {
|
||||
QTextBlockFormat blockFormat;
|
||||
|
|
@ -308,13 +323,16 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
charFormat.setFontPointSize(11);
|
||||
charFormat.setFontWeight(QFont::Bold);
|
||||
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;
|
||||
tableFormat.setCellPadding(0);
|
||||
tableFormat.setCellSpacing(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++) {
|
||||
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
||||
|
||||
|
|
@ -330,6 +348,13 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
cell.setFormat(cellCharFormat);
|
||||
cellCursor = cell.firstCursorPosition();
|
||||
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) {
|
||||
QTextBlockFormat blockFormat;
|
||||
|
|
@ -338,7 +363,10 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
charFormat.setFontWeight(QFont::Bold);
|
||||
|
||||
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;
|
||||
tableFormat.setCellPadding(10);
|
||||
|
|
@ -391,3 +419,14 @@ void DeckListModel::printDeckList(QPrinter *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:
|
|||
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
|
||||
int getNumber() const { return dataNode->getNumber(); }
|
||||
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(); }
|
||||
void setName(const QString &_name) { dataNode->setName(_name); }
|
||||
DecklistCardNode *getDataNode() const { return dataNode; }
|
||||
|
|
@ -32,7 +34,7 @@ public:
|
|||
DeckListModel(QObject *parent = 0);
|
||||
~DeckListModel();
|
||||
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 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
|
@ -45,6 +47,7 @@ public:
|
|||
void cleanList();
|
||||
DeckList *getDeckList() const { return deckList; }
|
||||
void setDeckList(DeckList *_deck);
|
||||
void pricesUpdated(InnerDecklistNode *node = 0);
|
||||
private:
|
||||
DeckList *deckList;
|
||||
InnerDecklistNode *root;
|
||||
|
|
|
|||
|
|
@ -455,6 +455,30 @@ void UserInterfaceSettingsPage::soundPathButtonClicked()
|
|||
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()
|
||||
{
|
||||
aAdd = new QAction(this);
|
||||
|
|
@ -533,6 +557,7 @@ DlgSettings::DlgSettings(QWidget *parent)
|
|||
pagesWidget->addWidget(new GeneralSettingsPage);
|
||||
pagesWidget->addWidget(new AppearanceSettingsPage);
|
||||
pagesWidget->addWidget(new UserInterfaceSettingsPage);
|
||||
pagesWidget->addWidget(new DeckEditorSettingsPage);
|
||||
pagesWidget->addWidget(new MessagesSettingsPage);
|
||||
|
||||
closeButton = new QPushButton;
|
||||
|
|
@ -577,6 +602,11 @@ void DlgSettings::createIcons()
|
|||
userInterfaceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
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->setTextAlignment(Qt::AlignHCenter);
|
||||
messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
|
@ -633,6 +663,7 @@ void DlgSettings::retranslateUi()
|
|||
generalButton->setText(tr("General"));
|
||||
appearanceButton->setText(tr("Appearance"));
|
||||
userInterfaceButton->setText(tr("User interface"));
|
||||
deckEditorButton->setText(tr("Deck editor"));
|
||||
messagesButton->setText(tr("Messages"));
|
||||
|
||||
closeButton->setText(tr("&Close"));
|
||||
|
|
|
|||
|
|
@ -93,6 +93,16 @@ public:
|
|||
void retranslateUi();
|
||||
};
|
||||
|
||||
class DeckEditorSettingsPage : public AbstractSettingsPage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DeckEditorSettingsPage();
|
||||
void retranslateUi();
|
||||
private:
|
||||
QCheckBox *priceTagsCheckBox;
|
||||
QGroupBox *generalGroupBox;
|
||||
};
|
||||
|
||||
class MessagesSettingsPage : public AbstractSettingsPage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -118,7 +128,7 @@ private slots:
|
|||
private:
|
||||
QListWidget *contentsWidget;
|
||||
QStackedWidget *pagesWidget;
|
||||
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *messagesButton;
|
||||
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *deckEditorButton, *messagesButton;
|
||||
QPushButton *closeButton;
|
||||
void createIcons();
|
||||
void retranslateUi();
|
||||
|
|
|
|||
81
cockatrice/src/priceupdater.cpp
Normal file
81
cockatrice/src/priceupdater.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* @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();
|
||||
}
|
||||
28
cockatrice/src/priceupdater.h
Normal file
28
cockatrice/src/priceupdater.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#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()
|
|||
|
||||
picDownload = settings->value("personal/picturedownload", true).toBool();
|
||||
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
|
||||
cardInfoMinimized = settings->value("interface/cardinfominimized", 0).toInt();
|
||||
tabGameSplitterSizes = settings->value("interface/tabgame_splittersizes").toByteArray();
|
||||
displayCardNames = settings->value("cards/displaycardnames", true).toBool();
|
||||
horizontalHand = settings->value("hand/horizontal", true).toBool();
|
||||
|
|
@ -30,6 +31,8 @@ SettingsCache::SettingsCache()
|
|||
|
||||
soundEnabled = settings->value("sound/enabled", false).toBool();
|
||||
soundPath = settings->value("sound/path").toString();
|
||||
|
||||
priceTagFeature = settings->value("deckeditor/pricetags", false).toBool();
|
||||
}
|
||||
|
||||
void SettingsCache::setLang(const QString &_lang)
|
||||
|
|
@ -107,6 +110,12 @@ void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay)
|
|||
settings->setValue("interface/doubleclicktoplay", doubleClickToPlay);
|
||||
}
|
||||
|
||||
void SettingsCache::setCardInfoMinimized(int _cardInfoMinimized)
|
||||
{
|
||||
cardInfoMinimized = _cardInfoMinimized;
|
||||
settings->setValue("interface/cardinfominimized", cardInfoMinimized);
|
||||
}
|
||||
|
||||
void SettingsCache::setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes)
|
||||
{
|
||||
tabGameSplitterSizes = _tabGameSplitterSizes;
|
||||
|
|
@ -164,3 +173,9 @@ void SettingsCache::setSoundPath(const QString &_soundPath)
|
|||
settings->setValue("sound/path", soundPath);
|
||||
emit soundPathChanged();
|
||||
}
|
||||
|
||||
void SettingsCache::setPriceTagFeature(int _priceTagFeature)
|
||||
{
|
||||
priceTagFeature = _priceTagFeature;
|
||||
settings->setValue("deckeditor/pricetags", priceTagFeature);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ private:
|
|||
QString handBgPath, stackBgPath, tableBgPath, playerBgPath, cardBackPicturePath;
|
||||
bool picDownload;
|
||||
bool doubleClickToPlay;
|
||||
int cardInfoMinimized;
|
||||
QByteArray tabGameSplitterSizes;
|
||||
bool displayCardNames;
|
||||
bool horizontalHand;
|
||||
|
|
@ -37,6 +38,7 @@ private:
|
|||
bool zoneViewSortByName, zoneViewSortByType;
|
||||
bool soundEnabled;
|
||||
QString soundPath;
|
||||
bool priceTagFeature;
|
||||
public:
|
||||
SettingsCache();
|
||||
QString getLang() const { return lang; }
|
||||
|
|
@ -50,6 +52,7 @@ public:
|
|||
QString getCardBackPicturePath() const { return cardBackPicturePath; }
|
||||
bool getPicDownload() const { return picDownload; }
|
||||
bool getDoubleClickToPlay() const { return doubleClickToPlay; }
|
||||
int getCardInfoMinimized() const { return cardInfoMinimized; }
|
||||
QByteArray getTabGameSplitterSizes() const { return tabGameSplitterSizes; }
|
||||
bool getDisplayCardNames() const { return displayCardNames; }
|
||||
bool getHorizontalHand() const { return horizontalHand; }
|
||||
|
|
@ -59,6 +62,7 @@ public:
|
|||
bool getZoneViewSortByType() const { return zoneViewSortByType; }
|
||||
bool getSoundEnabled() const { return soundEnabled; }
|
||||
QString getSoundPath() const { return soundPath; }
|
||||
bool getPriceTagFeature() const { return priceTagFeature; }
|
||||
public slots:
|
||||
void setLang(const QString &_lang);
|
||||
void setDeckPath(const QString &_deckPath);
|
||||
|
|
@ -71,6 +75,7 @@ public slots:
|
|||
void setCardBackPicturePath(const QString &_cardBackPicturePath);
|
||||
void setPicDownload(int _picDownload);
|
||||
void setDoubleClickToPlay(int _doubleClickToPlay);
|
||||
void setCardInfoMinimized(int _cardInfoMinimized);
|
||||
void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes);
|
||||
void setDisplayCardNames(int _displayCardNames);
|
||||
void setHorizontalHand(int _horizontalHand);
|
||||
|
|
@ -80,6 +85,7 @@ public slots:
|
|||
void setZoneViewSortByType(int _zoneViewSortByType);
|
||||
void setSoundEnabled(int _soundEnabled);
|
||||
void setSoundPath(const QString &_soundPath);
|
||||
void setPriceTagFeature(int _priceTagFeature);
|
||||
};
|
||||
|
||||
extern SettingsCache *settingsCache;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <QCheckBox>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QSplitter>
|
||||
#include "dlg_creategame.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include "tab_room.h"
|
||||
|
|
@ -153,12 +154,12 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
chatGroupBox = new QGroupBox;
|
||||
chatGroupBox->setLayout(chatVbox);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(gameSelector);
|
||||
vbox->addWidget(chatGroupBox);
|
||||
QSplitter *splitter = new QSplitter(Qt::Vertical);
|
||||
splitter->addWidget(gameSelector);
|
||||
splitter->addWidget(chatGroupBox);
|
||||
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
hbox->addLayout(vbox, 3);
|
||||
hbox->addWidget(splitter, 3);
|
||||
hbox->addWidget(userList, 1);
|
||||
|
||||
aLeaveRoom = new QAction(this);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "dlg_load_deck_from_clipboard.h"
|
||||
#include "main.h"
|
||||
#include "settingscache.h"
|
||||
#include "priceupdater.h"
|
||||
|
||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
|
|
@ -113,15 +114,37 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
|
|||
commentsEdit->setMaximumHeight(70);
|
||||
commentsLabel->setBuddy(commentsEdit);
|
||||
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(nameEdit, 0, 1);
|
||||
|
||||
grid->addWidget(commentsLabel, 1, 0);
|
||||
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;
|
||||
rightFrame->addLayout(grid);
|
||||
rightFrame->addWidget(deckView);
|
||||
rightFrame->addLayout(deckToolbarLayout);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addLayout(leftFrame, 10);
|
||||
|
|
@ -456,6 +479,21 @@ void WndDeckEditor::actDecrement()
|
|||
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)
|
||||
{
|
||||
deckModel->setDeckList(_deck);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ private slots:
|
|||
void actRemoveCard();
|
||||
void actIncrement();
|
||||
void actDecrement();
|
||||
void actUpdatePrices();
|
||||
|
||||
void finishedUpdatingPrices();
|
||||
private:
|
||||
void addCardHelper(const QString &zoneName);
|
||||
void recursiveExpand(const QModelIndex &index);
|
||||
|
|
@ -74,7 +77,7 @@ private:
|
|||
QMenu *deckMenu, *dbMenu;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aClose;
|
||||
QAction *aEditSets, *aSearch, *aClearSearch;
|
||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
|
||||
public:
|
||||
WndDeckEditor(QWidget *parent = 0);
|
||||
~WndDeckEditor();
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ void MainWindow::actAbout()
|
|||
+ tr("French:") + " Yannick Hammer, Arnaud Faes<br>"
|
||||
+ tr("Japanese:") + " Nagase Task<br>"
|
||||
+ tr("Russian:") + " Alexander Davidov<br>"
|
||||
+ tr("Czech:") + " Ondřej Trhoň<br>"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue