configurable set priority for card pictures
This commit is contained in:
parent
e0d773e4e5
commit
fb03c5cdbb
10 changed files with 242 additions and 17 deletions
|
@ -8,11 +8,12 @@ DEPENDPATH += . src
|
|||
INCLUDEPATH += . src
|
||||
MOC_DIR = build
|
||||
OBJECTS_DIR = build
|
||||
# CONFIG += qt debug
|
||||
|
||||
QT += network
|
||||
#QT += opengl
|
||||
#QTPLUGIN += qjpeg
|
||||
|
||||
# Input
|
||||
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h
|
||||
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp
|
||||
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h
|
||||
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp
|
||||
|
|
|
@ -41,6 +41,19 @@ void CardSet::updateSortKey()
|
|||
sortKey = settings.value("sortkey", 0).toInt();
|
||||
}
|
||||
|
||||
class SetList::CompareFunctor {
|
||||
public:
|
||||
inline bool operator()(CardSet *a, CardSet *b) const
|
||||
{
|
||||
return a->getSortKey() < b->getSortKey();
|
||||
}
|
||||
};
|
||||
|
||||
void SetList::sortByKey()
|
||||
{
|
||||
qSort(begin(), end(), CompareFunctor());
|
||||
}
|
||||
|
||||
CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QStringList &_text)
|
||||
: db(_db), name(_name), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), pixmap(NULL)
|
||||
{
|
||||
|
@ -95,14 +108,6 @@ void CardInfo::addToSet(CardSet *set)
|
|||
sets << set;
|
||||
}
|
||||
|
||||
class CardInfo::SetCompareFunctor {
|
||||
public:
|
||||
inline bool operator()(CardSet *a, CardSet *b) const
|
||||
{
|
||||
return a->getSortKey() < b->getSortKey();
|
||||
}
|
||||
};
|
||||
|
||||
QPixmap *CardInfo::loadPixmap()
|
||||
{
|
||||
if (pixmap)
|
||||
|
@ -112,7 +117,7 @@ QPixmap *CardInfo::loadPixmap()
|
|||
pixmap->load("../pics/back.jpg");
|
||||
return pixmap;
|
||||
}
|
||||
qSort(sets.begin(), sets.end(), SetCompareFunctor());
|
||||
sets.sortByKey();
|
||||
|
||||
QString debugOutput = QString("CardDatabase: loading pixmap for '%1' from ").arg(getName());
|
||||
for (int i = 0; i < sets.size(); i++)
|
||||
|
@ -227,6 +232,17 @@ CardSet *CardDatabase::getSet(const QString &setName)
|
|||
}
|
||||
}
|
||||
|
||||
SetList CardDatabase::getSetList() const
|
||||
{
|
||||
SetList result;
|
||||
QHashIterator<QString, CardSet *> i(setHash);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
result << i.value();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CardDatabase::importOracleFile(const QString &fileName, CardSet *set)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
|
|
@ -25,13 +25,20 @@ public:
|
|||
void saveToStream(QDataStream &stream);
|
||||
};
|
||||
|
||||
class SetList : public QList<CardSet *> {
|
||||
private:
|
||||
class CompareFunctor;
|
||||
public:
|
||||
void sortByKey();
|
||||
};
|
||||
|
||||
class CardInfo {
|
||||
private:
|
||||
class SetCompareFunctor;
|
||||
CardDatabase *db;
|
||||
|
||||
QString name;
|
||||
QList<CardSet *> sets;
|
||||
SetList sets;
|
||||
QString manacost;
|
||||
QString cardtype;
|
||||
QString powtough;
|
||||
|
@ -47,7 +54,7 @@ public:
|
|||
const QStringList &_text = QStringList());
|
||||
~CardInfo();
|
||||
QString getName() const { return name; }
|
||||
QList<CardSet *> getSets() const { return sets; }
|
||||
SetList getSets() const { return sets; }
|
||||
QString getManacost() const { return manacost; }
|
||||
QString getCardType() const { return cardtype; }
|
||||
QString getPowTough() const { return powtough; }
|
||||
|
@ -73,7 +80,8 @@ public:
|
|||
void clear();
|
||||
CardInfo *getCard(const QString &cardName = QString());
|
||||
CardSet *getSet(const QString &setName);
|
||||
QList<CardInfo *> getCardList() { return cardHash.values(); }
|
||||
QList<CardInfo *> getCardList() const { return cardHash.values(); }
|
||||
SetList getSetList() const;
|
||||
void importOracleFile(const QString &fileName, CardSet *set);
|
||||
void importOracleDir();
|
||||
int loadFromFile(const QString &fileName);
|
||||
|
|
|
@ -137,8 +137,8 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
|
|||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0: return QString(tr("Number"));
|
||||
case 1: return QString(tr("Card"));
|
||||
case 0: return tr("Number");
|
||||
case 1: return tr("Card");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
93
cockatrice/src/setsmodel.cpp
Normal file
93
cockatrice/src/setsmodel.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "setsmodel.h"
|
||||
|
||||
SetsModel::SetsModel(CardDatabase *_db, QObject *parent)
|
||||
: QAbstractTableModel(parent), sets(_db->getSetList())
|
||||
{
|
||||
sets.sortByKey();
|
||||
}
|
||||
|
||||
SetsModel::~SetsModel()
|
||||
{
|
||||
}
|
||||
|
||||
int SetsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
else
|
||||
return sets.size();
|
||||
}
|
||||
|
||||
QVariant SetsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || (index.column() >= 2) || (index.row() >= rowCount()) || (role != Qt::DisplayRole))
|
||||
return QVariant();
|
||||
|
||||
CardSet *set = sets[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0: return set->getShortName();
|
||||
case 1: return set->getLongName();
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant SetsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0: return tr("Short name");
|
||||
case 1: return tr("Long name");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags SetsModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags result = QAbstractTableModel::flags(index);
|
||||
return result | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions SetsModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
QMimeData *SetsModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return 0;
|
||||
|
||||
SetsMimeData *result = new SetsMimeData(indexes[0].row());
|
||||
return qobject_cast<QMimeData *>(result);
|
||||
}
|
||||
|
||||
bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex &parent)
|
||||
{
|
||||
if (action != Qt::MoveAction)
|
||||
return false;
|
||||
if (row == -1) {
|
||||
if (!parent.isValid())
|
||||
return false;
|
||||
row = parent.row();
|
||||
}
|
||||
int oldRow = qobject_cast<const SetsMimeData *>(data)->getOldRow();
|
||||
beginRemoveRows(QModelIndex(), oldRow, oldRow);
|
||||
CardSet *temp = sets.takeAt(oldRow);
|
||||
endRemoveRows();
|
||||
if (oldRow < row)
|
||||
row--;
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
sets.insert(row, temp);
|
||||
endInsertRows();
|
||||
|
||||
for (int i = 0; i < sets.size(); i++)
|
||||
sets[i]->setSortKey(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList SetsModel::mimeTypes() const
|
||||
{
|
||||
return QStringList() << "application/x-cockatricecardset";
|
||||
}
|
37
cockatrice/src/setsmodel.h
Normal file
37
cockatrice/src/setsmodel.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef SETSMODEL_H
|
||||
#define SETSMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QMimeData>
|
||||
#include "carddatabase.h"
|
||||
|
||||
class SetsMimeData : public QMimeData {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int oldRow;
|
||||
public:
|
||||
SetsMimeData(int _oldRow) : oldRow(_oldRow) { }
|
||||
int getOldRow() const { return oldRow; }
|
||||
QStringList formats() const { return QStringList() << "application/x-cockatricecardset"; }
|
||||
};
|
||||
|
||||
class SetsModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SetsModel(CardDatabase *_db, QObject *parent = 0);
|
||||
~SetsModel();
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &/*parent*/) const { return 2; }
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
QStringList mimeTypes() const;
|
||||
private:
|
||||
SetList sets;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#include <QtGui>
|
||||
#include "window_deckeditor.h"
|
||||
#include "window_sets.h"
|
||||
#include "carddatabase.h"
|
||||
#include "carddatabasemodel.h"
|
||||
#include "decklistmodel.h"
|
||||
|
@ -97,6 +98,9 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
aClose->setShortcut(tr("Ctrl+Q"));
|
||||
connect(aClose, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
aEditSets = new QAction(tr("&Edit sets..."), this);
|
||||
connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
|
||||
|
||||
deckMenu = menuBar()->addMenu(tr("&Deck"));
|
||||
deckMenu->addAction(aNewDeck);
|
||||
deckMenu->addAction(aLoadDeck);
|
||||
|
@ -105,6 +109,9 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
deckMenu->addSeparator();
|
||||
deckMenu->addAction(aClose);
|
||||
|
||||
setsMenu = menuBar()->addMenu(tr("&Sets"));
|
||||
setsMenu->addAction(aEditSets);
|
||||
|
||||
aAddCard = new QAction(tr("Add card to &maindeck"), this);
|
||||
connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard()));
|
||||
aAddCard->setShortcut(tr("Ctrl+M"));
|
||||
|
@ -227,6 +234,13 @@ bool WndDeckEditor::actSaveDeckAs()
|
|||
return false;
|
||||
}
|
||||
|
||||
void WndDeckEditor::actEditSets()
|
||||
{
|
||||
WndSets *w = new WndSets(db, this);
|
||||
w->setWindowModality(Qt::WindowModal);
|
||||
w->show();
|
||||
}
|
||||
|
||||
void WndDeckEditor::recursiveExpand(const QModelIndex &index)
|
||||
{
|
||||
if (index.parent().isValid())
|
||||
|
|
|
@ -25,6 +25,8 @@ private slots:
|
|||
bool actSaveDeck();
|
||||
bool actSaveDeckAs();
|
||||
|
||||
void actEditSets();
|
||||
|
||||
void actAddCard();
|
||||
void actAddCardToSideboard();
|
||||
void actRemoveCard();
|
||||
|
@ -46,8 +48,9 @@ private:
|
|||
CardInfoWidget *cardInfo;
|
||||
QLineEdit *searchEdit, *nameEdit, *commentsEdit;
|
||||
|
||||
QMenu *deckMenu;
|
||||
QMenu *deckMenu, *setsMenu;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aClose;
|
||||
QAction *aEditSets;
|
||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||
public:
|
||||
WndDeckEditor(CardDatabase *_db, QWidget *parent = 0);
|
||||
|
|
33
cockatrice/src/window_sets.cpp
Normal file
33
cockatrice/src/window_sets.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "window_sets.h"
|
||||
#include "setsmodel.h"
|
||||
#include <QtGui>
|
||||
|
||||
WndSets::WndSets(CardDatabase *_db, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
model = new SetsModel(_db, this);
|
||||
view = new QTreeView;
|
||||
view->setModel(model);
|
||||
view->setAlternatingRowColors(true);
|
||||
view->setUniformRowHeights(true);
|
||||
view->setAllColumnsShowFocus(true);
|
||||
|
||||
view->setDragEnabled(true);
|
||||
view->setAcceptDrops(true);
|
||||
view->setDropIndicatorShown(true);
|
||||
view->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(view);
|
||||
|
||||
QWidget *centralWidget = new QWidget;
|
||||
centralWidget->setLayout(mainLayout);
|
||||
setCentralWidget(centralWidget);
|
||||
|
||||
setWindowTitle(tr("Edit sets"));
|
||||
resize(400, 400);
|
||||
}
|
||||
|
||||
WndSets::~WndSets()
|
||||
{
|
||||
}
|
20
cockatrice/src/window_sets.h
Normal file
20
cockatrice/src/window_sets.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef WINDOW_SETS_H
|
||||
#define WINDOW_SETS_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class SetsModel;
|
||||
class QTreeView;
|
||||
class CardDatabase;
|
||||
|
||||
class WndSets : public QMainWindow {
|
||||
Q_OBJECT
|
||||
private:
|
||||
SetsModel *model;
|
||||
QTreeView *view;
|
||||
public:
|
||||
WndSets(CardDatabase *_db, QWidget *parent = 0);
|
||||
~WndSets();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue