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

#include <select_zone.h>

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

Classes

struct  StackLayoutParams
 Parameters describing a vertical card stack's geometry. More...
struct  ZoneLayout
 Result of computing a vertical stack layout. More...

Public Member Functions

 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
virtual void handleDropEvent (const QList< CardDragItem * > &dragItem, CardZoneLogic *startZone, const QPoint &dropPoint)=0
 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 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.

Protected Member Functions

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
virtual QPointF closestGridPoint (const QPointF &point)
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

static ZoneLayout computeZoneLayout (const StackLayoutParams &params)
 Computes layout for a vertical card stack (effective offset and start position).

Static Protected Attributes

static constexpr qreal MIN_CARD_VISIBLE = 10.0
 Minimum visible pixels of each card's top edge when stacking compresses offsets in tight zones.

Private Attributes

QPointF selectionOrigin
QSet< CardItem * > cardsInSelectionRect
QGraphicsRectItem * cardClipContainer = nullptr
 Invisible clipping parent for cards; owned by Qt parent-child tree (parented to this zone). Created by setupClipContainer(); null when no clip container is active.

Additional Inherited Members

Public Types inherited from CardZone
enum  { Type = typeZone }
Public Slots inherited from CardZone
bool showContextMenu (const QPoint &screenPos)
Protected Attributes inherited from CardZone
QMenu * menu
QAction * doubleClickAction

Detailed Description

A CardZone where the cards are laid out, with each card directly interactable by clicking.

Constructor & Destructor Documentation

◆ SelectZone()

SelectZone::SelectZone ( CardZoneLogic * logic,
QGraphicsItem * parent = nullptr )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~SelectZone()

SelectZone::~SelectZone ( )
override
Here is the call graph for this function:

Member Function Documentation

◆ buildStackParams()

SelectZone::StackLayoutParams SelectZone::buildStackParams ( qreal minOffset = 0.0) const
protected

Builds StackLayoutParams from the current card list and zone geometry.

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

◆ calcDropIndexFromY()

int SelectZone::calcDropIndexFromY ( qreal dropY,
qreal minOffset = 0.0 ) const
protected

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.

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

◆ computeZoneLayout()

SelectZone::ZoneLayout SelectZone::computeZoneLayout ( const StackLayoutParams & params)
staticprotected

Computes layout for a vertical card stack (effective offset and start position).

Three regimes:

  1. Minimized zone (totalHeight < card height with minOffset > 0): offsets compress so each card retains at least minOffset visible pixels of its top edge.
  2. Normal zone with allowBottomOverflow=false (default): the bottom card is guaranteed to fit within the zone boundary. Offsets compress as needed.
  3. Normal zone with allowBottomOverflow=true: the bottom card may partially overflow. The overflow allowance is scaled by sqrt(cardCount-1) so that adding one card shifts existing cards smoothly.

When the stack fits with room to spare, it is centered vertically.

Here is the caller graph for this function:

◆ escapeClipForHover()

void SelectZone::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).

◆ findOwningSelectZone()

SelectZone * SelectZone::findOwningSelectZone ( const QGraphicsItem * card)
static

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.

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

◆ layoutCardsVertically()

void SelectZone::layoutCardsVertically ( const StackLayoutParams & params)
protected

Positions cards vertically with alternating left/right x-offsets.

Cards alternate between left and right margins (5px padding from zone edges): even-indexed cards at left, odd-indexed at right. Cards are assigned ascending z-values.

Parameters
paramsStack layout geometry parameters (use allowBottomOverflow to control overflow)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMoveEvent()

void SelectZone::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected
Here is the call graph for this function:

◆ mousePressEvent()

void SelectZone::mousePressEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected
Here is the call graph for this function:

◆ mouseReleaseEvent()

void SelectZone::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

◆ onCardAdded()

void SelectZone::onCardAdded ( CardItem * addedCard)
overridevirtual

Called when a card is added to this zone. Default: reparents card to this item.

Virtual so subclasses (e.g. SelectZone) can override parenting behavior — the Qt signal connection in CardZone's constructor dispatches through the vtable.

Reimplemented from CardZone.

Here is the call graph for this function:

◆ restoreClipAfterHover()

void SelectZone::restoreClipAfterHover ( QGraphicsItem * card)

Restores a hover-escaped card back to the clip container. Guards against zone transitions that already reparented the card.

◆ restoreStaleEscapedCards()

void SelectZone::restoreStaleEscapedCards ( )
protected

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.

Here is the call graph for this function:

◆ setupClipContainer()

void SelectZone::setupClipContainer ( std::optional< qreal > zValue = std::nullopt)
protected

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.

Parameters
zValueOptional z-value for the clip container (e.g. ZValues::CARD_BASE)

◆ updateClipRect()

void SelectZone::updateClipRect ( )
protected

Updates the clip container rect to match this zone's current boundingRect().

Member Data Documentation

◆ cardClipContainer

QGraphicsRectItem* SelectZone::cardClipContainer = nullptr
private

Invisible clipping parent for cards; owned by Qt parent-child tree (parented to this zone). Created by setupClipContainer(); null when no clip container is active.

◆ cardsInSelectionRect

QSet<CardItem *> SelectZone::cardsInSelectionRect
private

◆ MIN_CARD_VISIBLE

qreal SelectZone::MIN_CARD_VISIBLE = 10.0
staticconstexprprotected

Minimum visible pixels of each card's top edge when stacking compresses offsets in tight zones.

◆ selectionOrigin

QPointF SelectZone::selectionOrigin
private

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