Cockatrice/cockatrice/src/game/zones/select_zone.cpp
BruebachL a8a3fca8c9
Clean up inter-library dependencies with interfaces (#6280)
* Have CardDatabase::getPreferredPrintingInfo respect card provider ID overrides (pinned printings)

Took 13 minutes

Took 37 seconds

Took 10 seconds

Took 10 seconds

# Commit time for manual adjustment:
# Took 30 seconds

Took 15 seconds


Took 8 minutes

Took 21 seconds

* Move settings cache and settings card preference provider out of libcockatrice_settings and into cockatrice

Took 52 minutes

Took 9 minutes

Took 1 minute

* Temp cache.

Took 16 minutes

* Dependency Injection for SettingsCache

* Turn SettingsCache into a QSharedPointer.
* Implement interfaces for settings that need it

Took 2 hours 38 minutes

* Adjust oracle.

Took 5 minutes

* Move abstract/noop interfaces to libcockatrice_interfaces so they can be linked against independently.

Took 52 minutes

* Clean up some links.

Took 3 minutes

* Cleanup two includes.

Took 3 minutes

* More fixes.

Took 7 minutes

* More includes that slipped past.

Took 3 minutes

* Stop mocking and start injecting for tests.

Took 15 minutes

* I don't know why remote_client was including main.

Took 4 minutes

* Include.

Took 3 minutes

* Lint.

Took 2 minutes

* Don't use Qt pointers.

Took 1 hour 7 minutes

* Make parser use CardSettingsInterface

Took 13 minutes

* Also adjust constructor lol.

Took 8 minutes

* Lint.

Took 32 minutes

* Revert "Lint."

This reverts commit ecb596c39e.


Took 3 minutes

* Test.

Took 3 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2025-11-08 22:19:40 +01:00

96 lines
3.2 KiB
C++

#include "select_zone.h"
#include "../../client/settings/cache_settings.h"
#include "../board/card_item.h"
#include "../game_scene.h"
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
qreal divideCardSpaceInZone(qreal index, int cardCount, qreal totalHeight, qreal cardHeight, bool reverse)
{
qreal cardMinOverlap = cardHeight * SettingsCache::instance().getStackCardOverlapPercent() / 100;
qreal desiredHeight = cardHeight * cardCount - cardMinOverlap * (cardCount - 1);
qreal y;
if (desiredHeight > totalHeight) {
if (reverse) {
y = index / ((totalHeight - cardHeight) / (cardCount - 1));
} else {
y = index * (totalHeight - cardHeight) / (cardCount - 1);
}
} else {
qreal start = (totalHeight - desiredHeight) / 2;
if (reverse) {
if (index <= start) {
return 0;
}
y = (index - start) / (cardHeight - cardMinOverlap);
} else {
y = index * (cardHeight - cardMinOverlap) + start;
}
}
return y;
}
SelectZone::SelectZone(CardZoneLogic *_logic, QGraphicsItem *parent) : CardZone(_logic, parent)
{
}
void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (event->buttons().testFlag(Qt::LeftButton)) {
QPointF pos = event->pos();
if (pos.x() < 0)
pos.setX(0);
QRectF br = boundingRect();
if (pos.x() > br.width())
pos.setX(br.width());
if (pos.y() < 0)
pos.setY(0);
if (pos.y() > br.height())
pos.setY(br.height());
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
for (auto card : getLogic()->getCards()) {
if (card->getAttachedTo() && card->getAttachedTo()->getZone() != getLogic()) {
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));
event->accept();
}
}
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
if (!event->modifiers().testFlag(Qt::ControlModifier)) {
scene()->clearSelection();
}
selectionOrigin = event->pos();
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
event->accept();
} else
CardZone::mousePressEvent(event);
}
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
selectionOrigin = QPoint();
cardsInSelectionRect.clear();
static_cast<GameScene *>(scene())->stopRubberBand();
event->accept();
}