From 9f79bd2c8e3ac7d684c11f66b8fd9727e97b1638 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Thu, 17 Jun 2010 21:54:05 +0200 Subject: [PATCH] nicer looking counters on cards --- cockatrice/src/abstractgraphicsitem.cpp | 11 ++++++++--- cockatrice/src/abstractgraphicsitem.h | 2 +- cockatrice/src/carditem.cpp | 2 +- cockatrice/src/handcounter.cpp | 2 +- cockatrice/src/pilezone.cpp | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/abstractgraphicsitem.cpp b/cockatrice/src/abstractgraphicsitem.cpp index b83b0834..47b21bbc 100644 --- a/cockatrice/src/abstractgraphicsitem.cpp +++ b/cockatrice/src/abstractgraphicsitem.cpp @@ -1,7 +1,7 @@ #include "abstractgraphicsitem.h" #include -void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, QPainter *painter) +void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, int count, QPainter *painter) { painter->save(); @@ -31,8 +31,13 @@ void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QC if (position == -1) textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h); else { - qreal offset = boundingRect().width() / 20.0; - textRect = QRectF(offset, offset * (position + 1) + h * position, w, h); + qreal xOffset = 10; + qreal yOffset = 20; + qreal spacing = 2; + if (position < 2) + textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h); + else + textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset + (spacing + h) * (position / 2), w, h); } painter->drawEllipse(textRect); diff --git a/cockatrice/src/abstractgraphicsitem.h b/cockatrice/src/abstractgraphicsitem.h index 3598b1a1..cee33ac3 100644 --- a/cockatrice/src/abstractgraphicsitem.h +++ b/cockatrice/src/abstractgraphicsitem.h @@ -5,7 +5,7 @@ class AbstractGraphicsItem : public QGraphicsItem { protected: - void paintNumberEllipse(int number, int radius, const QColor &color, int position, QPainter *painter); + void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter); public: AbstractGraphicsItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent) { } }; diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index 4c7f164c..41e6a385 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -34,7 +34,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QColor color; color.setHsv(counterIterator.key() * 60, 150, 255); - paintNumberEllipse(counterIterator.value(), 14, color, i, painter); + paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter); ++i; } if (!pt.isEmpty()) { diff --git a/cockatrice/src/handcounter.cpp b/cockatrice/src/handcounter.cpp index e340656d..7ff9bf53 100644 --- a/cockatrice/src/handcounter.cpp +++ b/cockatrice/src/handcounter.cpp @@ -42,5 +42,5 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect()); painter->restore(); - paintNumberEllipse(number, 24, Qt::white, -1, painter); + paintNumberEllipse(number, 24, Qt::white, -1, -1, painter); } diff --git a/cockatrice/src/pilezone.cpp b/cockatrice/src/pilezone.cpp index 9d1334b0..8df96a77 100644 --- a/cockatrice/src/pilezone.cpp +++ b/cockatrice/src/pilezone.cpp @@ -28,7 +28,7 @@ void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->restore(); } - paintNumberEllipse(cards.size(), 32, Qt::white, -1, painter); + paintNumberEllipse(cards.size(), 32, Qt::white, -1, -1, painter); painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1)); }