some fixes
This commit is contained in:
parent
ca07cce5ed
commit
00a2f49c94
9 changed files with 128 additions and 67 deletions
|
@ -53,8 +53,7 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
QPointF zonePos = currentZone->scenePos();
|
QPointF zonePos = currentZone->scenePos();
|
||||||
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
||||||
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
||||||
// QPointF cardCenter = cardTopLeft + QPointF(CARD_WIDTH / 2, CARD_HEIGHT / 2);
|
QPointF newPos = zonePos + cursorZone->closestGridPoint(cardTopLeft);
|
||||||
QPointF newPos = zonePos + cursorZone->closestGridPoint(cardTopLeft + QPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2));
|
|
||||||
|
|
||||||
// qDebug(QString("cardTopLeft = %1, %2 cardCenter = %3, %4").arg((cardTopLeft).x()).arg((cardTopLeft).y()).arg(cardCenter.x()).arg(cardCenter.y()).toLatin1());
|
// qDebug(QString("cardTopLeft = %1, %2 cardCenter = %3, %4").arg((cardTopLeft).x()).arg((cardTopLeft).y()).arg(cardCenter.x()).arg(cardCenter.y()).toLatin1());
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
// getCard() finds a card by id.
|
// getCard() finds a card by id.
|
||||||
CardItem *getCard(int cardId, const QString &cardName);
|
CardItem *getCard(int cardId, const QString &cardName);
|
||||||
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
||||||
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
virtual CardItem *takeCard(int position, int cardId, const QString &cardName);
|
||||||
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
||||||
ZoneViewZone *getView() const { return view; }
|
ZoneViewZone *getView() const { return view; }
|
||||||
void setView(ZoneViewZone *_view);
|
void setView(ZoneViewZone *_view);
|
||||||
|
|
|
@ -5,60 +5,57 @@
|
||||||
GameScene::GameScene(ZoneViewLayout *_zvLayout, QObject *parent)
|
GameScene::GameScene(ZoneViewLayout *_zvLayout, QObject *parent)
|
||||||
: QGraphicsScene(parent), zvLayout(_zvLayout)
|
: QGraphicsScene(parent), zvLayout(_zvLayout)
|
||||||
{
|
{
|
||||||
connect(zvLayout, SIGNAL(sizeChanged()), this, SLOT(updateSceneSize()));
|
connect(zvLayout, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||||
addItem(zvLayout);
|
addItem(zvLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::updateSceneSize()
|
|
||||||
{
|
|
||||||
int sceneWidth = 0;
|
|
||||||
int sceneHeight = 0;
|
|
||||||
for (int i = 0; i < players.size(); ++i) {
|
|
||||||
const QRectF br = players[i]->boundingRect();
|
|
||||||
if (i)
|
|
||||||
sceneHeight += playerAreaSpacing;
|
|
||||||
sceneHeight += br.height();
|
|
||||||
if (br.width() > sceneWidth)
|
|
||||||
sceneWidth = br.width();
|
|
||||||
}
|
|
||||||
sceneWidth += zvLayout->size().width();
|
|
||||||
qDebug(QString("updateSceneSize: w=%1 h=%2").arg(sceneWidth).arg(sceneHeight).toLatin1());
|
|
||||||
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameScene::addPlayer(Player *player)
|
void GameScene::addPlayer(Player *player)
|
||||||
{
|
{
|
||||||
players << player;
|
players << player;
|
||||||
updateSceneSize();
|
|
||||||
addItem(player);
|
addItem(player);
|
||||||
rearrangePlayers();
|
rearrange();
|
||||||
|
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
{
|
{
|
||||||
players.removeAt(players.indexOf(player));
|
players.removeAt(players.indexOf(player));
|
||||||
removeItem(player);
|
removeItem(player);
|
||||||
updateSceneSize();
|
rearrange();
|
||||||
rearrangePlayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::rearrangePlayers()
|
void GameScene::rearrange()
|
||||||
{
|
{
|
||||||
|
struct PlayerProcessor {
|
||||||
|
static void processPlayer(Player *p, qreal &w, qreal &h, QPointF &b)
|
||||||
|
{
|
||||||
|
const QRectF br = p->boundingRect();
|
||||||
|
if (br.width() > w)
|
||||||
|
w = br.width();
|
||||||
|
if (h)
|
||||||
|
h += playerAreaSpacing;
|
||||||
|
h += br.height();
|
||||||
|
p->setPos(b);
|
||||||
|
b += QPointF(0, br.height() + playerAreaSpacing);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
QPointF base;
|
QPointF base;
|
||||||
qreal maxWidth = 0;
|
qreal sceneWidth = 0;
|
||||||
|
qreal sceneHeight = 0;
|
||||||
Player *localPlayer = 0;
|
Player *localPlayer = 0;
|
||||||
for (int i = 0; i < players.size(); ++i) {
|
|
||||||
QRectF br = players[i]->boundingRect();
|
for (int i = 0; i < players.size(); ++i)
|
||||||
if (br.width() > maxWidth)
|
if (!players[i]->getLocal())
|
||||||
maxWidth = br.width();
|
PlayerProcessor::processPlayer(players[i], sceneWidth, sceneHeight, base);
|
||||||
if (!players[i]->getLocal()) {
|
else
|
||||||
players[i]->setPos(base);
|
|
||||||
// Change this for better multiplayer support.
|
|
||||||
base += QPointF(0, br.height() + playerAreaSpacing);
|
|
||||||
} else
|
|
||||||
localPlayer = players[i];
|
localPlayer = players[i];
|
||||||
}
|
|
||||||
if (localPlayer)
|
if (localPlayer)
|
||||||
localPlayer->setPos(base);
|
PlayerProcessor::processPlayer(localPlayer, sceneWidth, sceneHeight, base);
|
||||||
zvLayout->setPos(QPointF(maxWidth, 0));
|
|
||||||
|
zvLayout->setPos(QPointF(sceneWidth, 0));
|
||||||
|
sceneWidth += zvLayout->size().width();
|
||||||
|
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
||||||
|
|
||||||
|
qDebug(QString("rearrange(): w=%1 h=%2").arg(sceneWidth).arg(sceneHeight).toLatin1());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,13 @@ private:
|
||||||
|
|
||||||
QList<Player *> players;
|
QList<Player *> players;
|
||||||
ZoneViewLayout *zvLayout;
|
ZoneViewLayout *zvLayout;
|
||||||
|
|
||||||
void rearrangePlayers();
|
|
||||||
public:
|
public:
|
||||||
GameScene(ZoneViewLayout *_zvLayout, QObject *parent = 0);
|
GameScene(ZoneViewLayout *_zvLayout, QObject *parent = 0);
|
||||||
public slots:
|
public slots:
|
||||||
void addPlayer(Player *player);
|
void addPlayer(Player *player);
|
||||||
void removePlayer(Player *player);
|
void removePlayer(Player *player);
|
||||||
private slots:
|
private slots:
|
||||||
void updateSceneSize();
|
void rearrange();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,15 +37,16 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
|
||||||
PileZone *sb = new PileZone(this, "sb", false, true, this);
|
PileZone *sb = new PileZone(this, "sb", false, true, this);
|
||||||
sb->setVisible(false);
|
sb->setVisible(false);
|
||||||
|
|
||||||
CardZone *table = new TableZone(this, this);
|
table = new TableZone(this, this);
|
||||||
CardZone *hand = new HandZone(this, table->boundingRect().height(), this);
|
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
|
||||||
|
hand = new HandZone(this, table->boundingRect().height(), this);
|
||||||
|
|
||||||
base = QPointF(deck->boundingRect().width() + 60, 0);
|
base = QPointF(deck->boundingRect().width() + 60, 0);
|
||||||
hand->setPos(base);
|
hand->setPos(base);
|
||||||
base += QPointF(hand->boundingRect().width(), 0);
|
base += QPointF(hand->boundingRect().width(), 0);
|
||||||
table->setPos(base);
|
table->setPos(base);
|
||||||
|
|
||||||
bRect = QRectF(0, 0, base.x() + table->boundingRect().width(), base.y() + table->boundingRect().height());
|
updateBoundingRect();
|
||||||
|
|
||||||
if (local) {
|
if (local) {
|
||||||
aMoveHandToTopLibrary = new QAction(this);
|
aMoveHandToTopLibrary = new QAction(this);
|
||||||
|
@ -83,7 +84,7 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
|
||||||
handMenu = playerMenu->addMenu(QString());
|
handMenu = playerMenu->addMenu(QString());
|
||||||
handMenu->addAction(aMoveHandToTopLibrary);
|
handMenu->addAction(aMoveHandToTopLibrary);
|
||||||
handMenu->addAction(aMoveHandToBottomLibrary);
|
handMenu->addAction(aMoveHandToBottomLibrary);
|
||||||
zones.findZone("hand")->setMenu(handMenu);
|
hand->setMenu(handMenu);
|
||||||
|
|
||||||
libraryMenu = playerMenu->addMenu(QString());
|
libraryMenu = playerMenu->addMenu(QString());
|
||||||
libraryMenu->addAction(aDrawCard);
|
libraryMenu->addAction(aDrawCard);
|
||||||
|
@ -93,7 +94,7 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
|
||||||
libraryMenu->addSeparator();
|
libraryMenu->addSeparator();
|
||||||
libraryMenu->addAction(aViewLibrary);
|
libraryMenu->addAction(aViewLibrary);
|
||||||
libraryMenu->addAction(aViewTopCards);
|
libraryMenu->addAction(aViewTopCards);
|
||||||
zones.findZone("deck")->setMenu(libraryMenu, aDrawCard);
|
deck->setMenu(libraryMenu, aDrawCard);
|
||||||
} else {
|
} else {
|
||||||
handMenu = 0;
|
handMenu = 0;
|
||||||
libraryMenu = 0;
|
libraryMenu = 0;
|
||||||
|
@ -101,16 +102,16 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
|
||||||
|
|
||||||
graveMenu = playerMenu->addMenu(QString());
|
graveMenu = playerMenu->addMenu(QString());
|
||||||
graveMenu->addAction(aViewGraveyard);
|
graveMenu->addAction(aViewGraveyard);
|
||||||
zones.findZone("grave")->setMenu(graveMenu, aViewGraveyard);
|
grave->setMenu(graveMenu, aViewGraveyard);
|
||||||
|
|
||||||
rfgMenu = playerMenu->addMenu(QString());
|
rfgMenu = playerMenu->addMenu(QString());
|
||||||
rfgMenu->addAction(aViewRfg);
|
rfgMenu->addAction(aViewRfg);
|
||||||
zones.findZone("rfg")->setMenu(rfgMenu, aViewRfg);
|
rfg->setMenu(rfgMenu, aViewRfg);
|
||||||
|
|
||||||
if (local) {
|
if (local) {
|
||||||
sbMenu = playerMenu->addMenu(QString());
|
sbMenu = playerMenu->addMenu(QString());
|
||||||
sbMenu->addAction(aViewSideboard);
|
sbMenu->addAction(aViewSideboard);
|
||||||
zones.findZone("sb")->setMenu(sbMenu, aViewSideboard);
|
sb->setMenu(sbMenu, aViewSideboard);
|
||||||
} else
|
} else
|
||||||
sbMenu = 0;
|
sbMenu = 0;
|
||||||
|
|
||||||
|
@ -127,6 +128,12 @@ Player::~Player()
|
||||||
clearCounters();
|
clearCounters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::updateBoundingRect()
|
||||||
|
{
|
||||||
|
bRect = QRectF(0, 0, CARD_WIDTH + 60 + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
|
||||||
|
emit sizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Player::retranslateUi()
|
void Player::retranslateUi()
|
||||||
{
|
{
|
||||||
aViewGraveyard->setText(tr("&View graveyard"));
|
aViewGraveyard->setText(tr("&View graveyard"));
|
||||||
|
|
|
@ -13,6 +13,8 @@ class QAction;
|
||||||
class ZoneViewZone;
|
class ZoneViewZone;
|
||||||
class Game;
|
class Game;
|
||||||
class Counter;
|
class Counter;
|
||||||
|
class TableZone;
|
||||||
|
class HandZone;
|
||||||
|
|
||||||
class Player : public QObject, public QGraphicsItem {
|
class Player : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -29,7 +31,11 @@ signals:
|
||||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||||
|
|
||||||
|
void sizeChanged();
|
||||||
private slots:
|
private slots:
|
||||||
|
void updateBoundingRect();
|
||||||
|
|
||||||
void actMoveHandToTopLibrary();
|
void actMoveHandToTopLibrary();
|
||||||
void actMoveHandToBottomLibrary();
|
void actMoveHandToBottomLibrary();
|
||||||
|
|
||||||
|
@ -53,7 +59,11 @@ private:
|
||||||
int id;
|
int id;
|
||||||
bool active;
|
bool active;
|
||||||
bool local;
|
bool local;
|
||||||
|
|
||||||
ZoneList zones;
|
ZoneList zones;
|
||||||
|
TableZone *table;
|
||||||
|
HandZone *hand;
|
||||||
|
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards);
|
void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||||
height = 14.0 / 3 * CARD_HEIGHT + 3 * paddingY;
|
height = 14.0 / 3 * CARD_HEIGHT + 3 * paddingY;
|
||||||
else
|
else
|
||||||
height = 4 * CARD_HEIGHT + 3 * paddingY;
|
height = 4 * CARD_HEIGHT + 3 * paddingY;
|
||||||
width = 12 * CARD_WIDTH;
|
width = minWidth * CARD_WIDTH / 2;
|
||||||
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
|
@ -29,6 +29,25 @@ QRectF TableZone::boundingRect() const
|
||||||
|
|
||||||
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
// DEBUG
|
||||||
|
painter->fillRect(boundingRect(), Qt::black);
|
||||||
|
for (int i = 0; i < width; i += 2)
|
||||||
|
for (int j = 0; j < height; j += 2) {
|
||||||
|
// QPointF p = closestGridPoint(QPointF(i, j));
|
||||||
|
QPoint p = mapToGrid(QPointF(i, j));
|
||||||
|
QColor c;
|
||||||
|
// c.setHsv(p.x() / 2, p.y() / 3, 255);
|
||||||
|
c.setHsv(p.x() * 12, p.y() * 80, 255);
|
||||||
|
painter->setPen(c);
|
||||||
|
painter->setBrush(c);
|
||||||
|
painter->drawRect(i, j, 2, 2);
|
||||||
|
}
|
||||||
|
painter->setPen(Qt::black);
|
||||||
|
painter->drawLine(QPointF(0, 366), QPointF(1000, 366));
|
||||||
|
// DEBUG Ende
|
||||||
|
*/
|
||||||
|
|
||||||
if (bgPixmap.isNull())
|
if (bgPixmap.isNull())
|
||||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||||
else
|
else
|
||||||
|
@ -41,6 +60,11 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
|
||||||
qreal x = mapPoint.x();
|
qreal x = mapPoint.x();
|
||||||
qreal y = mapPoint.y();
|
qreal y = mapPoint.y();
|
||||||
|
|
||||||
|
if (x >= width - marginX - 2 * CARD_WIDTH) {
|
||||||
|
width += 2 * CARD_WIDTH;
|
||||||
|
emit sizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
cards.append(card);
|
cards.append(card);
|
||||||
// if ((x != -1) && (y != -1)) {
|
// if ((x != -1) && (y != -1)) {
|
||||||
if (!player->getLocal())
|
if (!player->getLocal())
|
||||||
|
@ -48,7 +72,7 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
|
||||||
card->setPos(x, y);
|
card->setPos(x, y);
|
||||||
// }
|
// }
|
||||||
card->setGridPoint(QPoint(_x, _y));
|
card->setGridPoint(QPoint(_x, _y));
|
||||||
card->setZValue((y + CARD_HEIGHT) * width + x + 1000);
|
card->setZValue((y + CARD_HEIGHT) * 10000000 + x + 1000);
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
card->setVisible(true);
|
card->setVisible(true);
|
||||||
card->update();
|
card->update();
|
||||||
|
@ -84,6 +108,23 @@ void TableZone::toggleTapped()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CardItem *TableZone::takeCard(int position, int cardId, const QString &cardName)
|
||||||
|
{
|
||||||
|
CardItem *result = CardZone::takeCard(position, cardId, cardName);
|
||||||
|
int xMax = 0;
|
||||||
|
for (int i = 0; i < cards.size(); ++i)
|
||||||
|
if (cards[i]->getGridPoint().x() > xMax)
|
||||||
|
xMax = cards[i]->getGridPoint().x();
|
||||||
|
if (xMax < minWidth)
|
||||||
|
xMax = minWidth;
|
||||||
|
int newWidth = (xMax + 1) * CARD_WIDTH / 2 + 2 * marginX;
|
||||||
|
if (newWidth < width - 2 * CARD_WIDTH) {
|
||||||
|
width = newWidth;
|
||||||
|
emit sizeChanged();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cards.size(); i++)
|
for (int i = 0; i < cards.size(); i++)
|
||||||
|
@ -115,19 +156,26 @@ QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
||||||
|
|
||||||
QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
||||||
{
|
{
|
||||||
qreal x = mapPoint.x() - 20;
|
qreal x = mapPoint.x() - marginX;
|
||||||
qreal y = mapPoint.y();
|
qreal y = mapPoint.y() + paddingY / 2;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
x = 0;
|
x = 0;
|
||||||
else if (x > width - CARD_WIDTH)
|
else if (x > width - CARD_WIDTH - marginX)
|
||||||
x = width - CARD_WIDTH;
|
x = width - CARD_WIDTH - marginX;
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
y = 0;
|
y = 0;
|
||||||
else if (y > height - CARD_HEIGHT)
|
else if (y > height - CARD_HEIGHT)
|
||||||
y = height - CARD_HEIGHT;
|
y = height - CARD_HEIGHT;
|
||||||
|
|
||||||
qDebug(QString("mapToGrid: %1, %2").arg(x).arg(y).toLatin1());
|
qDebug(QString("mapToGrid: %1, %2").arg(x).arg(y).toLatin1());
|
||||||
if (y >= (CARD_HEIGHT + paddingY) * 3 - paddingY / 2) {
|
QPoint result = QPoint(
|
||||||
|
// (int) round((double) x * 2 / CARD_WIDTH),
|
||||||
|
// (int) round((double) y / (CARD_HEIGHT + paddingY))
|
||||||
|
x * 2 / CARD_WIDTH,
|
||||||
|
y / (CARD_HEIGHT + paddingY)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.y() == 3) {
|
||||||
qDebug("UNTER grenze");
|
qDebug("UNTER grenze");
|
||||||
if (economicGrid)
|
if (economicGrid)
|
||||||
return QPoint(
|
return QPoint(
|
||||||
|
@ -135,18 +183,14 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
||||||
3
|
3
|
||||||
);
|
);
|
||||||
else {
|
else {
|
||||||
qDebug(QString("mapX = %1").arg((int) round((double) x / (1.25 * CARD_WIDTH))).toLatin1());
|
|
||||||
return QPoint(
|
return QPoint(
|
||||||
x / (1.5 * CARD_WIDTH),
|
round((double) x / (1.5 * CARD_WIDTH)),
|
||||||
3
|
3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug("UEBER grenze");
|
qDebug("UEBER grenze");
|
||||||
return QPoint(
|
return result;
|
||||||
x * 2 / CARD_WIDTH,
|
|
||||||
y / (CARD_HEIGHT + paddingY)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,5 +209,5 @@ QPoint TableZone::getFreeGridPoint(int row) const
|
||||||
|
|
||||||
QPointF TableZone::closestGridPoint(const QPointF &point)
|
QPointF TableZone::closestGridPoint(const QPointF &point)
|
||||||
{
|
{
|
||||||
return mapFromGrid(mapToGrid(point));
|
return mapFromGrid(mapToGrid(point + QPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,18 @@
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
|
|
||||||
class TableZone : public CardZone {
|
class TableZone : public QObject, public CardZone {
|
||||||
|
Q_OBJECT
|
||||||
|
signals:
|
||||||
|
void sizeChanged();
|
||||||
private:
|
private:
|
||||||
int width, height;
|
int width, height;
|
||||||
QPixmap bgPixmap;
|
QPixmap bgPixmap;
|
||||||
bool economicGrid;
|
bool economicGrid;
|
||||||
public:
|
public:
|
||||||
static const int paddingY = 20;
|
static const int paddingY = 20;
|
||||||
|
static const int marginX = 20;
|
||||||
|
static const int minWidth = 20;
|
||||||
|
|
||||||
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
|
@ -23,6 +28,7 @@ public:
|
||||||
QPoint mapToGrid(const QPointF &mapPoint) const;
|
QPoint mapToGrid(const QPointF &mapPoint) const;
|
||||||
QPoint getFreeGridPoint(int row) const;
|
QPoint getFreeGridPoint(int row) const;
|
||||||
QPointF closestGridPoint(const QPointF &point);
|
QPointF closestGridPoint(const QPointF &point);
|
||||||
|
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
ZoneViewLayout::ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent)
|
ZoneViewLayout::ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent)
|
||||||
: QGraphicsWidget(parent), db(_db)
|
: QGraphicsWidget(parent), db(_db)
|
||||||
{
|
{
|
||||||
|
resize(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewLayout::reorganize()
|
void ZoneViewLayout::reorganize()
|
||||||
|
|
Loading…
Reference in a new issue