Cockatrice 2026-10-19-Development-3.1.2-beta.2
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 <QPointF>
13#include <QSet>
14#include <QtGlobal>
15#include <optional>
16#include <qtmetamacros.h>
17
18class QGraphicsRectItem;
19class CardItem;
20class CardZoneLogic;
21class QGraphicsItem;
22
26class SelectZone : public CardZone
27{
28 Q_OBJECT
29public:
34 static SelectZone *findOwningSelectZone(const QGraphicsItem *card);
35
36 SelectZone(CardZoneLogic *logic, QGraphicsItem *parent = nullptr);
37 ~SelectZone() override;
38 void onCardAdded(CardItem *addedCard) override;
39
45 void escapeClipForHover(QGraphicsItem *card);
50 void restoreClipAfterHover(QGraphicsItem *card);
51
52private:
59 QGraphicsRectItem *cardClipContainer = nullptr;
60
61protected:
62 // -- Layout computation --
63
66 {
69 qreal cardHeight;
71 qreal minOffset = 0.0;
78 bool allowBottomOverflow = false;
79 };
80
83 {
85 qreal start;
86 };
87
89 static constexpr qreal MIN_CARD_VISIBLE = 10.0;
90
105 static ZoneLayout computeZoneLayout(const StackLayoutParams &params);
106
108 StackLayoutParams buildStackParams(qreal minOffset = 0.0) const;
109
118 int calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset = 0.0) const;
119
129 void layoutCardsVertically(const StackLayoutParams &params);
130
131 // -- Clip container --
132 // The clip container mechanism is available for future zones that need visual clipping
133 // (e.g., zones too short to fit a full card). To enable: call setupClipContainer() in the
134 // zone's constructor, and set allowBottomOverflow=true in layout params.
135
141
148 void setupClipContainer(std::optional<qreal> zValue = std::nullopt);
149
151 void updateClipRect();
152
153 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
154 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
155 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
156};
157
158#endif
Base graphics item for zones that contain cards.
Definition card_item.h:33
Definition card_zone_logic.h:27
CardZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition card_zone.cpp:17
CardZoneLogic * logic
Definition card_zone.h:86
Definition dlg_manage_sets.h:29
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:204
void restoreClipAfterHover(QGraphicsItem *card)
Restores a hover-escaped card back to the clip container. Guards against zone transitions that alread...
Definition select_zone.cpp:215
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:273
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:186
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:231
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:98
void layoutCardsVertically(const StackLayoutParams &params)
Positions cards vertically with alternating left/right x-offsets.
Definition select_zone.cpp:128
void onCardAdded(CardItem *addedCard) override
Called when a card is added to this zone. Default: reparents card to this item.
Definition select_zone.cpp:175
QGraphicsRectItem * cardClipContainer
Invisible clipping parent for cards; owned by Qt parent-child tree (parented to this zone)....
Definition select_zone.h:59
QSet< CardItem * > cardsInSelectionRect
Definition select_zone.h:54
static ZoneLayout computeZoneLayout(const StackLayoutParams &params)
Computes layout for a vertical card stack (effective offset and start position).
Definition select_zone.cpp:30
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:70
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition select_zone.cpp:288
void restoreStaleEscapedCards()
Restores any cards that were hover-escaped but whose hover state was not properly cleaned up....
Definition select_zone.cpp:113
void updateClipRect()
Updates the clip container rect to match this zone's current boundingRect().
Definition select_zone.cpp:224
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:89
StackLayoutParams buildStackParams(qreal minOffset=0.0) const
Builds StackLayoutParams from the current card list and zone geometry.
Definition select_zone.cpp:86
QPointF selectionOrigin
Definition select_zone.h:53
SelectZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition select_zone.cpp:156
Parameters describing a vertical card stack's geometry.
Definition select_zone.h:66
qreal minOffset
Minimum offset to preserve (0 allows full compression).
Definition select_zone.h:71
qreal desiredOffset
Preferred vertical offset between card tops.
Definition select_zone.h:70
bool allowBottomOverflow
When false (default), reserves full cardHeight for the bottom card, ensuring all cards remain within ...
Definition select_zone.h:78
qreal cardHeight
Height of a single card.
Definition select_zone.h:69
qreal totalHeight
Available height for the stack (zone height).
Definition select_zone.h:68
int cardCount
Number of cards in the stack.
Definition select_zone.h:67
Result of computing a vertical stack layout.
Definition select_zone.h:83
qreal start
Y coordinate of the first card's top edge.
Definition select_zone.h:85
qreal effectiveOffset
Actual offset between card tops (may be compressed).
Definition select_zone.h:84