mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [Refactor] Move game logic into libcockatrice_game * [Refactor] Include card_state.h in player_actions.h * [Game] Inject settings providers into libcockatrice_game, drop Widgets * [Game] Follow base rename to createCardRequested after rebase * [Game] Drop unused CardItem forward declaration * [Game] Fix includes after moving game logic into libcockatrice_game --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#include "hand_counter.h"
|
|
|
|
#include "../interface/pixel_map_generator.h"
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QPainter>
|
|
#include <QPixmap>
|
|
#include <QPixmapCache>
|
|
#include <QRectF>
|
|
#include <QSize>
|
|
#include <QSizeF>
|
|
#include <QString>
|
|
#include <QStringLiteral>
|
|
#include <QTransform>
|
|
#include <libcockatrice/game/board/card_list.h>
|
|
#include <libcockatrice/game/zones/card_zone_logic.h>
|
|
#include <qnamespace.h>
|
|
|
|
class QGraphicsItem;
|
|
|
|
HandCounter::HandCounter(QGraphicsItem *parent) : AbstractGraphicsItem(parent), number(0)
|
|
{
|
|
setCacheMode(DeviceCoordinateCache);
|
|
}
|
|
|
|
HandCounter::~HandCounter()
|
|
{
|
|
}
|
|
|
|
void HandCounter::updateNumber()
|
|
{
|
|
number = static_cast<CardZoneLogic *>(sender())->getCards().size();
|
|
update();
|
|
}
|
|
|
|
QRectF HandCounter::boundingRect() const
|
|
{
|
|
return QRectF(0, 0, 72, 72);
|
|
}
|
|
|
|
void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
|
{
|
|
painter->save();
|
|
QSize translatedSize = painter->combinedTransform().mapRect(boundingRect()).size().toSize();
|
|
QPixmap cachedPixmap;
|
|
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), &cachedPixmap)) {
|
|
cachedPixmap =
|
|
themePixmap(QStringLiteral("hand")).scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
|
|
}
|
|
resetPainterTransform(painter);
|
|
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
|
|
painter->restore();
|
|
|
|
paintNumberEllipse(number, 24, Qt::white, -1, -1, painter);
|
|
}
|
|
|
|
void HandCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::RightButton) {
|
|
emit showContextMenu(event->screenPos());
|
|
event->accept();
|
|
}
|
|
}
|