diff --git a/cockatrice/src/handcounter.cpp b/cockatrice/src/handcounter.cpp index a0e1c415..e340656d 100644 --- a/cockatrice/src/handcounter.cpp +++ b/cockatrice/src/handcounter.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "handcounter.h" #include "cardzone.h" @@ -7,17 +8,10 @@ HandCounter::HandCounter(QGraphicsItem *parent) : AbstractGraphicsItem(parent), number(0) { 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() { - delete handImage; } void HandCounter::updateNumber() @@ -33,6 +27,20 @@ QRectF HandCounter::boundingRect() const 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); } diff --git a/cockatrice/src/handcounter.h b/cockatrice/src/handcounter.h index 33afe8c3..9e942a64 100644 --- a/cockatrice/src/handcounter.h +++ b/cockatrice/src/handcounter.h @@ -11,7 +11,6 @@ class HandCounter : public QObject, public AbstractGraphicsItem { Q_OBJECT private: int number; - QPixmap *handImage; public slots: void updateNumber(); public: