mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
improved counters
This commit is contained in:
parent
939ab62273
commit
3388804e8f
18 changed files with 158 additions and 80 deletions
|
|
@ -1,16 +1,16 @@
|
|||
#include "counter.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include <QtGui>
|
||||
|
||||
Counter::Counter(Player *_player, const QString &_name, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), name(_name), value(0), player(_player)
|
||||
Counter::Counter(Player *_player, const QString &_name, QColor _color, int _value, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), name(_name), color(_color), value(_value), player(_player)
|
||||
{
|
||||
player->addCounter(this);
|
||||
}
|
||||
|
||||
QRectF Counter::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, 50, 30);
|
||||
return QRectF(0, 0, 40, 40);
|
||||
}
|
||||
|
||||
void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
|
|
@ -18,8 +18,12 @@ void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
|||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
painter->save();
|
||||
painter->fillRect(boundingRect(), QBrush(QColor("gray")));
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1").arg(value));
|
||||
painter->setBrush(QBrush(color));
|
||||
painter->drawEllipse(boundingRect());
|
||||
if (value) {
|
||||
painter->setFont(QFont("Times", 16, QFont::Bold));
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1").arg(value));
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
|
@ -28,3 +32,11 @@ void Counter::setValue(int _value)
|
|||
value = _value;
|
||||
update(boundingRect());
|
||||
}
|
||||
|
||||
void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
player->client->incCounter(name, 1);
|
||||
else if (event->button() == Qt::RightButton)
|
||||
player->client->incCounter(name, -1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue