Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
d792c3dd
Commit
d792c3dd
authored
Mar 17, 2012
by
Max-Wilhelm Bruker
Browse files
Merge branch 'devel' of
git://github.com/mbruker/Cockatrice
into servernetwork
parents
c23af447
9e1ee500
Changes
3
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
d792c3dd
...
...
@@ -78,8 +78,8 @@ bool PictureToLoad::nextSet()
return
true
;
}
PictureLoader
::
PictureLoader
(
QObject
*
parent
)
:
QObject
(
parent
),
downloadRunning
(
false
),
loadQueueRunning
(
false
)
PictureLoader
::
PictureLoader
(
const
QString
&
__picsPath
,
bool
_picDownload
,
QObject
*
parent
)
:
QObject
(
parent
),
_picsPath
(
__picsPath
),
picDownload
(
_picDownload
),
downloadRunning
(
false
),
loadQueueRunning
(
false
)
{
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
*
)));
}
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
()
{
if
(
loadQueueRunning
)
...
...
@@ -224,40 +230,6 @@ void PictureLoader::setPicDownload(bool _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
,
const
QString
&
_name
,
const
QString
&
_manacost
,
...
...
@@ -466,10 +438,11 @@ CardDatabase::CardDatabase(QObject *parent)
loadCardDatabase
();
loadingThread
=
new
PictureLoadingThread
(
settingsCache
->
getPicsPath
(),
settingsCache
->
getPicDownload
(),
this
);
connect
(
loadingThread
,
SIGNAL
(
imageLoaded
(
CardInfo
*
,
QImage
)),
this
,
SLOT
(
imageLoaded
(
CardInfo
*
,
QImage
)));
loadingThread
->
start
(
QThread
::
LowPriority
);
loadingThread
->
waitForInit
();
pictureLoaderThread
=
new
QThread
;
pictureLoader
=
new
PictureLoader
(
settingsCache
->
getPicsPath
(),
settingsCache
->
getPicDownload
());
pictureLoader
->
moveToThread
(
pictureLoaderThread
);
connect
(
pictureLoader
,
SIGNAL
(
imageLoaded
(
CardInfo
*
,
const
QImage
&
)),
this
,
SLOT
(
imageLoaded
(
CardInfo
*
,
const
QImage
&
)));
pictureLoaderThread
->
start
(
QThread
::
LowPriority
);
noCard
=
new
CardInfo
(
this
);
noCard
->
loadPixmap
();
// cache pixmap for card back
...
...
@@ -480,6 +453,10 @@ CardDatabase::~CardDatabase()
{
clear
();
delete
noCard
;
pictureLoader
->
deleteLater
();
pictureLoaderThread
->
wait
();
delete
pictureLoaderThread
;
}
void
CardDatabase
::
clear
()
...
...
@@ -673,7 +650,7 @@ bool CardDatabase::saveToFile(const QString &fileName)
void
CardDatabase
::
picDownloadChanged
()
{
loadingThread
->
getP
ictureLoader
()
->
setPicDownload
(
settingsCache
->
getPicDownload
());
p
ictureLoader
->
setPicDownload
(
settingsCache
->
getPicDownload
());
if
(
settingsCache
->
getPicDownload
())
{
QHashIterator
<
QString
,
CardInfo
*>
cardIterator
(
cardHash
);
while
(
cardIterator
.
hasNext
())
...
...
@@ -739,7 +716,7 @@ void CardDatabase::cacheCardPixmaps(const QStringList &cardNames)
void
CardDatabase
::
loadImage
(
CardInfo
*
card
)
{
loadingThread
->
getP
ictureLoader
()
->
loadImage
(
card
,
false
);
p
ictureLoader
->
loadImage
(
card
,
false
);
}
void
CardDatabase
::
imageLoaded
(
CardInfo
*
card
,
QImage
image
)
...
...
@@ -749,6 +726,6 @@ void CardDatabase::imageLoaded(CardInfo *card, QImage image)
void
CardDatabase
::
picsPathChanged
()
{
loadingThread
->
getP
ictureLoader
()
->
setPicsPath
(
settingsCache
->
getPicsPath
());
p
ictureLoader
->
setPicsPath
(
settingsCache
->
getPicsPath
());
clearPixmapCache
();
}
cockatrice/src/carddatabase.h
View file @
d792c3dd
...
...
@@ -71,7 +71,8 @@ private:
bool
picDownload
,
downloadRunning
,
loadQueueRunning
;
void
startNextPicDownload
();
public:
PictureLoader
(
QObject
*
parent
=
0
);
PictureLoader
(
const
QString
&
__picsPath
,
bool
_picDownload
,
QObject
*
parent
=
0
);
~
PictureLoader
();
void
setPicsPath
(
const
QString
&
path
);
void
setPicDownload
(
bool
_picDownload
);
void
loadImage
(
CardInfo
*
card
,
bool
stripped
);
...
...
@@ -84,24 +85,6 @@ signals:
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
{
Q_OBJECT
private:
...
...
@@ -178,7 +161,9 @@ protected:
QHash
<
QString
,
CardSet
*>
setHash
;
bool
loadSuccess
;
CardInfo
*
noCard
;
PictureLoadingThread
*
loadingThread
;
QThread
*
pictureLoaderThread
;
PictureLoader
*
pictureLoader
;
private:
void
loadCardsFromXml
(
QXmlStreamReader
&
xml
);
void
loadSetsFromXml
(
QXmlStreamReader
&
xml
);
...
...
cockatrice/src/cardinfowidget.cpp
View file @
d792c3dd
...
...
@@ -4,6 +4,7 @@
#include
<QPushButton>
#include
<QStyle>
#include
<QMouseEvent>
#include
<QDesktopWidget>
#include
"cardinfowidget.h"
#include
"carditem.h"
#include
"carddatabase.h"
...
...
@@ -74,8 +75,9 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, const QString &cardName, QWidge
textLabel
->
setMinimumHeight
(
100
);
setFixedWidth
(
sizeHint
().
width
());
}
else
if
(
mode
==
ModePopUp
)
{
setFixedWidth
(
350
);
pixmapWidth
=
250
;
QDesktopWidget
desktopWidget
;
pixmapWidth
=
desktopWidget
.
screenGeometry
().
height
()
/
3
/
aspectRatio
;
setFixedWidth
(
pixmapWidth
+
150
);
}
else
setFixedWidth
(
250
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment