track cards in rect so far and toggle isSelected on change

This commit is contained in:
RickyRister 2024-12-26 02:45:06 -08:00
parent 92cefe2a27
commit 8e9b111ae3
2 changed files with 13 additions and 1 deletions

View file

@ -62,7 +62,17 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (card->getAttachedTo() && card->getAttachedTo()->getZone() != this) {
continue;
}
card->setSelected(selectionRect.intersects(card->mapRectToParent(card->boundingRect())));
bool inRect = selectionRect.intersects(card->mapRectToParent(card->boundingRect()));
if (inRect && !cardsInSelectionRect.contains(card)) {
// selection has just expanded to cover the card
cardsInSelectionRect.insert(card);
card->setSelected(!card->isSelected());
} else if (!inRect && cardsInSelectionRect.contains(card)) {
// selection has just shrunk to no longer cover the card
cardsInSelectionRect.remove(card);
card->setSelected(!card->isSelected());
}
}
static_cast<GameScene *>(scene())->resizeRubberBand(
deviceTransform(static_cast<GameScene *>(scene())->getViewportTransform()).map(pos));
@ -85,6 +95,7 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
selectionOrigin = QPoint();
cardsInSelectionRect.clear();
static_cast<GameScene *>(scene())->stopRubberBand();
event->accept();
}

View file

@ -11,6 +11,7 @@ class SelectZone : public CardZone
Q_OBJECT
private:
QPointF selectionOrigin;
QSet<CardItem *> cardsInSelectionRect;
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);