mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Refactor] Give graphics zones a card item cache and own card placement (#7427)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
4879ddbd0f
commit
47c90cda10
18 changed files with 111 additions and 74 deletions
|
|
@ -85,7 +85,7 @@ SelectZone *SelectZone::findOwningSelectZone(const QGraphicsItem *card)
|
|||
|
||||
SelectZone::StackLayoutParams SelectZone::buildStackParams(qreal minOffset) const
|
||||
{
|
||||
const auto &cards = getLogic()->getCards();
|
||||
const auto &cards = cardItems();
|
||||
if (cards.isEmpty()) {
|
||||
return {0, boundingRect().height(), 0.0, 0.0, minOffset};
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ SelectZone::StackLayoutParams SelectZone::buildStackParams(qreal minOffset) cons
|
|||
|
||||
int SelectZone::calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset) const
|
||||
{
|
||||
const auto &cards = getLogic()->getCards();
|
||||
const auto &cards = cardItems();
|
||||
if (cards.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ void SelectZone::restoreStaleEscapedCards()
|
|||
if (!cardClipContainer) {
|
||||
return;
|
||||
}
|
||||
for (auto *card : getLogic()->getCards()) {
|
||||
for (auto *card : cardItems()) {
|
||||
// A card parented to the zone (instead of the clip container) should
|
||||
// only occur while it is actively hovered. If hover cleanup was
|
||||
// missed, reparent it back so clipping resumes.
|
||||
|
|
@ -127,7 +127,7 @@ void SelectZone::restoreStaleEscapedCards()
|
|||
|
||||
void SelectZone::layoutCardsVertically(const StackLayoutParams ¶ms)
|
||||
{
|
||||
const auto &cards = getLogic()->getCards();
|
||||
const auto &cards = cardItems();
|
||||
if (cards.isEmpty() || params.cardCount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -162,9 +162,9 @@ SelectZone::~SelectZone()
|
|||
if (cardClipContainer) {
|
||||
// Reparent any hover-escaped cards back to the clip container so Qt's
|
||||
// parent-child tree is consistent for destruction. setParentItem() does
|
||||
// not invalidate getLogic()->getCards() (it modifies the graphics tree,
|
||||
// not the zone's logical card list).
|
||||
for (auto *card : getLogic()->getCards()) {
|
||||
// not invalidate cardItems() — it only moves the item in the graphics
|
||||
// tree, it never changes the zone's contents.
|
||||
for (auto *card : cardItems()) {
|
||||
if (card && card->parentItem() == this) {
|
||||
card->setParentItem(cardClipContainer);
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
}
|
||||
|
||||
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
||||
for (auto card : getLogic()->getCards()) {
|
||||
for (auto card : cardItems()) {
|
||||
if (card->getAttachedTo() && card->getAttachedTo()->getZone() != getLogic()) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue