Cockatrice 2026-06-01-Development-3.1.0-beta.3
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
108 int calcDropIndexFromY(qreal dropY, qreal minOffset = 0.0) const;
109
119 void layoutCardsVertically(const StackLayoutParams &params);
120
121 // -- Clip container --
122 // The clip container mechanism is available for future zones that need visual clipping
123 // (e.g., zones too short to fit a full card). To enable: call setupClipContainer() in the
124 // zone's constructor, and set allowBottomOverflow=true in layout params.
125
131
138 void setupClipContainer(std::optional<qreal> zValue = std::nullopt);
139
141 void updateClipRect();
142
143 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
144 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
145 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
146};
147
148#endif
Base graphics item for zones that contain cards.
Definition card_item.h:28
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:198
void restoreClipAfterHover(QGraphicsItem *card)
Restores a hover-escaped card back to the clip container. Guards against zone transitions that alread...
Definition select_zone.cpp:209
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:267
~SelectZone() override
Definition select_zone.cpp:154
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:180
int calcDropIndexFromY(qreal dropY, qreal minOffset=0.0) const
Computes the card index at a given y-coordinate within the zone's vertical layout....
Definition select_zone.cpp:93
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:225
void layoutCardsVertically(const StackLayoutParams &params)
Positions cards vertically with alternating left/right x-offsets.
Definition select_zone.cpp:122
void onCardAdded(CardItem *addedCard) override
Called when a card is added to this zone. Default: reparents card to this item.
Definition select_zone.cpp:169
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:17
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:65
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:282
void restoreStaleEscapedCards()
Restores any cards that were hover-escaped but whose hover state was not properly cleaned up....
Definition select_zone.cpp:107
void updateClipRect()
Updates the clip container rect to match this zone's current boundingRect().
Definition select_zone.cpp:218
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:81
QPointF selectionOrigin
Definition select_zone.h:47
SelectZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition select_zone.cpp:150
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