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
4beb990f
Commit
4beb990f
authored
Aug 29, 2009
by
Max-Wilhelm Bruker
Browse files
dynamic pixmap cache update
parent
0f737e61
Changes
6
Show whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
4beb990f
...
...
@@ -224,6 +224,8 @@ void CardInfo::updatePixmapCache()
qDebug
(
QString
(
"Updating pixmap cache for %1"
).
arg
(
name
).
toLatin1
());
clearPixmapCache
();
loadPixmap
();
emit
pixmapUpdated
();
}
QXmlStreamWriter
&
operator
<<
(
QXmlStreamWriter
&
xml
,
const
CardInfo
*
info
)
...
...
cockatrice/src/carddatabase.h
View file @
4beb990f
...
...
@@ -33,7 +33,7 @@ public:
void
sortByKey
();
};
class
CardInfo
:
QObject
{
class
CardInfo
:
public
QObject
{
Q_OBJECT
private:
CardDatabase
*
db
;
...
...
@@ -86,6 +86,8 @@ public:
void
updatePixmapCache
();
private
slots
:
void
picDownloadFinished
(
int
id
,
bool
error
);
signals:
void
pixmapUpdated
();
};
class
CardDatabase
:
public
QObject
{
...
...
cockatrice/src/cardinfowidget.cpp
View file @
4beb990f
...
...
@@ -6,7 +6,7 @@
#include
<QMessageBox>
CardInfoWidget
::
CardInfoWidget
(
CardDatabase
*
_db
,
QWidget
*
parent
)
:
QFrame
(
parent
),
db
(
_db
),
pixmapHeight
(
pixmapWidth
)
:
QFrame
(
parent
),
db
(
_db
),
pixmapHeight
(
pixmapWidth
)
,
info
(
0
)
{
cardPicture
=
new
QLabel
;
cardPicture
->
setAlignment
(
Qt
::
AlignCenter
);
...
...
@@ -71,12 +71,12 @@ void CardInfoWidget::setCard(CardInfo *card)
if
(
!
card
)
return
;
QPixmap
*
resizedPixmap
=
card
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapHeight
));
if
(
resizedPixmap
)
cardPicture
->
setPixmap
(
*
resizedPixmap
);
else
cardPicture
->
setPixmap
(
*
(
db
->
getCard
()
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapHeight
))));
if
(
info
)
disconnect
(
info
,
0
,
this
,
0
);
info
=
card
;
connect
(
info
,
SIGNAL
(
pixmapUpdated
()),
this
,
SLOT
(
updatePixmap
()));
updatePixmap
();
nameLabel2
->
setText
(
card
->
getName
());
manacostLabel2
->
setText
(
card
->
getManaCost
());
cardtypeLabel2
->
setText
(
card
->
getCardType
());
...
...
@@ -89,6 +89,15 @@ void CardInfoWidget::setCard(const QString &cardName)
setCard
(
db
->
getCard
(
cardName
));
}
void
CardInfoWidget
::
updatePixmap
()
{
QPixmap
*
resizedPixmap
=
info
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapHeight
));
if
(
resizedPixmap
)
cardPicture
->
setPixmap
(
*
resizedPixmap
);
else
cardPicture
->
setPixmap
(
*
(
db
->
getCard
()
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapHeight
))));
}
void
CardInfoWidget
::
retranslateUi
()
{
nameLabel1
->
setText
(
tr
(
"Name:"
));
...
...
cockatrice/src/cardinfowidget.h
View file @
4beb990f
...
...
@@ -20,12 +20,16 @@ private:
QLabel
*
cardtypeLabel1
,
*
cardtypeLabel2
;
QLabel
*
powtoughLabel1
,
*
powtoughLabel2
;
QTextEdit
*
textLabel
;
CardInfo
*
info
;
public:
CardInfoWidget
(
CardDatabase
*
_db
,
QWidget
*
parent
=
0
);
void
retranslateUi
();
public
slots
:
void
setCard
(
CardInfo
*
card
);
void
setCard
(
const
QString
&
cardName
);
private
slots
:
void
updatePixmap
();
};
#endif
cockatrice/src/carditem.cpp
View file @
4beb990f
...
...
@@ -15,6 +15,8 @@ CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphi
setFlag
(
ItemIsSelectable
);
setAcceptsHoverEvents
(
true
);
setCacheMode
(
DeviceCoordinateCache
);
connect
(
info
,
SIGNAL
(
pixmapUpdated
()),
this
,
SLOT
(
pixmapUpdated
()));
}
CardItem
::~
CardItem
()
...
...
@@ -28,6 +30,11 @@ QRectF CardItem::boundingRect() const
return
QRectF
(
0
,
0
,
CARD_WIDTH
,
CARD_HEIGHT
);
}
void
CardItem
::
pixmapUpdated
()
{
update
();
}
void
CardItem
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*/
*
widget
*/
)
{
painter
->
save
();
...
...
@@ -105,8 +112,10 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void
CardItem
::
setName
(
const
QString
&
_name
)
{
disconnect
(
info
,
0
,
this
,
0
);
name
=
_name
;
info
=
db
->
getCard
(
name
);
connect
(
info
,
SIGNAL
(
pixmapUpdated
()),
this
,
SLOT
(
pixmapUpdated
()));
update
();
}
...
...
cockatrice/src/carditem.h
View file @
4beb990f
...
...
@@ -20,7 +20,8 @@ enum CardItemType {
typeOther
=
QGraphicsItem
::
UserType
+
4
};
class
CardItem
:
public
AbstractGraphicsItem
{
class
CardItem
:
public
QObject
,
public
AbstractGraphicsItem
{
Q_OBJECT
private:
CardDatabase
*
db
;
CardInfo
*
info
;
...
...
@@ -34,6 +35,8 @@ private:
bool
doesntUntap
;
QPoint
gridPoint
;
CardDragItem
*
dragItem
;
private
slots
:
void
pixmapUpdated
();
public:
enum
{
Type
=
typeCard
};
int
type
()
const
{
return
Type
;
}
...
...
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