Cockatrice 2026-06-27-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
TableZone Class Reference

TableZone is the grid based rect where CardItems may be placed. More...

#include <table_zone.h>

Inheritance diagram for TableZone:
[legend]
Collaboration diagram for TableZone:
[legend]

Public Slots

void reorganizeCards () override
void setMirrored (bool isMirrored)
Public Slots inherited from CardZone
bool showContextMenu (const QPoint &screenPos)

Signals

void sizeChanged ()

Public Member Functions

 TableZone (TableZoneLogic *_logic, bool mirrored, QGraphicsItem *parent=nullptr)
QRectF boundingRect () const override
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void toggleTapped ()
void handleDropEvent (const QList< CardDragItem * > &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override
void handleDropEventByGrid (const QList< CardDragItem * > &dragItems, CardZoneLogic *startZone, const QPoint &gridPoint)
CardItemgetCardFromGrid (const QPoint &gridPoint) const
CardItemgetCardFromCoords (const QPointF &point) const
QPointF closestGridPoint (const QPointF &point) override
void resizeToContents ()
int getMinimumWidth () const
void setWidth (qreal _width)
qreal getWidth () const
void setActive (bool _active)
Public Member Functions inherited from SelectZone
 SelectZone (CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
 ~SelectZone () override
void onCardAdded (CardItem *addedCard) override
 Called when a card is added to this zone. Default: reparents card to this item.
void escapeClipForHover (QGraphicsItem *card)
 Temporarily reparents a card from the clip container to this zone so hover scaling is visible beyond clip bounds. Safe no-op if no clip container exists. Coordinates are preserved (clip container is at (0,0) with no transform).
void restoreClipAfterHover (QGraphicsItem *card)
 Restores a hover-escaped card back to the clip container. Guards against zone transitions that already reparented the card.
Public Member Functions inherited from CardZone
int type () const override
 CardZone (CardZoneLogic *logic, QGraphicsItem *parent=nullptr)
void retranslateUi ()
CardZoneLogicgetLogic () const
void setMenu (QMenu *_menu, QAction *_doubleClickAction=0)
Public Member Functions inherited from AbstractGraphicsItem
 AbstractGraphicsItem (QGraphicsItem *parent=nullptr)

Static Public Member Functions

static int clampValidTableRow (const int row)
static int tableRowToGridY (int tableRow)
Static Public Member Functions inherited from SelectZone
static SelectZonefindOwningSelectZone (const QGraphicsItem *card)
 Finds the SelectZone that owns a card, regardless of whether the card is parented to the zone directly or to its clip container. Returns nullptr if not in a SelectZone.

Private Slots

void updateBg ()

Private Member Functions

bool isInverted () const
void paintZoneOutline (QPainter *painter)
void paintLandDivider (QPainter *painter)
void computeCardStackWidths ()
QPointF mapFromGrid (QPoint gridPoint) const
QPoint mapToGrid (const QPointF &mapPoint) const
int getCardStackMapKey (int x, int y) const

Private Attributes

int width
int height
int currentMinimumWidth
QMap< int, int > cardStackWidth
QPixmap backgroundPixelMap
bool active = false
bool mirrored = false

Static Private Attributes

static const int TABLEROWS = 3
static const int MARGIN_LEFT = 20
static const int MARGIN_RIGHT = 15
static const int MARGIN_TOP = 10
static const int MARGIN_BOTTOM = 30
static const int PADDING_X = 35
static const int PADDING_Y = 30
static const int MIN_WIDTH = MARGIN_LEFT + (5 * CardDimensions::WIDTH) + MARGIN_RIGHT
static const int STACKED_CARD_OFFSET_X = CardDimensions::WIDTH / 3
static const int STACKED_CARD_OFFSET_Y = PADDING_Y / 3
static const int BOX_LINE_WIDTH = 10
static const QColor BACKGROUND_COLOR = QColor(100, 100, 100)
static const QColor FADE_MASK = QColor(0, 0, 0, 80)
static const QColor GRADIENT_COLOR = QColor(255, 255, 255, 150)
static const QColor GRADIENT_COLORLESS = QColor(255, 255, 255, 0)

Additional Inherited Members

Public Types inherited from CardZone
enum  { Type = typeZone }
Protected Member Functions inherited from SelectZone
StackLayoutParams buildStackParams (qreal minOffset=0.0) const
 Builds StackLayoutParams from the current card list and zone geometry.
int calcDropIndexFromY (qreal dropY, qreal minOffset=0.0) const
 Computes the card index at a given y-coordinate within the zone's vertical layout. Returns 0 if the zone has no cards or the offset is zero.
void layoutCardsVertically (const StackLayoutParams &params)
 Positions cards vertically with alternating left/right x-offsets.
void restoreStaleEscapedCards ()
 Restores any cards that were hover-escaped but whose hover state was not properly cleaned up. Call at the start of reorganizeCards() in zones that use a clip container.
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 are reparented to this container by the onCardAdded override. Disables zone-level child clipping; clipping is delegated to the container.
void updateClipRect ()
 Updates the clip container rect to match this zone's current boundingRect().
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
Protected Member Functions inherited from CardZone
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
virtual void reorganizeCards ()=0
QMenu * getMenu () const
Protected Member Functions inherited from AbstractGraphicsItem
void paintNumberEllipse (int number, int radius, const QColor &color, int position, int count, QPainter *painter)
Static Protected Member Functions inherited from SelectZone
static ZoneLayout computeZoneLayout (const StackLayoutParams &params)
 Computes layout for a vertical card stack (effective offset and start position).
Protected Attributes inherited from CardZone
QMenu * menu
QAction * doubleClickAction
Static Protected Attributes inherited from SelectZone
static constexpr qreal MIN_CARD_VISIBLE = 10.0
 Minimum visible pixels of each card's top edge when stacking compresses offsets in tight zones.

Detailed Description

TableZone is the grid based rect where CardItems may be placed.

Todo
Document this file.

It is the main play zone and can be customized with background images.

Todo
Refactor methods to make more readable, extract logic to private methods (especially reorganizeCards()).

Constructor & Destructor Documentation

◆ TableZone()

TableZone::TableZone ( TableZoneLogic * _logic,
bool mirrored,
QGraphicsItem * parent = nullptr )
explicit

Constructs TableZone.

Parameters
_pthe Player
parentdefaults to null
Here is the call graph for this function:

Member Function Documentation

◆ boundingRect()

QRectF TableZone::boundingRect ( ) const
nodiscardoverride
Returns
a QRectF of the TableZone bounding box.
Here is the caller graph for this function:

◆ clampValidTableRow()

int TableZone::clampValidTableRow ( const int row)
static
Here is the caller graph for this function:

◆ closestGridPoint()

QPointF TableZone::closestGridPoint ( const QPointF & point)
overridevirtual

Reimplemented from CardZone.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ computeCardStackWidths()

void TableZone::computeCardStackWidths ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardFromCoords()

CardItem * TableZone::getCardFromCoords ( const QPointF & point) const
nodiscard
Returns
CardItem from coordinate location
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardFromGrid()

CardItem * TableZone::getCardFromGrid ( const QPoint & gridPoint) const
nodiscard
Returns
CardItem from grid location
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardStackMapKey()

int TableZone::getCardStackMapKey ( int x,
int y ) const
inlinenodiscardprivate
Here is the caller graph for this function:

◆ getMinimumWidth()

int TableZone::getMinimumWidth ( ) const
inlinenodiscard

◆ getWidth()

qreal TableZone::getWidth ( ) const
inlinenodiscard

◆ handleDropEvent()

void TableZone::handleDropEvent ( const QList< CardDragItem * > & dragItems,
CardZoneLogic * startZone,
const QPoint & dropPoint )
overridevirtual

See HandleDropEventByGrid

Implements CardZone.

Here is the call graph for this function:

◆ handleDropEventByGrid()

void TableZone::handleDropEventByGrid ( const QList< CardDragItem * > & dragItems,
CardZoneLogic * startZone,
const QPoint & gridPoint )

Handles the placement of cards

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInverted()

bool TableZone::isInverted ( ) const
nodiscardprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mapFromGrid()

QPointF TableZone::mapFromGrid ( QPoint gridPoint) const
nodiscardprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mapToGrid()

QPoint TableZone::mapToGrid ( const QPointF & mapPoint) const
nodiscardprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ paint()

void TableZone::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Render the TableZone

Parameters
painter
option
Here is the call graph for this function:

◆ paintLandDivider()

void TableZone::paintLandDivider ( QPainter * painter)
private

Render a division line for land placement

@painter QPainter object

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintZoneOutline()

void TableZone::paintZoneOutline ( QPainter * painter)
private

Render a soft outline around the edge of the TableZone.

Parameters
painterQPainter object
Here is the caller graph for this function:

◆ reorganizeCards

void TableZone::reorganizeCards ( )
overrideslot

Reorganizes CardItems in the TableZone

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resizeToContents()

void TableZone::resizeToContents ( )

Resizes the TableZone in case CardItems are within or outside of the TableZone constraints.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActive()

void TableZone::setActive ( bool _active)
inline

◆ setMirrored

void TableZone::setMirrored ( bool isMirrored)
slot
Here is the caller graph for this function:

◆ setWidth()

void TableZone::setWidth ( qreal _width)
inline

◆ sizeChanged

void TableZone::sizeChanged ( )
signal
Here is the caller graph for this function:

◆ tableRowToGridY()

int TableZone::tableRowToGridY ( int tableRow)
static

Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands) to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g., instants/sorceries) default to the noncreatures row.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toggleTapped()

void TableZone::toggleTapped ( )

Toggles the selected items as tapped.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateBg

void TableZone::updateBg ( )
privateslot

Loads in any found custom background and updates

Here is the caller graph for this function:

Member Data Documentation

◆ active

bool TableZone::active = false
private

◆ BACKGROUND_COLOR

const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100)
staticprivate

◆ backgroundPixelMap

QPixmap TableZone::backgroundPixelMap
private

◆ BOX_LINE_WIDTH

const int TableZone::BOX_LINE_WIDTH = 10
staticprivate

◆ cardStackWidth

QMap<int, int> TableZone::cardStackWidth
private

◆ currentMinimumWidth

int TableZone::currentMinimumWidth
private

◆ FADE_MASK

const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80)
staticprivate

◆ GRADIENT_COLOR

const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150)
staticprivate

◆ GRADIENT_COLORLESS

const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0)
staticprivate

◆ height

int TableZone::height
private

◆ MARGIN_BOTTOM

const int TableZone::MARGIN_BOTTOM = 30
staticprivate

◆ MARGIN_LEFT

const int TableZone::MARGIN_LEFT = 20
staticprivate

◆ MARGIN_RIGHT

const int TableZone::MARGIN_RIGHT = 15
staticprivate

◆ MARGIN_TOP

const int TableZone::MARGIN_TOP = 10
staticprivate

◆ MIN_WIDTH

const int TableZone::MIN_WIDTH = MARGIN_LEFT + (5 * CardDimensions::WIDTH) + MARGIN_RIGHT
staticprivate

◆ mirrored

bool TableZone::mirrored = false
private

◆ PADDING_X

const int TableZone::PADDING_X = 35
staticprivate

◆ PADDING_Y

const int TableZone::PADDING_Y = 30
staticprivate

◆ STACKED_CARD_OFFSET_X

const int TableZone::STACKED_CARD_OFFSET_X = CardDimensions::WIDTH / 3
staticprivate

◆ STACKED_CARD_OFFSET_Y

const int TableZone::STACKED_CARD_OFFSET_Y = PADDING_Y / 3
staticprivate

◆ TABLEROWS

const int TableZone::TABLEROWS = 3
staticprivate

◆ width

int TableZone::width
private

The documentation for this class was generated from the following files: