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
f33abf14
Commit
f33abf14
authored
Jun 17, 2010
by
Max-Wilhelm Bruker
Browse files
proper pixmap caching for hand counter
parent
df7bcf17
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/handcounter.cpp
View file @
f33abf14
#include
<QPainter>
#include
<QPainter>
#include
<QSvgRenderer>
#include
<QSvgRenderer>
#include
<QPixmapCache>
#include
"handcounter.h"
#include
"handcounter.h"
#include
"cardzone.h"
#include
"cardzone.h"
...
@@ -7,17 +8,10 @@ HandCounter::HandCounter(QGraphicsItem *parent)
...
@@ -7,17 +8,10 @@ HandCounter::HandCounter(QGraphicsItem *parent)
:
AbstractGraphicsItem
(
parent
),
number
(
0
)
:
AbstractGraphicsItem
(
parent
),
number
(
0
)
{
{
setCacheMode
(
DeviceCoordinateCache
);
setCacheMode
(
DeviceCoordinateCache
);
QSvgRenderer
svg
(
QString
(
":/resources/hand.svg"
));
handImage
=
new
QPixmap
(
72
,
72
);
handImage
->
fill
(
Qt
::
transparent
);
QPainter
painter
(
handImage
);
svg
.
render
(
&
painter
,
QRectF
(
0
,
0
,
72
,
72
));
}
}
HandCounter
::~
HandCounter
()
HandCounter
::~
HandCounter
()
{
{
delete
handImage
;
}
}
void
HandCounter
::
updateNumber
()
void
HandCounter
::
updateNumber
()
...
@@ -33,6 +27,20 @@ QRectF HandCounter::boundingRect() const
...
@@ -33,6 +27,20 @@ QRectF HandCounter::boundingRect() const
void
HandCounter
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
)
void
HandCounter
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
/*option*/
,
QWidget
*
/*widget*/
)
{
{
painter
->
drawPixmap
(
handImage
->
rect
(),
*
handImage
,
handImage
->
rect
());
painter
->
save
();
QSize
translatedSize
=
painter
->
combinedTransform
().
mapRect
(
boundingRect
()).
size
().
toSize
();
QPixmap
cachedPixmap
;
if
(
!
QPixmapCache
::
find
(
"handCounter"
+
QString
::
number
(
translatedSize
.
width
()),
&
cachedPixmap
))
{
QSvgRenderer
svg
(
QString
(
":/resources/hand.svg"
));
cachedPixmap
=
QPixmap
(
translatedSize
);
cachedPixmap
.
fill
(
Qt
::
transparent
);
QPainter
painter
(
&
cachedPixmap
);
svg
.
render
(
&
painter
,
QRectF
(
0
,
0
,
translatedSize
.
width
(),
translatedSize
.
height
()));
QPixmapCache
::
insert
(
"handCounter"
+
QString
::
number
(
translatedSize
.
width
()),
cachedPixmap
);
}
painter
->
resetTransform
();
painter
->
drawPixmap
(
cachedPixmap
.
rect
(),
cachedPixmap
,
cachedPixmap
.
rect
());
painter
->
restore
();
paintNumberEllipse
(
number
,
24
,
Qt
::
white
,
-
1
,
painter
);
paintNumberEllipse
(
number
,
24
,
Qt
::
white
,
-
1
,
painter
);
}
}
cockatrice/src/handcounter.h
View file @
f33abf14
...
@@ -11,7 +11,6 @@ class HandCounter : public QObject, public AbstractGraphicsItem {
...
@@ -11,7 +11,6 @@ class HandCounter : public QObject, public AbstractGraphicsItem {
Q_OBJECT
Q_OBJECT
private:
private:
int
number
;
int
number
;
QPixmap
*
handImage
;
public
slots
:
public
slots
:
void
updateNumber
();
void
updateNumber
();
public:
public:
...
...
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