Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
select_zone.h
Go to the documentation of this file.
1
6
7#ifndef SELECTZONE_H
8#define SELECTZONE_H
9
10#include "card_zone.h"
11
12#include <QSet>
13#include <optional>
14
15class QGraphicsRectItem;
16
20class SelectZone : public CardZone
21{
22 Q_OBJECT
23public:
28 static SelectZone *findOwningSelectZone(const QGraphicsItem *card);
29
30 SelectZone(CardZoneLogic *logic, QGraphicsItem *parent = nullptr);
31 ~SelectZone() override;
32 void onCardAdded(CardItem *addedCard) override;
33
39 void escapeClipForHover(QGraphicsItem *card);
44 void restoreClipAfterHover(QGraphicsItem *card);
45
46private:
48 QSet<CardItem *> cardsInSelectionRect;
53 QGraphicsRectItem *cardClipContainer = nullptr;
54
55protected:
56 // -- Layout computation --
57
60 {
63 qreal cardHeight;
65 qreal minOffset = 0.0;
72 bool allowBottomOverflow = false;
73 };
74
77 {
79 qreal start;
80 };
81
83 static constexpr qreal MIN_CARD_VISIBLE = 10.0;
84
100
102 StackLayoutParams buildStackParams(qreal minOffset = 0.0) const;
103
112 int calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset = 0.0) const;
113
123 void layoutCardsVertically(const StackLayoutParams &params);
124
125 // -- Clip container --
126 // The clip container mechanism is available for future zones that need visual clipping
127 // (e.g., zones too short to fit a full card). To enable: call setupClipContainer() in the
128 // zone's constructor, and set allowBottomOverflow=true in layout params.
129
135
142 void setupClipContainer(std::optional<qreal> zValue = std::nullopt);
143
145 void updateClipRect();
146
147 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
148 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
149 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
150};
151
152#endif
Base graphics item for zones that contain cards.
Definition card_item.h:27
Definition card_zone_logic.h:26
CardZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition card_zone.cpp:9
CardZoneLogic * logic
Definition card_zone.h:77
void escapeClipForHover(QGraphicsItem *card)
Temporarily reparents a card from the clip container to this zone so hover scaling is visible beyond ...
Definition select_zone.cpp:192
void restoreClipAfterHover(QGraphicsItem *card)
Restores a hover-escaped card back to the clip container. Guards against zone transitions that alread...
Definition select_zone.cpp:203
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:261
~SelectZone() override
Definition select_zone.cpp:148
void setupClipContainer(std::optional< qreal > zValue=std::nullopt)
Creates a clip container child item that clips card overflow to zone bounds. Cards entering this zone...
Definition select_zone.cpp:174
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:219
int calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset=0.0) const
Computes the card index at a given y-coordinate within the zone's vertical layout....
Definition select_zone.cpp:86
void layoutCardsVertically(const StackLayoutParams &params)
Positions cards vertically with alternating left/right x-offsets.
Definition select_zone.cpp:116
void onCardAdded(CardItem *addedCard) override
Called when a card is added to this zone. Default: reparents card to this item.
Definition select_zone.cpp:163
QGraphicsRectItem * cardClipContainer
Invisible clipping parent for cards; owned by Qt parent-child tree (parented to this zone)....
Definition select_zone.h:53
QSet< CardItem * > cardsInSelectionRect
Definition select_zone.h:48
static ZoneLayout computeZoneLayout(const StackLayoutParams &params)
Computes layout for a vertical card stack (effective offset and start position).
Definition select_zone.cpp:18
static SelectZone * findOwningSelectZone(const QGraphicsItem *card)
Finds the SelectZone that owns a card, regardless of whether the card is parented to the zone directl...
Definition select_zone.cpp:58
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:276
void restoreStaleEscapedCards()
Restores any cards that were hover-escaped but whose hover state was not properly cleaned up....
Definition select_zone.cpp:101
void updateClipRect()
Updates the clip container rect to match this zone's current boundingRect().
Definition select_zone.cpp:212
static constexpr qreal MIN_CARD_VISIBLE
Minimum visible pixels of each card's top edge when stacking compresses offsets in tight zones.
Definition select_zone.h:83
StackLayoutParams buildStackParams(qreal minOffset=0.0) const
Builds StackLayoutParams from the current card list and zone geometry.
Definition select_zone.cpp:74
QPointF selectionOrigin
Definition select_zone.h:47
SelectZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition select_zone.cpp:144
Parameters describing a vertical card stack's geometry.
Definition select_zone.h:60
qreal minOffset
Minimum offset to preserve (0 allows full compression).
Definition select_zone.h:65
qreal desiredOffset
Preferred vertical offset between card tops.
Definition select_zone.h:64
bool allowBottomOverflow
When false (default), reserves full cardHeight for the bottom card, ensuring all cards remain within ...
Definition select_zone.h:72
qreal cardHeight
Height of a single card.
Definition select_zone.h:63
qreal totalHeight
Available height for the stack (zone height).
Definition select_zone.h:62
int cardCount
Number of cards in the stack.
Definition select_zone.h:61
Result of computing a vertical stack layout.
Definition select_zone.h:77
qreal start
Y coordinate of the first card's top edge.
Definition select_zone.h:79
qreal effectiveOffset
Actual offset between card tops (may be compressed).
Definition select_zone.h:78