correct mirroring of players when spectating

This commit is contained in:
Max-Wilhelm Bruker 2010-05-29 17:31:16 +02:00
parent e1a728328e
commit f2092b89e9
18 changed files with 690 additions and 179 deletions

View file

@ -21,8 +21,6 @@ HEADERS += src/counter.h \
src/tablezone.h \
src/handzone.h \
src/handcounter.h \
src/handzone_vert.h \
src/handzone_horiz.h \
src/carddatabase.h \
src/gameview.h \
src/deck_picturecacher.h \
@ -78,8 +76,6 @@ SOURCES += src/counter.cpp \
src/tablezone.cpp \
src/handzone.cpp \
src/handcounter.cpp \
src/handzone_vert.cpp \
src/handzone_horiz.cpp \
src/carddatabase.cpp \
src/gameview.cpp \
src/deck_picturecacher.cpp \

View file

@ -0,0 +1,487 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="500"
height="500"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.47pre4 r22446"
sodipodi:docname="back.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.0">
<defs
id="defs4">
<linearGradient
id="linearGradient3169">
<stop
style="stop-color:#0000ff;stop-opacity:1;"
offset="0"
id="stop3171" />
<stop
style="stop-color:#000067;stop-opacity:1;"
offset="1"
id="stop3173" />
</linearGradient>
<linearGradient
id="linearGradient4766">
<stop
style="stop-color:#784421;stop-opacity:1;"
offset="0"
id="stop4768" />
<stop
style="stop-color:#3d2210;stop-opacity:0;"
offset="1"
id="stop4770" />
</linearGradient>
<linearGradient
id="linearGradient4758">
<stop
style="stop-color:#a05a2c;stop-opacity:1;"
offset="0"
id="stop4760" />
<stop
style="stop-color:#3d2210;stop-opacity:1;"
offset="1"
id="stop4762" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
<inkscape:perspective
id="perspective2484"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 526.18109 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758"
id="linearGradient4764"
x1="466.09601"
y1="485.96021"
x2="715.14801"
y2="485.96021"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766"
id="linearGradient4772"
x1="496.548"
y1="485.26816"
x2="683.31201"
y2="485.26816"
gradientUnits="userSpaceOnUse" />
<filter
inkscape:collect="always"
id="filter3287"
color-interpolation-filters="sRGB">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.88403668"
id="feGaussianBlur3289" />
</filter>
<inkscape:perspective
id="perspective3123"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
id="linearGradient4758-4">
<stop
style="stop-color:#a05a2c;stop-opacity:1;"
offset="0"
id="stop4760-1" />
<stop
style="stop-color:#3d2210;stop-opacity:1;"
offset="1"
id="stop4762-5" />
</linearGradient>
<linearGradient
id="linearGradient4766-1">
<stop
style="stop-color:#784421;stop-opacity:1;"
offset="0"
id="stop4768-5" />
<stop
style="stop-color:#3d2210;stop-opacity:0;"
offset="1"
id="stop4770-5" />
</linearGradient>
<filter
color-interpolation-filters="sRGB"
inkscape:collect="always"
id="filter3287-4">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.88403668"
id="feGaussianBlur3289-9" />
</filter>
<inkscape:perspective
id="perspective3123-2"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
id="linearGradient4758-7">
<stop
style="stop-color:#a05a2c;stop-opacity:1;"
offset="0"
id="stop4760-0" />
<stop
style="stop-color:#3d2210;stop-opacity:1;"
offset="1"
id="stop4762-3" />
</linearGradient>
<linearGradient
id="linearGradient4766-3">
<stop
style="stop-color:#784421;stop-opacity:1;"
offset="0"
id="stop4768-6" />
<stop
style="stop-color:#3d2210;stop-opacity:0;"
offset="1"
id="stop4770-3" />
</linearGradient>
<filter
color-interpolation-filters="sRGB"
inkscape:collect="always"
id="filter3287-3">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.88403668"
id="feGaussianBlur3289-4" />
</filter>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-4"
id="linearGradient3292"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-1"
id="linearGradient3294"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758"
id="linearGradient3296"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766"
id="linearGradient3298"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-7"
id="linearGradient3300"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-3"
id="linearGradient3302"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-7"
id="linearGradient3340"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-3"
id="linearGradient3342"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758"
id="linearGradient3344"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766"
id="linearGradient3346"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-4"
id="linearGradient3348"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-1"
id="linearGradient3350"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-4"
id="linearGradient3369"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-1"
id="linearGradient3371"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758"
id="linearGradient3373"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766"
id="linearGradient3375"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4758-7"
id="linearGradient3377"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="590.62201"
y1="434.7522"
x2="698.54004"
y2="517.79218" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4766-3"
id="linearGradient3379"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9650128,0,0,0.9948433,-449.70565,-312.80927)"
x1="661.24402"
y1="602.90814"
x2="431.5"
y2="201.5482" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.0399859"
inkscape:cx="321.84821"
inkscape:cy="191.87768"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1280"
inkscape:window-height="950"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,160)">
<g
id="g3352"
transform="translate(-15.384821,4.3269809)">
<g
id="g3109-8"
transform="matrix(0.96592583,-0.25881905,0.25881905,0.96592583,29.101426,-50.437705)">
<g
id="g3008-3">
<rect
y="9.8962135"
x="9.7330923"
height="321.49753"
width="221.03812"
id="rect2490-8"
style="fill:url(#linearGradient3369);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:19.59629059;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
y="31.237556"
x="30.434542"
height="277.43793"
width="178.29964"
id="rect3302-5"
style="fill:url(#linearGradient3371);fill-opacity:1;stroke:#000000;stroke-width:1.95962906;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<path
transform="matrix(1.1399786,0,0,1.0181427,-552.19487,-329.3838)"
d="m 661.55199,489.76617 c 0,71.08568 -32.22118,128.71201 -71.96801,128.71201 -39.74683,0 -71.968,-57.62633 -71.968,-128.71201 0,-71.08567 32.22117,-128.712 71.968,-128.712 39.74683,0 71.96801,57.62633 71.96801,128.712 z"
sodipodi:ry="128.71201"
sodipodi:rx="71.968002"
sodipodi:cy="489.76617"
sodipodi:cx="589.58398"
id="path3304-2"
style="opacity:0.39208954;fill:#a05a2c;stroke:#000000;stroke-width:2.00029755;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;filter:url(#filter3287-4)"
sodipodi:type="arc" />
</g>
</g>
<g
transform="translate(143.26779,-93.267107)"
id="g3109">
<g
id="g3008">
<rect
y="9.8962135"
x="9.7330923"
height="321.49753"
width="221.03812"
id="rect2490"
style="fill:url(#linearGradient3373);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:19.59629059;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
y="31.237556"
x="30.434542"
height="277.43793"
width="178.29964"
id="rect3302"
style="fill:url(#linearGradient3375);fill-opacity:1;stroke:#000000;stroke-width:1.95962906;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<path
transform="matrix(1.1399786,0,0,1.0181427,-552.19487,-329.3838)"
d="m 661.55199,489.76617 c 0,71.08568 -32.22118,128.71201 -71.96801,128.71201 -39.74683,0 -71.968,-57.62633 -71.968,-128.71201 0,-71.08567 32.22117,-128.712 71.968,-128.712 39.74683,0 71.96801,57.62633 71.96801,128.712 z"
sodipodi:ry="128.71201"
sodipodi:rx="71.968002"
sodipodi:cy="489.76617"
sodipodi:cx="589.58398"
id="path3304"
style="opacity:0.39208954;fill:#a05a2c;stroke:#000000;stroke-width:2.00029755;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;filter:url(#filter3287)"
sodipodi:type="arc" />
</g>
</g>
<g
id="g3109-4"
transform="matrix(0.96592583,0.25881905,-0.25881905,0.96592583,269.3589,-107.87704)">
<g
id="g3008-39">
<rect
y="9.8962135"
x="9.7330923"
height="321.49753"
width="221.03812"
id="rect2490-7"
style="fill:url(#linearGradient3377);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:19.59629059;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
y="31.237556"
x="30.434542"
height="277.43793"
width="178.29964"
id="rect3302-2"
style="fill:url(#linearGradient3379);fill-opacity:1;stroke:#000000;stroke-width:1.95962906;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<path
transform="matrix(1.1399786,0,0,1.0181427,-552.19487,-329.3838)"
d="m 661.55199,489.76617 c 0,71.08568 -32.22118,128.71201 -71.96801,128.71201 -39.74683,0 -71.968,-57.62633 -71.968,-128.71201 0,-71.08567 32.22117,-128.712 71.968,-128.712 39.74683,0 71.96801,57.62633 71.96801,128.712 z"
sodipodi:ry="128.71201"
sodipodi:rx="71.968002"
sodipodi:cy="489.76617"
sodipodi:cx="589.58398"
id="path3304-5"
style="opacity:0.39208954;fill:#a05a2c;stroke:#000000;stroke-width:2.00029755;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;filter:url(#filter3287-3)"
sodipodi:type="arc" />
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -35,7 +35,7 @@ void GameScene::removePlayer(Player *player)
void GameScene::rearrange()
{
struct PlayerProcessor {
static void processPlayer(Player *p, qreal &w, qreal &h, QPointF &b)
static void processPlayer(Player *p, qreal &w, qreal &h, QPointF &b, bool singlePlayer)
{
const QRectF br = p->boundingRect();
if (br.width() > w)
@ -44,6 +44,7 @@ void GameScene::rearrange()
h += playerAreaSpacing;
h += br.height();
p->setPos(b);
p->setMirrored((b.y() < playerAreaSpacing) && !singlePlayer);
b += QPointF(0, br.height() + playerAreaSpacing);
}
};
@ -55,11 +56,11 @@ void GameScene::rearrange()
for (int i = 0; i < players.size(); ++i)
if (!players[i]->getLocal())
PlayerProcessor::processPlayer(players[i], sceneWidth, sceneHeight, base);
PlayerProcessor::processPlayer(players[i], sceneWidth, sceneHeight, base, players.size() == 1);
else
localPlayer = players[i];
if (localPlayer)
PlayerProcessor::processPlayer(localPlayer, sceneWidth, sceneHeight, base);
PlayerProcessor::processPlayer(localPlayer, sceneWidth, sceneHeight, base, players.size() == 1);
playersRect = QRectF(0, 0, sceneWidth, sceneHeight);

View file

@ -0,0 +1,38 @@
#include <QPainter>
#include <QSvgRenderer>
#include "handcounter.h"
#include "cardzone.h"
HandCounter::HandCounter(QGraphicsItem *parent)
: AbstractGraphicsItem(parent), number(0)
{
setCacheMode(DeviceCoordinateCache);
QSvgRenderer svg(QString(":/resources/hand.svg"));
handImage = new QPixmap(72, 72);
handImage->fill(Qt::transparent);
QPainter painter(handImage);
svg.render(&painter, QRectF(0, 0, 72, 72));
}
HandCounter::~HandCounter()
{
delete handImage;
}
void HandCounter::updateNumber()
{
number = static_cast<CardZone *>(sender())->getCards().size();
update();
}
QRectF HandCounter::boundingRect() const
{
return QRectF(0, 0, 72, 72);
}
void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
painter->drawPixmap(handImage->rect(), *handImage, handImage->rect());
paintNumberEllipse(number, painter);
}

View file

@ -0,0 +1,27 @@
#ifndef HANDCOUNTER_H
#define HANDCOUNTER_H
#include <QString>
#include "abstractcarditem.h"
class QPainter;
class QPixmap;
class HandCounter : public QObject, public AbstractGraphicsItem {
Q_OBJECT
private:
int number;
QPixmap *handImage;
public slots:
void updateNumber();
public:
enum { Type = typeOther };
int type() const { return Type; }
HandCounter(QGraphicsItem *parent = 0);
~HandCounter();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};
#endif

View file

@ -1,13 +1,15 @@
#include <QPainter>
#include "handzone.h"
#include "settingscache.h"
#include "player.h"
#include "protocol_items.h"
HandZone::HandZone(Player *_p, bool _contentsKnown, QGraphicsItem *parent)
: CardZone(_p, "hand", false, false, _contentsKnown, parent)
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: CardZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
{
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
updateBgPixmap();
setCacheMode(DeviceCoordinateCache);
}
void HandZone::updateBgPixmap()
@ -38,3 +40,79 @@ void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*
{
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), cards.size(), -1, false));
}
QRectF HandZone::boundingRect() const
{
if (settingsCache->getHorizontalHand())
return QRectF(0, 0, width, CARD_HEIGHT + 10);
else
return QRectF(0, 0, 100, zoneHeight);
}
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
if (bgPixmap.isNull())
painter->fillRect(boundingRect(), Qt::darkGreen);
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
}
void HandZone::reorganizeCards()
{
if (!cards.isEmpty()) {
const int cardCount = cards.size();
if (settingsCache->getHorizontalHand()) {
const int xPadding = 5;
qreal totalWidth = boundingRect().width() - 2 * xPadding;
qreal cardWidth = cards.at(0)->boundingRect().width();
for (int i = 0; i < cardCount; i++) {
CardItem *c = cards.at(i);
// If the total width of the cards is smaller than the available width,
// the cards do not need to overlap and are displayed in the center of the area.
if (cardWidth * cardCount > totalWidth)
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
else
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
c->setZValue(i);
}
} else {
qreal totalWidth = boundingRect().width();
qreal totalHeight = boundingRect().height();
qreal cardWidth = cards.at(0)->boundingRect().width();
qreal cardHeight = cards.at(0)->boundingRect().height();
qreal xspace = 5;
qreal x1 = xspace;
qreal x2 = totalWidth - xspace - cardWidth;
for (int i = 0; i < cardCount; i++) {
CardItem *c = cards.at(i);
qreal x = i % 2 ? x2 : x1;
// If the total height of the cards is smaller than the available height,
// the cards do not need to overlap and are displayed in the center of the area.
if (cardHeight * cardCount > totalHeight)
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
else
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
c->setZValue(i);
}
}
}
update();
}
void HandZone::setWidth(qreal _width)
{
if (settingsCache->getHorizontalHand()) {
prepareGeometryChange();
width = _width;
reorganizeCards();
}
}
void HandZone::updateOrientation()
{
prepareGeometryChange();
reorganizeCards();
}

View file

@ -5,14 +5,20 @@
class HandZone : public CardZone {
Q_OBJECT
protected:
private:
qreal width, zoneHeight;
QPixmap bgPixmap;
private slots:
void updateBgPixmap();
public slots:
void updateOrientation();
public:
HandZone(Player *_p, bool _contentsKnown, QGraphicsItem *parent = 0);
HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
virtual void setWidth(qreal _width) = 0;
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void setWidth(qreal _width);
protected:
void addCardImpl(CardItem *card, int x, int y);
};

View file

@ -1,52 +0,0 @@
#include <QPainter>
#include "handzone_horiz.h"
#include "player.h"
HandZoneHoriz::HandZoneHoriz(Player *_p, bool _contentsKnown, QGraphicsItem *parent)
: HandZone(_p, _contentsKnown, parent), width(CARD_WIDTH * 10)
{
setCacheMode(DeviceCoordinateCache);
}
QRectF HandZoneHoriz::boundingRect() const
{
return QRectF(0, 0, width, CARD_HEIGHT + 10);
}
void HandZoneHoriz::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
if (bgPixmap.isNull())
painter->fillRect(boundingRect(), Qt::darkGreen);
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
}
void HandZoneHoriz::reorganizeCards()
{
if (!cards.isEmpty()) {
const int cardCount = cards.size();
const int xPadding = 5;
qreal totalWidth = boundingRect().width() - 2 * xPadding;
qreal cardWidth = cards.at(0)->boundingRect().width();
for (int i = 0; i < cardCount; i++) {
CardItem *c = cards.at(i);
// If the total width of the cards is smaller than the available width,
// the cards do not need to overlap and are displayed in the center of the area.
if (cardWidth * cardCount > totalWidth)
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
else
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
c->setZValue(i);
}
}
update();
}
void HandZoneHoriz::setWidth(qreal _width)
{
prepareGeometryChange();
width = _width;
reorganizeCards();
}

View file

@ -1,18 +0,0 @@
#ifndef HANDZONE_HORIZ_H
#define HANDZONE_HORIZ_H
#include "handzone.h"
class HandZoneHoriz : public HandZone {
Q_OBJECT
private:
qreal width;
public:
HandZoneHoriz(Player *_p, bool _contentsKnown, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void setWidth(qreal _width);
};
#endif

View file

@ -1,52 +0,0 @@
#include <QtGui>
#include "handzone_vert.h"
#include "player.h"
#include "client.h"
#include "protocol_items.h"
#include "settingscache.h"
HandZoneVert::HandZoneVert(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: HandZone(_p, _contentsKnown, parent), zoneHeight(_zoneHeight)
{
setCacheMode(DeviceCoordinateCache);
}
QRectF HandZoneVert::boundingRect() const
{
return QRectF(0, 0, 100, zoneHeight);
}
void HandZoneVert::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
if (bgPixmap.isNull())
painter->fillRect(boundingRect(), Qt::darkGreen);
else
painter->fillRect(boundingRect(), QBrush(bgPixmap));
}
void HandZoneVert::reorganizeCards()
{
if (!cards.isEmpty()) {
const int cardCount = cards.size();
qreal totalWidth = boundingRect().width();
qreal totalHeight = boundingRect().height();
qreal cardWidth = cards.at(0)->boundingRect().width();
qreal cardHeight = cards.at(0)->boundingRect().height();
qreal xspace = 5;
qreal x1 = xspace;
qreal x2 = totalWidth - xspace - cardWidth;
for (int i = 0; i < cardCount; i++) {
CardItem *c = cards.at(i);
qreal x = i % 2 ? x2 : x1;
// If the total height of the cards is smaller than the available height,
// the cards do not need to overlap and are displayed in the center of the area.
if (cardHeight * cardCount > totalHeight)
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
else
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
c->setZValue(i);
}
}
update();
}

View file

@ -1,18 +0,0 @@
#ifndef HANDZONE_VERT_H
#define HANDZONE_VERT_H
#include "handzone.h"
class HandZoneVert : public HandZone {
Q_OBJECT
private:
int zoneHeight;
public:
HandZoneVert(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void setWidth(qreal /*_width*/) { }
};
#endif

View file

@ -9,8 +9,6 @@
#include "tablezone.h"
#include "handzone.h"
#include "handcounter.h"
#include "handzone_vert.h"
#include "handzone_horiz.h"
#include "cardlist.h"
#include "tab_game.h"
#include "protocol_items.h"
@ -20,11 +18,12 @@
#include <QPainter>
#include <QMenu>
Player::Player(const QString &_name, int _id, bool _local, bool _mirrored, Client *_client, TabGame *_parent)
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), mirrored(_mirrored), client(_client)
Player::Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent)
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), mirrored(false), client(_client)
{
setCacheMode(DeviceCoordinateCache);
connect(settingsCache, SIGNAL(horizontalHandChanged()), this, SLOT(rearrangeZones()));
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap()));
updateBgPixmap();
@ -33,7 +32,7 @@ Player::Player(const QString &_name, int _id, bool _local, bool _mirrored, Clien
PileZone *deck = new PileZone(this, "deck", true, false, this);
deck->setPos(base);
qreal h = deck->boundingRect().height() + 20;
qreal h = deck->boundingRect().height() + 10;
PileZone *grave = new PileZone(this, "grave", false, true, this);
grave->setPos(base + QPointF(0, h));
@ -50,24 +49,7 @@ Player::Player(const QString &_name, int _id, bool _local, bool _mirrored, Clien
table = new TableZone(this, this);
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
base = QPointF(deck->boundingRect().width() + counterAreaWidth + 5, 0);
if (settingsCache->getHorizontalHand()) {
hand = new HandZoneHoriz(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), this);
if (mirrored) {
hand->setPos(counterAreaWidth + CARD_WIDTH + 5, base.y());
table->setPos(base.x(), base.y() + hand->boundingRect().height());
} else {
table->setPos(base);
hand->setPos(counterAreaWidth + CARD_WIDTH + 5, base.y() + table->boundingRect().height());
}
} else {
hand = new HandZoneVert(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), (int) table->boundingRect().height(), this);
hand->setPos(base);
base += QPointF(hand->boundingRect().width(), 0);
table->setPos(base);
}
hand = new HandZone(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), (int) table->boundingRect().height(), this);
connect(hand, SIGNAL(cardCountChanged()), handCounter, SLOT(updateNumber()));
updateBoundingRect();
@ -269,6 +251,7 @@ Player::Player(const QString &_name, int _id, bool _local, bool _mirrored, Clien
cardMenu = 0;
}
rearrangeZones();
retranslateUi();
}
@ -288,6 +271,29 @@ Player::~Player()
delete cardMenu;
}
void Player::rearrangeZones()
{
QPointF base = QPointF(CARD_WIDTH + counterAreaWidth + 5, 0);
if (settingsCache->getHorizontalHand()) {
if (mirrored) {
hand->setPos(counterAreaWidth + CARD_WIDTH + 5, base.y());
table->setPos(base.x(), base.y() + hand->boundingRect().height());
} else {
table->setPos(base);
hand->setPos(counterAreaWidth + CARD_WIDTH + 5, base.y() + table->boundingRect().height());
}
hand->setWidth(table->getWidth());
} else {
hand->setPos(base);
base += QPointF(hand->boundingRect().width(), 0);
table->setPos(base);
}
hand->updateOrientation();
updateBoundingRect();
rearrangeCounters();
}
void Player::updateBgPixmap()
{
QString bgPath = settingsCache->getPlayerBgPath();
@ -1023,6 +1029,14 @@ qreal Player::getMinimumWidth() const
return table->getMinimumWidth() + CARD_WIDTH + 5 + counterAreaWidth;
}
void Player::setMirrored(bool _mirrored)
{
if (mirrored != _mirrored) {
mirrored = _mirrored;
rearrangeZones();
}
}
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)

View file

@ -80,6 +80,7 @@ private slots:
void updateBoundingRect();
void cardMenuAction();
void actSetCounters();
void rearrangeZones();
private:
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu;
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
@ -165,7 +166,7 @@ public:
void clearArrows();
Client *client;
Player(const QString &_name, int _id, bool _local, bool _mirrored, Client *_client, TabGame *_parent);
Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent);
~Player();
void retranslateUi();
QMenu *getPlayerMenu() const { return playerMenu; }
@ -181,6 +182,7 @@ public:
void setActive(bool _active);
qreal getMinimumWidth() const;
void setMirrored(bool _mirrored);
void processSceneSizeChange(const QSizeF &newSize);
void processPlayerInfo(ServerInfo_Player *info);

View file

@ -89,6 +89,7 @@ void SettingsCache::setHorizontalHand(int _horizontalHand)
{
horizontalHand = _horizontalHand;
settings->setValue("hand/horizontal", horizontalHand);
emit horizontalHandChanged();
}
void SettingsCache::setEconomicGrid(int _economicGrid)

View file

@ -15,6 +15,7 @@ signals:
void tableBgPathChanged();
void playerBgPathChanged();
void picDownloadChanged();
void horizontalHandChanged();
void economicGridChanged();
private:
QSettings *settings;

View file

@ -208,8 +208,7 @@ void TabGame::actRemoveLocalArrows()
Player *TabGame::addPlayer(int playerId, const QString &playerName)
{
// XXX Find a different criterion for the 'mirrored' flag. When spectating, both players are not local, but only one should be mirrored.
Player *newPlayer = new Player(playerName, playerId, playerId == localPlayerId, playerId != localPlayerId, client, this);
Player *newPlayer = new Player(playerName, playerId, playerId == localPlayerId, client, this);
scene->addPlayer(newPlayer);
connect(newPlayer, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *)));

View file

@ -76,7 +76,7 @@ void TableZone::reorganizeCards()
qreal x = mapPoint.x();
qreal y = mapPoint.y();
if (!player->getLocal())
if (player->getMirrored())
y = height - CARD_HEIGHT - y;
cards[i]->setPos(x, y);
cards[i]->setZValue((y + CARD_HEIGHT) * 10000000 + x + 1000);

View file

@ -35,6 +35,7 @@ public:
void resizeToContents();
int getMinimumWidth() const { return currentMinimumWidth; }
void setWidth(qreal _width);
qreal getWidth() const { return width; }
protected:
void addCardImpl(CardItem *card, int x, int y);
};