mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Ctrl drag now adds/removes to selection (#5336)
* refactor: clean up to use for-each loop * track cards in rect so far and toggle isSelected on change * only clear selection if ctrl isn't held * fix build errors
This commit is contained in:
parent
ca486e5ed9
commit
d5ae4eed26
2 changed files with 22 additions and 6 deletions
|
|
@ -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<GameScene *>(scene())->resizeRubberBand(
|
||||
deviceTransform(static_cast<GameScene *>(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<GameScene *>(scene())->startRubberBand(event->scenePos());
|
||||
|
|
@ -85,6 +97,7 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
selectionOrigin = QPoint();
|
||||
cardsInSelectionRect.clear();
|
||||
static_cast<GameScene *>(scene())->stopRubberBand();
|
||||
event->accept();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "card_zone.h"
|
||||
|
||||
#include <QSet>
|
||||
|
||||
/**
|
||||
* 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<CardItem *> cardsInSelectionRect;
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue