Cockatrice 2026-06-01-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
86 [[nodiscard]] bool isInverted() const;
87
88private slots:
92 void updateBg();
93
94public slots:
98 void reorganizeCards() override;
99
100public:
107 explicit TableZone(TableZoneLogic *_logic, QGraphicsItem *parent = nullptr);
108
112 [[nodiscard]] QRectF boundingRect() const override;
113
120 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
121
125 void toggleTapped();
126
130 void
131 handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override;
132
136 void
137 handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &gridPoint);
138
142 [[nodiscard]] CardItem *getCardFromGrid(const QPoint &gridPoint) const;
143
147 [[nodiscard]] CardItem *getCardFromCoords(const QPointF &point) const;
148
149 QPointF closestGridPoint(const QPointF &point) override;
150
151 static int clampValidTableRow(const int row);
152
158 static int tableRowToGridY(int tableRow);
159
164 void resizeToContents();
165
166 [[nodiscard]] int getMinimumWidth() const
167 {
168 return currentMinimumWidth;
169 }
170 void setWidth(qreal _width)
171 {
172 prepareGeometryChange();
173 width = _width;
174 }
175 [[nodiscard]] qreal getWidth() const
176 {
177 return width;
178 }
179 void setActive(bool _active)
180 {
181 active = _active;
182 update();
183 }
184
185private:
186 void paintZoneOutline(QPainter *painter);
187 void paintLandDivider(QPainter *painter);
188
189 /*
190 Calculates card stack widths so mapping functions work properly
191 */
193
194 /*
195 Mapping functions for points to/from gridpoints.
196 */
197 [[nodiscard]] QPointF mapFromGrid(QPoint gridPoint) const;
198 [[nodiscard]] QPoint mapToGrid(const QPointF &mapPoint) const;
199
200 /*
201 Helper function to create a single key from a card stack location.
202 */
203 [[nodiscard]] int getCardStackMapKey(int x, int y) const
204 {
205 return x + (y * 1000);
206 }
207};
208
209#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:254
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition table_zone.cpp:61
void reorganizeCards() override
Definition table_zone.cpp:154
CardItem * getCardFromCoords(const QPointF &point) const
Definition table_zone.cpp:264
int getCardStackMapKey(int x, int y) const
Definition table_zone.h:203
void setActive(bool _active)
Definition table_zone.h:179
static const int MARGIN_BOTTOM
Definition table_zone.h:36
static int clampValidTableRow(const int row)
Definition table_zone.cpp:393
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:125
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:43
static const QColor FADE_MASK
Definition table_zone.h:60
static const int PADDING_X
Definition table_zone.h:37
void paintZoneOutline(QPainter *painter)
Definition table_zone.cpp:82
static int tableRowToGridY(int tableRow)
Definition table_zone.cpp:404
static const int TABLEROWS
Definition table_zone.h:28
TableZone(TableZoneLogic *_logic, QGraphicsItem *parent=nullptr)
Definition table_zone.cpp:25
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:228
static const int MARGIN_LEFT
Definition table_zone.h:33
void computeCardStackWidths()
Definition table_zone.cpp:270
qreal getWidth() const
Definition table_zone.h:175
QRectF boundingRect() const override
Definition table_zone.cpp:48
QPixmap backgroundPixelMap
Definition table_zone.h:79
QPointF closestGridPoint(const QPointF &point) override
Definition table_zone.cpp:380
int getMinimumWidth() const
Definition table_zone.h:166
void handleDropEvent(const QList< CardDragItem * > &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override
Definition table_zone.cpp:118
void paintLandDivider(QPainter *painter)
Definition table_zone.cpp:106
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:195
QPointF mapFromGrid(QPoint gridPoint) const
Definition table_zone.cpp:304
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:170
QPoint mapToGrid(const QPointF &mapPoint) const
Definition table_zone.cpp:332
bool isInverted() const
Definition table_zone.cpp:53
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.