Rework "paths" settings loading and card database loading
* main.cpp: removed path checking and db loading * card database: merge card loading methods into a single one * settings cache: take care of returning safe paths for decks, replays, etc.. * main window: if db loading fails (eg. first run), propose to run oracle NSIS: propose to run cockatrice instead of oracle Rework card database loading * Move carddatabase-related method out of deckeditor tab * Load cards in another thread and render them progressively * Optimize database reload after enabled sets change Fix deck editor column width * removed the noCard hack. * getCard() no more creates cards instead of just returning existing ones * Fix the “edit tokens” dialog. * PictureLoader: avoid trying to download twice the same card * PictureLoader: correct return of card background * AbstractCardItem: avoid recalculating card color at every paint Use a different file to save custom tokens Misc required improvements * Use nullptr; * Refactor CardInfoWidget to use CardInfoPicture and CardInfoText instead of duplicating code; * Added CardInfo::getColorChar() * Fixed some potential crashes * removed dead code related to CardInfoWidget * Don't require a restart after adding a new custom sets file * Bump CMake requirements to 3.1
This commit is contained in:
parent
0b8f52e084
commit
1e3fb6c6e1
41 changed files with 855 additions and 1074 deletions
|
@ -5,7 +5,8 @@
|
||||||
# This file sets all the variables shared between the projects
|
# This file sets all the variables shared between the projects
|
||||||
# like the installation path, compilation flags etc..
|
# like the installation path, compilation flags etc..
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
# Cmake 3.1 is required to enable C++11 support correctly
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
|
||||||
if(POLICY CMP0020)
|
if(POLICY CMP0020)
|
||||||
cmake_policy(SET CMP0020 OLD)
|
cmake_policy(SET CMP0020 OLD)
|
||||||
|
@ -171,7 +172,7 @@ IF(WIN32)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# Package builder
|
# Package builder
|
||||||
set(CPACK_PACKAGE_CONTACT "Daenyth+github@gmail.com")
|
set(CPACK_PACKAGE_CONTACT "Gavin Bisesi <Daenyth+github@gmail.com>")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME})
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME})
|
||||||
set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team")
|
set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
|
||||||
|
|
|
@ -16,9 +16,8 @@ InstallDir "$PROGRAMFILES\Cockatrice"
|
||||||
!define MUI_HEADERIMAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
!define MUI_HEADERIMAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
||||||
!define MUI_HEADERIMAGE_UNBITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
!define MUI_HEADERIMAGE_UNBITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
||||||
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Cockatrice.$\r$\n$\r$\nClick Next to continue."
|
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Cockatrice.$\r$\n$\r$\nClick Next to continue."
|
||||||
!define MUI_FINISHPAGE_RUN "$INSTDIR/oracle.exe"
|
!define MUI_FINISHPAGE_RUN "$INSTDIR/cockatrice.exe"
|
||||||
!define MUI_FINISHPAGE_RUN_TEXT "Run 'Oracle' now to update your card database"
|
!define MUI_FINISHPAGE_RUN_TEXT "Run 'Cockatrice' now"
|
||||||
!define MUI_FINISHPAGE_RUN_PARAMETERS "-dlsets"
|
|
||||||
|
|
||||||
!insertmacro MUI_PAGE_WELCOME
|
!insertmacro MUI_PAGE_WELCOME
|
||||||
!insertmacro MUI_PAGE_LICENSE "${NSIS_SOURCE_PATH}\COPYING"
|
!insertmacro MUI_PAGE_LICENSE "${NSIS_SOURCE_PATH}\COPYING"
|
||||||
|
@ -68,22 +67,20 @@ Section "Start menu item" SecStartMenu
|
||||||
createShortCut "$SMPROGRAMS\Cockatrice\Cockatrice.lnk" "$INSTDIR\cockatrice.exe"
|
createShortCut "$SMPROGRAMS\Cockatrice\Cockatrice.lnk" "$INSTDIR\cockatrice.exe"
|
||||||
createShortCut "$SMPROGRAMS\Cockatrice\Oracle.lnk" "$INSTDIR\oracle.exe"
|
createShortCut "$SMPROGRAMS\Cockatrice\Oracle.lnk" "$INSTDIR\oracle.exe"
|
||||||
createShortCut "$SMPROGRAMS\Cockatrice\Servatrice.lnk" "$INSTDIR\servatrice.exe"
|
createShortCut "$SMPROGRAMS\Cockatrice\Servatrice.lnk" "$INSTDIR\servatrice.exe"
|
||||||
createShortCut "$SMPROGRAMS\Cockatrice\Usermanual.lnk" "$INSTDIR\Usermanual.pdf"
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "un.Application" UnSecApplication
|
Section "un.Application" UnSecApplication
|
||||||
SetShellVarContext all
|
SetShellVarContext all
|
||||||
RMDir /r "$INSTDIR\zonebg"
|
|
||||||
RMDir /r "$INSTDIR\plugins"
|
RMDir /r "$INSTDIR\plugins"
|
||||||
RMDir /r "$INSTDIR\sounds"
|
RMDir /r "$INSTDIR\sounds"
|
||||||
|
RMDir /r "$INSTDIR\themes"
|
||||||
RMDir /r "$INSTDIR\translations"
|
RMDir /r "$INSTDIR\translations"
|
||||||
Delete "$INSTDIR\uninstall.exe"
|
Delete "$INSTDIR\uninstall.exe"
|
||||||
Delete "$INSTDIR\cockatrice.exe"
|
Delete "$INSTDIR\cockatrice.exe"
|
||||||
Delete "$INSTDIR\oracle.exe"
|
Delete "$INSTDIR\oracle.exe"
|
||||||
Delete "$INSTDIR\servatrice.exe"
|
Delete "$INSTDIR\servatrice.exe"
|
||||||
Delete "$INSTDIR\Usermanual.pdf"
|
|
||||||
Delete "$INSTDIR\libprotobuf.lib"
|
|
||||||
Delete "$INSTDIR\Qt*.dll"
|
Delete "$INSTDIR\Qt*.dll"
|
||||||
|
Delete "$INSTDIR\libmysql.dll"
|
||||||
Delete "$INSTDIR\icu*.dll"
|
Delete "$INSTDIR\icu*.dll"
|
||||||
Delete "$INSTDIR\libeay32.dll"
|
Delete "$INSTDIR\libeay32.dll"
|
||||||
Delete "$INSTDIR\ssleay32.dll"
|
Delete "$INSTDIR\ssleay32.dll"
|
||||||
|
@ -91,7 +88,7 @@ Section "un.Application" UnSecApplication
|
||||||
Delete "$INSTDIR\qdebug.txt"
|
Delete "$INSTDIR\qdebug.txt"
|
||||||
Delete "$INSTDIR\servatrice.sql"
|
Delete "$INSTDIR\servatrice.sql"
|
||||||
Delete "$INSTDIR\servatrice.ini.example"
|
Delete "$INSTDIR\servatrice.ini.example"
|
||||||
Delete "$INSTDIR\zlib1.dll"
|
Delete "$INSTDIR\zlib*.dll"
|
||||||
RMDir "$INSTDIR"
|
RMDir "$INSTDIR"
|
||||||
|
|
||||||
RMDir "$SMPROGRAMS\Cockatrice"
|
RMDir "$SMPROGRAMS\Cockatrice"
|
||||||
|
|
|
@ -7,7 +7,6 @@ PROJECT(cockatrice)
|
||||||
SET(cockatrice_SOURCES
|
SET(cockatrice_SOURCES
|
||||||
src/abstractcounter.cpp
|
src/abstractcounter.cpp
|
||||||
src/counter_general.cpp
|
src/counter_general.cpp
|
||||||
src/dlg_add_set_result.cpp
|
|
||||||
src/dlg_creategame.cpp
|
src/dlg_creategame.cpp
|
||||||
src/dlg_filter_games.cpp
|
src/dlg_filter_games.cpp
|
||||||
src/dlg_connect.cpp
|
src/dlg_connect.cpp
|
||||||
|
@ -175,6 +174,13 @@ if(Qt5Widgets_FOUND)
|
||||||
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
||||||
list(APPEND COCKATRICE_LIBS Widgets)
|
list(APPEND COCKATRICE_LIBS Widgets)
|
||||||
|
|
||||||
|
# QtConcurrent
|
||||||
|
find_package(Qt5Concurrent)
|
||||||
|
if(Qt5Concurrent_FOUND)
|
||||||
|
include_directories(${Qt5Concurrent_INCLUDE_DIRS})
|
||||||
|
list(APPEND ORACLE_LIBS Concurrent)
|
||||||
|
endif()
|
||||||
|
|
||||||
# QtNetwork
|
# QtNetwork
|
||||||
find_package(Qt5Network)
|
find_package(Qt5Network)
|
||||||
if(Qt5Network_FOUND)
|
if(Qt5Network_FOUND)
|
||||||
|
|
|
@ -7,22 +7,19 @@
|
||||||
#include "round.h"
|
#include "round.h"
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "cardinfowidget.h"
|
|
||||||
#include "abstractcarditem.h"
|
#include "abstractcarditem.h"
|
||||||
#include "pictureloader.h"
|
#include "pictureloader.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "gamescene.h"
|
#include "gamescene.h"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
|
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
|
||||||
: ArrowTarget(_owner, parent), infoWidget(0), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), isHovered(false), realZValue(0)
|
: ArrowTarget(_owner, parent), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
setFlag(ItemIsSelectable);
|
setFlag(ItemIsSelectable);
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
|
|
||||||
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
||||||
cardInfoUpdated();
|
cardInfoUpdated();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +43,11 @@ void AbstractCardItem::pixmapUpdated()
|
||||||
void AbstractCardItem::cardInfoUpdated()
|
void AbstractCardItem::cardInfoUpdated()
|
||||||
{
|
{
|
||||||
info = db->getCard(name);
|
info = db->getCard(name);
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
if(info)
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
|
|
||||||
|
cacheBgColor();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setRealZValue(qreal _zValue)
|
void AbstractCardItem::setRealZValue(qreal _zValue)
|
||||||
|
@ -89,45 +90,35 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
|
||||||
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
|
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
|
||||||
{
|
{
|
||||||
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
qreal scaleFactor = translatedSize.width() / boundingRect().width();
|
||||||
|
|
||||||
CardInfo *imageSource = facedown ? db->getCard() : info;
|
|
||||||
QPixmap translatedPixmap;
|
QPixmap translatedPixmap;
|
||||||
// don't even spend time trying to load the picture if our size is too small
|
bool paintImage = true;
|
||||||
if(translatedSize.width() > 10)
|
|
||||||
PictureLoader::getPixmap(translatedPixmap, imageSource, translatedSize.toSize());
|
if(facedown)
|
||||||
|
{
|
||||||
|
// never reveal card color, always paint the card back
|
||||||
|
PictureLoader::getPixmap(translatedPixmap, nullptr, translatedSize.toSize());
|
||||||
|
} else {
|
||||||
|
// don't even spend time trying to load the picture if our size is too small
|
||||||
|
if(info && translatedSize.width() > 10)
|
||||||
|
{
|
||||||
|
PictureLoader::getPixmap(translatedPixmap, info, translatedSize.toSize());
|
||||||
|
if(translatedPixmap.isNull())
|
||||||
|
paintImage = false;
|
||||||
|
} else {
|
||||||
|
paintImage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
QColor bgColor = Qt::transparent;
|
|
||||||
if (translatedPixmap.isNull()) {
|
|
||||||
QString colorStr;
|
|
||||||
if (!color.isEmpty())
|
|
||||||
colorStr = color;
|
|
||||||
else if (info->getColors().size() > 1)
|
|
||||||
colorStr = "m";
|
|
||||||
else if (!info->getColors().isEmpty())
|
|
||||||
colorStr = info->getColors().first().toLower();
|
|
||||||
|
|
||||||
if (colorStr == "b")
|
if (paintImage) {
|
||||||
bgColor = QColor(0, 0, 0);
|
|
||||||
else if (colorStr == "u")
|
|
||||||
bgColor = QColor(0, 140, 180);
|
|
||||||
else if (colorStr == "w")
|
|
||||||
bgColor = QColor(255, 250, 140);
|
|
||||||
else if (colorStr == "r")
|
|
||||||
bgColor = QColor(230, 0, 0);
|
|
||||||
else if (colorStr == "g")
|
|
||||||
bgColor = QColor(0, 160, 0);
|
|
||||||
else if (colorStr == "m")
|
|
||||||
bgColor = QColor(250, 190, 30);
|
|
||||||
else
|
|
||||||
bgColor = QColor(230, 230, 230);
|
|
||||||
} else {
|
|
||||||
painter->save();
|
painter->save();
|
||||||
transformPainter(painter, translatedSize, angle);
|
transformPainter(painter, translatedSize, angle);
|
||||||
painter->drawPixmap(QPointF(1, 1), translatedPixmap);
|
painter->drawPixmap(QPointF(1, 1), translatedPixmap);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
} else {
|
||||||
|
painter->setBrush(bgColor);
|
||||||
}
|
}
|
||||||
painter->setBrush(bgColor);
|
|
||||||
|
|
||||||
QPen pen(Qt::black);
|
QPen pen(Qt::black);
|
||||||
pen.setJoinStyle(Qt::MiterJoin);
|
pen.setJoinStyle(Qt::MiterJoin);
|
||||||
|
@ -192,11 +183,11 @@ void AbstractCardItem::setName(const QString &_name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit deleteCardInfoPopup(name);
|
emit deleteCardInfoPopup(name);
|
||||||
disconnect(info, 0, this, 0);
|
if(info)
|
||||||
|
disconnect(info, nullptr, this, nullptr);
|
||||||
name = _name;
|
name = _name;
|
||||||
info = db->getCard(name);
|
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
cardInfoUpdated();
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setHovered(bool _hovered)
|
void AbstractCardItem::setHovered(bool _hovered)
|
||||||
|
@ -216,9 +207,47 @@ void AbstractCardItem::setHovered(bool _hovered)
|
||||||
void AbstractCardItem::setColor(const QString &_color)
|
void AbstractCardItem::setColor(const QString &_color)
|
||||||
{
|
{
|
||||||
color = _color;
|
color = _color;
|
||||||
|
cacheBgColor();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::cacheBgColor()
|
||||||
|
{
|
||||||
|
QChar colorChar;
|
||||||
|
if (color.isEmpty())
|
||||||
|
{
|
||||||
|
if(info)
|
||||||
|
colorChar = info->getColorChar();
|
||||||
|
} else {
|
||||||
|
colorChar = color.at(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(colorChar.toLower().toLatin1())
|
||||||
|
{
|
||||||
|
case 'b':
|
||||||
|
bgColor = QColor(0, 0, 0);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
bgColor = QColor(0, 140, 180);
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
bgColor = QColor(255, 250, 140);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
bgColor = QColor(230, 0, 0);
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
bgColor = QColor(0, 160, 0);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
bgColor = QColor(250, 190, 30);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bgColor = QColor(230, 230, 230);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
||||||
{
|
{
|
||||||
if (tapped == _tapped)
|
if (tapped == _tapped)
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
#include "arrowtarget.h"
|
#include "arrowtarget.h"
|
||||||
|
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
class CardInfoWidget;
|
|
||||||
class Player;
|
class Player;
|
||||||
class QTimer;
|
|
||||||
|
|
||||||
const int CARD_WIDTH = 72;
|
const int CARD_WIDTH = 72;
|
||||||
const int CARD_HEIGHT = 102;
|
const int CARD_HEIGHT = 102;
|
||||||
|
@ -15,13 +13,13 @@ class AbstractCardItem : public ArrowTarget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
CardInfoWidget *infoWidget;
|
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
bool tapped;
|
bool tapped;
|
||||||
bool facedown;
|
bool facedown;
|
||||||
int tapAngle;
|
int tapAngle;
|
||||||
QString color;
|
QString color;
|
||||||
|
QColor bgColor;
|
||||||
private:
|
private:
|
||||||
bool isHovered;
|
bool isHovered;
|
||||||
qreal realZValue;
|
qreal realZValue;
|
||||||
|
@ -65,6 +63,7 @@ protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||||
|
void cacheBgColor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -287,6 +287,22 @@ QString CardInfo::simplifyName(const QString &name) {
|
||||||
return simpleName;
|
return simpleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QChar CardInfo::getColorChar() const
|
||||||
|
{
|
||||||
|
switch(colors.size())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return QChar();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
return colors.first().isEmpty() ? QChar() : colors.first().at(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return QChar('m');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
{
|
{
|
||||||
xml.writeStartElement("card");
|
xml.writeStartElement("card");
|
||||||
|
@ -341,39 +357,35 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabase::CardDatabase(QObject *parent)
|
CardDatabase::CardDatabase(QObject *parent)
|
||||||
: QObject(parent), noCard(0), loadStatus(NotLoaded)
|
: QObject(parent), loadStatus(NotLoaded)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(cardDatabasePathChanged()), this, SLOT(loadCardDatabase()));
|
connect(settingsCache, SIGNAL(cardDatabasePathChanged()), this, SLOT(loadCardDatabases()));
|
||||||
connect(settingsCache, SIGNAL(tokenDatabasePathChanged()), this, SLOT(loadTokenDatabase()));
|
|
||||||
|
|
||||||
noCard = new CardInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabase::~CardDatabase()
|
CardDatabase::~CardDatabase()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
delete noCard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::clear()
|
void CardDatabase::clear()
|
||||||
{
|
{
|
||||||
|
QHashIterator<QString, CardInfo *> i(cards);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
removeCard(i.value());
|
||||||
|
i.value()->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
// The pointers themselves were already deleted, so we don't delete them again.
|
||||||
|
cards.clear();
|
||||||
|
simpleNameCards.clear();
|
||||||
|
|
||||||
QHashIterator<QString, CardSet *> setIt(sets);
|
QHashIterator<QString, CardSet *> setIt(sets);
|
||||||
while (setIt.hasNext()) {
|
while (setIt.hasNext()) {
|
||||||
setIt.next();
|
setIt.next();
|
||||||
delete setIt.value();
|
delete setIt.value();
|
||||||
}
|
}
|
||||||
sets.clear();
|
sets.clear();
|
||||||
|
|
||||||
QHashIterator<QString, CardInfo *> i(cards);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
i.next();
|
|
||||||
delete i.value();
|
|
||||||
}
|
|
||||||
cards.clear();
|
|
||||||
|
|
||||||
// The pointers themselves were already deleted, so we don't delete them
|
|
||||||
// again.
|
|
||||||
simpleNameCards.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::addCard(CardInfo *card)
|
void CardDatabase::addCard(CardInfo *card)
|
||||||
|
@ -390,22 +402,23 @@ void CardDatabase::removeCard(CardInfo *card)
|
||||||
emit cardRemoved(card);
|
emit cardRemoved(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo *CardDatabase::getCard(const QString &cardName, bool createIfNotFound) {
|
CardInfo *CardDatabase::getCard(const QString &cardName) const
|
||||||
return getCardFromMap(cards, cardName, createIfNotFound);
|
{
|
||||||
|
return getCardFromMap(cards, cardName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CardInfo *> CardDatabase::getCards(const QStringList &cardNames)
|
QList<CardInfo *> CardDatabase::getCards(const QStringList &cardNames) const
|
||||||
{
|
{
|
||||||
QList<CardInfo *> cardInfos;
|
QList<CardInfo *> cardInfos;
|
||||||
foreach(QString cardName, cardNames)
|
foreach(QString cardName, cardNames)
|
||||||
cardInfos.append(getCardFromMap(cards, cardName, false));
|
cardInfos.append(getCardFromMap(cards, cardName));
|
||||||
|
|
||||||
return cardInfos;
|
return cardInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo *CardDatabase::getCardBySimpleName(const QString &cardName, bool createIfNotFound) {
|
CardInfo *CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
QString simpleName = CardInfo::simplifyName(cardName);
|
{
|
||||||
return getCardFromMap(simpleNameCards, simpleName, createIfNotFound);
|
return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
CardSet *CardDatabase::getSet(const QString &setName)
|
CardSet *CardDatabase::getSet(const QString &setName)
|
||||||
|
@ -459,7 +472,7 @@ void CardDatabase::loadSetsFromXml(QXmlStreamReader &xml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
|
void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
{
|
{
|
||||||
while (!xml.atEnd()) {
|
while (!xml.atEnd()) {
|
||||||
if (xml.readNext() == QXmlStreamReader::EndElement)
|
if (xml.readNext() == QXmlStreamReader::EndElement)
|
||||||
|
@ -518,28 +531,20 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
|
||||||
isToken = xml.readElementText().toInt();
|
isToken = xml.readElementText().toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isToken == tokens) {
|
addCard(new CardInfo(name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, reverseRelatedCards, upsideDown, loyalty, cipt, tableRow, sets, customPicURLs, muids));
|
||||||
addCard(new CardInfo(name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, reverseRelatedCards, upsideDown, loyalty, cipt, tableRow, sets, customPicURLs, muids));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo *CardDatabase::getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound) {
|
CardInfo *CardDatabase::getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const
|
||||||
|
{
|
||||||
if (cardMap.contains(cardName))
|
if (cardMap.contains(cardName))
|
||||||
return cardMap.value(cardName);
|
return cardMap.value(cardName);
|
||||||
|
|
||||||
if (createIfNotFound) {
|
return nullptr;
|
||||||
CardInfo *newCard = new CardInfo(cardName, true);
|
|
||||||
newCard->addToSet(getSet(CardDatabase::TOKENS_SETNAME));
|
|
||||||
cardMap.insert(cardName, newCard);
|
|
||||||
return newCard;
|
|
||||||
}
|
|
||||||
|
|
||||||
return noCard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadFromFile(const QString &fileName, bool tokens)
|
LoadStatus CardDatabase::loadFromFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
|
@ -562,11 +567,10 @@ LoadStatus CardDatabase::loadFromFile(const QString &fileName, bool tokens)
|
||||||
if (xml.name() == "sets")
|
if (xml.name() == "sets")
|
||||||
loadSetsFromXml(xml);
|
loadSetsFromXml(xml);
|
||||||
else if (xml.name() == "cards")
|
else if (xml.name() == "cards")
|
||||||
loadCardsFromXml(xml, tokens);
|
loadCardsFromXml(xml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << cards.size() << "cards in" << sets.size() << "sets loaded";
|
|
||||||
|
|
||||||
if (cards.isEmpty()) return NoCards;
|
if (cards.isEmpty()) return NoCards;
|
||||||
|
|
||||||
|
@ -609,57 +613,59 @@ bool CardDatabase::saveToFile(const QString &fileName, bool tokens)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::emitCardListChanged()
|
LoadStatus CardDatabase::loadCardDatabase(const QString &path)
|
||||||
{
|
|
||||||
emit cardListChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens)
|
|
||||||
{
|
{
|
||||||
LoadStatus tempLoadStatus = NotLoaded;
|
LoadStatus tempLoadStatus = NotLoaded;
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
tempLoadStatus = loadFromFile(path, tokens);
|
tempLoadStatus = loadFromFile(path);
|
||||||
|
|
||||||
if (tempLoadStatus == Ok) {
|
qDebug() << "[CardDatabase] loadCardDatabase(): Path =" << path << "Status =" << tempLoadStatus << "Cards =" << cards.size() << "Sets=" << sets.size();
|
||||||
SetList allSets;
|
|
||||||
QHashIterator<QString, CardSet *> setsIterator(sets);
|
|
||||||
while (setsIterator.hasNext())
|
|
||||||
allSets.append(setsIterator.next().value());
|
|
||||||
allSets.sortByKey();
|
|
||||||
|
|
||||||
if(!tokens)
|
|
||||||
checkUnknownSets();
|
|
||||||
emit cardListChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tokens)
|
|
||||||
loadStatus = tempLoadStatus;
|
|
||||||
|
|
||||||
qDebug() << "loadCardDatabase(): Path =" << path << "Tokens =" << tokens << "Status =" << loadStatus;
|
|
||||||
|
|
||||||
return tempLoadStatus;
|
return tempLoadStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadCardDatabase()
|
LoadStatus CardDatabase::loadCardDatabases()
|
||||||
{
|
{
|
||||||
return loadCardDatabase(settingsCache->getCardDatabasePath(), false);
|
qDebug() << "CardDatabase::loadCardDatabases start";
|
||||||
}
|
// clean old db
|
||||||
|
clear();
|
||||||
LoadStatus CardDatabase::loadTokenDatabase()
|
// load main card database
|
||||||
{
|
loadStatus = loadCardDatabase(settingsCache->getCardDatabasePath());
|
||||||
return loadCardDatabase(settingsCache->getTokenDatabasePath(), true);
|
// laod tokens database
|
||||||
}
|
loadCardDatabase(settingsCache->getTokenDatabasePath());
|
||||||
|
// load custom card databases
|
||||||
void CardDatabase::loadCustomCardDatabases(const QString &path)
|
QDir dir(settingsCache->getCustomCardDatabasePath());
|
||||||
{
|
|
||||||
QDir dir(path);
|
|
||||||
if(!dir.exists())
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach(QString fileName, dir.entryList(QStringList("*.xml"), QDir::Files | QDir::Readable, QDir::Name | QDir::IgnoreCase))
|
foreach(QString fileName, dir.entryList(QStringList("*.xml"), QDir::Files | QDir::Readable, QDir::Name | QDir::IgnoreCase))
|
||||||
{
|
{
|
||||||
loadCardDatabase(dir.absoluteFilePath(fileName), false);
|
loadCardDatabase(dir.absoluteFilePath(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AFTER all the cards have been loaded
|
||||||
|
|
||||||
|
// reorder sets (TODO: refactor, this smells)
|
||||||
|
SetList allSets;
|
||||||
|
QHashIterator<QString, CardSet *> setsIterator(sets);
|
||||||
|
while (setsIterator.hasNext())
|
||||||
|
allSets.append(setsIterator.next().value());
|
||||||
|
allSets.sortByKey();
|
||||||
|
|
||||||
|
// resolve the reverse-related tags
|
||||||
|
refreshCachedReverseRelatedCards();
|
||||||
|
|
||||||
|
if(loadStatus == Ok)
|
||||||
|
{
|
||||||
|
// check for unknown sets
|
||||||
|
checkUnknownSets();
|
||||||
|
// update deck editors, etc
|
||||||
|
qDebug() << "CardDatabase::loadCardDatabases success";
|
||||||
|
} else {
|
||||||
|
// bring up thr settings dialog
|
||||||
|
qDebug() << "CardDatabase::loadCardDatabases failed";
|
||||||
|
emit cardDatabaseLoadingFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the loadstatus of the main card database.
|
||||||
|
return loadStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::refreshCachedReverseRelatedCards()
|
void CardDatabase::refreshCachedReverseRelatedCards()
|
||||||
|
@ -716,48 +722,70 @@ void CardDatabase::checkUnknownSets()
|
||||||
{
|
{
|
||||||
SetList sets = getSetList();
|
SetList sets = getSetList();
|
||||||
|
|
||||||
// no set is enabled. Probably this is the first time running trice
|
if(sets.getEnabledSetsNum())
|
||||||
if(!sets.getEnabledSetsNum())
|
|
||||||
{
|
{
|
||||||
|
// if some sets are first found on thus run, ask the user
|
||||||
|
int numUnknownSets = sets.getUnknownSetsNum();
|
||||||
|
if(numUnknownSets > 0)
|
||||||
|
emit cardDatabaseNewSetsFound(numUnknownSets);
|
||||||
|
} else {
|
||||||
|
// No set enabled. Probably this is the first time running trice
|
||||||
sets.guessSortKeys();
|
sets.guessSortKeys();
|
||||||
sets.sortByKey();
|
sets.sortByKey();
|
||||||
sets.enableAll();
|
sets.enableAll();
|
||||||
|
notifyEnabledSetsChanged();
|
||||||
|
|
||||||
detectedFirstRun = true;
|
emit cardDatabaseAllNewSetsEnabled();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detectedFirstRun = false;
|
|
||||||
|
|
||||||
int numUnknownSets = sets.getUnknownSetsNum();
|
|
||||||
// no unkown sets.
|
|
||||||
if(!numUnknownSets)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QMessageBox msgbox(QMessageBox::Question, tr("New sets found"), tr("%1 new set(s) have been found in the card database. Do you want to enable them?").arg(numUnknownSets), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
|
||||||
|
|
||||||
switch(msgbox.exec())
|
|
||||||
{
|
|
||||||
case QMessageBox::No:
|
|
||||||
sets.markAllAsKnown();
|
|
||||||
break;
|
|
||||||
case QMessageBox::Yes:
|
|
||||||
sets.enableAllUnknown();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardDatabase::hasDetectedFirstRun()
|
void CardDatabase::enableAllUnknownSets()
|
||||||
{
|
{
|
||||||
if(detectedFirstRun)
|
SetList sets = getSetList();
|
||||||
{
|
sets.enableAllUnknown();
|
||||||
detectedFirstRun=false;
|
}
|
||||||
return true;
|
|
||||||
}
|
void CardDatabase::markAllSetsAsKnown()
|
||||||
|
{
|
||||||
return false;
|
SetList sets = getSetList();
|
||||||
|
sets.markAllAsKnown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabase::notifyEnabledSetsChanged()
|
||||||
|
{
|
||||||
|
// refresh the list of cached set names
|
||||||
|
foreach(CardInfo * card, cards)
|
||||||
|
card->refreshCachedSetNames();
|
||||||
|
|
||||||
|
// inform the carddatabasemodels that they need to re-check their list of cards
|
||||||
|
emit cardDatabaseEnabledSetsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CardDatabase::saveCustomTokensToFile()
|
||||||
|
{
|
||||||
|
CardSet * customTokensSet = getSet(CardDatabase::TOKENS_SETNAME);
|
||||||
|
QString fileName = settingsCache->getCustomCardDatabasePath() + "/" + CardDatabase::TOKENS_SETNAME + ".xml";
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QIODevice::WriteOnly))
|
||||||
|
return false;
|
||||||
|
QXmlStreamWriter xml(&file);
|
||||||
|
|
||||||
|
xml.setAutoFormatting(true);
|
||||||
|
xml.writeStartDocument();
|
||||||
|
xml.writeStartElement("cockatrice_carddatabase");
|
||||||
|
xml.writeAttribute("version", QString::number(versionNeeded));
|
||||||
|
|
||||||
|
xml.writeStartElement("cards");
|
||||||
|
QHashIterator<QString, CardInfo *> cardIterator(cards);
|
||||||
|
while (cardIterator.hasNext()) {
|
||||||
|
CardInfo *card = cardIterator.next().value();
|
||||||
|
if(card->getSets().contains(customTokensSet))
|
||||||
|
xml << card;
|
||||||
|
}
|
||||||
|
xml.writeEndElement(); // cards
|
||||||
|
|
||||||
|
xml.writeEndElement(); // cockatrice_carddatabase
|
||||||
|
xml.writeEndDocument();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
|
@ -90,8 +90,6 @@ private:
|
||||||
bool cipt;
|
bool cipt;
|
||||||
int tableRow;
|
int tableRow;
|
||||||
QString pixmapCacheKey;
|
QString pixmapCacheKey;
|
||||||
|
|
||||||
void refreshCachedSetNames();
|
|
||||||
public:
|
public:
|
||||||
CardInfo(const QString &_name = QString(),
|
CardInfo(const QString &_name = QString(),
|
||||||
bool _isToken = false,
|
bool _isToken = false,
|
||||||
|
@ -131,6 +129,7 @@ public:
|
||||||
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
|
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
|
||||||
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
|
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
|
||||||
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
|
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
|
||||||
|
const QChar getColorChar() const;
|
||||||
const QStringList &getColors() const { return colors; }
|
const QStringList &getColors() const { return colors; }
|
||||||
const QStringList &getRelatedCards() const { return relatedCards; }
|
const QStringList &getRelatedCards() const { return relatedCards; }
|
||||||
const QStringList &getReverseRelatedCards() const { return reverseRelatedCards; }
|
const QStringList &getReverseRelatedCards() const { return reverseRelatedCards; }
|
||||||
|
@ -149,6 +148,7 @@ public:
|
||||||
void setMuId(const QString &_set, const int &_muId) { muIds.insert(_set, _muId); }
|
void setMuId(const QString &_set, const int &_muId) { muIds.insert(_set, _muId); }
|
||||||
void addToSet(CardSet *set);
|
void addToSet(CardSet *set);
|
||||||
void emitPixmapUpdated() { emit pixmapUpdated(); }
|
void emitPixmapUpdated() { emit pixmapUpdated(); }
|
||||||
|
void refreshCachedSetNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplify a name to have no punctuation and lowercase all letters, for
|
* Simplify a name to have no punctuation and lowercase all letters, for
|
||||||
|
@ -183,20 +183,15 @@ protected:
|
||||||
*/
|
*/
|
||||||
SetNameMap sets;
|
SetNameMap sets;
|
||||||
|
|
||||||
/*
|
|
||||||
* A dummy card returned by getCard() ad a fallback
|
|
||||||
*/
|
|
||||||
CardInfo *noCard;
|
|
||||||
|
|
||||||
LoadStatus loadStatus;
|
LoadStatus loadStatus;
|
||||||
bool detectedFirstRun;
|
|
||||||
private:
|
private:
|
||||||
static const int versionNeeded;
|
static const int versionNeeded;
|
||||||
void loadCardsFromXml(QXmlStreamReader &xml, bool tokens);
|
void loadCardsFromXml(QXmlStreamReader &xml);
|
||||||
void loadSetsFromXml(QXmlStreamReader &xml);
|
void loadSetsFromXml(QXmlStreamReader &xml);
|
||||||
|
|
||||||
CardInfo *getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound);
|
CardInfo *getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const;
|
||||||
void checkUnknownSets();
|
void checkUnknownSets();
|
||||||
|
void refreshCachedReverseRelatedCards();
|
||||||
public:
|
public:
|
||||||
static const char* TOKENS_SETNAME;
|
static const char* TOKENS_SETNAME;
|
||||||
|
|
||||||
|
@ -205,38 +200,37 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
void addCard(CardInfo *card);
|
void addCard(CardInfo *card);
|
||||||
void removeCard(CardInfo *card);
|
void removeCard(CardInfo *card);
|
||||||
/*
|
CardInfo *getCard(const QString &cardName) const;
|
||||||
* Get card object by name. Ensured to return a valid CardInfo * object; check noCard
|
QList <CardInfo *> getCards(const QStringList &cardNames) const;
|
||||||
*/
|
|
||||||
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = false);
|
|
||||||
QList <CardInfo *> getCards(const QStringList &cardNames);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a card by its simple name. The name will be simplified in this
|
* Get a card by its simple name. The name will be simplified in this
|
||||||
* function, so you don't need to simplify it beforehand.
|
* function, so you don't need to simplify it beforehand.
|
||||||
*/
|
*/
|
||||||
CardInfo *getCardBySimpleName(const QString &cardName = QString(), bool createIfNotFound = false);
|
CardInfo *getCardBySimpleName(const QString &cardName) const;
|
||||||
|
|
||||||
CardSet *getSet(const QString &setName);
|
CardSet *getSet(const QString &setName);
|
||||||
QList<CardInfo *> getCardList() const { return cards.values(); }
|
QList<CardInfo *> getCardList() const { return cards.values(); }
|
||||||
SetList getSetList() const;
|
SetList getSetList() const;
|
||||||
LoadStatus loadFromFile(const QString &fileName, bool tokens = false);
|
LoadStatus loadFromFile(const QString &fileName);
|
||||||
bool saveToFile(const QString &fileName, bool tokens = false);
|
bool saveToFile(const QString &fileName, bool tokens = false);
|
||||||
|
bool saveCustomTokensToFile();
|
||||||
QStringList getAllColors() const;
|
QStringList getAllColors() const;
|
||||||
QStringList getAllMainCardTypes() const;
|
QStringList getAllMainCardTypes() const;
|
||||||
LoadStatus getLoadStatus() const { return loadStatus; }
|
LoadStatus getLoadStatus() const { return loadStatus; }
|
||||||
bool getLoadSuccess() const { return loadStatus == Ok; }
|
void enableAllUnknownSets();
|
||||||
bool hasDetectedFirstRun();
|
void markAllSetsAsKnown();
|
||||||
void refreshCachedReverseRelatedCards();
|
void notifyEnabledSetsChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
LoadStatus loadCardDatabase();
|
LoadStatus loadCardDatabases();
|
||||||
LoadStatus loadTokenDatabase();
|
|
||||||
void loadCustomCardDatabases(const QString &path);
|
|
||||||
void emitCardListChanged();
|
|
||||||
private slots:
|
private slots:
|
||||||
LoadStatus loadCardDatabase(const QString &path, bool tokens = false);
|
LoadStatus loadCardDatabase(const QString &path);
|
||||||
signals:
|
signals:
|
||||||
void cardListChanged();
|
void cardDatabaseLoadingFailed();
|
||||||
|
void cardDatabaseNewSetsFound(int numUnknownSets);
|
||||||
|
void cardDatabaseAllNewSetsEnabled();
|
||||||
|
void cardDatabaseEnabledSetsChanged();
|
||||||
void cardAdded(CardInfo *card);
|
void cardAdded(CardInfo *card);
|
||||||
void cardRemoved(CardInfo *card);
|
void cardRemoved(CardInfo *card);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
||||||
: QAbstractListModel(parent), db(_db)
|
: QAbstractListModel(parent), db(_db)
|
||||||
{
|
{
|
||||||
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
|
||||||
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
||||||
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
||||||
updateCardList();
|
connect(db, SIGNAL(cardDatabaseEnabledSetsChanged()), this, SLOT(cardDatabaseEnabledSetsChanged()));
|
||||||
|
|
||||||
|
cardDatabaseEnabledSetsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabaseModel::~CardDatabaseModel()
|
CardDatabaseModel::~CardDatabaseModel()
|
||||||
|
@ -63,37 +64,6 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::updateCardList()
|
|
||||||
{
|
|
||||||
beginResetModel();
|
|
||||||
|
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
|
||||||
disconnect(cardList[i], 0, this, 0);
|
|
||||||
|
|
||||||
cardList.clear();
|
|
||||||
|
|
||||||
foreach(CardInfo * card, db->getCardList())
|
|
||||||
{
|
|
||||||
bool hasSet = false;
|
|
||||||
foreach(CardSet * set, card->getSets())
|
|
||||||
{
|
|
||||||
if(set->getEnabled())
|
|
||||||
{
|
|
||||||
hasSet = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hasSet)
|
|
||||||
{
|
|
||||||
cardList.append(card);
|
|
||||||
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
|
@ -103,12 +73,44 @@ void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
||||||
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfo *card)
|
||||||
|
{
|
||||||
|
foreach(CardSet * set, card->getSets())
|
||||||
|
{
|
||||||
|
if(set->getEnabled())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabaseModel::cardDatabaseEnabledSetsChanged()
|
||||||
|
{
|
||||||
|
// remove all the cards no more present in at least one enabled set
|
||||||
|
foreach(CardInfo * card, cardList)
|
||||||
|
{
|
||||||
|
if(!checkCardHasAtLeastOneEnabledSet(card))
|
||||||
|
cardRemoved(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-check all the card currently not shown, maybe their part of a newly-enabled set
|
||||||
|
foreach(CardInfo * card, db->getCardList())
|
||||||
|
{
|
||||||
|
if(!cardList.contains(card))
|
||||||
|
cardAdded(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardAdded(CardInfo *card)
|
void CardDatabaseModel::cardAdded(CardInfo *card)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
if(checkCardHasAtLeastOneEnabledSet(card))
|
||||||
cardList.append(card);
|
{
|
||||||
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
// add the card if it's present in at least one enabled set
|
||||||
endInsertRows();
|
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
||||||
|
cardList.append(card);
|
||||||
|
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
||||||
|
@ -118,6 +120,7 @@ void CardDatabaseModel::cardRemoved(CardInfo *card)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
disconnect(card, 0, this, 0);
|
||||||
cardList.removeAt(row);
|
cardList.removeAt(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
@ -220,3 +223,16 @@ void CardDatabaseDisplayModel::filterTreeChanged()
|
||||||
{
|
{
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TokenDisplayModel::TokenDisplayModel(QObject *parent)
|
||||||
|
: CardDatabaseDisplayModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TokenDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
|
{
|
||||||
|
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
|
|
||||||
|
return info->getIsToken();
|
||||||
|
}
|
||||||
|
|
|
@ -25,11 +25,13 @@ public:
|
||||||
private:
|
private:
|
||||||
QList<CardInfo *> cardList;
|
QList<CardInfo *> cardList;
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
|
|
||||||
|
inline bool checkCardHasAtLeastOneEnabledSet(CardInfo *card);
|
||||||
private slots:
|
private slots:
|
||||||
void updateCardList();
|
|
||||||
void cardAdded(CardInfo *card);
|
void cardAdded(CardInfo *card);
|
||||||
void cardRemoved(CardInfo *card);
|
void cardRemoved(CardInfo *card);
|
||||||
void cardInfoChanged(CardInfo *card);
|
void cardInfoChanged(CardInfo *card);
|
||||||
|
void cardDatabaseEnabledSetsChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||||
|
@ -66,4 +68,12 @@ private slots:
|
||||||
void filterTreeChanged();
|
void filterTreeChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TokenDisplayModel : public CardDatabaseDisplayModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TokenDisplayModel(QObject *parent = 0);
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
CardFrame::CardFrame(const QString &cardName, QWidget *parent)
|
CardFrame::CardFrame(const QString &cardName, QWidget *parent)
|
||||||
: QTabWidget(parent), info(0), cardTextOnly(false)
|
: QTabWidget(parent), info(nullptr), cardTextOnly(false)
|
||||||
{
|
{
|
||||||
setContentsMargins(3, 3, 3, 3);
|
setContentsMargins(3, 3, 3, 3);
|
||||||
pic = new CardInfoPicture();
|
pic = new CardInfoPicture();
|
||||||
|
@ -91,9 +91,11 @@ void CardFrame::setViewMode(int mode)
|
||||||
void CardFrame::setCard(CardInfo *card)
|
void CardFrame::setCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (info)
|
if (info)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, nullptr, this, nullptr);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
if(info)
|
||||||
|
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||||
|
|
||||||
text->setCard(info);
|
text->setCard(info);
|
||||||
pic->setCard(info);
|
pic->setCard(info);
|
||||||
}
|
}
|
||||||
|
@ -110,5 +112,5 @@ void CardFrame::setCard(AbstractCardItem *card)
|
||||||
|
|
||||||
void CardFrame::clear()
|
void CardFrame::clear()
|
||||||
{
|
{
|
||||||
setCard(db->getCard());
|
setCard((CardInfo*) nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
CardInfoPicture::CardInfoPicture(QWidget *parent)
|
CardInfoPicture::CardInfoPicture(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
info(0),
|
info(nullptr),
|
||||||
pixmapDirty(true)
|
pixmapDirty(true)
|
||||||
{
|
{
|
||||||
setMinimumHeight(100);
|
setMinimumHeight(100);
|
||||||
|
@ -20,9 +20,10 @@ CardInfoPicture::CardInfoPicture(QWidget *parent)
|
||||||
void CardInfoPicture::setCard(CardInfo *card)
|
void CardInfoPicture::setCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (info)
|
if (info)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, nullptr, this, nullptr);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
if(info)
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
||||||
|
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
}
|
}
|
||||||
|
@ -40,14 +41,7 @@ void CardInfoPicture::updatePixmap()
|
||||||
|
|
||||||
void CardInfoPicture::loadPixmap()
|
void CardInfoPicture::loadPixmap()
|
||||||
{
|
{
|
||||||
if(info)
|
PictureLoader::getPixmap(resizedPixmap, info, size());
|
||||||
PictureLoader::getPixmap(resizedPixmap, info, size());
|
|
||||||
else
|
|
||||||
resizedPixmap = QPixmap();
|
|
||||||
|
|
||||||
|
|
||||||
if (resizedPixmap.isNull())
|
|
||||||
PictureLoader::getPixmap(resizedPixmap, db->getCard(), size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoPicture::paintEvent(QPaintEvent *)
|
void CardInfoPicture::paintEvent(QPaintEvent *)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
CardInfoText::CardInfoText(QWidget *parent)
|
CardInfoText::CardInfoText(QWidget *parent)
|
||||||
: QFrame(parent), info(0)
|
: QFrame(parent), info(nullptr)
|
||||||
{
|
{
|
||||||
nameLabel1 = new QLabel;
|
nameLabel1 = new QLabel;
|
||||||
nameLabel2 = new QLabel;
|
nameLabel2 = new QLabel;
|
||||||
|
@ -53,13 +53,24 @@ CardInfoText::CardInfoText(QWidget *parent)
|
||||||
|
|
||||||
void CardInfoText::setCard(CardInfo *card)
|
void CardInfoText::setCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
nameLabel2->setText(card->getName());
|
if(card)
|
||||||
manacostLabel2->setText(card->getManaCost());
|
{
|
||||||
colorLabel2->setText(card->getColors().join(""));
|
nameLabel2->setText(card->getName());
|
||||||
cardtypeLabel2->setText(card->getCardType());
|
manacostLabel2->setText(card->getManaCost());
|
||||||
powtoughLabel2->setText(card->getPowTough());
|
colorLabel2->setText(card->getColors().join(""));
|
||||||
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
cardtypeLabel2->setText(card->getCardType());
|
||||||
textLabel->setText(card->getText());
|
powtoughLabel2->setText(card->getPowTough());
|
||||||
|
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
||||||
|
textLabel->setText(card->getText());
|
||||||
|
} else {
|
||||||
|
nameLabel2->setText("");
|
||||||
|
manacostLabel2->setText("");
|
||||||
|
colorLabel2->setText("");
|
||||||
|
cardtypeLabel2->setText("");
|
||||||
|
powtoughLabel2->setText("");
|
||||||
|
loyaltyLabel2->setText("");
|
||||||
|
textLabel->setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoText::retranslateUi()
|
void CardInfoText::retranslateUi()
|
||||||
|
|
|
@ -1,179 +1,57 @@
|
||||||
#include <QGridLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QLabel>
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include "cardinfowidget.h"
|
#include "cardinfowidget.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "pictureloader.h"
|
#include "cardinfopicture.h"
|
||||||
|
#include "cardinfotext.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "settingscache.h"
|
|
||||||
|
|
||||||
CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
|
CardInfoWidget::CardInfoWidget(const QString &cardName, QWidget *parent, Qt::WindowFlags flags)
|
||||||
: QFrame(parent, flags)
|
: QFrame(parent, flags)
|
||||||
, pixmapWidth(0)
|
|
||||||
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
|
, aspectRatio((qreal) CARD_HEIGHT / (qreal) CARD_WIDTH)
|
||||||
, minimized(settingsCache->getCardInfoMinimized()) // Initialize the cardinfo view status from cache.
|
, info(nullptr)
|
||||||
, mode(_mode)
|
|
||||||
, info(0)
|
|
||||||
{
|
{
|
||||||
if (mode == ModeGameTab) {
|
setContentsMargins(3, 3, 3, 3);
|
||||||
// Create indexed list of status views for card.
|
pic = new CardInfoPicture();
|
||||||
const QStringList cardInfoStatus = QStringList() << tr("Show card only") << tr("Show text only") << tr("Show full info");
|
pic->setObjectName("pic");
|
||||||
|
text = new CardInfoText();
|
||||||
|
text->setObjectName("text");
|
||||||
|
|
||||||
// Create droplist for cardinfo view selection, and set right current index.
|
QVBoxLayout * layout = new QVBoxLayout();
|
||||||
dropList = new QComboBox();
|
layout->setObjectName("layout");
|
||||||
dropList->addItems(cardInfoStatus);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
dropList->setCurrentIndex(minimized);
|
layout->setSpacing(0);
|
||||||
connect(dropList, SIGNAL(currentIndexChanged(int)), this, SLOT(minimizeClicked(int)));
|
layout->addWidget(pic, 0, Qt::AlignCenter);
|
||||||
}
|
layout->addWidget(text, 0, Qt::AlignCenter);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
cardPicture = new QLabel;
|
|
||||||
cardPicture->setAlignment(Qt::AlignCenter);
|
|
||||||
|
|
||||||
nameLabel1 = new QLabel;
|
|
||||||
nameLabel2 = new QLabel;
|
|
||||||
nameLabel2->setWordWrap(true);
|
|
||||||
manacostLabel1 = new QLabel;
|
|
||||||
manacostLabel2 = new QLabel;
|
|
||||||
manacostLabel2->setWordWrap(true);
|
|
||||||
colorLabel1 = new QLabel;
|
|
||||||
colorLabel2 = new QLabel;
|
|
||||||
colorLabel2->setWordWrap(true);
|
|
||||||
cardtypeLabel1 = new QLabel;
|
|
||||||
cardtypeLabel2 = new QLabel;
|
|
||||||
cardtypeLabel2->setWordWrap(true);
|
|
||||||
powtoughLabel1 = new QLabel;
|
|
||||||
powtoughLabel2 = new QLabel;
|
|
||||||
loyaltyLabel1 = new QLabel;
|
|
||||||
loyaltyLabel2 = new QLabel;
|
|
||||||
|
|
||||||
textLabel = new QTextEdit();
|
|
||||||
textLabel->setReadOnly(true);
|
|
||||||
|
|
||||||
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);
|
|
||||||
grid->addWidget(manacostLabel1, row, 0);
|
|
||||||
grid->addWidget(manacostLabel2, row++, 1);
|
|
||||||
grid->addWidget(colorLabel1, row, 0);
|
|
||||||
grid->addWidget(colorLabel2, row++, 1);
|
|
||||||
grid->addWidget(cardtypeLabel1, row, 0);
|
|
||||||
grid->addWidget(cardtypeLabel2, row++, 1);
|
|
||||||
grid->addWidget(powtoughLabel1, row, 0);
|
|
||||||
grid->addWidget(powtoughLabel2, row++, 1);
|
|
||||||
grid->addWidget(loyaltyLabel1, row, 0);
|
|
||||||
grid->addWidget(loyaltyLabel2, row++, 1);
|
|
||||||
grid->addWidget(textLabel, row, 0, -1, 2);
|
|
||||||
grid->setRowStretch(row, 1);
|
|
||||||
grid->setColumnStretch(1, 1);
|
|
||||||
|
|
||||||
retranslateUi();
|
|
||||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||||
if (mode == ModeGameTab) {
|
QDesktopWidget desktopWidget;
|
||||||
textLabel->setMinimumHeight(100);
|
int pixmapHeight = desktopWidget.screenGeometry().height() / 3;
|
||||||
setFixedWidth(sizeHint().width());
|
int pixmapWidth = pixmapHeight / aspectRatio;
|
||||||
} else if (mode == ModePopUp) {
|
pic->setFixedWidth(pixmapWidth);
|
||||||
QDesktopWidget desktopWidget;
|
pic->setFixedHeight(pixmapHeight);
|
||||||
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
|
setFixedWidth(pixmapWidth + 150);
|
||||||
setFixedWidth(pixmapWidth + 150);
|
|
||||||
} else
|
|
||||||
setFixedWidth(250);
|
|
||||||
|
|
||||||
setCard(getCard(cardName));
|
setCard(cardName);
|
||||||
setMinimized(settingsCache->getCardInfoMinimized());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardInfoWidget::minimizeClicked(int newMinimized)
|
|
||||||
{
|
|
||||||
// Set new status, and store it in the settings cache.
|
|
||||||
setMinimized(newMinimized);
|
|
||||||
settingsCache->setCardInfoMinimized(newMinimized);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CardInfoWidget::shouldShowPowTough()
|
|
||||||
{
|
|
||||||
return !info->getPowTough().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CardInfoWidget::shouldShowLoyalty()
|
|
||||||
{
|
|
||||||
return (info->getLoyalty() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardInfoWidget::setMinimized(int _minimized)
|
|
||||||
{
|
|
||||||
minimized = _minimized;
|
|
||||||
|
|
||||||
// Toggle oracle fields according to selected view.
|
|
||||||
bool showAll = ((minimized == 1) || (minimized == 2));
|
|
||||||
bool showPowTough = info ? (showAll && shouldShowPowTough()) : true;
|
|
||||||
bool showLoyalty = info ? (showAll && shouldShowLoyalty()) : true;
|
|
||||||
if (mode == ModeGameTab) {
|
|
||||||
nameLabel1->setVisible(showAll);
|
|
||||||
nameLabel2->setVisible(showAll);
|
|
||||||
manacostLabel1->setVisible(showAll);
|
|
||||||
manacostLabel2->setVisible(showAll);
|
|
||||||
colorLabel1->setVisible(showAll);
|
|
||||||
colorLabel2->setVisible(showAll);
|
|
||||||
cardtypeLabel1->setVisible(showAll);
|
|
||||||
cardtypeLabel2->setVisible(showAll);
|
|
||||||
powtoughLabel1->setVisible(showPowTough);
|
|
||||||
powtoughLabel2->setVisible(showPowTough);
|
|
||||||
loyaltyLabel1->setVisible(showLoyalty);
|
|
||||||
loyaltyLabel2->setVisible(showLoyalty);
|
|
||||||
textLabel->setVisible(showAll);
|
|
||||||
}
|
|
||||||
|
|
||||||
cardPicture->hide();
|
|
||||||
cardHeightOffset = minimumSizeHint().height() + 10;
|
|
||||||
|
|
||||||
// Set the picture to be shown only at "card only" (0) and "full info" (2)
|
|
||||||
if (mode == ModeGameTab) {
|
|
||||||
cardPicture->setVisible((minimized == 0) || (minimized == 2));
|
|
||||||
|
|
||||||
if (minimized == 0)
|
|
||||||
setMaximumHeight(cardHeightOffset + width() * aspectRatio);
|
|
||||||
else
|
|
||||||
setMaximumHeight(1000000);
|
|
||||||
} else
|
|
||||||
cardPicture->show();
|
|
||||||
resize(width(), sizeHint().height());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(CardInfo *card)
|
void CardInfoWidget::setCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (info)
|
if (info)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, nullptr, this, nullptr);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
if(info)
|
||||||
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||||
|
|
||||||
updatePixmap();
|
text->setCard(info);
|
||||||
nameLabel2->setText(card->getName());
|
pic->setCard(info);
|
||||||
manacostLabel2->setText(card->getManaCost());
|
|
||||||
colorLabel2->setText(card->getColors().join(""));
|
|
||||||
cardtypeLabel2->setText(card->getCardType());
|
|
||||||
powtoughLabel2->setText(card->getPowTough());
|
|
||||||
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString());
|
|
||||||
textLabel->setText(card->getText());
|
|
||||||
|
|
||||||
powtoughLabel1->setVisible(shouldShowPowTough());
|
|
||||||
powtoughLabel2->setVisible(shouldShowPowTough());
|
|
||||||
loyaltyLabel1->setVisible(shouldShowLoyalty());
|
|
||||||
loyaltyLabel2->setVisible(shouldShowLoyalty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(const QString &cardName)
|
void CardInfoWidget::setCard(const QString &cardName)
|
||||||
{
|
{
|
||||||
setCard(getCard(cardName));
|
setCard(db->getCard(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(AbstractCardItem *card)
|
void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
|
@ -183,51 +61,5 @@ void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
|
|
||||||
void CardInfoWidget::clear()
|
void CardInfoWidget::clear()
|
||||||
{
|
{
|
||||||
setCard(getCard());
|
setCard((CardInfo *) nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
CardInfo *CardInfoWidget::getCard(const QString &cardName) {
|
|
||||||
return db->getCardBySimpleName(cardName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardInfoWidget::updatePixmap()
|
|
||||||
{
|
|
||||||
if (pixmapWidth == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPixmap resizedPixmap;
|
|
||||||
PictureLoader::getPixmap(resizedPixmap, info, QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
|
||||||
|
|
||||||
if (resizedPixmap.isNull())
|
|
||||||
PictureLoader::getPixmap(resizedPixmap, getCard(), QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
|
||||||
cardPicture->setPixmap(resizedPixmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardInfoWidget::retranslateUi()
|
|
||||||
{
|
|
||||||
nameLabel1->setText(tr("Name:"));
|
|
||||||
manacostLabel1->setText(tr("Mana cost:"));
|
|
||||||
colorLabel1->setText(tr("Color(s):"));
|
|
||||||
cardtypeLabel1->setText(tr("Card type:"));
|
|
||||||
powtoughLabel1->setText(tr("P / T:"));
|
|
||||||
loyaltyLabel1->setText(tr("Loyalty:"));
|
|
||||||
}
|
|
||||||
void CardInfoWidget::resizeEvent(QResizeEvent * /*event*/)
|
|
||||||
{
|
|
||||||
if (mode == ModePopUp)
|
|
||||||
return;
|
|
||||||
if ((minimized == 1) && (mode == ModeGameTab)) {
|
|
||||||
pixmapWidth = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qreal newPixmapWidth = qMax((qreal) 100.0, qMin((qreal) cardPicture->width(), (qreal) ((height() - cardHeightOffset) / aspectRatio)));
|
|
||||||
if (newPixmapWidth != pixmapWidth) {
|
|
||||||
pixmapWidth = newPixmapWidth;
|
|
||||||
updatePixmap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CardInfoWidget::getCardName() const
|
|
||||||
{
|
|
||||||
return nameLabel2->text();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,53 +5,21 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
||||||
class QLabel;
|
|
||||||
class QTextEdit;
|
|
||||||
class QPushButton;
|
|
||||||
class AbstractCardItem;
|
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
class QResizeEvent;
|
class CardInfoPicture;
|
||||||
class QMouseEvent;
|
class CardInfoText;
|
||||||
|
class AbstractCardItem;
|
||||||
|
|
||||||
class CardInfoWidget : public QFrame {
|
class CardInfoWidget : public QFrame {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
|
||||||
enum ResizeMode { ModeDeckEditor, ModeGameTab, ModePopUp };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int pixmapWidth;
|
|
||||||
qreal cardHeightOffset;
|
|
||||||
qreal aspectRatio;
|
qreal aspectRatio;
|
||||||
// XXX: Why isn't this an eunm?
|
|
||||||
int minimized; // 0 - card, 1 - oracle only, 2 - full
|
|
||||||
ResizeMode mode;
|
|
||||||
|
|
||||||
QComboBox *dropList;
|
|
||||||
QLabel *cardPicture;
|
|
||||||
QLabel *nameLabel1, *nameLabel2;
|
|
||||||
QLabel *manacostLabel1, *manacostLabel2;
|
|
||||||
QLabel *colorLabel1, *colorLabel2;
|
|
||||||
QLabel *cardtypeLabel1, *cardtypeLabel2;
|
|
||||||
QLabel *powtoughLabel1, *powtoughLabel2;
|
|
||||||
QLabel *loyaltyLabel1, *loyaltyLabel2;
|
|
||||||
QTextEdit *textLabel;
|
|
||||||
|
|
||||||
bool shouldShowPowTough();
|
|
||||||
bool shouldShowLoyalty();
|
|
||||||
|
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
void setMinimized(int _minimized);
|
CardInfoPicture *pic;
|
||||||
|
CardInfoText *text;
|
||||||
/*
|
|
||||||
* Wrapper around db->getCardBySimpleName.
|
|
||||||
*/
|
|
||||||
CardInfo *getCard(const QString &cardName = QString());
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardInfoWidget(ResizeMode _mode, const QString &cardName = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
|
CardInfoWidget(const QString &cardName, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
void retranslateUi();
|
|
||||||
QString getCardName() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCard(CardInfo *card);
|
void setCard(CardInfo *card);
|
||||||
|
@ -60,11 +28,6 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void clear();
|
void clear();
|
||||||
void updatePixmap();
|
|
||||||
void minimizeClicked(int newMinimized);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void resizeEvent(QResizeEvent *event);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -107,13 +107,18 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
painter->save();
|
painter->save();
|
||||||
transformPainter(painter, translatedSize, tapAngle);
|
transformPainter(painter, translatedSize, tapAngle);
|
||||||
|
|
||||||
QStringList ptDbSplit = db->getCard(name)->getPowTough().split("/");
|
if(info)
|
||||||
QStringList ptSplit = pt.split("/");
|
{
|
||||||
|
QStringList ptSplit = pt.split("/");
|
||||||
|
QStringList ptDbSplit = info->getPowTough().split("/");
|
||||||
|
|
||||||
if (getFaceDown() || ptDbSplit.at(0) != ptSplit.at(0) || ptDbSplit.at(1) != ptSplit.at(1))
|
if (getFaceDown() || ptDbSplit.at(0) != ptSplit.at(0) || ptDbSplit.at(1) != ptSplit.at(1))
|
||||||
painter->setPen(QColor(255, 150, 0));
|
painter->setPen(QColor(255, 150, 0));
|
||||||
else
|
else
|
||||||
|
painter->setPen(Qt::white);
|
||||||
|
} else {
|
||||||
painter->setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
|
}
|
||||||
painter->setBackground(Qt::black);
|
painter->setBackground(Qt::black);
|
||||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
|
|
||||||
|
@ -329,7 +334,7 @@ void CardItem::playCard(bool faceDown)
|
||||||
if (tz)
|
if (tz)
|
||||||
tz->toggleTapped();
|
tz->toggleTapped();
|
||||||
else
|
else
|
||||||
zone->getPlayer()->playCard(this, faceDown, info->getCipt());
|
zone->getPlayer()->playCard(this, faceDown, info ? info->getCipt() : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
|
@ -44,11 +44,7 @@ void DeckListModel::rebuildTree()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CardInfo *info = db->getCard(currentCard->getName());
|
CardInfo *info = db->getCard(currentCard->getName());
|
||||||
QString cardType;
|
QString cardType = info ? info->getMainCardType() : "unknown";
|
||||||
if (!info)
|
|
||||||
cardType = "unknown";
|
|
||||||
else
|
|
||||||
cardType = info->getMainCardType();
|
|
||||||
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
||||||
if (!cardTypeNode)
|
if (!cardTypeNode)
|
||||||
cardTypeNode = new InnerDecklistNode(cardType, node);
|
cardTypeNode = new InnerDecklistNode(cardType, node);
|
||||||
|
@ -280,6 +276,9 @@ QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneN
|
||||||
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||||
|
|
||||||
CardInfo *info = db->getCard(cardName);
|
CardInfo *info = db->getCard(cardName);
|
||||||
|
if(!info)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
QString cardType = info->getMainCardType();
|
QString cardType = info->getMainCardType();
|
||||||
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,8 @@ struct CopyIfNotAToken {
|
||||||
const InnerDecklistNode *node,
|
const InnerDecklistNode *node,
|
||||||
const DecklistCardNode *card
|
const DecklistCardNode *card
|
||||||
) const {
|
) const {
|
||||||
if (!cardDatabase.getCard(card->getName())->getIsToken()) {
|
CardInfo * dbCard = cardDatabase.getCard(card->getName());
|
||||||
|
if (dbCard && !dbCard->getIsToken()) {
|
||||||
DecklistCardNode *addedCard = destination.addCard(
|
DecklistCardNode *addedCard = destination.addCard(
|
||||||
card->getName(),
|
card->getName(),
|
||||||
node->getName()
|
node->getName()
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
#include "dlg_add_set_result.h"
|
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success, QString msg) : QDialog(parent) {
|
|
||||||
status = new QLabel(this);
|
|
||||||
message = new QLabel(this);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
setWindowTitle(tr("Success"));
|
|
||||||
status->setText(QString("Sets/cards added to Cockatrice."));
|
|
||||||
message->setText(QString("You must restart Cockatrice to use the new sets/cards."));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setWindowTitle(tr("Failed"));
|
|
||||||
status->setText(QString("Sets/cards failed to import."));
|
|
||||||
message->setText(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
|
||||||
ok = new QPushButton(tr("Ok"), this);
|
|
||||||
buttonBox->addButton(ok, QDialogButtonBox::AcceptRole);
|
|
||||||
connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog()));
|
|
||||||
|
|
||||||
QVBoxLayout *parentLayout = new QVBoxLayout(this);
|
|
||||||
parentLayout->addWidget(status);
|
|
||||||
parentLayout->addWidget(message);
|
|
||||||
parentLayout->addWidget(buttonBox);
|
|
||||||
|
|
||||||
setLayout(parentLayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DlgAddSetResult::closeDialog()
|
|
||||||
{
|
|
||||||
accept();
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef DLG_ADD_SET_RESULT_H
|
|
||||||
#define DLG_ADD_SET_RESULT_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
class DlgAddSetResult : public QDialog {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
DlgAddSetResult(QWidget *parent, bool success, QString msg);
|
|
||||||
private slots:
|
|
||||||
void closeDialog();
|
|
||||||
private:
|
|
||||||
QLabel *status, *message;
|
|
||||||
QPushButton *ok;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -27,13 +27,13 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
|
||||||
|
|
||||||
colorLabel = new QLabel(tr("C&olor:"));
|
colorLabel = new QLabel(tr("C&olor:"));
|
||||||
colorEdit = new QComboBox;
|
colorEdit = new QComboBox;
|
||||||
colorEdit->addItem(tr("white"), "w");
|
colorEdit->addItem(tr("white"), QChar('w'));
|
||||||
colorEdit->addItem(tr("blue"), "u");
|
colorEdit->addItem(tr("blue"), QChar('u'));
|
||||||
colorEdit->addItem(tr("black"), "b");
|
colorEdit->addItem(tr("black"), QChar('b'));
|
||||||
colorEdit->addItem(tr("red"), "r");
|
colorEdit->addItem(tr("red"), QChar('r'));
|
||||||
colorEdit->addItem(tr("green"), "g");
|
colorEdit->addItem(tr("green"), QChar('g'));
|
||||||
colorEdit->addItem(tr("multicolor"), "m");
|
colorEdit->addItem(tr("multicolor"), QChar('m'));
|
||||||
colorEdit->addItem(tr("colorless"), QString());
|
colorEdit->addItem(tr("colorless"), QChar());
|
||||||
colorLabel->setBuddy(colorEdit);
|
colorLabel->setBuddy(colorEdit);
|
||||||
|
|
||||||
ptLabel = new QLabel(tr("&P/T:"));
|
ptLabel = new QLabel(tr("&P/T:"));
|
||||||
|
@ -132,14 +132,22 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
|
||||||
void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||||
{
|
{
|
||||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||||
const CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : db->getCard();
|
const CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : 0;
|
||||||
|
|
||||||
nameEdit->setText(cardInfo->getName());
|
if(cardInfo)
|
||||||
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
{
|
||||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
nameEdit->setText(cardInfo->getName());
|
||||||
ptEdit->setText(cardInfo->getPowTough());
|
const QChar cardColor = cardInfo->getColorChar();
|
||||||
if(settingsCache->getAnnotateTokens())
|
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||||
annotationEdit->setText(cardInfo->getText());
|
ptEdit->setText(cardInfo->getPowTough());
|
||||||
|
if(settingsCache->getAnnotateTokens())
|
||||||
|
annotationEdit->setText(cardInfo->getText());
|
||||||
|
} else {
|
||||||
|
nameEdit->setText("");
|
||||||
|
colorEdit->setCurrentIndex(colorEdit->findData(QString(), Qt::UserRole, Qt::MatchFixedString));
|
||||||
|
ptEdit->setText("");
|
||||||
|
annotationEdit->setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgCreateToken::actChooseTokenFromAll(bool checked)
|
void DlgCreateToken::actChooseTokenFromAll(bool checked)
|
||||||
|
@ -166,7 +174,7 @@ QString DlgCreateToken::getName() const
|
||||||
|
|
||||||
QString DlgCreateToken::getColor() const
|
QString DlgCreateToken::getColor() const
|
||||||
{
|
{
|
||||||
return colorEdit->itemData(colorEdit->currentIndex()).toString();
|
return QString(colorEdit->itemData(colorEdit->currentIndex()).toChar());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgCreateToken::getPT() const
|
QString DlgCreateToken::getPT() const
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "dlg_edit_tokens.h"
|
#include "dlg_edit_tokens.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
#include "carddatabasemodel.h"
|
#include "carddatabasemodel.h"
|
||||||
|
#include "main.h"
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
@ -15,8 +17,8 @@
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent)
|
DlgEditTokens::DlgEditTokens(QWidget *parent)
|
||||||
: QDialog(parent), currentCard(0), cardDatabaseModel(_cardDatabaseModel)
|
: QDialog(parent), currentCard(0)
|
||||||
{
|
{
|
||||||
nameLabel = new QLabel(tr("&Name:"));
|
nameLabel = new QLabel(tr("&Name:"));
|
||||||
nameEdit = new QLineEdit;
|
nameEdit = new QLineEdit;
|
||||||
|
@ -25,13 +27,13 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
|
||||||
|
|
||||||
colorLabel = new QLabel(tr("C&olor:"));
|
colorLabel = new QLabel(tr("C&olor:"));
|
||||||
colorEdit = new QComboBox;
|
colorEdit = new QComboBox;
|
||||||
colorEdit->addItem(tr("white"), "w");
|
colorEdit->addItem(tr("white"), QChar('w'));
|
||||||
colorEdit->addItem(tr("blue"), "u");
|
colorEdit->addItem(tr("blue"), QChar('u'));
|
||||||
colorEdit->addItem(tr("black"), "b");
|
colorEdit->addItem(tr("black"), QChar('b'));
|
||||||
colorEdit->addItem(tr("red"), "r");
|
colorEdit->addItem(tr("red"), QChar('r'));
|
||||||
colorEdit->addItem(tr("green"), "g");
|
colorEdit->addItem(tr("green"), QChar('g'));
|
||||||
colorEdit->addItem(tr("multicolor"), "m");
|
colorEdit->addItem(tr("multicolor"), QChar('m'));
|
||||||
colorEdit->addItem(tr("colorless"), QString());
|
colorEdit->addItem(tr("colorless"), QChar());
|
||||||
colorLabel->setBuddy(colorEdit);
|
colorLabel->setBuddy(colorEdit);
|
||||||
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
||||||
|
|
||||||
|
@ -58,8 +60,10 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
|
||||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||||
tokenDataGroupBox->setLayout(grid);
|
tokenDataGroupBox->setLayout(grid);
|
||||||
|
|
||||||
cardDatabaseDisplayModel = new CardDatabaseDisplayModel(this);
|
databaseModel = new CardDatabaseModel(db, this);
|
||||||
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
databaseModel->setObjectName("databaseModel");
|
||||||
|
cardDatabaseDisplayModel = new TokenDisplayModel(this);
|
||||||
|
cardDatabaseDisplayModel->setSourceModel(databaseModel);
|
||||||
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
||||||
|
|
||||||
chooseTokenView = new QTreeView;
|
chooseTokenView = new QTreeView;
|
||||||
|
@ -116,39 +120,43 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
|
||||||
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /* previous */)
|
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /* previous */)
|
||||||
{
|
{
|
||||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||||
CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : cardDatabaseModel->getDatabase()->getCard();
|
currentCard = current.row() >= 0 ? databaseModel->getCard(realIndex.row()) : 0;
|
||||||
if (!cardInfo->getName().isEmpty())
|
|
||||||
currentCard = cardInfo;
|
|
||||||
else
|
|
||||||
currentCard = 0;
|
|
||||||
|
|
||||||
nameEdit->setText(cardInfo->getName());
|
if(currentCard)
|
||||||
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
|
{
|
||||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
nameEdit->setText(currentCard->getName());
|
||||||
ptEdit->setText(cardInfo->getPowTough());
|
const QChar cardColor = currentCard->getColorChar();
|
||||||
annotationEdit->setText(cardInfo->getText());
|
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||||
|
ptEdit->setText(currentCard->getPowTough());
|
||||||
|
annotationEdit->setText(currentCard->getText());
|
||||||
|
} else {
|
||||||
|
nameEdit->setText("");
|
||||||
|
colorEdit->setCurrentIndex(colorEdit->findData(QChar(), Qt::UserRole, Qt::MatchFixedString));
|
||||||
|
ptEdit->setText("");
|
||||||
|
annotationEdit->setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::actAddToken()
|
void DlgEditTokens::actAddToken()
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
bool askAgain;
|
bool askAgain = true;
|
||||||
do {
|
do {
|
||||||
name = QInputDialog::getText(this, tr("Add token"), tr("Please enter the name of the token:"));
|
name = QInputDialog::getText(this, tr("Add token"), tr("Please enter the name of the token:"));
|
||||||
if (!name.isEmpty() && cardDatabaseModel->getDatabase()->getCard(name, false)) {
|
if(name.isEmpty())
|
||||||
|
return;
|
||||||
|
if (databaseModel->getDatabase()->getCard(name)) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The chosen name conflicts with an existing card or token.\nMake sure to enable the 'token set' in the 'Edit sets...' dialog to display them correctly."));
|
QMessageBox::critical(this, tr("Error"), tr("The chosen name conflicts with an existing card or token.\nMake sure to enable the 'token set' in the 'Edit sets...' dialog to display them correctly."));
|
||||||
askAgain = true;
|
} else {
|
||||||
} else
|
|
||||||
askAgain = false;
|
askAgain = false;
|
||||||
|
}
|
||||||
} while (askAgain);
|
} while (askAgain);
|
||||||
|
|
||||||
if (name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
CardInfo *card = new CardInfo(name, true);
|
CardInfo *card = new CardInfo(name, true);
|
||||||
card->addToSet(cardDatabaseModel->getDatabase()->getSet(CardDatabase::TOKENS_SETNAME));
|
card->addToSet(databaseModel->getDatabase()->getSet(CardDatabase::TOKENS_SETNAME));
|
||||||
card->setCardType("Token");
|
card->setCardType("Token");
|
||||||
cardDatabaseModel->getDatabase()->addCard(card);
|
databaseModel->getDatabase()->addCard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::actRemoveToken()
|
void DlgEditTokens::actRemoveToken()
|
||||||
|
@ -156,7 +164,7 @@ void DlgEditTokens::actRemoveToken()
|
||||||
if (currentCard) {
|
if (currentCard) {
|
||||||
CardInfo *cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
CardInfo *cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
||||||
currentCard = 0;
|
currentCard = 0;
|
||||||
cardDatabaseModel->getDatabase()->removeCard(cardToRemove);
|
databaseModel->getDatabase()->removeCard(cardToRemove);
|
||||||
delete cardToRemove;
|
delete cardToRemove;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +172,7 @@ void DlgEditTokens::actRemoveToken()
|
||||||
void DlgEditTokens::colorChanged(int colorIndex)
|
void DlgEditTokens::colorChanged(int colorIndex)
|
||||||
{
|
{
|
||||||
if (currentCard)
|
if (currentCard)
|
||||||
currentCard->setColors(QStringList() << colorEdit->itemData(colorIndex).toString());
|
currentCard->setColors(QStringList() << QString(colorEdit->itemData(colorIndex).toChar()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgEditTokens::ptChanged(const QString &_pt)
|
void DlgEditTokens::ptChanged(const QString &_pt)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class CardDatabaseModel;
|
class CardDatabaseModel;
|
||||||
class CardDatabaseDisplayModel;
|
class TokenDisplayModel;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
@ -24,15 +24,15 @@ private slots:
|
||||||
void actRemoveToken();
|
void actRemoveToken();
|
||||||
private:
|
private:
|
||||||
CardInfo *currentCard;
|
CardInfo *currentCard;
|
||||||
CardDatabaseModel *cardDatabaseModel;
|
CardDatabaseModel *databaseModel;
|
||||||
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
|
TokenDisplayModel *cardDatabaseDisplayModel;
|
||||||
QStringList predefinedTokens;
|
QStringList predefinedTokens;
|
||||||
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
||||||
QComboBox *colorEdit;
|
QComboBox *colorEdit;
|
||||||
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
||||||
QTreeView *chooseTokenView;
|
QTreeView *chooseTokenView;
|
||||||
public:
|
public:
|
||||||
DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *parent = 0);
|
DlgEditTokens(QWidget *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include "QtNetwork/QNetworkInterface"
|
#include "QtNetwork/QNetworkInterface"
|
||||||
|
@ -86,14 +85,6 @@ void installNewTranslator()
|
||||||
qApp->installTranslator(translator);
|
qApp->installTranslator(translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool settingsValid()
|
|
||||||
{
|
|
||||||
return QDir(settingsCache->getDeckPath()).exists() &&
|
|
||||||
!settingsCache->getDeckPath().isEmpty() &&
|
|
||||||
QDir(settingsCache->getPicsPath()).exists() &&
|
|
||||||
!settingsCache->getPicsPath().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString const generateClientID()
|
QString const generateClientID()
|
||||||
{
|
{
|
||||||
QString macList;
|
QString macList;
|
||||||
|
@ -156,73 +147,21 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
#ifdef PORTABLE_BUILD
|
qDebug("main(): starting main program");
|
||||||
const QString dataDir = "data/";
|
|
||||||
#elif QT_VERSION < 0x050000
|
|
||||||
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
const QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (settingsCache->getCardDatabasePath().isEmpty() ||
|
MainWindow ui;
|
||||||
db->loadCardDatabase() != Ok)
|
qDebug("main(): MainWindow constructor finished");
|
||||||
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
|
|
||||||
|
|
||||||
if (settingsCache->getTokenDatabasePath().isEmpty() ||
|
ui.setWindowIcon(QPixmap("theme:cockatrice"));
|
||||||
db->loadTokenDatabase() != Ok)
|
|
||||||
settingsCache->setTokenDatabasePath(dataDir + "/tokens.xml");
|
|
||||||
|
|
||||||
if (!QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty()) {
|
settingsCache->setClientID(generateClientID());
|
||||||
QDir().mkpath(dataDir + "/decks");
|
|
||||||
settingsCache->setDeckPath(dataDir + "/decks");
|
|
||||||
}
|
|
||||||
if (!QDir(settingsCache->getReplaysPath()).exists() || settingsCache->getReplaysPath().isEmpty()) {
|
|
||||||
QDir().mkpath(dataDir + "/replays");
|
|
||||||
settingsCache->setReplaysPath(dataDir + "/replays");
|
|
||||||
}
|
|
||||||
if (!QDir(settingsCache->getPicsPath()).exists() || settingsCache->getPicsPath().isEmpty()) {
|
|
||||||
QDir().mkpath(dataDir + "/pics");
|
|
||||||
settingsCache->setPicsPath(dataDir + "/pics");
|
|
||||||
}
|
|
||||||
if (!QDir().mkpath(settingsCache->getPicsPath() + "/CUSTOM"))
|
|
||||||
qDebug() << "Could not create " + settingsCache->getPicsPath().toUtf8() + "/CUSTOM. Will fall back on default card images.";
|
|
||||||
|
|
||||||
if (!settingsValid() || db->getLoadStatus() != Ok) {
|
ui.show();
|
||||||
qDebug("main(): invalid settings or load status");
|
qDebug("main(): ui.show() finished");
|
||||||
DlgSettings dlgSettings;
|
|
||||||
dlgSettings.show();
|
|
||||||
app.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
// load custom databased after LoadStatus check, so that they don't bring up the settings dialog
|
|
||||||
if (QDir().mkpath(dataDir + "/customsets"))
|
|
||||||
{
|
|
||||||
// if the dir exists (or has just been created)
|
|
||||||
db->loadCustomCardDatabases(dataDir + "/customsets");
|
|
||||||
} else {
|
|
||||||
qDebug() << "Could not create " + dataDir + "/customsets folder.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// when all the cards have been loaded, resolve the reverse-related tags
|
|
||||||
db->refreshCachedReverseRelatedCards();
|
|
||||||
|
|
||||||
if (settingsValid()) {
|
|
||||||
qDebug("main(): starting main program");
|
|
||||||
|
|
||||||
MainWindow ui;
|
|
||||||
qDebug("main(): MainWindow constructor finished");
|
|
||||||
|
|
||||||
ui.setWindowIcon(QPixmap("theme:cockatrice"));
|
|
||||||
|
|
||||||
settingsCache->setClientID(generateClientID());
|
|
||||||
|
|
||||||
ui.show();
|
|
||||||
qDebug("main(): ui.show() finished");
|
|
||||||
#if QT_VERSION > 0x050000
|
#if QT_VERSION > 0x050000
|
||||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
#endif
|
#endif
|
||||||
app.exec();
|
app.exec();
|
||||||
}
|
|
||||||
|
|
||||||
qDebug("Event loop finished, terminating...");
|
qDebug("Event loop finished, terminating...");
|
||||||
delete db;
|
delete db;
|
||||||
|
|
|
@ -16,6 +16,4 @@ void installNewTranslator();
|
||||||
|
|
||||||
QString const generateClientID();
|
QString const generateClientID();
|
||||||
|
|
||||||
bool settingsValid();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
class CardInfoWidget;
|
|
||||||
class GameEventContext;
|
class GameEventContext;
|
||||||
class CardItem;
|
class CardItem;
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ PictureLoaderWorker::PictureLoaderWorker()
|
||||||
downloadRunning(false), loadQueueRunning(false)
|
downloadRunning(false), loadQueueRunning(false)
|
||||||
{
|
{
|
||||||
picsPath = settingsCache->getPicsPath();
|
picsPath = settingsCache->getPicsPath();
|
||||||
|
customPicsPath = settingsCache->getCustomPicsPath();
|
||||||
picDownload = settingsCache->getPicDownload();
|
picDownload = settingsCache->getPicDownload();
|
||||||
|
|
||||||
connect(this, SIGNAL(startLoadQueue()), this, SLOT(processLoadQueue()), Qt::QueuedConnection);
|
connect(this, SIGNAL(startLoadQueue()), this, SLOT(processLoadQueue()), Qt::QueuedConnection);
|
||||||
|
@ -167,7 +168,7 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString & setName, QString & cor
|
||||||
imgReader.setDecideFormatFromContent(true);
|
imgReader.setDecideFormatFromContent(true);
|
||||||
|
|
||||||
//The list of paths to the folders in which to search for images
|
//The list of paths to the folders in which to search for images
|
||||||
QList<QString> picsPaths = QList<QString>() << picsPath + "/CUSTOM/" + correctedCardname;
|
QList<QString> picsPaths = QList<QString>() << customPicsPath + correctedCardname;
|
||||||
|
|
||||||
if(!setName.isEmpty())
|
if(!setName.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -196,7 +197,7 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString & setName, QString & cor
|
||||||
|
|
||||||
QString PictureLoaderWorker::getPicUrl()
|
QString PictureLoaderWorker::getPicUrl()
|
||||||
{
|
{
|
||||||
if (!picDownload) return QString("");
|
if (!picDownload) return QString();
|
||||||
|
|
||||||
CardInfo *card = cardBeingDownloaded.getCard();
|
CardInfo *card = cardBeingDownloaded.getCard();
|
||||||
CardSet *set=cardBeingDownloaded.getCurrentSet();
|
CardSet *set=cardBeingDownloaded.getCurrentSet();
|
||||||
|
@ -236,7 +237,7 @@ QString PictureLoaderWorker::getPicUrl()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl;
|
qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl;
|
||||||
return QString("");
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return picUrl;
|
return picUrl;
|
||||||
|
@ -275,12 +276,12 @@ void PictureLoaderWorker::picDownloadFailed()
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
loadQueue.prepend(cardBeingDownloaded);
|
loadQueue.prepend(cardBeingDownloaded);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
emit startLoadQueue();
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Picture NOT found, download failed, no more sets to try: BAILING OUT (oldset: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getCorrectedName() << ")";
|
qDebug() << "Picture NOT found, download failed, no more sets to try: BAILING OUT (oldset: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getCorrectedName() << ")";
|
||||||
cardBeingDownloaded = 0;
|
|
||||||
imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
||||||
|
cardBeingDownloaded = 0;
|
||||||
}
|
}
|
||||||
|
emit startLoadQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PictureLoaderWorker::imageIsBlackListed(const QByteArray &picData)
|
bool PictureLoaderWorker::imageIsBlackListed(const QByteArray &picData)
|
||||||
|
@ -354,7 +355,7 @@ void PictureLoaderWorker::enqueueImageLoad(CardInfo *card)
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
|
|
||||||
// avoid queueing the same card more than once
|
// avoid queueing the same card more than once
|
||||||
if(card == 0 || card == cardBeingLoaded.getCard() || card == cardBeingDownloaded.getCard())
|
if(!card || card == cardBeingLoaded.getCard() || card == cardBeingDownloaded.getCard())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach(PictureToLoad pic, loadQueue)
|
foreach(PictureToLoad pic, loadQueue)
|
||||||
|
@ -363,6 +364,12 @@ void PictureLoaderWorker::enqueueImageLoad(CardInfo *card)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach(PictureToLoad pic, cardsToDownload)
|
||||||
|
{
|
||||||
|
if(pic.getCard() == card)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
loadQueue.append(PictureToLoad(card));
|
loadQueue.append(PictureToLoad(card));
|
||||||
emit startLoadQueue();
|
emit startLoadQueue();
|
||||||
}
|
}
|
||||||
|
@ -377,6 +384,7 @@ void PictureLoaderWorker::picsPathChanged()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
picsPath = settingsCache->getPicsPath();
|
picsPath = settingsCache->getPicsPath();
|
||||||
|
customPicsPath = settingsCache->getCustomPicsPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
PictureLoader::PictureLoader()
|
PictureLoader::PictureLoader()
|
||||||
|
@ -409,11 +417,6 @@ void PictureLoader::getPixmap(QPixmap &pixmap, CardInfo *card, QSize size)
|
||||||
{
|
{
|
||||||
if(card)
|
if(card)
|
||||||
{
|
{
|
||||||
if (card->getName().isEmpty()) {
|
|
||||||
internalGetCardBackPixmap(pixmap, size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// search for an exact size copy of the picure in cache
|
// search for an exact size copy of the picure in cache
|
||||||
QString key = card->getPixmapCacheKey();
|
QString key = card->getPixmapCacheKey();
|
||||||
QString sizekey = key + QLatin1Char('_') + QString::number(size.width()) + QString::number(size.height());
|
QString sizekey = key + QLatin1Char('_') + QString::number(size.width()) + QString::number(size.height());
|
||||||
|
@ -428,30 +431,28 @@ void PictureLoader::getPixmap(QPixmap &pixmap, CardInfo *card, QSize size)
|
||||||
QPixmapCache::insert(sizekey, pixmap);
|
QPixmapCache::insert(sizekey, pixmap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// load a temporary back picture
|
|
||||||
internalGetCardBackPixmap(pixmap, size);
|
|
||||||
|
|
||||||
if(card)
|
|
||||||
{
|
|
||||||
// add the card to the load queue
|
// add the card to the load queue
|
||||||
getInstance().worker->enqueueImageLoad(card);
|
getInstance().worker->enqueueImageLoad(card);
|
||||||
|
} else {
|
||||||
|
// requesting the image for a null card is a shortcut to get the card background image
|
||||||
|
internalGetCardBackPixmap(pixmap, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PictureLoader::imageLoaded(CardInfo *card, const QImage &image)
|
void PictureLoader::imageLoaded(CardInfo *card, const QImage &image)
|
||||||
{
|
{
|
||||||
if(image.isNull())
|
if(image.isNull())
|
||||||
return;
|
|
||||||
|
|
||||||
if(card->getUpsideDownArt())
|
|
||||||
{
|
{
|
||||||
QImage mirrorImage = image.mirrored(true, true);
|
QPixmapCache::insert(card->getPixmapCacheKey(), QPixmap());
|
||||||
QPixmapCache::insert(card->getPixmapCacheKey(), QPixmap::fromImage(mirrorImage));
|
|
||||||
} else {
|
} else {
|
||||||
QPixmapCache::insert(card->getPixmapCacheKey(), QPixmap::fromImage(image));
|
if(card->getUpsideDownArt())
|
||||||
|
{
|
||||||
|
QImage mirrorImage = image.mirrored(true, true);
|
||||||
|
QPixmapCache::insert(card->getPixmapCacheKey(), QPixmap::fromImage(mirrorImage));
|
||||||
|
} else {
|
||||||
|
QPixmapCache::insert(card->getPixmapCacheKey(), QPixmap::fromImage(image));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
card->emitPixmapUpdated();
|
card->emitPixmapUpdated();
|
||||||
|
|
|
@ -39,7 +39,7 @@ private:
|
||||||
static QStringList md5Blacklist;
|
static QStringList md5Blacklist;
|
||||||
|
|
||||||
QThread *pictureLoaderThread;
|
QThread *pictureLoaderThread;
|
||||||
QString picsPath;
|
QString picsPath, customPicsPath;
|
||||||
QList<PictureToLoad> loadQueue;
|
QList<PictureToLoad> loadQueue;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
QNetworkAccessManager *networkManager;
|
QNetworkAccessManager *networkManager;
|
||||||
|
|
|
@ -1081,7 +1081,8 @@ void Player::actCreateToken()
|
||||||
|
|
||||||
lastTokenName = dlg.getName();
|
lastTokenName = dlg.getName();
|
||||||
lastTokenPT = dlg.getPT();
|
lastTokenPT = dlg.getPT();
|
||||||
if (CardInfo *correctedCard = db->getCardBySimpleName(lastTokenName, false)) {
|
CardInfo *correctedCard = db->getCardBySimpleName(lastTokenName);
|
||||||
|
if (correctedCard) {
|
||||||
lastTokenName = correctedCard->getName();
|
lastTokenName = correctedCard->getName();
|
||||||
lastTokenTableRow = table->clampValidTableRow(2 - correctedCard->getTableRow());
|
lastTokenTableRow = table->clampValidTableRow(2 - correctedCard->getTableRow());
|
||||||
if (lastTokenPT.isEmpty())
|
if (lastTokenPT.isEmpty())
|
||||||
|
@ -1114,6 +1115,8 @@ void Player::actCreatePredefinedToken()
|
||||||
{
|
{
|
||||||
QAction *action = static_cast<QAction *>(sender());
|
QAction *action = static_cast<QAction *>(sender());
|
||||||
CardInfo *cardInfo = db->getCard(action->text());
|
CardInfo *cardInfo = db->getCard(action->text());
|
||||||
|
if(!cardInfo)
|
||||||
|
return;
|
||||||
|
|
||||||
lastTokenName = cardInfo->getName();
|
lastTokenName = cardInfo->getName();
|
||||||
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first().toLower();
|
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first().toLower();
|
||||||
|
@ -1141,6 +1144,8 @@ void Player::actCreateRelatedCard()
|
||||||
if (spaces.at(0).indexOf("/") != -1) // Strip space from creatures
|
if (spaces.at(0).indexOf("/") != -1) // Strip space from creatures
|
||||||
spaces.removeFirst();
|
spaces.removeFirst();
|
||||||
CardInfo *cardInfo = db->getCard(spaces.join(" "));
|
CardInfo *cardInfo = db->getCard(spaces.join(" "));
|
||||||
|
if(!cardInfo)
|
||||||
|
return;
|
||||||
|
|
||||||
// get the target token's location
|
// get the target token's location
|
||||||
// TODO: Define this QPoint into its own function along with the one below
|
// TODO: Define this QPoint into its own function along with the one below
|
||||||
|
@ -1256,9 +1261,13 @@ void Player::eventCreateToken(const Event_CreateToken &event)
|
||||||
CardItem *card = new CardItem(this, QString::fromStdString(event.card_name()), event.card_id());
|
CardItem *card = new CardItem(this, QString::fromStdString(event.card_name()), event.card_id());
|
||||||
// use db PT if not provided in event
|
// use db PT if not provided in event
|
||||||
if (!QString::fromStdString(event.pt()).isEmpty())
|
if (!QString::fromStdString(event.pt()).isEmpty())
|
||||||
|
{
|
||||||
card->setPT(QString::fromStdString(event.pt()));
|
card->setPT(QString::fromStdString(event.pt()));
|
||||||
else
|
} else {
|
||||||
card->setPT(db->getCard(QString::fromStdString(event.card_name()))->getPowTough());
|
CardInfo * dbCard = db->getCard(QString::fromStdString(event.card_name()));
|
||||||
|
if(dbCard)
|
||||||
|
card->setPT(dbCard->getPowTough());
|
||||||
|
}
|
||||||
card->setColor(QString::fromStdString(event.color()));
|
card->setColor(QString::fromStdString(event.color()));
|
||||||
card->setAnnotation(QString::fromStdString(event.annotation()));
|
card->setAnnotation(QString::fromStdString(event.annotation()));
|
||||||
card->setDestroyOnZoneChange(event.destroy_on_zone_change());
|
card->setDestroyOnZoneChange(event.destroy_on_zone_change());
|
||||||
|
@ -1713,6 +1722,8 @@ void Player::playCard(CardItem *c, bool faceDown, bool tapped)
|
||||||
cardToMove->set_card_id(c->getId());
|
cardToMove->set_card_id(c->getId());
|
||||||
|
|
||||||
CardInfo *ci = c->getInfo();
|
CardInfo *ci = c->getInfo();
|
||||||
|
if(!ci)
|
||||||
|
return;
|
||||||
if (!faceDown && ((!settingsCache->getPlayToStack() && ci->getTableRow() == 3) ||
|
if (!faceDown && ((!settingsCache->getPlayToStack() && ci->getTableRow() == 3) ||
|
||||||
((settingsCache->getPlayToStack() && ci->getTableRow() != 0) &&
|
((settingsCache->getPlayToStack() && ci->getTableRow() != 0) &&
|
||||||
c->getZone()->getName().toStdString() != "stack"))) {
|
c->getZone()->getName().toStdString() != "stack"))) {
|
||||||
|
@ -2293,7 +2304,8 @@ void Player::actPlay()
|
||||||
if(!game->getActiveCard())
|
if(!game->getActiveCard())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
playCard(game->getActiveCard(), false, game->getActiveCard()->getInfo()->getCipt());
|
bool cipt = game->getActiveCard()->getInfo() ? game->getActiveCard()->getInfo()->getCipt(): false;
|
||||||
|
playCard(game->getActiveCard(), false, cipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actHide()
|
void Player::actHide()
|
||||||
|
@ -2374,20 +2386,23 @@ void Player::updateCardMenu(CardItem *card)
|
||||||
if (card->getFaceDown())
|
if (card->getFaceDown())
|
||||||
cardMenu->addAction(aPeek);
|
cardMenu->addAction(aPeek);
|
||||||
|
|
||||||
QStringList relatedCards = card->getInfo()->getRelatedCards();
|
if(card->getInfo())
|
||||||
QStringList reverserelatedCards2Me = card->getInfo()->getReverseRelatedCards2Me();
|
|
||||||
if(relatedCards.size() || reverserelatedCards2Me.size())
|
|
||||||
{
|
{
|
||||||
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
|
QStringList relatedCards = card->getInfo()->getRelatedCards();
|
||||||
|
QStringList reverserelatedCards2Me = card->getInfo()->getReverseRelatedCards2Me();
|
||||||
|
if(relatedCards.size() || reverserelatedCards2Me.size())
|
||||||
|
{
|
||||||
|
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
|
||||||
|
|
||||||
for (int i = 0; i < relatedCards.size(); ++i) {
|
for (int i = 0; i < relatedCards.size(); ++i) {
|
||||||
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
|
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
|
||||||
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < reverserelatedCards2Me.size(); ++i) {
|
for (int i = 0; i < reverserelatedCards2Me.size(); ++i) {
|
||||||
QAction *a = createRelatedCardMenu->addAction(reverserelatedCards2Me.at(i));
|
QAction *a = createRelatedCardMenu->addAction(reverserelatedCards2Me.at(i));
|
||||||
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cardMenu->addSeparator();
|
cardMenu->addSeparator();
|
||||||
|
@ -2413,20 +2428,23 @@ void Player::updateCardMenu(CardItem *card)
|
||||||
cardMenu->addAction(aDrawArrow);
|
cardMenu->addAction(aDrawArrow);
|
||||||
cardMenu->addMenu(moveMenu);
|
cardMenu->addMenu(moveMenu);
|
||||||
|
|
||||||
QStringList relatedCards = card->getInfo()->getRelatedCards();
|
if(card->getInfo())
|
||||||
QStringList reverserelatedCards2Me = card->getInfo()->getReverseRelatedCards2Me();
|
|
||||||
if(relatedCards.size() || reverserelatedCards2Me.size())
|
|
||||||
{
|
{
|
||||||
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
|
QStringList relatedCards = card->getInfo()->getRelatedCards();
|
||||||
|
QStringList reverserelatedCards2Me = card->getInfo()->getReverseRelatedCards2Me();
|
||||||
|
if(relatedCards.size() || reverserelatedCards2Me.size())
|
||||||
|
{
|
||||||
|
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
|
||||||
|
|
||||||
for (int i = 0; i < relatedCards.size(); ++i) {
|
for (int i = 0; i < relatedCards.size(); ++i) {
|
||||||
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
|
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
|
||||||
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < reverserelatedCards2Me.size(); ++i) {
|
for (int i = 0; i < reverserelatedCards2Me.size(); ++i) {
|
||||||
QAction *a = createRelatedCardMenu->addAction(reverserelatedCards2Me.at(i));
|
QAction *a = createRelatedCardMenu->addAction(reverserelatedCards2Me.at(i));
|
||||||
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,7 +60,9 @@ void DBPriceUpdater::updatePrices()
|
||||||
bool bNotFirst=false;
|
bool bNotFirst=false;
|
||||||
|
|
||||||
for (int i = 0; i < cards.size(); ++i) {
|
for (int i = 0; i < cards.size(); ++i) {
|
||||||
card = db->getCard(cards[i], false);
|
card = db->getCard(cards[i]);
|
||||||
|
if(!card)
|
||||||
|
continue;
|
||||||
sets = card->getSets();
|
sets = card->getSets();
|
||||||
for(int j = 0; j < sets.size(); ++j)
|
for(int j = 0; j < sets.size(); ++j)
|
||||||
{
|
{
|
||||||
|
|
|
@ -194,7 +194,7 @@ void SetsModel::save(CardDatabase *db)
|
||||||
|
|
||||||
sets.sortByKey();
|
sets.sortByKey();
|
||||||
|
|
||||||
db->emitCardListChanged();
|
db->notifyEnabledSetsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetsModel::restore(CardDatabase *db)
|
void SetsModel::restore(CardDatabase *db)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
|
@ -9,20 +11,21 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QString SettingsCache::getDataPath()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
#ifdef PORTABLE_BUILD
|
||||||
|
qApp->applicationDirPath() + "/data/";
|
||||||
|
#elif QT_VERSION >= 0x050000
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
||||||
|
#else
|
||||||
|
QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
QString SettingsCache::getSettingsPath()
|
QString SettingsCache::getSettingsPath()
|
||||||
{
|
{
|
||||||
QString file = qApp->applicationDirPath() + "/settings/";
|
return getDataPath() + "/settings/";
|
||||||
|
|
||||||
#ifndef PORTABLE_BUILD
|
|
||||||
#if QT_VERSION >= 0x050000
|
|
||||||
file = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
|
||||||
#else
|
|
||||||
file = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#endif
|
|
||||||
file.append("/settings/");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::translateLegacySettings()
|
void SettingsCache::translateLegacySettings()
|
||||||
|
@ -119,8 +122,31 @@ void SettingsCache::translateLegacySettings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPath) const
|
||||||
|
{
|
||||||
|
QString tmp = settings->value(configEntry).toString();
|
||||||
|
// if the config settings is empty or refers to a not-existing folder,
|
||||||
|
// ensure that the defaut path exists and return it
|
||||||
|
if (!QDir(tmp).exists() || tmp.isEmpty()) {
|
||||||
|
if(!QDir().mkpath(defaultPath))
|
||||||
|
qDebug() << "[SettingsCache] Could not create folder:" << defaultPath;
|
||||||
|
tmp = defaultPath;
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaultPath) const
|
||||||
|
{
|
||||||
|
QString tmp = settings->value(configEntry).toString();
|
||||||
|
// if the config settings is empty or refers to a not-existing file,
|
||||||
|
// return the default Path
|
||||||
|
if (!QFile::exists(tmp) || tmp.isEmpty())
|
||||||
|
tmp = defaultPath;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
SettingsCache::SettingsCache()
|
SettingsCache::SettingsCache()
|
||||||
{
|
{
|
||||||
|
QString dataPath = getDataPath();
|
||||||
QString settingsPath = getSettingsPath();
|
QString settingsPath = getSettingsPath();
|
||||||
settings = new QSettings(settingsPath+"global.ini", QSettings::IniFormat, this);
|
settings = new QSettings(settingsPath+"global.ini", QSettings::IniFormat, this);
|
||||||
shortcutsSettings = new ShortcutsSettings(settingsPath,this);
|
shortcutsSettings = new ShortcutsSettings(settingsPath,this);
|
||||||
|
@ -133,20 +159,20 @@ SettingsCache::SettingsCache()
|
||||||
if(!QFile(settingsPath+"global.ini").exists())
|
if(!QFile(settingsPath+"global.ini").exists())
|
||||||
translateLegacySettings();
|
translateLegacySettings();
|
||||||
|
|
||||||
#ifdef PORTABLE_BUILD
|
|
||||||
setDeckPath(qApp->applicationDirPath() + "data/decks");
|
|
||||||
setReplaysPath(qApp->applicationDirPath() +"data/replays");
|
|
||||||
setPicsPath(qApp->applicationDirPath() + "data/pics");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
|
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
|
||||||
lang = settings->value("personal/lang").toString();
|
lang = settings->value("personal/lang").toString();
|
||||||
keepalive = settings->value("personal/keepalive", 5).toInt();
|
keepalive = settings->value("personal/keepalive", 5).toInt();
|
||||||
deckPath = settings->value("paths/decks").toString();
|
|
||||||
replaysPath = settings->value("paths/replays").toString();
|
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
||||||
picsPath = settings->value("paths/pics").toString();
|
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
||||||
cardDatabasePath = settings->value("paths/carddatabase").toString();
|
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
||||||
tokenDatabasePath = settings->value("paths/tokendatabase").toString();
|
// this has never been exposed as an user-configurable setting
|
||||||
|
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "/CUSTOM/");
|
||||||
|
// this has never been exposed as an user-configurable setting
|
||||||
|
customCardDatabasePath = getSafeConfigPath("paths/customsets", dataPath + "/customsets/");
|
||||||
|
|
||||||
|
cardDatabasePath = getSafeConfigFilePath("paths/carddatabase", dataPath + "/cards.xml");
|
||||||
|
tokenDatabasePath = getSafeConfigFilePath("paths/tokendatabase", dataPath + "/tokens.xml");
|
||||||
|
|
||||||
themeName = settings->value("theme/name").toString();
|
themeName = settings->value("theme/name").toString();
|
||||||
|
|
||||||
|
@ -175,7 +201,6 @@ SettingsCache::SettingsCache()
|
||||||
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
|
doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool();
|
||||||
playToStack = settings->value("interface/playtostack", true).toBool();
|
playToStack = settings->value("interface/playtostack", true).toBool();
|
||||||
annotateTokens = settings->value("interface/annotatetokens", false).toBool();
|
annotateTokens = settings->value("interface/annotatetokens", false).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();
|
||||||
|
@ -291,6 +316,8 @@ void SettingsCache::setPicsPath(const QString &_picsPath)
|
||||||
{
|
{
|
||||||
picsPath = _picsPath;
|
picsPath = _picsPath;
|
||||||
settings->setValue("paths/pics", picsPath);
|
settings->setValue("paths/pics", picsPath);
|
||||||
|
// get a new value for customPicsPath, currently derived from picsPath
|
||||||
|
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
|
||||||
emit picsPathChanged();
|
emit picsPathChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +332,7 @@ void SettingsCache::setTokenDatabasePath(const QString &_tokenDatabasePath)
|
||||||
{
|
{
|
||||||
tokenDatabasePath = _tokenDatabasePath;
|
tokenDatabasePath = _tokenDatabasePath;
|
||||||
settings->setValue("paths/tokendatabase", tokenDatabasePath);
|
settings->setValue("paths/tokendatabase", tokenDatabasePath);
|
||||||
emit tokenDatabasePathChanged();
|
emit cardDatabasePathChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setThemeName(const QString &_themeName)
|
void SettingsCache::setThemeName(const QString &_themeName)
|
||||||
|
@ -363,12 +390,6 @@ void SettingsCache::setAnnotateTokens(int _annotateTokens)
|
||||||
settings->setValue("interface/annotatetokens", annotateTokens);
|
settings->setValue("interface/annotatetokens", annotateTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -27,7 +27,6 @@ signals:
|
||||||
void langChanged();
|
void langChanged();
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
void cardDatabasePathChanged();
|
void cardDatabasePathChanged();
|
||||||
void tokenDatabasePathChanged();
|
|
||||||
void themeChanged();
|
void themeChanged();
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void displayCardNamesChanged();
|
void displayCardNamesChanged();
|
||||||
|
@ -54,7 +53,7 @@ private:
|
||||||
|
|
||||||
QByteArray mainWindowGeometry;
|
QByteArray mainWindowGeometry;
|
||||||
QString lang;
|
QString lang;
|
||||||
QString deckPath, replaysPath, picsPath, cardDatabasePath, tokenDatabasePath, themeName;
|
QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, tokenDatabasePath, themeName;
|
||||||
bool notifyAboutUpdates;
|
bool notifyAboutUpdates;
|
||||||
bool picDownload;
|
bool picDownload;
|
||||||
bool notificationsEnabled;
|
bool notificationsEnabled;
|
||||||
|
@ -62,7 +61,6 @@ private:
|
||||||
bool doubleClickToPlay;
|
bool doubleClickToPlay;
|
||||||
bool playToStack;
|
bool playToStack;
|
||||||
bool annotateTokens;
|
bool annotateTokens;
|
||||||
int cardInfoMinimized;
|
|
||||||
QByteArray tabGameSplitterSizes;
|
QByteArray tabGameSplitterSizes;
|
||||||
bool displayCardNames;
|
bool displayCardNames;
|
||||||
bool horizontalHand;
|
bool horizontalHand;
|
||||||
|
@ -105,16 +103,21 @@ private:
|
||||||
bool spectatorsCanSeeEverything;
|
bool spectatorsCanSeeEverything;
|
||||||
int keepalive;
|
int keepalive;
|
||||||
void translateLegacySettings();
|
void translateLegacySettings();
|
||||||
|
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
||||||
|
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
||||||
bool rememberGameSettings;
|
bool rememberGameSettings;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SettingsCache();
|
SettingsCache();
|
||||||
|
QString getDataPath();
|
||||||
QString getSettingsPath();
|
QString getSettingsPath();
|
||||||
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
||||||
QString getLang() const { return lang; }
|
QString getLang() const { return lang; }
|
||||||
QString getDeckPath() const { return deckPath; }
|
QString getDeckPath() const { return deckPath; }
|
||||||
QString getReplaysPath() const { return replaysPath; }
|
QString getReplaysPath() const { return replaysPath; }
|
||||||
QString getPicsPath() const { return picsPath; }
|
QString getPicsPath() const { return picsPath; }
|
||||||
|
QString getCustomPicsPath() const { return customPicsPath; }
|
||||||
|
QString getCustomCardDatabasePath() const { return customCardDatabasePath; }
|
||||||
QString getCardDatabasePath() const { return cardDatabasePath; }
|
QString getCardDatabasePath() const { return cardDatabasePath; }
|
||||||
QString getTokenDatabasePath() const { return tokenDatabasePath; }
|
QString getTokenDatabasePath() const { return tokenDatabasePath; }
|
||||||
QString getThemeName() const { return themeName; }
|
QString getThemeName() const { return themeName; }
|
||||||
|
@ -128,7 +131,6 @@ public:
|
||||||
bool getDoubleClickToPlay() const { return doubleClickToPlay; }
|
bool getDoubleClickToPlay() const { return doubleClickToPlay; }
|
||||||
bool getPlayToStack() const { return playToStack; }
|
bool getPlayToStack() const { return playToStack; }
|
||||||
bool getAnnotateTokens() const { return annotateTokens; }
|
bool getAnnotateTokens() const { return annotateTokens; }
|
||||||
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; }
|
||||||
|
@ -200,7 +202,6 @@ public slots:
|
||||||
void setDoubleClickToPlay(int _doubleClickToPlay);
|
void setDoubleClickToPlay(int _doubleClickToPlay);
|
||||||
void setPlayToStack(int _playToStack);
|
void setPlayToStack(int _playToStack);
|
||||||
void setAnnotateTokens(int _annotateTokens);
|
void setAnnotateTokens(int _annotateTokens);
|
||||||
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);
|
||||||
|
|
|
@ -15,7 +15,7 @@ void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName)
|
||||||
infoPopup->deleteLater();
|
infoPopup->deleteLater();
|
||||||
}
|
}
|
||||||
currentCardName = cardName;
|
currentCardName = cardName;
|
||||||
infoPopup = new CardInfoWidget(CardInfoWidget::ModePopUp, cardName, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
|
infoPopup = new CardInfoWidget(cardName, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
|
||||||
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
|
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
QRect screenRect = qApp->desktop()->screenGeometry(this);
|
QRect screenRect = qApp->desktop()->screenGeometry(this);
|
||||||
infoPopup->move(
|
infoPopup->move(
|
||||||
|
|
|
@ -24,15 +24,11 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include "tab_deck_editor.h"
|
#include "tab_deck_editor.h"
|
||||||
#include "window_sets.h"
|
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "pictureloader.h"
|
#include "pictureloader.h"
|
||||||
#include "carddatabasemodel.h"
|
#include "carddatabasemodel.h"
|
||||||
#include "decklistmodel.h"
|
#include "decklistmodel.h"
|
||||||
#include "cardinfowidget.h"
|
|
||||||
#include "dlg_load_deck_from_clipboard.h"
|
#include "dlg_load_deck_from_clipboard.h"
|
||||||
#include "dlg_edit_tokens.h"
|
|
||||||
#include "dlg_add_set_result.h"
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
#include "priceupdater.h"
|
#include "priceupdater.h"
|
||||||
|
@ -46,10 +42,6 @@
|
||||||
#include "cardframe.h"
|
#include "cardframe.h"
|
||||||
#include "filterbuilder.h"
|
#include "filterbuilder.h"
|
||||||
|
|
||||||
const QStringList TabDeckEditor::fileNameFilters = QStringList()
|
|
||||||
<< QObject::tr("Cockatrice card database (*.xml)")
|
|
||||||
<< QObject::tr("All files (*.*)");
|
|
||||||
|
|
||||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down)))
|
if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down)))
|
||||||
|
@ -251,9 +243,6 @@ void TabDeckEditor::createMenus()
|
||||||
aSaveDeckAs = new QAction(QString(), this);
|
aSaveDeckAs = new QAction(QString(), this);
|
||||||
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
|
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
|
||||||
|
|
||||||
aOpenCustomsetsFolder = new QAction(QString(), this);
|
|
||||||
connect(aOpenCustomsetsFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomsetsFolder()));
|
|
||||||
|
|
||||||
aLoadDeckFromClipboard = new QAction(QString(), this);
|
aLoadDeckFromClipboard = new QAction(QString(), this);
|
||||||
connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard()));
|
connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard()));
|
||||||
|
|
||||||
|
@ -269,17 +258,13 @@ void TabDeckEditor::createMenus()
|
||||||
aClose = new QAction(QString(), this);
|
aClose = new QAction(QString(), this);
|
||||||
connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest()));
|
connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest()));
|
||||||
|
|
||||||
aOpenCustomFolder = new QAction(QString(), this);
|
aClearFilterAll = new QAction(QString(), this);
|
||||||
connect(aOpenCustomFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomFolder()));
|
aClearFilterAll->setIcon(QPixmap("theme:icons/clearsearch"));
|
||||||
|
connect(aClearFilterAll, SIGNAL(triggered()), this, SLOT(actClearFilterAll()));
|
||||||
|
|
||||||
aAddCustomSet = new QAction(QString(), this);
|
aClearFilterOne = new QAction(QString(), this);
|
||||||
connect(aAddCustomSet, SIGNAL(triggered()), this, SLOT(actAddCustomSet()));
|
aClearFilterOne->setIcon(QPixmap("theme:icons/decrement"));
|
||||||
|
connect(aClearFilterOne, SIGNAL(triggered()), this, SLOT(actClearFilterOne()));
|
||||||
aEditSets = new QAction(QString(), this);
|
|
||||||
connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
|
|
||||||
|
|
||||||
aEditTokens = new QAction(QString(), this);
|
|
||||||
connect(aEditTokens, SIGNAL(triggered()), this, SLOT(actEditTokens()));
|
|
||||||
|
|
||||||
deckMenu = new QMenu(this);
|
deckMenu = new QMenu(this);
|
||||||
deckMenu->addAction(aNewDeck);
|
deckMenu->addAction(aNewDeck);
|
||||||
|
@ -291,34 +276,14 @@ void TabDeckEditor::createMenus()
|
||||||
deckMenu->addAction(aSaveDeckToClipboard);
|
deckMenu->addAction(aSaveDeckToClipboard);
|
||||||
deckMenu->addSeparator();
|
deckMenu->addSeparator();
|
||||||
deckMenu->addAction(aPrintDeck);
|
deckMenu->addAction(aPrintDeck);
|
||||||
deckMenu->addSeparator();
|
|
||||||
deckMenu->addAction(aAnalyzeDeck);
|
deckMenu->addAction(aAnalyzeDeck);
|
||||||
deckMenu->addSeparator();
|
deckMenu->addSeparator();
|
||||||
|
deckMenu->addAction(aClearFilterOne);
|
||||||
|
deckMenu->addAction(aClearFilterAll);
|
||||||
|
deckMenu->addSeparator();
|
||||||
deckMenu->addAction(aClose);
|
deckMenu->addAction(aClose);
|
||||||
addTabMenu(deckMenu);
|
addTabMenu(deckMenu);
|
||||||
|
|
||||||
aClearFilterAll = new QAction(QString(), this);
|
|
||||||
aClearFilterAll->setIcon(QPixmap("theme:icons/clearsearch"));
|
|
||||||
connect(aClearFilterAll, SIGNAL(triggered()), this, SLOT(actClearFilterAll()));
|
|
||||||
|
|
||||||
aClearFilterOne = new QAction(QString(), this);
|
|
||||||
aClearFilterOne->setIcon(QPixmap("theme:icons/decrement"));
|
|
||||||
connect(aClearFilterOne, SIGNAL(triggered()), this, SLOT(actClearFilterOne()));
|
|
||||||
|
|
||||||
dbMenu = new QMenu(this);
|
|
||||||
dbMenu->addAction(aEditSets);
|
|
||||||
dbMenu->addAction(aEditTokens);
|
|
||||||
dbMenu->addSeparator();
|
|
||||||
dbMenu->addAction(aClearFilterOne);
|
|
||||||
dbMenu->addAction(aClearFilterAll);
|
|
||||||
dbMenu->addSeparator();
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
|
||||||
dbMenu->addAction(aOpenCustomFolder);
|
|
||||||
dbMenu->addAction(aOpenCustomsetsFolder);
|
|
||||||
#endif
|
|
||||||
dbMenu->addAction(aAddCustomSet);
|
|
||||||
addTabMenu(dbMenu);
|
|
||||||
|
|
||||||
viewMenu = new QMenu(this);
|
viewMenu = new QMenu(this);
|
||||||
|
|
||||||
cardInfoDockMenu = viewMenu->addMenu(QString());
|
cardInfoDockMenu = viewMenu->addMenu(QString());
|
||||||
|
@ -392,7 +357,12 @@ void TabDeckEditor::createCentralFrame()
|
||||||
databaseView->setSortingEnabled(true);
|
databaseView->setSortingEnabled(true);
|
||||||
databaseView->sortByColumn(0, Qt::AscendingOrder);
|
databaseView->sortByColumn(0, Qt::AscendingOrder);
|
||||||
databaseView->setModel(databaseDisplayModel);
|
databaseView->setModel(databaseDisplayModel);
|
||||||
databaseView->resizeColumnToContents(0);
|
databaseView->header()->setStretchLastSection(false);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
databaseView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
|
#else
|
||||||
|
databaseView->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||||
|
#endif
|
||||||
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
|
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
|
||||||
connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard()));
|
connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard()));
|
||||||
searchEdit->setTreeView(databaseView);
|
searchEdit->setTreeView(databaseView);
|
||||||
|
@ -497,9 +467,6 @@ void TabDeckEditor::refreshShortcuts()
|
||||||
aPrintDeck->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aPrintDeck"));
|
aPrintDeck->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aPrintDeck"));
|
||||||
aAnalyzeDeck->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aAnalyzeDeck"));
|
aAnalyzeDeck->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aAnalyzeDeck"));
|
||||||
aClose->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClose"));
|
aClose->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClose"));
|
||||||
aOpenCustomFolder->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aOpenCustomFolder"));
|
|
||||||
aEditSets->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aEditSets"));
|
|
||||||
aEditTokens->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aEditTokens"));
|
|
||||||
aResetLayout->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aResetLayout"));
|
aResetLayout->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aResetLayout"));
|
||||||
aClearFilterAll->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterAll"));
|
aClearFilterAll->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterAll"));
|
||||||
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
aClearFilterOne->setShortcuts(settingsCache->shortcuts().getShortcut("TabDeckEditor/aClearFilterOne"));
|
||||||
|
@ -561,7 +528,6 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(checkFirstRunDetected()));
|
|
||||||
QTimer::singleShot(0, this, SLOT(loadLayout()));
|
QTimer::singleShot(0, this, SLOT(loadLayout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,9 +558,6 @@ void TabDeckEditor::retranslateUi()
|
||||||
aSaveDeckToClipboard->setText(tr("Save deck to clip&board"));
|
aSaveDeckToClipboard->setText(tr("Save deck to clip&board"));
|
||||||
aPrintDeck->setText(tr("&Print deck..."));
|
aPrintDeck->setText(tr("&Print deck..."));
|
||||||
aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net"));
|
aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net"));
|
||||||
aOpenCustomFolder->setText(tr("Open custom image folder"));
|
|
||||||
aOpenCustomsetsFolder->setText(tr("Open custom sets folder"));
|
|
||||||
aAddCustomSet->setText(tr("Add custom sets/cards"));
|
|
||||||
aClose->setText(tr("&Close"));
|
aClose->setText(tr("&Close"));
|
||||||
|
|
||||||
aAddCard->setText(tr("Add card to &maindeck"));
|
aAddCard->setText(tr("Add card to &maindeck"));
|
||||||
|
@ -607,10 +570,6 @@ void TabDeckEditor::retranslateUi()
|
||||||
aDecrement->setText(tr("&Decrement number"));
|
aDecrement->setText(tr("&Decrement number"));
|
||||||
|
|
||||||
deckMenu->setTitle(tr("&Deck Editor"));
|
deckMenu->setTitle(tr("&Deck Editor"));
|
||||||
dbMenu->setTitle(tr("C&ard Database"));
|
|
||||||
|
|
||||||
aEditSets->setText(tr("&Edit sets..."));
|
|
||||||
aEditTokens->setText(tr("Edit &tokens..."));
|
|
||||||
|
|
||||||
cardInfoDock->setWindowTitle(tr("Card Info"));
|
cardInfoDock->setWindowTitle(tr("Card Info"));
|
||||||
deckDock->setWindowTitle(tr("Deck"));
|
deckDock->setWindowTitle(tr("Deck"));
|
||||||
|
@ -822,117 +781,6 @@ void TabDeckEditor::actAnalyzeDeck()
|
||||||
interface->analyzeDeck(deckModel->getDeckList());
|
interface->analyzeDeck(deckModel->getDeckList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TabDeckEditor::actOpenCustomFolder() {
|
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
|
||||||
|
|
||||||
QStringList scriptArgs;
|
|
||||||
scriptArgs << QLatin1String("-e");
|
|
||||||
scriptArgs << QString::fromLatin1("tell application \"Finder\" to open POSIX file \"%1\"").arg(settingsCache->getPicsPath() + "/custom/");
|
|
||||||
scriptArgs << QLatin1String("-e");
|
|
||||||
scriptArgs << QLatin1String("tell application \"Finder\" to activate");
|
|
||||||
|
|
||||||
QProcess::execute("/usr/bin/osascript", scriptArgs);
|
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
QStringList args;
|
|
||||||
QString pathToFolder = settingsCache->getPicsPath().append("/custom");
|
|
||||||
args << QDir::toNativeSeparators(pathToFolder);
|
|
||||||
QProcess::startDetached("explorer", args);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::actOpenCustomsetsFolder() {
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
|
||||||
|
|
||||||
QStringList scriptArgs;
|
|
||||||
scriptArgs << QLatin1String("-e");
|
|
||||||
scriptArgs << QString::fromLatin1("tell application \"Finder\" to open POSIX file \"%1\"").arg(dataDir + "/customsets/");
|
|
||||||
scriptArgs << QLatin1String("-e");
|
|
||||||
scriptArgs << QLatin1String("tell application \"Finder\" to activate");
|
|
||||||
|
|
||||||
QProcess::execute("/usr/bin/osascript", scriptArgs);
|
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
QStringList args;
|
|
||||||
dataDir.append("/customsets");
|
|
||||||
args << QDir::toNativeSeparators(dataDir);
|
|
||||||
QProcess::startDetached("explorer", args);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::actAddCustomSet()
|
|
||||||
{
|
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
|
||||||
QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QFileDialog dialog(this, tr("Load sets/cards"));
|
|
||||||
dialog.setDirectory(dataDir);
|
|
||||||
dialog.setNameFilters(TabDeckEditor::fileNameFilters);
|
|
||||||
if (!dialog.exec())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
|
||||||
|
|
||||||
if (!QFile::exists(fileName)) {
|
|
||||||
DlgAddSetResult dlg(this, false, QString("Selected file cannot be found."));
|
|
||||||
dlg.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir dir(dataDir + "/customsets");
|
|
||||||
int nextPrefix = getNextCustomSetPrefix(dir);
|
|
||||||
|
|
||||||
bool res = QFile::copy(
|
|
||||||
fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") +
|
|
||||||
QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName()
|
|
||||||
);
|
|
||||||
|
|
||||||
DlgAddSetResult dlg(this, res, QString());
|
|
||||||
dlg.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
int TabDeckEditor::getNextCustomSetPrefix(QDir dataDir) {
|
|
||||||
QStringList files = dataDir.entryList();
|
|
||||||
int maxIndex = 0;
|
|
||||||
|
|
||||||
QStringList::const_iterator filesIterator;
|
|
||||||
for (filesIterator = files.constBegin(); filesIterator != files.constEnd(); ++filesIterator) {
|
|
||||||
int fileIndex = (*filesIterator).split(".").at(0).toInt();
|
|
||||||
if (fileIndex > maxIndex)
|
|
||||||
maxIndex = fileIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxIndex + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::actEditSets()
|
|
||||||
{
|
|
||||||
WndSets *w = new WndSets;
|
|
||||||
w->setWindowModality(Qt::WindowModal);
|
|
||||||
w->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::actEditTokens()
|
|
||||||
{
|
|
||||||
DlgEditTokens dlg(databaseModel);
|
|
||||||
dlg.exec();
|
|
||||||
db->saveToFile(settingsCache->getTokenDatabasePath(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::actClearFilterAll()
|
void TabDeckEditor::actClearFilterAll()
|
||||||
{
|
{
|
||||||
databaseDisplayModel->clearFilterAll();
|
databaseDisplayModel->clearFilterAll();
|
||||||
|
@ -1158,15 +1006,6 @@ void TabDeckEditor::filterRemove(QAction *action) {
|
||||||
filterModel->removeRow(idx.row(), idx.parent());
|
filterModel->removeRow(idx.row(), idx.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::checkFirstRunDetected()
|
|
||||||
{
|
|
||||||
if(db->hasDetectedFirstRun())
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("Welcome"), tr("Hi! It seems like you're running this version of Cockatrice for the first time.\nAll the sets in the card database have been enabled.\nRead more about changing the set order or disabling specific sets and consequent effects in the \"Edit Sets\" window."));
|
|
||||||
actEditSets();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method uses to sync docks state with menu items state
|
// Method uses to sync docks state with menu items state
|
||||||
bool TabDeckEditor::eventFilter(QObject * o, QEvent * e)
|
bool TabDeckEditor::eventFilter(QObject * o, QEvent * e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,12 +53,6 @@ class TabDeckEditor : public Tab {
|
||||||
void actSaveDeckToClipboard();
|
void actSaveDeckToClipboard();
|
||||||
void actPrintDeck();
|
void actPrintDeck();
|
||||||
void actAnalyzeDeck();
|
void actAnalyzeDeck();
|
||||||
void actOpenCustomFolder();
|
|
||||||
void actOpenCustomsetsFolder();
|
|
||||||
void actAddCustomSet();
|
|
||||||
|
|
||||||
void actEditSets();
|
|
||||||
void actEditTokens();
|
|
||||||
|
|
||||||
void actClearFilterAll();
|
void actClearFilterAll();
|
||||||
void actClearFilterOne();
|
void actClearFilterOne();
|
||||||
|
@ -90,13 +84,11 @@ class TabDeckEditor : public Tab {
|
||||||
void dockFloatingTriggered();
|
void dockFloatingTriggered();
|
||||||
void dockTopLevelChanged(bool topLevel);
|
void dockTopLevelChanged(bool topLevel);
|
||||||
private:
|
private:
|
||||||
static const QStringList fileNameFilters;
|
|
||||||
CardInfo *currentCardInfo() const;
|
CardInfo *currentCardInfo() const;
|
||||||
void addCardHelper(QString zoneName);
|
void addCardHelper(QString zoneName);
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
void decrementCardHelper(QString zoneName);
|
void decrementCardHelper(QString zoneName);
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
int getNextCustomSetPrefix(QDir dataDir);
|
|
||||||
|
|
||||||
CardDatabaseModel *databaseModel;
|
CardDatabaseModel *databaseModel;
|
||||||
CardDatabaseDisplayModel *databaseDisplayModel;
|
CardDatabaseDisplayModel *databaseDisplayModel;
|
||||||
|
@ -119,9 +111,9 @@ private:
|
||||||
QTreeView *filterView;
|
QTreeView *filterView;
|
||||||
QWidget *filterBox;
|
QWidget *filterBox;
|
||||||
|
|
||||||
QMenu *deckMenu, *dbMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu;
|
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
|
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose;
|
||||||
QAction *aEditSets, *aEditTokens, *aClearFilterAll, *aClearFilterOne;
|
QAction *aClearFilterAll, *aClearFilterOne;
|
||||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;// *aUpdatePrices;
|
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;// *aUpdatePrices;
|
||||||
QAction *aResetLayout;
|
QAction *aResetLayout;
|
||||||
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible, *aFilterDockFloating;
|
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible, *aFilterDockFloating;
|
||||||
|
@ -149,7 +141,6 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
void checkFirstRunDetected();
|
|
||||||
signals:
|
signals:
|
||||||
void deckEditorClosing(TabDeckEditor *tab);
|
void deckEditorClosing(TabDeckEditor *tab);
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
|
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
#include <QtGui/qtextdocument.h> // for Qt::escape()
|
#include <QtGui/qtextdocument.h> // for Qt::escape()
|
||||||
|
#else
|
||||||
|
#include <QtConcurrent>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -51,6 +53,9 @@
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
#include "version_string.h"
|
#include "version_string.h"
|
||||||
#include "update_checker.h"
|
#include "update_checker.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include "window_sets.h"
|
||||||
|
#include "dlg_edit_tokens.h"
|
||||||
|
|
||||||
#include "pb/game_replay.pb.h"
|
#include "pb/game_replay.pb.h"
|
||||||
#include "pb/room_commands.pb.h"
|
#include "pb/room_commands.pb.h"
|
||||||
|
@ -69,6 +74,9 @@
|
||||||
#define DOWNLOAD_URL "https://dl.bintray.com/cockatrice/Cockatrice/"
|
#define DOWNLOAD_URL "https://dl.bintray.com/cockatrice/Cockatrice/"
|
||||||
|
|
||||||
const QString MainWindow::appName = "Cockatrice";
|
const QString MainWindow::appName = "Cockatrice";
|
||||||
|
const QStringList MainWindow::fileNameFilters = QStringList()
|
||||||
|
<< QObject::tr("Cockatrice card database (*.xml)")
|
||||||
|
<< QObject::tr("All files (*.*)");
|
||||||
|
|
||||||
void MainWindow::updateTabMenu(const QList<QMenu *> &newMenuList)
|
void MainWindow::updateTabMenu(const QList<QMenu *> &newMenuList)
|
||||||
{
|
{
|
||||||
|
@ -507,6 +515,13 @@ void MainWindow::retranslateUi()
|
||||||
cockatriceMenu->setTitle(tr("&Cockatrice"));
|
cockatriceMenu->setTitle(tr("&Cockatrice"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
dbMenu->setTitle(tr("C&ard Database"));
|
||||||
|
aOpenCustomFolder->setText(tr("Open custom image folder"));
|
||||||
|
aOpenCustomsetsFolder->setText(tr("Open custom sets folder"));
|
||||||
|
aAddCustomSet->setText(tr("Add custom sets/cards"));
|
||||||
|
aEditSets->setText(tr("&Edit sets..."));
|
||||||
|
aEditTokens->setText(tr("Edit &tokens..."));
|
||||||
|
|
||||||
aAbout->setText(tr("&About Cockatrice"));
|
aAbout->setText(tr("&About Cockatrice"));
|
||||||
aUpdate->setText(tr("&Update Cockatrice"));
|
aUpdate->setText(tr("&Update Cockatrice"));
|
||||||
helpMenu->setTitle(tr("&Help"));
|
helpMenu->setTitle(tr("&Help"));
|
||||||
|
@ -545,6 +560,21 @@ void MainWindow::createActions()
|
||||||
aCheckCardUpdates = new QAction(this);
|
aCheckCardUpdates = new QAction(this);
|
||||||
connect(aCheckCardUpdates, SIGNAL(triggered()), this, SLOT(actCheckCardUpdates()));
|
connect(aCheckCardUpdates, SIGNAL(triggered()), this, SLOT(actCheckCardUpdates()));
|
||||||
|
|
||||||
|
aOpenCustomsetsFolder = new QAction(QString(), this);
|
||||||
|
connect(aOpenCustomsetsFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomsetsFolder()));
|
||||||
|
|
||||||
|
aOpenCustomFolder = new QAction(QString(), this);
|
||||||
|
connect(aOpenCustomFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomFolder()));
|
||||||
|
|
||||||
|
aAddCustomSet = new QAction(QString(), this);
|
||||||
|
connect(aAddCustomSet, SIGNAL(triggered()), this, SLOT(actAddCustomSet()));
|
||||||
|
|
||||||
|
aEditSets = new QAction(QString(), this);
|
||||||
|
connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
|
||||||
|
|
||||||
|
aEditTokens = new QAction(QString(), this);
|
||||||
|
connect(aEditTokens, SIGNAL(triggered()), this, SLOT(actEditTokens()));
|
||||||
|
|
||||||
#if defined(__APPLE__) /* For OSX */
|
#if defined(__APPLE__) /* For OSX */
|
||||||
aSettings->setMenuRole(QAction::PreferencesRole);
|
aSettings->setMenuRole(QAction::PreferencesRole);
|
||||||
aExit->setMenuRole(QAction::QuitRole);
|
aExit->setMenuRole(QAction::QuitRole);
|
||||||
|
@ -580,6 +610,16 @@ void MainWindow::createMenus()
|
||||||
cockatriceMenu->addSeparator();
|
cockatriceMenu->addSeparator();
|
||||||
cockatriceMenu->addAction(aExit);
|
cockatriceMenu->addAction(aExit);
|
||||||
|
|
||||||
|
dbMenu = menuBar()->addMenu(QString());
|
||||||
|
dbMenu->addAction(aEditSets);
|
||||||
|
dbMenu->addAction(aEditTokens);
|
||||||
|
dbMenu->addSeparator();
|
||||||
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||||
|
dbMenu->addAction(aOpenCustomFolder);
|
||||||
|
dbMenu->addAction(aOpenCustomsetsFolder);
|
||||||
|
#endif
|
||||||
|
dbMenu->addAction(aAddCustomSet);
|
||||||
|
|
||||||
helpMenu = menuBar()->addMenu(QString());
|
helpMenu = menuBar()->addMenu(QString());
|
||||||
helpMenu->addAction(aAbout);
|
helpMenu->addAction(aAbout);
|
||||||
helpMenu->addAction(aUpdate);
|
helpMenu->addAction(aUpdate);
|
||||||
|
@ -635,6 +675,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
||||||
|
connect(db, SIGNAL(cardDatabaseLoadingFailed()), this, SLOT(cardDatabaseLoadingFailed()));
|
||||||
|
connect(db, SIGNAL(cardDatabaseNewSetsFound(int)), this, SLOT(cardDatabaseNewSetsFound(int)));
|
||||||
|
connect(db, SIGNAL(cardDatabaseAllNewSetsEnabled()), this, SLOT(cardDatabaseAllNewSetsEnabled()));
|
||||||
|
QtConcurrent::run(db, &CardDatabase::loadCardDatabases);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -727,6 +772,59 @@ void MainWindow::showWindowIfHidden() {
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::cardDatabaseLoadingFailed()
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Card database"));
|
||||||
|
msgBox.setIcon(QMessageBox::Question);
|
||||||
|
msgBox.setText(tr("Cockatrice is unable to load the card database.\n"
|
||||||
|
"Do you want to update your card database now?\n"
|
||||||
|
"If unsure or first time user, choose \"Yes\""));
|
||||||
|
|
||||||
|
QPushButton *yesButton = msgBox.addButton(tr("Yes"), QMessageBox::YesRole);
|
||||||
|
msgBox.addButton(tr("No"), QMessageBox::NoRole);
|
||||||
|
QPushButton *settingsButton = msgBox.addButton(tr("Open settings"), QMessageBox::ActionRole);
|
||||||
|
msgBox.setDefaultButton(yesButton);
|
||||||
|
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
if (msgBox.clickedButton() == yesButton) {
|
||||||
|
actCheckCardUpdates();
|
||||||
|
} else if (msgBox.clickedButton() == settingsButton) {
|
||||||
|
actSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::cardDatabaseNewSetsFound(int numUnknownSets)
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("New sets found"));
|
||||||
|
msgBox.setIcon(QMessageBox::Question);
|
||||||
|
msgBox.setText(tr("%1 new set(s) have been found in the card database.\n"
|
||||||
|
"Do you want to enable them?").arg(numUnknownSets));
|
||||||
|
|
||||||
|
QPushButton *yesButton = msgBox.addButton(tr("Yes"), QMessageBox::YesRole);
|
||||||
|
QPushButton *noButton = msgBox.addButton(tr("No"), QMessageBox::NoRole);
|
||||||
|
QPushButton *settingsButton = msgBox.addButton(tr("View sets"), QMessageBox::ActionRole);
|
||||||
|
msgBox.setDefaultButton(yesButton);
|
||||||
|
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
if (msgBox.clickedButton() == yesButton) {
|
||||||
|
db->enableAllUnknownSets();
|
||||||
|
} else if (msgBox.clickedButton() == noButton) {
|
||||||
|
db->markAllSetsAsKnown();
|
||||||
|
} else if (msgBox.clickedButton() == settingsButton) {
|
||||||
|
actEditSets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::cardDatabaseAllNewSetsEnabled()
|
||||||
|
{
|
||||||
|
QMessageBox::information(this, tr("Welcome"), tr("Hi! It seems like you're running this version of Cockatrice for the first time.\nAll the sets in the card database have been enabled.\nRead more about changing the set order or disabling specific sets and consequent effects in the \"Edit Sets\" window."));
|
||||||
|
actEditSets();
|
||||||
|
}
|
||||||
|
|
||||||
/* CARD UPDATER */
|
/* CARD UPDATER */
|
||||||
|
|
||||||
void MainWindow::actCheckCardUpdates()
|
void MainWindow::actCheckCardUpdates()
|
||||||
|
@ -811,11 +909,9 @@ void MainWindow::cardUpdateFinished(int, QProcess::ExitStatus)
|
||||||
cardUpdateProcess->deleteLater();
|
cardUpdateProcess->deleteLater();
|
||||||
cardUpdateProcess = 0;
|
cardUpdateProcess = 0;
|
||||||
|
|
||||||
QMessageBox::information(this, tr("Information"), tr("Update completed successfully. Cockatrice will now reload the card database."));
|
QMessageBox::information(this, tr("Information"), tr("Update completed successfully.\nCockatrice will now reload the card database."));
|
||||||
|
|
||||||
// this will force a database reload
|
QtConcurrent::run(db, &CardDatabase::loadCardDatabases);
|
||||||
settingsCache->setCardDatabasePath(settingsCache->getCardDatabasePath());
|
|
||||||
settingsCache->setTokenDatabasePath(settingsCache->getTokenDatabasePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::refreshShortcuts()
|
void MainWindow::refreshShortcuts()
|
||||||
|
@ -830,9 +926,107 @@ void MainWindow::refreshShortcuts()
|
||||||
aSettings->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aSettings"));
|
aSettings->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aSettings"));
|
||||||
aExit->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aExit"));
|
aExit->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aExit"));
|
||||||
aCheckCardUpdates->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aCheckCardUpdates"));
|
aCheckCardUpdates->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aCheckCardUpdates"));
|
||||||
|
aOpenCustomFolder->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aOpenCustomFolder"));
|
||||||
|
aEditSets->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aEditSets"));
|
||||||
|
aEditTokens->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aEditTokens"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::notifyUserAboutUpdate()
|
void MainWindow::notifyUserAboutUpdate()
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, tr("Information"), tr("Your client appears to be missing features that the server supports.\nThis usually means that your client version is out of date, please check to see if there is a new client available for download."));
|
QMessageBox::information(this, tr("Information"), tr("Your client appears to be missing features that the server supports.\nThis usually means that your client version is out of date, please check to see if there is a new client available for download."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::actOpenCustomFolder()
|
||||||
|
{
|
||||||
|
QString dir = settingsCache->getCustomPicsPath();
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
QStringList scriptArgs;
|
||||||
|
scriptArgs << QLatin1String("-e");
|
||||||
|
scriptArgs << QString::fromLatin1("tell application \"Finder\" to open POSIX file \"%1\"").arg(dir);
|
||||||
|
scriptArgs << QLatin1String("-e");
|
||||||
|
scriptArgs << QLatin1String("tell application \"Finder\" to activate");
|
||||||
|
|
||||||
|
QProcess::execute("/usr/bin/osascript", scriptArgs);
|
||||||
|
#elif defined(Q_OS_WIN)
|
||||||
|
QStringList args;
|
||||||
|
args << QDir::toNativeSeparators(dir);
|
||||||
|
QProcess::startDetached("explorer", args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::actOpenCustomsetsFolder()
|
||||||
|
{
|
||||||
|
QString dir = settingsCache->getCustomCardDatabasePath();
|
||||||
|
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
QStringList scriptArgs;
|
||||||
|
scriptArgs << QLatin1String("-e");
|
||||||
|
scriptArgs << QString::fromLatin1("tell application \"Finder\" to open POSIX file \"%1\"").arg(dir);
|
||||||
|
scriptArgs << QLatin1String("-e");
|
||||||
|
scriptArgs << QLatin1String("tell application \"Finder\" to activate");
|
||||||
|
|
||||||
|
QProcess::execute("/usr/bin/osascript", scriptArgs);
|
||||||
|
#elif defined(Q_OS_WIN)
|
||||||
|
QStringList args;
|
||||||
|
args << QDir::toNativeSeparators(dir);
|
||||||
|
QProcess::startDetached("explorer", args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::actAddCustomSet()
|
||||||
|
{
|
||||||
|
QFileDialog dialog(this, tr("Load sets/cards"), QDir::homePath());
|
||||||
|
dialog.setNameFilters(MainWindow::fileNameFilters);
|
||||||
|
if (!dialog.exec())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
|
|
||||||
|
if (!QFile::exists(fileName)) {
|
||||||
|
QMessageBox::warning(this, tr("Load sets/cards"), tr("Selected file cannot be found."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir dir = settingsCache->getCustomCardDatabasePath();
|
||||||
|
int nextPrefix = getNextCustomSetPrefix(dir);
|
||||||
|
|
||||||
|
bool res = QFile::copy(
|
||||||
|
fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") +
|
||||||
|
QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
QMessageBox::information(this, tr("Load sets/cards"), tr("The new sets/cards have been added successfully.\nCockatrice will now reload the card database."));
|
||||||
|
QtConcurrent::run(db, &CardDatabase::loadCardDatabases);
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(this, tr("Load sets/cards"), tr("Sets/cards failed to import."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::getNextCustomSetPrefix(QDir dataDir) {
|
||||||
|
QStringList files = dataDir.entryList();
|
||||||
|
int maxIndex = 0;
|
||||||
|
|
||||||
|
QStringList::const_iterator filesIterator;
|
||||||
|
for (filesIterator = files.constBegin(); filesIterator != files.constEnd(); ++filesIterator) {
|
||||||
|
int fileIndex = (*filesIterator).split(".").at(0).toInt();
|
||||||
|
if (fileIndex > maxIndex)
|
||||||
|
maxIndex = fileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::actEditSets()
|
||||||
|
{
|
||||||
|
WndSets *w = new WndSets;
|
||||||
|
w->setWindowModality(Qt::WindowModal);
|
||||||
|
w->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::actEditTokens()
|
||||||
|
{
|
||||||
|
DlgEditTokens dlg;
|
||||||
|
dlg.exec();
|
||||||
|
db->saveCustomTokensToFile();
|
||||||
|
}
|
||||||
|
|
|
@ -79,8 +79,19 @@ private slots:
|
||||||
void cardUpdateError(QProcess::ProcessError err);
|
void cardUpdateError(QProcess::ProcessError err);
|
||||||
void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
void refreshShortcuts();
|
void refreshShortcuts();
|
||||||
|
void cardDatabaseLoadingFailed();
|
||||||
|
void cardDatabaseNewSetsFound(int numUnknownSets);
|
||||||
|
void cardDatabaseAllNewSetsEnabled();
|
||||||
|
|
||||||
|
void actOpenCustomFolder();
|
||||||
|
void actOpenCustomsetsFolder();
|
||||||
|
void actAddCustomSet();
|
||||||
|
|
||||||
|
void actEditSets();
|
||||||
|
void actEditTokens();
|
||||||
private:
|
private:
|
||||||
static const QString appName;
|
static const QString appName;
|
||||||
|
static const QStringList fileNameFilters;
|
||||||
void setClientStatusTitle();
|
void setClientStatusTitle();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void createActions();
|
void createActions();
|
||||||
|
@ -88,13 +99,15 @@ private:
|
||||||
|
|
||||||
void createTrayIcon();
|
void createTrayIcon();
|
||||||
void createTrayActions();
|
void createTrayActions();
|
||||||
|
int getNextCustomSetPrefix(QDir dataDir);
|
||||||
// TODO: add a preference item to choose updater name for other games
|
// TODO: add a preference item to choose updater name for other games
|
||||||
inline QString getCardUpdaterBinaryName() { return "oracle"; };
|
inline QString getCardUpdaterBinaryName() { return "oracle"; };
|
||||||
|
|
||||||
QList<QMenu *> tabMenus;
|
QList<QMenu *> tabMenus;
|
||||||
QMenu *cockatriceMenu, *helpMenu;
|
QMenu *cockatriceMenu, *dbMenu, *helpMenu;
|
||||||
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
|
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
|
||||||
*aAbout, *aCheckCardUpdates, *aRegister, *aUpdate;
|
*aAbout, *aCheckCardUpdates, *aRegister, *aUpdate;
|
||||||
|
QAction *aEditSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
|
|
||||||
QMenu *trayIconMenu;
|
QMenu *trayIconMenu;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#
|
#
|
||||||
# provides the common library
|
# provides the common library
|
||||||
|
|
||||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
|
||||||
add_subdirectory(pb)
|
add_subdirectory(pb)
|
||||||
|
|
||||||
SET(common_SOURCES
|
SET(common_SOURCES
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
#
|
#
|
||||||
# provides the protobuf interfaces
|
# provides the protobuf interfaces
|
||||||
|
|
||||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
|
||||||
|
|
||||||
SET(PROTO_FILES
|
SET(PROTO_FILES
|
||||||
admin_commands.proto
|
admin_commands.proto
|
||||||
card_attributes.proto
|
card_attributes.proto
|
||||||
|
|
|
@ -48,19 +48,7 @@ OracleWizard::OracleWizard(QWidget *parent)
|
||||||
settings = new QSettings(settingsCache->getSettingsPath()+"global.ini",QSettings::IniFormat, this);
|
settings = new QSettings(settingsCache->getSettingsPath()+"global.ini",QSettings::IniFormat, this);
|
||||||
connect(settingsCache, SIGNAL(langChanged()), this, SLOT(updateLanguage()));
|
connect(settingsCache, SIGNAL(langChanged()), this, SLOT(updateLanguage()));
|
||||||
|
|
||||||
QString dataDir;
|
importer = new OracleImporter(settingsCache->getDataPath(), this);
|
||||||
|
|
||||||
#ifndef PORTABLE_BUILD
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
dataDir.append("data");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
importer = new OracleImporter(dataDir, this);
|
|
||||||
|
|
||||||
addPage(new IntroPage);
|
addPage(new IntroPage);
|
||||||
addPage(new LoadSetsPage);
|
addPage(new LoadSetsPage);
|
||||||
|
@ -521,47 +509,19 @@ void SaveSetsPage::updateTotalProgress(int cardsImported, int /* setIndex */, co
|
||||||
bool SaveSetsPage::validatePage()
|
bool SaveSetsPage::validatePage()
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString dataDir;
|
QString defaultPath = settingsCache->getCardDatabasePath();
|
||||||
#ifndef PORTABLE_BUILD
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
dataDir = qApp->applicationDirPath() + "/data";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PORTABLE_BUILD
|
|
||||||
QSettings* settings = new QSettings("settings/global.ini",QSettings::IniFormat,this);
|
|
||||||
QString defaultPath = "data/cards.xml";
|
|
||||||
settings->setValue("paths/carddatabase", defaultPath);
|
|
||||||
#else
|
|
||||||
QSettings* settings = new QSettings(settingsCache->getSettingsPath()+"global.ini",QSettings::IniFormat,this);
|
|
||||||
QString defaultPath = settings->value("paths/carddatabase").toString();
|
|
||||||
#endif
|
|
||||||
QString windowName = tr("Save card database");
|
QString windowName = tr("Save card database");
|
||||||
QString fileType = tr("XML; card database (*.xml)");
|
QString fileType = tr("XML; card database (*.xml)");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
QString fileName;
|
QString fileName;
|
||||||
if (defaultPath.isEmpty()) {
|
if (defaultPathCheckBox->isChecked())
|
||||||
if (defaultPathCheckBox->isChecked())
|
fileName = defaultPath;
|
||||||
fileName = dataDir + "/cards.xml";
|
else
|
||||||
else
|
fileName = QFileDialog::getSaveFileName(this, windowName, defaultPath, fileType);
|
||||||
fileName = QFileDialog::getSaveFileName(this, windowName, dataDir + "/cards.xml", fileType);
|
|
||||||
|
|
||||||
settings->setValue("paths/carddatabase", fileName);
|
if (fileName.isEmpty())
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (defaultPathCheckBox->isChecked())
|
|
||||||
fileName = defaultPath;
|
|
||||||
else
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, windowName, defaultPath, fileType);
|
|
||||||
}
|
|
||||||
if (fileName.isEmpty()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QDir fileDir(fi.path());
|
QDir fileDir(fi.path());
|
||||||
|
@ -741,55 +701,24 @@ void SaveTokensPage::retranslateUi()
|
||||||
"Press \"Save\" to save the imported tokens to the Cockatrice tokens database."));
|
"Press \"Save\" to save the imported tokens to the Cockatrice tokens database."));
|
||||||
|
|
||||||
defaultPathCheckBox->setText(tr("Save to the default path (recommended)"));
|
defaultPathCheckBox->setText(tr("Save to the default path (recommended)"));
|
||||||
#ifdef PORTABLE_BUILD
|
|
||||||
defaultPathCheckBox->setEnabled(false);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SaveTokensPage::validatePage()
|
bool SaveTokensPage::validatePage()
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString dataDir;
|
QString defaultPath = settingsCache->getTokenDatabasePath();
|
||||||
#ifndef PORTABLE_BUILD
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
||||||
#else
|
|
||||||
dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
dataDir = qApp->applicationDirPath() + "/data";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PORTABLE_BUILD
|
|
||||||
QSettings* settings = new QSettings("settings/global.ini",QSettings::IniFormat,this);
|
|
||||||
QString defaultPath = "data/tokens.xml";
|
|
||||||
settings->setValue("paths/tokendatabase", defaultPath);
|
|
||||||
#else
|
|
||||||
QSettings* settings = new QSettings(settingsCache->getSettingsPath()+"global.ini",QSettings::IniFormat,this);
|
|
||||||
QString defaultPath = settings->value("paths/tokendatabase").toString();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QString windowName = tr("Save token database");
|
QString windowName = tr("Save token database");
|
||||||
QString fileType = tr("XML; token database (*.xml)");
|
QString fileType = tr("XML; token database (*.xml)");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
QString fileName;
|
QString fileName;
|
||||||
if (defaultPath.isEmpty()) {
|
if (defaultPathCheckBox->isChecked())
|
||||||
if (defaultPathCheckBox->isChecked())
|
fileName = defaultPath;
|
||||||
fileName = dataDir + "/tokens.xml";
|
else
|
||||||
else
|
fileName = QFileDialog::getSaveFileName(this, windowName, defaultPath, fileType);
|
||||||
fileName = QFileDialog::getSaveFileName(this, windowName, dataDir + "/tokens.xml", fileType);
|
|
||||||
settings->setValue("paths/tokendatabase", fileName);
|
if (fileName.isEmpty())
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (defaultPathCheckBox->isChecked())
|
|
||||||
fileName = defaultPath;
|
|
||||||
else
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, windowName, defaultPath, fileType);
|
|
||||||
}
|
|
||||||
if (fileName.isEmpty()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QDir fileDir(fi.path());
|
QDir fileDir(fi.path());
|
||||||
|
|
|
@ -11,9 +11,10 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then
|
||||||
brew upgrade cmake
|
brew upgrade cmake
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# common prerequisites
|
# common prerequisites
|
||||||
|
sudo add-apt-repository -y ppa:smspillaz/cmake-master
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
|
sudo apt-get -y purge cmake
|
||||||
sudo apt-get install -y libprotobuf-dev protobuf-compiler cmake bc
|
sudo apt-get install -y libprotobuf-dev protobuf-compiler cmake bc
|
||||||
|
|
||||||
if (( QT4 )); then
|
if (( QT4 )); then
|
||||||
|
@ -28,15 +29,7 @@ else
|
||||||
|
|
||||||
# prerequisites for tests
|
# prerequisites for tests
|
||||||
if [[ $BUILDTYPE == "Debug" ]]; then
|
if [[ $BUILDTYPE == "Debug" ]]; then
|
||||||
if [[ $DIST == "precise" ]]; then
|
sudo apt-get install -y libgtest-dev
|
||||||
sudo add-apt-repository -y ppa:george-edison55/precise-backports
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y cmake cmake-data libgtest-dev
|
|
||||||
else
|
|
||||||
sudo add-apt-repository -y ppa:george-edison55/cmake-3.x
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y cmake cmake-extras libgtest-dev
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo mkdir /usr/src/gtest/build
|
sudo mkdir /usr/src/gtest/build
|
||||||
cd /usr/src/gtest/build
|
cd /usr/src/gtest/build
|
||||||
|
|
Loading…
Reference in a new issue