nicer looking counters on cards

This commit is contained in:
Max-Wilhelm Bruker 2010-06-17 21:54:05 +02:00
parent f33abf14ca
commit 9f79bd2c8e
5 changed files with 12 additions and 7 deletions

View file

@ -1,7 +1,7 @@
#include "abstractgraphicsitem.h" #include "abstractgraphicsitem.h"
#include <QPainter> #include <QPainter>
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(); painter->save();
@ -31,8 +31,13 @@ void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QC
if (position == -1) if (position == -1)
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h); textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
else { else {
qreal offset = boundingRect().width() / 20.0; qreal xOffset = 10;
textRect = QRectF(offset, offset * (position + 1) + h * position, w, h); 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); painter->drawEllipse(textRect);

View file

@ -5,7 +5,7 @@
class AbstractGraphicsItem : public QGraphicsItem { class AbstractGraphicsItem : public QGraphicsItem {
protected: 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: public:
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent) { } AbstractGraphicsItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent) { }
}; };

View file

@ -34,7 +34,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QColor color; QColor color;
color.setHsv(counterIterator.key() * 60, 150, 255); color.setHsv(counterIterator.key() * 60, 150, 255);
paintNumberEllipse(counterIterator.value(), 14, color, i, painter); paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter);
++i; ++i;
} }
if (!pt.isEmpty()) { if (!pt.isEmpty()) {

View file

@ -42,5 +42,5 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect()); painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
painter->restore(); painter->restore();
paintNumberEllipse(number, 24, Qt::white, -1, painter); paintNumberEllipse(number, 24, Qt::white, -1, -1, painter);
} }

View file

@ -28,7 +28,7 @@ void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->restore(); 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)); painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
} }