fixed player area layout

This commit is contained in:
Max-Wilhelm Bruker 2010-11-05 16:46:59 +01:00
parent 7bff204461
commit 2451c39ef2
7 changed files with 41 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());
@ -58,7 +58,7 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(tapAngle);
pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform);
@ -70,16 +70,16 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
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);
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
qreal scaleFactor = translatedSize.width() / boundingRect().width();
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
painter->save();
if (translatedPixmap) {
transformPainter(painter, translatedSize);
transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
} else {
QString colorStr;
@ -116,12 +116,19 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
transformPainter(painter, translatedSize);
transformPainter(painter, translatedSize, angle);
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->restore();
}
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
painter->save();
paintPicture(painter, tapAngle);
if (isSelected()) {
painter->setPen(Qt::red);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));

View file

@ -35,6 +35,7 @@ public:
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, QGraphicsItem *parent = 0);
~AbstractCardItem();
QRectF boundingRect() const;
void paintPicture(QPainter *painter, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
CardInfo *getInfo() const { return info; }
QString getName() const { return name; }
@ -46,7 +47,7 @@ public:
void processHoverEvent();
protected:
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 mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);

View file

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

View file

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

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!
setAcceptsHoverEvents(true);
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
@ -22,14 +24,15 @@ QRectF PileZone::boundingRect() const
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (!cards.isEmpty()) {
painter->save();
cards.at(0)->paint(painter, option, widget);
painter->restore();
}
if (!cards.isEmpty())
cards.at(0)->paintPicture(painter, 90);
paintNumberEllipse(cards.size(), 32, Qt::white, -1, -1, painter);
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*/)

View file

@ -32,14 +32,13 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
updateBgPixmap();
playerTarget = new PlayerTarget(this);
playerTarget->setPos(QPointF(counterAreaWidth + (CARD_WIDTH + 5 - playerTarget->boundingRect().width()) / 2.0, 5));
QPointF base = QPointF(counterAreaWidth, 5 + playerTarget->boundingRect().height() + 10);
playerTarget->setPos(QPointF(counterAreaWidth + (CARD_HEIGHT + 5 - playerTarget->boundingRect().width()) / 2.0, 5));
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);
qreal h = deck->boundingRect().height() + 10;
qreal h = deck->boundingRect().width() + 5;
PileZone *grave = new PileZone(this, "grave", false, true, this);
grave->setPos(base + QPointF(0, h));
@ -51,7 +50,7 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
sb->setVisible(false);
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);
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
@ -310,7 +309,7 @@ void Player::playerListActionTriggered()
void Player::rearrangeZones()
{
QPointF base = QPointF(CARD_WIDTH + counterAreaWidth + 5, 0);
QPointF base = QPointF(CARD_HEIGHT + counterAreaWidth + 5, 0);
if (settingsCache->getHorizontalHand()) {
if (mirrored) {
@ -358,7 +357,7 @@ void Player::updateBgPixmap()
void Player::updateBoundingRect()
{
prepareGeometryChange();
qreal width = CARD_WIDTH + 5 + counterAreaWidth + stack->boundingRect().width();
qreal width = CARD_HEIGHT + 5 + counterAreaWidth + stack->boundingRect().width();
if (settingsCache->getHorizontalHand())
bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + hand->boundingRect().height());
else
@ -981,7 +980,7 @@ QRectF Player::boundingRect() const
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())
painter->fillRect(QRectF(0, 0, totalWidth, boundingRect().height()), QColor(200, 200, 200));
else
@ -1404,7 +1403,7 @@ QString Player::getName() 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())
result += hand->boundingRect().width();
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)
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())
tableWidth -= hand->boundingRect().width();

View file

@ -17,7 +17,7 @@ PlayerTarget::PlayerTarget(Player *_owner)
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*/)
@ -41,7 +41,10 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
QPixmapCache::insert(cacheKey, cachedPixmap);
}
painter->resetTransform();
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
painter->resetTransform();
QString name = info->getName();
if (name.size() > 13)