diff --git a/cockatrice/src/game/zones/select_zone.cpp b/cockatrice/src/game/zones/select_zone.cpp index 9947bc405..949b3fba2 100644 --- a/cockatrice/src/game/zones/select_zone.cpp +++ b/cockatrice/src/game/zones/select_zone.cpp @@ -58,11 +58,21 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event) pos.setY(br.height()); QRectF selectionRect = QRectF(selectionOrigin, pos).normalized(); - for (int i = 0; i < cards.size(); ++i) { - if (cards[i]->getAttachedTo()) - if (cards[i]->getAttachedTo()->getZone() != this) - continue; - cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect()))); + for (auto card : cards) { + if (card->getAttachedTo() && card->getAttachedTo()->getZone() != this) { + continue; + } + + 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(scene())->resizeRubberBand( deviceTransform(static_cast(scene())->getViewportTransform()).map(pos)); @@ -73,7 +83,9 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - scene()->clearSelection(); + if (!event->modifiers().testFlag(Qt::ControlModifier)) { + scene()->clearSelection(); + } selectionOrigin = event->pos(); static_cast(scene())->startRubberBand(event->scenePos()); @@ -85,6 +97,7 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event) void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { selectionOrigin = QPoint(); + cardsInSelectionRect.clear(); static_cast(scene())->stopRubberBand(); event->accept(); } diff --git a/cockatrice/src/game/zones/select_zone.h b/cockatrice/src/game/zones/select_zone.h index ff0c12182..07a8d7a0d 100644 --- a/cockatrice/src/game/zones/select_zone.h +++ b/cockatrice/src/game/zones/select_zone.h @@ -3,6 +3,8 @@ #include "card_zone.h" +#include + /** * A CardZone where the cards are laid out, with each card directly interactable by clicking. */ @@ -11,6 +13,7 @@ class SelectZone : public CardZone Q_OBJECT private: QPointF selectionOrigin; + QSet cardsInSelectionRect; protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event);