void StackZone::reorganizeCards() { if (!cards.isEmpty()) { QList<ArrowItem *> arrowsToUpdate; const int cardCount = cards.size(); qreal totalWidth = boundingRect().width(); qreal totalHeight = boundingRect().height(); qreal cardWidth = cards.at(0)->boundingRect().width(); qreal cardHeight = cards.at(0)->boundingRect().height(); qreal xspace = 5; qreal x1 = xspace; qreal x2 = totalWidth - xspace - cardWidth; for (int i = 0; i < cardCount; i++) { CardItem *c = cards.at(i); qreal x = i % 2 ? x2 : x1; // If the total height of the cards is smaller than the available height, // the cards do not need to overlap and are displayed in the center of the area. if (cardHeight * cardCount > totalHeight) c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1)); else c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2); c->setRealZValue(i); arrowsToUpdate.append(c->getArrowsFrom()); arrowsToUpdate.append(c->getArrowsTo()); } QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate)); while (arrowIterator.hasNext()) arrowIterator.next()->updatePath(); } update(); }
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(); }