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)
|
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, CardDragItem *parentDrag)
|
||||||
: QGraphicsItem(), id(_id), item(_item), hotSpot(_hotSpot), faceDown(_faceDown), currentZone(0)
|
: QGraphicsItem(), id(_id), item(_item), hotSpot(_hotSpot), faceDown(_faceDown), currentZone(0)
|
||||||
{
|
{
|
||||||
if (parentDrag)
|
if (parentDrag) {
|
||||||
parentDrag->addChildDrag(this);
|
parentDrag->addChildDrag(this);
|
||||||
else {
|
setZValue(1000000000 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
||||||
|
} else {
|
||||||
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
||||||
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
||||||
hotSpot = QPointF();
|
hotSpot = QPointF();
|
||||||
|
@ -18,11 +19,11 @@ CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bo
|
||||||
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
setZValue(1000000000);
|
||||||
}
|
}
|
||||||
if (item->getTapped())
|
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));
|
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);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,13 +210,22 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
createDragItem(id, event->pos(), event->scenePos(), faceDown);
|
createDragItem(id, event->pos(), event->scenePos(), faceDown);
|
||||||
dragItem->grabMouse();
|
dragItem->grabMouse();
|
||||||
|
|
||||||
|
CardZone *zone = (CardZone *) parentItem();
|
||||||
|
|
||||||
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||||
|
int j = 0;
|
||||||
for (int i = 0; i < sel.size(); i++) {
|
for (int i = 0; i < sel.size(); i++) {
|
||||||
CardItem *c = (CardItem *) sel.at(i);
|
CardItem *c = (CardItem *) sel.at(i);
|
||||||
if (c == this)
|
if (c == this)
|
||||||
continue;
|
continue;
|
||||||
CardDragItem *drag = new CardDragItem(c, c->getId(), c->pos() - pos(), false, dragItem);
|
++j;
|
||||||
drag->setPos(dragItem->pos() + c->pos() - pos());
|
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);
|
scene()->addItem(drag);
|
||||||
}
|
}
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
|
@ -33,6 +33,11 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*optio
|
||||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||||
else
|
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)
|
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()
|
void TableZone::resizeToContents()
|
||||||
{
|
{
|
||||||
qDebug("resizeToContents");
|
|
||||||
int xMax = 0;
|
int xMax = 0;
|
||||||
for (int i = 0; i < cards.size(); ++i)
|
for (int i = 0; i < cards.size(); ++i)
|
||||||
if (cards[i]->pos().x() > xMax)
|
if (cards[i]->pos().x() > xMax)
|
||||||
xMax = cards[i]->pos().x();
|
xMax = cards[i]->pos().x();
|
||||||
qDebug(QString("xMax = %1").arg(xMax).toLatin1());
|
|
||||||
xMax += 2 * CARD_WIDTH;
|
xMax += 2 * CARD_WIDTH;
|
||||||
if (xMax < minWidth)
|
if (xMax < minWidth)
|
||||||
xMax = minWidth;
|
xMax = minWidth;
|
||||||
|
@ -121,7 +124,6 @@ CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
||||||
|
|
||||||
QPointF TableZone::mapFromGrid(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 (gridPoint.y() == 3) {
|
||||||
if (economicGrid)
|
if (economicGrid)
|
||||||
return QPointF(
|
return QPointF(
|
||||||
|
@ -153,32 +155,25 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
||||||
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());
|
|
||||||
QPoint result = QPoint(
|
QPoint result = QPoint(
|
||||||
// (int) round((double) x * 2 / CARD_WIDTH),
|
|
||||||
// (int) round((double) y / (CARD_HEIGHT + paddingY))
|
|
||||||
x * 2 / CARD_WIDTH,
|
x * 2 / CARD_WIDTH,
|
||||||
y / (CARD_HEIGHT + paddingY)
|
y / (CARD_HEIGHT + paddingY)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.y() == 3) {
|
if (result.y() == 3) {
|
||||||
qDebug("UNTER grenze");
|
|
||||||
if (economicGrid)
|
if (economicGrid)
|
||||||
return QPoint(
|
return QPoint(
|
||||||
x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH)),
|
x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH)),
|
||||||
3
|
3
|
||||||
);
|
);
|
||||||
else {
|
else
|
||||||
return QPoint(
|
return QPoint(
|
||||||
x / (1.5 * CARD_WIDTH),
|
x / (1.5 * CARD_WIDTH),
|
||||||
3
|
3
|
||||||
);
|
);
|
||||||
}
|
} else
|
||||||
} else {
|
|
||||||
qDebug("UEBER grenze");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QPoint TableZone::getFreeGridPoint(int row) const
|
QPoint TableZone::getFreeGridPoint(int row) const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue