some fixes

This commit is contained in:
Max-Wilhelm Bruker 2009-09-08 22:45:48 +02:00
parent ca07cce5ed
commit 00a2f49c94
9 changed files with 128 additions and 67 deletions

View file

@ -16,7 +16,7 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
height = 14.0 / 3 * CARD_HEIGHT + 3 * paddingY;
else
height = 4 * CARD_HEIGHT + 3 * paddingY;
width = 12 * CARD_WIDTH;
width = minWidth * CARD_WIDTH / 2;
setCacheMode(DeviceCoordinateCache);
setAcceptsHoverEvents(true);
@ -29,6 +29,25 @@ QRectF TableZone::boundingRect() const
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())
painter->fillRect(boundingRect(), QColor(0, 0, 100));
else
@ -41,6 +60,11 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
qreal x = mapPoint.x();
qreal y = mapPoint.y();
if (x >= width - marginX - 2 * CARD_WIDTH) {
width += 2 * CARD_WIDTH;
emit sizeChanged();
}
cards.append(card);
// if ((x != -1) && (y != -1)) {
if (!player->getLocal())
@ -48,7 +72,7 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
card->setPos(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->setVisible(true);
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
{
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
{
qreal x = mapPoint.x() - 20;
qreal y = mapPoint.y();
qreal x = mapPoint.x() - marginX;
qreal y = mapPoint.y() + paddingY / 2;
if (x < 0)
x = 0;
else if (x > width - CARD_WIDTH)
x = width - CARD_WIDTH;
else if (x > width - CARD_WIDTH - marginX)
x = width - CARD_WIDTH - marginX;
if (y < 0)
y = 0;
else if (y > height - CARD_HEIGHT)
y = height - CARD_HEIGHT;
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");
if (economicGrid)
return QPoint(
@ -135,18 +183,14 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
3
);
else {
qDebug(QString("mapX = %1").arg((int) round((double) x / (1.25 * CARD_WIDTH))).toLatin1());
return QPoint(
x / (1.5 * CARD_WIDTH),
round((double) x / (1.5 * CARD_WIDTH)),
3
);
}
} else {
qDebug("UEBER grenze");
return QPoint(
x * 2 / CARD_WIDTH,
y / (CARD_HEIGHT + paddingY)
);
return result;
}
}
@ -165,5 +209,5 @@ QPoint TableZone::getFreeGridPoint(int row) const
QPointF TableZone::closestGridPoint(const QPointF &point)
{
return mapFromGrid(mapToGrid(point));
return mapFromGrid(mapToGrid(point + QPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2)));
}