Merge branch 'master' of ssh://cockatrice.git.sourceforge.net/gitroot/cockatrice/cockatrice

This commit is contained in:
Max-Wilhelm Bruker 2010-11-05 21:54:06 +01:00
commit f158408747
7 changed files with 48 additions and 27 deletions

View file

@ -50,7 +50,7 @@ QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
); );
} }
void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize) void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
{ {
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
@ -58,7 +58,7 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
QTransform pixmapTransform; QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(tapAngle); pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2); pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform); painter->setTransform(pixmapTransform);
@ -70,16 +70,16 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
painter->setFont(f); painter->setFont(f);
} }
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void AbstractCardItem::paintPicture(QPainter *painter, int angle)
{ {
painter->save();
QSizeF translatedSize = getTranslatedSize(painter); QSizeF translatedSize = getTranslatedSize(painter);
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
qreal scaleFactor = translatedSize.width() / boundingRect().width(); qreal scaleFactor = translatedSize.width() / boundingRect().width();
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize()); QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
painter->save(); painter->save();
if (translatedPixmap) { if (translatedPixmap) {
transformPainter(painter, translatedSize); transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap); painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
} else { } else {
QString colorStr; QString colorStr;
@ -116,12 +116,19 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
painter->setPen(pen); painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2)); painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
transformPainter(painter, translatedSize); transformPainter(painter, translatedSize, angle);
painter->setPen(textColor); painter->setPen(textColor);
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name); painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name);
} }
painter->restore(); painter->restore();
}
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
painter->save();
paintPicture(painter, tapAngle);
if (isSelected()) { if (isSelected()) {
painter->setPen(Qt::red); painter->setPen(Qt::red);
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));
@ -188,6 +195,12 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept(); event->accept();
} }
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
// This function ensures the parent function doesn't mess around with our selection.
event->accept();
}
void AbstractCardItem::processHoverEvent() void AbstractCardItem::processHoverEvent()
{ {
emit hovered(this); emit hovered(this);

View file

@ -35,6 +35,7 @@ public:
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, QGraphicsItem *parent = 0); AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, QGraphicsItem *parent = 0);
~AbstractCardItem(); ~AbstractCardItem();
QRectF boundingRect() const; QRectF boundingRect() const;
void paintPicture(QPainter *painter, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
CardInfo *getInfo() const { return info; } CardInfo *getInfo() const { return info; }
QString getName() const { return name; } QString getName() const { return name; }
@ -46,8 +47,9 @@ public:
void processHoverEvent(); void processHoverEvent();
protected: protected:
QSizeF getTranslatedSize(QPainter *painter) const; QSizeF getTranslatedSize(QPainter *painter) const;
void transformPainter(QPainter *painter, const QSizeF &translatedSize); void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
}; };

View file

@ -174,7 +174,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QSizeF translatedSize = getTranslatedSize(painter); QSizeF translatedSize = getTranslatedSize(painter);
qreal scaleFactor = translatedSize.width() / boundingRect().width(); qreal scaleFactor = translatedSize.width() / boundingRect().width();
transformPainter(painter, translatedSize); transformPainter(painter, translatedSize, tapAngle);
painter->setBackground(Qt::black); painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode); painter->setBackgroundMode(Qt::OpaqueMode);
painter->setPen(Qt::white); painter->setPen(Qt::white);

View file

@ -3,6 +3,7 @@
#include "zoneviewwidget.h" #include "zoneviewwidget.h"
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include <QAction> #include <QAction>
#include <QDebug>
GameScene::GameScene(QObject *parent) GameScene::GameScene(QObject *parent)
: QGraphicsScene(parent) : QGraphicsScene(parent)
@ -131,10 +132,10 @@ void GameScene::processViewSizeChange(const QSize &newSize)
qreal minRatio = minWidth / sceneRect().height(); qreal minRatio = minWidth / sceneRect().height();
if (minRatio > newRatio) { if (minRatio > newRatio) {
// Aspect ratio is dominated by table width. // Aspect ratio is dominated by table width.
setSceneRect(sceneRect().x(), sceneRect().y(), minWidth, sceneRect().height()); setSceneRect(0, 0, minWidth, sceneRect().height());
} else { } else {
// Aspect ratio is dominated by window dimensions. // Aspect ratio is dominated by window dimensions.
setSceneRect(sceneRect().x(), sceneRect().y(), newRatio * sceneRect().height(), sceneRect().height()); setSceneRect(0, 0, newRatio * sceneRect().height(), sceneRect().height());
} }
for (int i = 0; i < players.size(); ++i) for (int i = 0; i < players.size(); ++i)

View file

@ -13,6 +13,8 @@ PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _c
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor! setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
} }
QRectF PileZone::boundingRect() const QRectF PileZone::boundingRect() const
@ -22,14 +24,15 @@ QRectF PileZone::boundingRect() const
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
if (!cards.isEmpty()) { if (!cards.isEmpty())
painter->save(); cards.at(0)->paintPicture(painter, 90);
cards.at(0)->paint(painter, option, widget);
painter->restore();
}
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));
painter->translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2);
painter->rotate(-90);
painter->translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2);
paintNumberEllipse(cards.size(), 28, Qt::white, -1, -1, painter);
} }
void PileZone::addCardImpl(CardItem *card, int x, int /*y*/) void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)

View file

@ -32,14 +32,13 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
updateBgPixmap(); updateBgPixmap();
playerTarget = new PlayerTarget(this); playerTarget = new PlayerTarget(this);
playerTarget->setPos(QPointF(counterAreaWidth + (CARD_WIDTH + 5 - playerTarget->boundingRect().width()) / 2.0, 5)); playerTarget->setPos(QPointF(counterAreaWidth + (CARD_HEIGHT + 5 - playerTarget->boundingRect().width()) / 2.0, 5));
QPointF base = QPointF(counterAreaWidth, 5 + playerTarget->boundingRect().height() + 10);
PileZone *deck = new PileZone(this, "deck", true, false, this); PileZone *deck = new PileZone(this, "deck", true, false, this);
QPointF base = QPointF(counterAreaWidth + (CARD_HEIGHT - CARD_WIDTH + 5) / 2.0, 5 + playerTarget->boundingRect().height() + 5 - (CARD_HEIGHT - CARD_WIDTH) / 2.0);
deck->setPos(base); deck->setPos(base);
qreal h = deck->boundingRect().height() + 10; qreal h = deck->boundingRect().width() + 5;
PileZone *grave = new PileZone(this, "grave", false, true, this); PileZone *grave = new PileZone(this, "grave", false, true, this);
grave->setPos(base + QPointF(0, h)); grave->setPos(base + QPointF(0, h));
@ -51,7 +50,7 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
sb->setVisible(false); sb->setVisible(false);
HandCounter *handCounter = new HandCounter(this); HandCounter *handCounter = new HandCounter(this);
handCounter->setPos(base + QPointF(0, 3 * h)); handCounter->setPos(base + QPointF(0, 3 * h + 7));
table = new TableZone(this, this); table = new TableZone(this, this);
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect())); connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
@ -310,7 +309,7 @@ void Player::playerListActionTriggered()
void Player::rearrangeZones() void Player::rearrangeZones()
{ {
QPointF base = QPointF(CARD_WIDTH + counterAreaWidth + 5, 0); QPointF base = QPointF(CARD_HEIGHT + counterAreaWidth + 5, 0);
if (settingsCache->getHorizontalHand()) { if (settingsCache->getHorizontalHand()) {
if (mirrored) { if (mirrored) {
@ -358,7 +357,7 @@ void Player::updateBgPixmap()
void Player::updateBoundingRect() void Player::updateBoundingRect()
{ {
prepareGeometryChange(); prepareGeometryChange();
qreal width = CARD_WIDTH + 5 + counterAreaWidth + stack->boundingRect().width(); qreal width = CARD_HEIGHT + 5 + counterAreaWidth + stack->boundingRect().width();
if (settingsCache->getHorizontalHand()) if (settingsCache->getHorizontalHand())
bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + hand->boundingRect().height()); bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + hand->boundingRect().height());
else else
@ -981,7 +980,7 @@ QRectF Player::boundingRect() const
void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
int totalWidth = CARD_WIDTH + counterAreaWidth + 5; int totalWidth = CARD_HEIGHT + counterAreaWidth + 5;
if (bgPixmap.isNull()) if (bgPixmap.isNull())
painter->fillRect(QRectF(0, 0, totalWidth, boundingRect().height()), QColor(200, 200, 200)); painter->fillRect(QRectF(0, 0, totalWidth, boundingRect().height()), QColor(200, 200, 200));
else else
@ -1404,7 +1403,7 @@ QString Player::getName() const
qreal Player::getMinimumWidth() const qreal Player::getMinimumWidth() const
{ {
qreal result = table->getMinimumWidth() + CARD_WIDTH + 5 + counterAreaWidth + stack->boundingRect().width(); qreal result = table->getMinimumWidth() + CARD_HEIGHT + 5 + counterAreaWidth + stack->boundingRect().width();
if (!settingsCache->getHorizontalHand()) if (!settingsCache->getHorizontalHand())
result += hand->boundingRect().width(); result += hand->boundingRect().width();
return result; return result;
@ -1423,7 +1422,7 @@ void Player::processSceneSizeChange(const QSizeF &newSize)
// This will need to be changed if player areas are displayed side by side (e.g. 2x2 for a 4-player game) // This will need to be changed if player areas are displayed side by side (e.g. 2x2 for a 4-player game)
qreal fullPlayerWidth = newSize.width(); qreal fullPlayerWidth = newSize.width();
qreal tableWidth = fullPlayerWidth - CARD_WIDTH - 5 - counterAreaWidth - stack->boundingRect().width(); qreal tableWidth = fullPlayerWidth - CARD_HEIGHT - 5 - counterAreaWidth - stack->boundingRect().width();
if (!settingsCache->getHorizontalHand()) if (!settingsCache->getHorizontalHand())
tableWidth -= hand->boundingRect().width(); tableWidth -= hand->boundingRect().width();

View file

@ -17,7 +17,7 @@ PlayerTarget::PlayerTarget(Player *_owner)
QRectF PlayerTarget::boundingRect() const QRectF PlayerTarget::boundingRect() const
{ {
return QRectF(0, 0, 64, 64); return QRectF(0, 0, 100, 64);
} }
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
@ -41,7 +41,10 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
QPixmapCache::insert(cacheKey, cachedPixmap); QPixmapCache::insert(cacheKey, cachedPixmap);
} }
painter->resetTransform(); painter->resetTransform();
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect()); painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
painter->resetTransform();
QString name = info->getName(); QString name = info->getName();
if (name.size() > 13) if (name.size() > 13)