Merge branch 'devel' of git://github.com/mbruker/Cockatrice into servernetwork
This commit is contained in:
commit
d792c3ddc6
3 changed files with 29 additions and 65 deletions
|
@ -78,8 +78,8 @@ bool PictureToLoad::nextSet()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PictureLoader::PictureLoader(QObject *parent)
|
PictureLoader::PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent)
|
||||||
: QObject(parent), downloadRunning(false), loadQueueRunning(false)
|
: QObject(parent), _picsPath(__picsPath), picDownload(_picDownload), downloadRunning(false), loadQueueRunning(false)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(startLoadQueue()), this, SLOT(processLoadQueue()), Qt::QueuedConnection);
|
connect(this, SIGNAL(startLoadQueue()), this, SLOT(processLoadQueue()), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
@ -87,6 +87,12 @@ PictureLoader::PictureLoader(QObject *parent)
|
||||||
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(picDownloadFinished(QNetworkReply *)));
|
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(picDownloadFinished(QNetworkReply *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PictureLoader::~PictureLoader()
|
||||||
|
{
|
||||||
|
// This does not work with the destroyed() signal as this destructor is called after the main event loop is done.
|
||||||
|
thread()->quit();
|
||||||
|
}
|
||||||
|
|
||||||
void PictureLoader::processLoadQueue()
|
void PictureLoader::processLoadQueue()
|
||||||
{
|
{
|
||||||
if (loadQueueRunning)
|
if (loadQueueRunning)
|
||||||
|
@ -224,40 +230,6 @@ void PictureLoader::setPicDownload(bool _picDownload)
|
||||||
picDownload = _picDownload;
|
picDownload = _picDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
PictureLoadingThread::PictureLoadingThread(const QString &_picsPath, bool _picDownload, QObject *parent)
|
|
||||||
: QThread(parent), picsPath(_picsPath), picDownload(_picDownload)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PictureLoadingThread::~PictureLoadingThread()
|
|
||||||
{
|
|
||||||
quit();
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PictureLoadingThread::run()
|
|
||||||
{
|
|
||||||
pictureLoader = new PictureLoader;
|
|
||||||
connect(pictureLoader, SIGNAL(imageLoaded(CardInfo *, const QImage &)), this, SIGNAL(imageLoaded(CardInfo *, const QImage &)));
|
|
||||||
pictureLoader->setPicsPath(picsPath);
|
|
||||||
pictureLoader->setPicDownload(picDownload);
|
|
||||||
|
|
||||||
usleep(100000);
|
|
||||||
initWaitCondition.wakeAll();
|
|
||||||
|
|
||||||
exec();
|
|
||||||
|
|
||||||
delete pictureLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PictureLoadingThread::waitForInit()
|
|
||||||
{
|
|
||||||
QMutex mutex;
|
|
||||||
mutex.lock();
|
|
||||||
initWaitCondition.wait(&mutex);
|
|
||||||
mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
CardInfo::CardInfo(CardDatabase *_db,
|
CardInfo::CardInfo(CardDatabase *_db,
|
||||||
const QString &_name,
|
const QString &_name,
|
||||||
const QString &_manacost,
|
const QString &_manacost,
|
||||||
|
@ -466,10 +438,11 @@ CardDatabase::CardDatabase(QObject *parent)
|
||||||
|
|
||||||
loadCardDatabase();
|
loadCardDatabase();
|
||||||
|
|
||||||
loadingThread = new PictureLoadingThread(settingsCache->getPicsPath(), settingsCache->getPicDownload(), this);
|
pictureLoaderThread = new QThread;
|
||||||
connect(loadingThread, SIGNAL(imageLoaded(CardInfo *, QImage)), this, SLOT(imageLoaded(CardInfo *, QImage)));
|
pictureLoader = new PictureLoader(settingsCache->getPicsPath(), settingsCache->getPicDownload());
|
||||||
loadingThread->start(QThread::LowPriority);
|
pictureLoader->moveToThread(pictureLoaderThread);
|
||||||
loadingThread->waitForInit();
|
connect(pictureLoader, SIGNAL(imageLoaded(CardInfo *, const QImage &)), this, SLOT(imageLoaded(CardInfo *, const QImage &)));
|
||||||
|
pictureLoaderThread->start(QThread::LowPriority);
|
||||||
|
|
||||||
noCard = new CardInfo(this);
|
noCard = new CardInfo(this);
|
||||||
noCard->loadPixmap(); // cache pixmap for card back
|
noCard->loadPixmap(); // cache pixmap for card back
|
||||||
|
@ -480,6 +453,10 @@ CardDatabase::~CardDatabase()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
delete noCard;
|
delete noCard;
|
||||||
|
|
||||||
|
pictureLoader->deleteLater();
|
||||||
|
pictureLoaderThread->wait();
|
||||||
|
delete pictureLoaderThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::clear()
|
void CardDatabase::clear()
|
||||||
|
@ -673,7 +650,7 @@ bool CardDatabase::saveToFile(const QString &fileName)
|
||||||
|
|
||||||
void CardDatabase::picDownloadChanged()
|
void CardDatabase::picDownloadChanged()
|
||||||
{
|
{
|
||||||
loadingThread->getPictureLoader()->setPicDownload(settingsCache->getPicDownload());
|
pictureLoader->setPicDownload(settingsCache->getPicDownload());
|
||||||
if (settingsCache->getPicDownload()) {
|
if (settingsCache->getPicDownload()) {
|
||||||
QHashIterator<QString, CardInfo *> cardIterator(cardHash);
|
QHashIterator<QString, CardInfo *> cardIterator(cardHash);
|
||||||
while (cardIterator.hasNext())
|
while (cardIterator.hasNext())
|
||||||
|
@ -739,7 +716,7 @@ void CardDatabase::cacheCardPixmaps(const QStringList &cardNames)
|
||||||
|
|
||||||
void CardDatabase::loadImage(CardInfo *card)
|
void CardDatabase::loadImage(CardInfo *card)
|
||||||
{
|
{
|
||||||
loadingThread->getPictureLoader()->loadImage(card, false);
|
pictureLoader->loadImage(card, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::imageLoaded(CardInfo *card, QImage image)
|
void CardDatabase::imageLoaded(CardInfo *card, QImage image)
|
||||||
|
@ -749,6 +726,6 @@ void CardDatabase::imageLoaded(CardInfo *card, QImage image)
|
||||||
|
|
||||||
void CardDatabase::picsPathChanged()
|
void CardDatabase::picsPathChanged()
|
||||||
{
|
{
|
||||||
loadingThread->getPictureLoader()->setPicsPath(settingsCache->getPicsPath());
|
pictureLoader->setPicsPath(settingsCache->getPicsPath());
|
||||||
clearPixmapCache();
|
clearPixmapCache();
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,8 @@ private:
|
||||||
bool picDownload, downloadRunning, loadQueueRunning;
|
bool picDownload, downloadRunning, loadQueueRunning;
|
||||||
void startNextPicDownload();
|
void startNextPicDownload();
|
||||||
public:
|
public:
|
||||||
PictureLoader(QObject *parent = 0);
|
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
|
||||||
|
~PictureLoader();
|
||||||
void setPicsPath(const QString &path);
|
void setPicsPath(const QString &path);
|
||||||
void setPicDownload(bool _picDownload);
|
void setPicDownload(bool _picDownload);
|
||||||
void loadImage(CardInfo *card, bool stripped);
|
void loadImage(CardInfo *card, bool stripped);
|
||||||
|
@ -84,24 +85,6 @@ signals:
|
||||||
void imageLoaded(CardInfo *card, const QImage &image);
|
void imageLoaded(CardInfo *card, const QImage &image);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PictureLoadingThread : public QThread {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
QString picsPath;
|
|
||||||
bool picDownload;
|
|
||||||
PictureLoader *pictureLoader;
|
|
||||||
QWaitCondition initWaitCondition;
|
|
||||||
protected:
|
|
||||||
void run();
|
|
||||||
public:
|
|
||||||
PictureLoadingThread(const QString &_picsPath, bool _picDownload, QObject *parent);
|
|
||||||
~PictureLoadingThread();
|
|
||||||
PictureLoader *getPictureLoader() const { return pictureLoader; }
|
|
||||||
void waitForInit();
|
|
||||||
signals:
|
|
||||||
void imageLoaded(CardInfo *card, const QImage &image);
|
|
||||||
};
|
|
||||||
|
|
||||||
class CardInfo : public QObject {
|
class CardInfo : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
@ -178,7 +161,9 @@ protected:
|
||||||
QHash<QString, CardSet *> setHash;
|
QHash<QString, CardSet *> setHash;
|
||||||
bool loadSuccess;
|
bool loadSuccess;
|
||||||
CardInfo *noCard;
|
CardInfo *noCard;
|
||||||
PictureLoadingThread *loadingThread;
|
|
||||||
|
QThread *pictureLoaderThread;
|
||||||
|
PictureLoader *pictureLoader;
|
||||||
private:
|
private:
|
||||||
void loadCardsFromXml(QXmlStreamReader &xml);
|
void loadCardsFromXml(QXmlStreamReader &xml);
|
||||||
void loadSetsFromXml(QXmlStreamReader &xml);
|
void loadSetsFromXml(QXmlStreamReader &xml);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include "cardinfowidget.h"
|
#include "cardinfowidget.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
|
@ -74,8 +75,9 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidge
|
||||||
textLabel->setMinimumHeight(100);
|
textLabel->setMinimumHeight(100);
|
||||||
setFixedWidth(sizeHint().width());
|
setFixedWidth(sizeHint().width());
|
||||||
} else if (mode == ModePopUp) {
|
} else if (mode == ModePopUp) {
|
||||||
setFixedWidth(350);
|
QDesktopWidget desktopWidget;
|
||||||
pixmapWidth = 250;
|
pixmapWidth = desktopWidget.screenGeometry().height() / 3 / aspectRatio;
|
||||||
|
setFixedWidth(pixmapWidth + 150);
|
||||||
} else
|
} else
|
||||||
setFixedWidth(250);
|
setFixedWidth(250);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue