fixed multi-card dragging
This commit is contained in:
parent
aa9ebd3179
commit
5fa009714b
3 changed files with 23 additions and 18 deletions
|
@ -7,9 +7,10 @@
|
|||
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, CardDragItem *parentDrag)
|
||||
: QGraphicsItem(), id(_id), item(_item), hotSpot(_hotSpot), faceDown(_faceDown), currentZone(0)
|
||||
{
|
||||
if (parentDrag)
|
||||
if (parentDrag) {
|
||||
parentDrag->addChildDrag(this);
|
||||
else {
|
||||
setZValue(1000000000 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
||||
} else {
|
||||
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
||||
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
||||
hotSpot = QPointF();
|
||||
|
@ -18,11 +19,11 @@ CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bo
|
|||
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
setZValue(1000000000);
|
||||
}
|
||||
if (item->getTapped())
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
|
||||
setZValue(2000000000);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
}
|
||||
|
||||
|
|
|
@ -209,14 +209,23 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
createDragItem(id, event->pos(), event->scenePos(), faceDown);
|
||||
dragItem->grabMouse();
|
||||
|
||||
CardZone *zone = (CardZone *) parentItem();
|
||||
|
||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||
int j = 0;
|
||||
for (int i = 0; i < sel.size(); i++) {
|
||||
CardItem *c = (CardItem *) sel.at(i);
|
||||
if (c == this)
|
||||
continue;
|
||||
CardDragItem *drag = new CardDragItem(c, c->getId(), c->pos() - pos(), false, dragItem);
|
||||
drag->setPos(dragItem->pos() + c->pos() - pos());
|
||||
++j;
|
||||
QPointF childPos;
|
||||
if (zone->getHasCardAttr())
|
||||
childPos = c->pos() - pos();
|
||||
else
|
||||
childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
||||
CardDragItem *drag = new CardDragItem(c, c->getId(), childPos, false, dragItem);
|
||||
drag->setPos(dragItem->pos() + childPos);
|
||||
scene()->addItem(drag);
|
||||
}
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
|
|
|
@ -32,7 +32,12 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*optio
|
|||
if (bgPixmap.isNull())
|
||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||
else
|
||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||
painter->setPen(QColor(255, 255, 255, 40));
|
||||
qreal separatorY = 3 * (CARD_HEIGHT + paddingY) - paddingY / 2;
|
||||
if (!player->getLocal())
|
||||
separatorY = height - separatorY;
|
||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||
}
|
||||
|
||||
void TableZone::addCardImpl(CardItem *card, int _x, int _y)
|
||||
|
@ -95,12 +100,10 @@ CardItem *TableZone::takeCard(int position, int cardId, const QString &cardName,
|
|||
|
||||
void TableZone::resizeToContents()
|
||||
{
|
||||
qDebug("resizeToContents");
|
||||
int xMax = 0;
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
if (cards[i]->pos().x() > xMax)
|
||||
xMax = cards[i]->pos().x();
|
||||
qDebug(QString("xMax = %1").arg(xMax).toLatin1());
|
||||
xMax += 2 * CARD_WIDTH;
|
||||
if (xMax < minWidth)
|
||||
xMax = minWidth;
|
||||
|
@ -121,7 +124,6 @@ CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
|||
|
||||
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
||||
{
|
||||
qDebug(QString("mapFromGrid: %1, %2").arg(gridPoint.x()).arg(gridPoint.y()).toLatin1());
|
||||
if (gridPoint.y() == 3) {
|
||||
if (economicGrid)
|
||||
return QPointF(
|
||||
|
@ -153,31 +155,24 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
else if (y > height - CARD_HEIGHT)
|
||||
y = height - CARD_HEIGHT;
|
||||
|
||||
qDebug(QString("mapToGrid: %1, %2").arg(x).arg(y).toLatin1());
|
||||
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(
|
||||
x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH)),
|
||||
3
|
||||
);
|
||||
else {
|
||||
else
|
||||
return QPoint(
|
||||
x / (1.5 * CARD_WIDTH),
|
||||
3
|
||||
);
|
||||
}
|
||||
} else {
|
||||
qDebug("UEBER grenze");
|
||||
} else
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
QPoint TableZone::getFreeGridPoint(int row) const
|
||||
|
|
Loading…
Reference in a new issue