QPointF TableZone::closestGridPoint(const QPointF &point) { QPoint gridPoint = mapToGrid(point + QPoint(1, 1)); gridPoint.setX((gridPoint.x() / 3) * 3); if (getCardFromGrid(gridPoint)) gridPoint.setX(gridPoint.x() + 1); if (getCardFromGrid(gridPoint)) gridPoint.setX(gridPoint.x() + 1); return mapFromGrid(gridPoint); }
void TableZone::reorganizeCards() { QList<ArrowItem *> arrowsToUpdate; // Calculate card stack widths so mapping functions work properly computeCardStackWidths(); for (int i = 0; i < cards.size(); ++i) { QPoint gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; QPointF mapPoint = mapFromGrid(gridPoint); qreal x = mapPoint.x(); qreal y = mapPoint.y(); int numberAttachedCards = cards[i]->getAttachedCards().size(); qreal actualX = x + numberAttachedCards * STACKED_CARD_OFFSET_X; qreal actualY = y; if (numberAttachedCards) actualY += 15; cards[i]->setPos(actualX, actualY); cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100); QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards()); int j = 0; while (attachedCardIterator.hasNext()) { ++j; CardItem *attachedCard = attachedCardIterator.next(); qreal childX = actualX - j * STACKED_CARD_OFFSET_X; qreal childY = y + 5; attachedCard->setPos(childX, childY); attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100); arrowsToUpdate.append(attachedCard->getArrowsFrom()); arrowsToUpdate.append(attachedCard->getArrowsTo()); } arrowsToUpdate.append(cards[i]->getArrowsFrom()); arrowsToUpdate.append(cards[i]->getArrowsTo()); } QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate)); while (arrowIterator.hasNext()) arrowIterator.next()->updatePath(); resizeToContents(); update(); }
void TableZone::reorganizeCards() { QList<ArrowItem *> arrowsToUpdate; // Calculate table grid distortion so that the mapping functions work properly QMap<int, int> gridPointStackCount; for (int i = 0; i < cards.size(); ++i) { const QPoint &gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; const int key = gridPoint.x() / 3 + gridPoint.y() * 1000; gridPointStackCount.insert(key, gridPointStackCount.value(key, 0) + 1); } gridPointWidth.clear(); for (int i = 0; i < cards.size(); ++i) { const QPoint &gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; const int key = gridPoint.x() / 3 + gridPoint.y() * 1000; const int stackCount = gridPointStackCount.value(key, 0); if (stackCount == 1) gridPointWidth.insert(key, CARD_WIDTH * (1 + cards[i]->getAttachedCards().size() / 3.0)); else gridPointWidth.insert(key, CARD_WIDTH * (1 + (stackCount - 1) / 3.0)); } for (int i = 0; i < cards.size(); ++i) { QPoint gridPoint = cards[i]->getGridPos(); if (gridPoint.x() == -1) continue; QPointF mapPoint = mapFromGrid(gridPoint); qreal x = mapPoint.x(); qreal y = mapPoint.y(); int numberAttachedCards = cards[i]->getAttachedCards().size(); qreal actualX = x + numberAttachedCards * CARD_WIDTH / 3.0; qreal actualY = y; if (numberAttachedCards) actualY += 15; cards[i]->setPos(actualX, actualY); cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100); QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards()); int j = 0; while (attachedCardIterator.hasNext()) { ++j; CardItem *attachedCard = attachedCardIterator.next(); qreal childX = actualX - j * CARD_WIDTH / 3.0; qreal childY = y + 5; attachedCard->setPos(childX, childY); attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100); arrowsToUpdate.append(attachedCard->getArrowsFrom()); arrowsToUpdate.append(attachedCard->getArrowsTo()); } arrowsToUpdate.append(cards[i]->getArrowsFrom()); arrowsToUpdate.append(cards[i]->getArrowsTo()); } QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate)); while (arrowIterator.hasNext()) arrowIterator.next()->updatePath(); resizeToContents(); update(); }