Cockatrice 2026-06-27-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
table_zone.h
Go to the documentation of this file.
1
6
7#ifndef TABLEZONE_H
8#define TABLEZONE_H
9
12#include "select_zone.h"
13
20class TableZone : public SelectZone
21{
22 Q_OBJECT
23
24signals:
26
27private:
28 static const int TABLEROWS = 3;
29
30 /*
31 Margins between table edges and cards, paddings between cards
32 */
33 static const int MARGIN_LEFT = 20;
34 static const int MARGIN_RIGHT = 15;
35 static const int MARGIN_TOP = 10;
36 static const int MARGIN_BOTTOM = 30;
37 static const int PADDING_X = 35;
38 static const int PADDING_Y = 30;
39
40 /*
41 Minimum width of the table zone including margins.
42 */
44
45 /*
46 Offset sizes when cards are stacked on each other in the grid
47 */
49 static const int STACKED_CARD_OFFSET_Y = PADDING_Y / 3;
50
51 /*
52 Width of the box line drawn in the margin around the active player's area
53 */
54 static const int BOX_LINE_WIDTH = 10;
55
56 /*
57 Default inactive mask and border gradient
58 */
59 static const QColor BACKGROUND_COLOR;
60 static const QColor FADE_MASK;
61 static const QColor GRADIENT_COLOR;
62 static const QColor GRADIENT_COLORLESS;
63
64 /*
65 Size and shape variables
66 */
67 int width;
68 int height;
70
71 /*
72 Internal cache for widths of stacks of cards by row and column.
73 */
74 QMap<int, int> cardStackWidth;
75
76 /*
77 Holds any custom background image for the TableZone
78 */
80
81 /*
82 If this TableZone is currently active
83 */
84 bool active = false;
85 bool mirrored = false;
86
87 [[nodiscard]] bool isInverted() const;
88
89private slots:
93 void updateBg();
94
95public slots:
99 void reorganizeCards() override;
100 void setMirrored(bool isMirrored);
101
102public:
109 explicit TableZone(TableZoneLogic *_logic, bool mirrored, QGraphicsItem *parent = nullptr);
110
114 [[nodiscard]] QRectF boundingRect() const override;
115
122 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
123
127 void toggleTapped();
128
132 void
133 handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override;
134
138 void
139 handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &gridPoint);
140
144 [[nodiscard]] CardItem *getCardFromGrid(const QPoint &gridPoint) const;
145
149 [[nodiscard]] CardItem *getCardFromCoords(const QPointF &point) const;
150
151 QPointF closestGridPoint(const QPointF &point) override;
152
153 static int clampValidTableRow(const int row);
154
160 static int tableRowToGridY(int tableRow);
161
166 void resizeToContents();
167
168 [[nodiscard]] int getMinimumWidth() const
169 {
170 return currentMinimumWidth;
171 }
172 void setWidth(qreal _width)
173 {
174 prepareGeometryChange();
175 width = _width;
176 }
177 [[nodiscard]] qreal getWidth() const
178 {
179 return width;
180 }
181 void setActive(bool _active)
182 {
183 active = _active;
184 update();
185 }
186
187private:
188 void paintZoneOutline(QPainter *painter);
189 void paintLandDivider(QPainter *painter);
190
191 /*
192 Calculates card stack widths so mapping functions work properly
193 */
195
196 /*
197 Mapping functions for points to/from gridpoints.
198 */
199 [[nodiscard]] QPointF mapFromGrid(QPoint gridPoint) const;
200 [[nodiscard]] QPoint mapToGrid(const QPointF &mapPoint) const;
201
202 /*
203 Helper function to create a single key from a card stack location.
204 */
205 [[nodiscard]] int getCardStackMapKey(int x, int y) const
206 {
207 return x + (y * 1000);
208 }
209};
210
211#endif
Base class for graphical card items, providing shared rendering, identity, and interaction logic.
Definition card_item.h:28
Definition card_zone_logic.h:26
SelectZone(CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
Definition select_zone.cpp:150
Definition table_zone_logic.h:12
CardItem * getCardFromGrid(const QPoint &gridPoint) const
Definition table_zone.cpp:259
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition table_zone.cpp:66
void reorganizeCards() override
Definition table_zone.cpp:159
CardItem * getCardFromCoords(const QPointF &point) const
Definition table_zone.cpp:269
int getCardStackMapKey(int x, int y) const
Definition table_zone.h:205
void setActive(bool _active)
Definition table_zone.h:181
static const int MARGIN_BOTTOM
Definition table_zone.h:36
static int clampValidTableRow(const int row)
Definition table_zone.cpp:398
int width
Definition table_zone.h:67
static const int STACKED_CARD_OFFSET_Y
Definition table_zone.h:49
void handleDropEventByGrid(const QList< CardDragItem * > &dragItems, CardZoneLogic *startZone, const QPoint &gridPoint)
Definition table_zone.cpp:130
QMap< int, int > cardStackWidth
Definition table_zone.h:74
static const int PADDING_Y
Definition table_zone.h:38
void updateBg()
Definition table_zone.cpp:44
static const QColor FADE_MASK
Definition table_zone.h:60
static const int PADDING_X
Definition table_zone.h:37
void setMirrored(bool isMirrored)
Definition table_zone.cpp:54
void paintZoneOutline(QPainter *painter)
Definition table_zone.cpp:87
static int tableRowToGridY(int tableRow)
Definition table_zone.cpp:409
static const int TABLEROWS
Definition table_zone.h:28
bool mirrored
Definition table_zone.h:85
static const QColor GRADIENT_COLOR
Definition table_zone.h:61
static const int STACKED_CARD_OFFSET_X
Definition table_zone.h:48
int height
Definition table_zone.h:68
void resizeToContents()
Definition table_zone.cpp:233
static const int MARGIN_LEFT
Definition table_zone.h:33
void computeCardStackWidths()
Definition table_zone.cpp:275
qreal getWidth() const
Definition table_zone.h:177
QRectF boundingRect() const override
Definition table_zone.cpp:49
QPixmap backgroundPixelMap
Definition table_zone.h:79
QPointF closestGridPoint(const QPointF &point) override
Definition table_zone.cpp:385
TableZone(TableZoneLogic *_logic, bool mirrored, QGraphicsItem *parent=nullptr)
Definition table_zone.cpp:25
int getMinimumWidth() const
Definition table_zone.h:168
void handleDropEvent(const QList< CardDragItem * > &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override
Definition table_zone.cpp:123
void paintLandDivider(QPainter *painter)
Definition table_zone.cpp:111
static const int MIN_WIDTH
Definition table_zone.h:43
bool active
Definition table_zone.h:84
static const int BOX_LINE_WIDTH
Definition table_zone.h:54
void toggleTapped()
Definition table_zone.cpp:200
QPointF mapFromGrid(QPoint gridPoint) const
Definition table_zone.cpp:309
static const int MARGIN_RIGHT
Definition table_zone.h:34
static const QColor GRADIENT_COLORLESS
Definition table_zone.h:62
static const QColor BACKGROUND_COLOR
Definition table_zone.h:59
int currentMinimumWidth
Definition table_zone.h:69
void setWidth(qreal _width)
Definition table_zone.h:172
QPoint mapToGrid(const QPointF &mapPoint) const
Definition table_zone.cpp:337
bool isInverted() const
Definition table_zone.cpp:60
static const int MARGIN_TOP
Definition table_zone.h:35
void sizeChanged()
constexpr int WIDTH
Card width in pixels.
Definition card_dimensions.h:16
Base class for zones where cards are laid out and individually interactable.