[Game] Add hover zoom and a tabbed card panel to the board (#7700)

* [Settings] Add hover zoom/panel triggers, delays, and double-confirm

* [Game] Smooth board hover-zoom with fade helpers

* [Game] Add hover card panel with tabbed actions

* [Game] Wire hover zoom/panel triggers through the scene

* [Game] Repaint cached zones when the hover zoom moves

`TableZone` cuts the hovered card out of its own paint so zone washes,
indicators, dimming and the land divider never draw over the zoom. It is a
`DeviceCoordinateCache` item, so the card changing geometry never dirtied it
and the stale hole stayed transparent, uncovering the black viewport as soon
as the zoom crossed a zone edge.

- Emit `hoverFootprintChanged(old, new)` from `setCardScale()` and once from
  `setHovered(false)`.
- Repaint every overlapping `TableZone` on that signal.
- Clip with the card's painted outline instead of its bounding rectangle, and
  treat a zoom covering the whole zone as "paint nothing".

* [Interface] Keep the hover panel P/T controls out of the way

The P/T set/inc/dec rows were always visible and sat under the cursor, so
clicking a card to select it could mutate its P/T instead.

- Collapse the controls to a pill on the printed P/T box, anchored on the
  drawn artwork so letterboxed and sideways cards stay aligned.
- Open the rows only from the pill and grow them upward, and re-measure the
  pill on every value so three-digit P/T does not clip.
- Close the panel when another card is hovered, and repaint the area it
  covered so no patch is left behind.

* [Interface] Address hover panel review findings

* [Game] Fix include order flagged by the format gate

The card hover widget header was included before theme_manager.h, which
clang-format rejects; the branch's format CI job failed on it.

* [Interface] Load the hover panel icons through the themed icon engine

The panel still named pre-#7595 assets (arrow_*_green, arrow_right_blue,
cogwheel) and built QIcon snapshots from themePixmap(), so the deleted names
rendered blank and every other glyph froze one palette.

Load every glyph through loadThemedIcon() with the emphasis axis the adoption
plan calls for: the category tabs take the primary level as panel wayfinding,
the action grid the quiet level because its glyphs label the button text.
Semantic tints keep their family and follow the same quiet level; Clone keeps
its sticker treatment.

* [Icons] Add an Informational semantic color family

Face-down play and the exile zone are states that are neither a gain nor a
loss, and the pre-#7595 art painted them blue (arrow_right_blue). #7595 dropped
that hue, and the icon engine has had only Positive and Negative since, so both
states fall back to neutral ink.

Add the family with the same three-level ladder the other semantic roles use:
authored roles per theme, scheme defaults otherwise, an emphasis mapping, the
palette-editor rows and the generator seed. The defaults clear the 4.5:1 label
floor on both schemes and the ladder's saturation ordering; the existing
emphasis, hue and preview tests now cover the new family. Preview sheets that
name roles resolve an unauthored one through the same default the client
paints.

* [Interface] Split the hover panel icons by emphasis and semantics

Category tabs only navigate between pages, so they take the quiet level; the
action grid is the surface the player works in and takes the primary level. Both
stay line glyphs: a filled treatment reads as a second state on every cell.

Hue marks an outcome where the glyph cannot. Play, clone and to hand are
Positive; reduce life and graveyard Negative; play face down and exile
Informational. Direction-only moves (top and bottom of library) stay neutral
because the arrow already carries the meaning.

* [Icons] Add Hidden and Marked semantic color families

Two game concepts had no hue of their own. Hidden information (a face-down
play, peeking at a card face) now has violet, and the marks a player leaves on a
card (annotation, draw arrow) now share amber instead of splitting blue and red
for the same job.

Both families follow the existing three-level ladder: authored roles per theme,
scheme defaults otherwise, an emphasis mapping, palette-editor rows and generator
seeding. The defaults clear the 4.5:1 floor on the representative platform
surfaces and keep the saturation ordering the emphasis tests assert; the hue
tests pin violet's blue-red-green dominance and amber's red-green-blue one, and
every preview sheet now renders the two families.

The hover panel grid preview is added alongside: it renders the real pages
(section headers, two-column cells, glyph over label) so the whole map can be
judged at once instead of glyph by glyph.

* [Icons] Add a Movement semantic color family

A card changing position inside the library is neither a gain, a loss nor
information, so it had no hue. Movement names it with teal and covers the three
library placements (top, bottom, X from top).

It follows the existing ladder: authored roles per theme, scheme defaults
otherwise, an emphasis mapping, palette-editor rows and generator seeding. The
defaults clear the 4.5:1 floor on the representative platform surfaces, keep
strong > base > soft saturation, and keep green > blue > red so teal cannot be
mistaken for the green gain family.

* [Interface] Give every hover panel action a semantic color

The quick actions are the panel's whole point, so a neutral glyph made the
most-used buttons the hardest to scan. Every action now names a game fact with
its hue: gain, loss, information, hidden information, a mark on the card or a
move. The line glyph stays identical, so the colour is the only difference
between neighbours.

The grid is also ordered by family so a row reads as one idea: the two state
toggles, the two gains, the two marks, the two hidden-information actions and
the two losses each share a row. Conditional actions (Peek, Unattach) sit at the
end of their pair, so a missing one leaves a hole at the section edge instead of
splitting a row. In a zone, Play and Play Face Down stay adjacent on purpose:
the same action, one of them hiding information. The move tab leads with the
three library placements (Movement), then the destinations.

actionGridIcon is removed; semanticActionIcon is now the only grid ink. The
preview renders the real pages so the whole map can be judged at once.

* [Icons] Use quiet emphasis for glyphs that label rather than act

The search and info glyphs inside the search fields, and the combo-box
chevron, label or afford an action rather than performing one. At the
default secondary weight they compete with the actual controls next to
them. Paint them at quiet emphasis so they stay legible without claiming
attention.

Sites: deck editor, visual database display, visual deck storage, set
manager, settings search, in-game zone view, and the dropdown chevron.

* [Icons] Restore sticker treatment to the add, remove and delete actions

The pre-#7595 add and delete glyphs were filled shapes with an outline.
After the line migration they read as ordinary toolbar glyphs, losing the
weight their verbs had. Give the add and delete family the sticker
treatment again.

- Deck editor Add card: primary positive sticker. It is the one action
  the database panel exists for.
- Visual database Clear filters: negative sticker, matching the delete
  family.
- Filter dock Clear all: negative sticker, matching Clear one.

* [Icons] Give sharing and pinning their semantic families

Sharing is an informational act: the app already tints reveal and
make-public with the informational family, so the deck storage share
action, the replay share-code action and the visual deck storage share
button follow it.

The printing-selector pin badge marks a card as pinned. Paint it with the
marked family, the same one used for a mark left on a card, instead of
leaving it neutral.

* [Game] Dismiss the hover panel before opening a modal dialog

The hover panel is a Qt::ToolTip window, i.e. a popup: it is always on
top and holds the input grab. Actions on the panel that open a modal
dialog (Set power/toughness, Set annotation, Set counter value, token
creation) therefore opened the dialog behind the panel, where it could
not be seen or activated.

Hide the panel synchronously and defer the action to the next event-loop
turn, so the popup grab is released before the dialog's event loop
starts. The panel asks the scene to dismiss it through a new
dismissRequested signal, keeping hover timers and the covered-card fade
on the scene's side.

Reported from the P/T overlay SET button; the same path covers the
counter tab and the token tab.

* [Icons] Refine VDE and VDD emphasis and semantics

The visual database filter section and the syntax help are information
aids, so paint them with the informational family at the default
emphasis: the filter section glyph and the search field's help glyph.
The help glyph leaves quiet emphasis because it is a clickable action,
not a field label.

The visual deck editor's display-type toggle is the one control that
changes the whole view, so it takes primary emphasis.

The search glyphs stay quiet; only the help action changes.

* [Icons] Raise the visual database filter controls to primary

The six quick-filter buttons are the controls the filter section exists
for, so paint them at primary emphasis instead of the default weight.

The sort glyph carries the same informational family as the filter
glyph, in both the visual database toolbar label and the visual deck
editor's sort-criteria button.

* [Icons] Keep the display options sort glyph neutral

The sort button beside the display-mode toggle is not part of the
informational family. Only the visual database toolbar's sort glyph
carries informational; the display options button returns to the
default neutral weight.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-11-08 21:51:31 +01:00 • committed by GitHub
parent 6138fbd0a0
commit b1c8f156dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 3796 additions and 76 deletions

View file

@ -13,6 +13,7 @@
#include "libcockatrice/card/printing/exact_card.h"
#include "libcockatrice/utility/card_ref.h"
#include <QAbstractAnimation>
#include <QApplication>
#include <QBrush>
#include <QChar>
@ -21,6 +22,7 @@
#include <QFont>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QHash>
#include <QLineF>
#include <QList>
@ -29,6 +31,7 @@
#include <QPen>
#include <QPixmap>
#include <QPointF>
#include <QPropertyAnimation>
#include <QRectF>
#include <QTimer>
#include <QTransform>
@ -42,9 +45,19 @@
class QSizeF;
// Width the hovered card smooth-zooms to: exactly the hover panel picture size, so
// all four corners coincide when the panel swaps in over it.
static constexpr qreal HOVER_ZOOM_WIDTH = 270.0;
// The pre-panel hover enlargement. The smooth zoom is opt-in, so this stays the hover
// behavior whenever no zoom trigger is configured (see setHoverHighlighted).
static constexpr qreal LEGACY_HOVER_SCALE = 1.1;
static constexpr int HOVER_ZOOM_IN_MS = 220;
static constexpr int HOVER_ZOOM_OUT_MS = 140;
static constexpr int FADE_DURATION_MS = 140;
AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef, PlayerLogic *_owner, int _id)
: ArrowTarget(_owner, parent), state(new CardState(this, nullptr, cardRef, _id)), tapAngle(0),
bgColor(Qt::transparent), isHovered(false), realZValue(0)
bgColor(Qt::transparent), isHovered(false), isHoverHighlighted(false), realZValue(0)
{
setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable);
@ -54,12 +67,38 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef
connect(state, &CardState::cardInfoChanged, this, &AbstractCardItem::onCardInfoChanged);
connect(state, &CardState::cardRefChanged, this, &AbstractCardItem::onCardRefChanged);
connect(state, &CardState::tappedChanged, this, &AbstractCardItem::onTappedChanged);
connect(state, &CardState::facedownChanged, this, [this] { update(); });
connect(state, &CardState::facedownChanged, this, [this](bool faceDown) {
update();
emit faceDownChanged(faceDown);
});
connect(state, &CardState::colorChanged, this, [this] {
cacheBgColor();
update();
});
hoverZoom = new QPropertyAnimation(this, "cardScale", this);
hoverZoom->setEasingCurve(QEasingCurve::InOutCubic);
// Settling the unhover waits for the shrink-out to finish: the stacking override,
// the clip escape and the ancestor lift all stay put while the card is still large,
// so siblings and the clip container cannot cut through the shrinking card.
connect(hoverZoom, &QPropertyAnimation::finished, this, [this] {
if (!isHovered) {
// The cursor may still rest on the card (e.g. wheel-up reverts the zoom),
// in which case the highlight keeps it raised.
setZValue(isHoverHighlighted ? ZValues::HOVERED_CARD : realZValue);
// Final repaint at the settled footprint: with no scale delta the animation
// emits no per-frame updates, and zones would keep a stale clip hole behind.
if (scene()) {
scene()->update(sceneBoundingRect());
}
emit hoverShrinkFinished(this);
}
});
opacityAnim = new QPropertyAnimation(this, "cardOpacity", this);
opacityAnim->setDuration(FADE_DURATION_MS);
opacityAnim->setEasingCurve(QEasingCurve::OutCubic);
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::displayCardNamesChanged, this,
[this] { update(); });
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardLangChanged, this,
@ -131,7 +170,7 @@ void AbstractCardItem::setRealZValue(qreal _zValue)
// During hover, zValue is overridden to HOVERED_CARD. Layout operations
// like reorganizeCards() call setRealZValue() on all cards including the
// hovered one — skip setZValue() here to avoid clobbering the override.
if (!isHovered) {
if (!isHovered && !isHoverHighlighted) {
setZValue(_zValue);
}
}
@ -229,9 +268,9 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
painter->setRenderHint(QPainter::Antialiasing, false);
if (isSelected() || isHovered) {
if (isSelected() || isHovered || isHoverHighlighted) {
QPen pen;
if (isHovered) {
if (isHovered || isHoverHighlighted) {
pen.setColor(Qt::yellow);
}
if (isSelected()) {
@ -257,14 +296,88 @@ void AbstractCardItem::setHovered(bool _hovered)
// Mark the hovered card's current scene footprint dirty so overlapped
// sibling zones (e.g. StackZone) repaint after the card moves away.
if (scene()) {
scene()->update(sceneBoundingRect());
const QRectF footprint = sceneBoundingRect();
scene()->update(footprint);
// The hole disappears the moment the card is no longer hovered, even though the
// card has not changed size yet: tell the zones so they repaint it shut.
emit hoverFootprintChanged(footprint, footprint);
}
}
isHovered = _hovered;
setZValue(_hovered ? ZValues::HOVERED_CARD : realZValue);
setScale(_hovered && SettingsCache::instance().cardsDisplay().getScaleCards() ? 1.1 : 1);
setTransformOriginPoint(_hovered ? CardDimensions::WIDTH_HALF_F : 0, _hovered ? CardDimensions::HEIGHT_HALF_F : 0);
// The stacking override is one-directional: it applies the moment the hover starts
// and only drops once the shrink-out finishes (see the hoverZoom finished handler).
// Restoring it here would let siblings paint over the still-enlarged card.
if (_hovered) {
setZValue(ZValues::HOVERED_CARD);
}
// Scale about the center in both directions: at scale 1 the origin is moot,
// and keeping it centered avoids drift while shrinking back down.
setTransformOriginPoint(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F);
// Smooth-zoom up to the hover picture size (instead of the old 1.1 snap) so the
// hover panel can then swap in over the zoomed card with matching corners.
// The target is constant ON-SCREEN pixels: divide out the board view zoom so
// fullscreen (or zoomed) boards don't overshoot while the fixed-size panel matches.
qreal target = 1.0;
if (_hovered && SettingsCache::instance().cardsDisplay().getScaleCards()) {
const qreal w = boundingRect().width();
qreal viewScale = 1.0;
if (scene() && !scene()->views().isEmpty()) {
if (const auto *view = scene()->views().first()) {
viewScale = qAbs(view->transform().m11());
}
}
if (w > 0.0 && viewScale > 0.0) {
target = qBound(1.0, HOVER_ZOOM_WIDTH / (w * viewScale), 6.0);
}
}
hoverZoom->stop();
hoverZoom->setStartValue(scale());
hoverZoom->setEndValue(target);
hoverZoom->setDuration(_hovered ? HOVER_ZOOM_IN_MS : HOVER_ZOOM_OUT_MS);
hoverZoom->start();
update();
}
void AbstractCardItem::setHoverHighlighted(bool highlighted)
{
if (isHoverHighlighted == highlighted) {
return;
}
if (highlighted) {
// The card-info widget listens for this: hovering still updates it right away.
processHoverEvent();
}
isHoverHighlighted = highlighted;
if (highlighted) {
setZValue(ZValues::HOVERED_CARD);
}
// Fallback to the historical hover scale: the smooth hover zoom is opt-in and its
// trigger defaults to Off, so when hovering drives neither the zoom nor the panel
// (zoom trigger Off, panel not on hover) contact alone must still enlarge the card
// to the old 1.1x while scaleCards is on. Otherwise every existing user silently
// loses the hover enlargement on upgrade.
auto &display = SettingsCache::instance().cardsDisplay();
const bool legacyHoverScale = display.getScaleCards() &&
display.getHoverZoomTrigger() == CardsDisplaySettings::HoverPanelTriggerOff &&
display.getHoverPanelTrigger() != CardsDisplaySettings::HoverPanelTriggerHover;
if (legacyHoverScale) {
// Centered like the smooth zoom, so growing and shrinking never drift.
setTransformOriginPoint(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F);
hoverZoom->stop();
hoverZoom->setStartValue(scale());
hoverZoom->setEndValue(highlighted ? LEGACY_HOVER_SCALE : 1.0);
hoverZoom->setDuration(highlighted ? HOVER_ZOOM_IN_MS : HOVER_ZOOM_OUT_MS);
hoverZoom->start();
} else if (!highlighted && !isHovered && hoverZoom->state() != QAbstractAnimation::Running) {
// A zoomed card keeps its raised z until the shrink-out finishes (its finished
// handler restores it); a highlight-only card has nothing to unwind.
setZValue(realZValue);
}
update();
}
@ -273,6 +386,64 @@ void AbstractCardItem::setColor(const QString &_color)
state->setColor(_color);
}
qreal AbstractCardItem::getCardScale() const
{
return scale();
}
void AbstractCardItem::setCardScale(qreal _scale)
{
if (qFuzzyCompare(_scale, scale())) {
return;
}
// The scale animates every frame: keep the scene index in step or hover
// picking tests a stale rect and the hover oscillates on/off by itself.
// Repaint the union of the old and new footprints, not just the card: zones
// dodge the zoomed card via a clip hole computed at paint time, and without
// a repaint they keep a stale hole — covering the card mid-animation and
// leaving a black rect behind once the hover ends.
const QRectF oldFootprint = sceneBoundingRect();
prepareGeometryChange();
setScale(_scale);
const QRectF newFootprint = sceneBoundingRect();
if (scene()) {
scene()->update(oldFootprint.united(newFootprint));
// Marking the scene region dirty is not enough for cached items: a zone that cuts a
// hover hole out of itself keeps the hole from its last repaint, which then shows as
// an uncovered black rectangle under the zoom.
emit hoverFootprintChanged(oldFootprint, newFootprint);
} else {
update();
}
}
qreal AbstractCardItem::getCardOpacity() const
{
return opacity();
}
void AbstractCardItem::setCardOpacity(qreal _opacity)
{
setOpacity(_opacity);
update();
}
void AbstractCardItem::fadeCardOut()
{
opacityAnim->stop();
opacityAnim->setStartValue(opacity());
opacityAnim->setEndValue(0.0);
opacityAnim->start();
}
void AbstractCardItem::fadeCardIn()
{
opacityAnim->stop();
opacityAnim->setStartValue(opacity());
opacityAnim->setEndValue(1.0);
opacityAnim->start();
}
void AbstractCardItem::cacheBgColor()
{
QChar colorChar;
@ -310,6 +481,7 @@ void AbstractCardItem::cacheBgColor()
void AbstractCardItem::onTappedChanged(bool newTapped, bool canAnimate)
{
emit tappedChanged(newTapped);
if (SettingsCache::instance().cardsDisplay().getTapAnimation() && canAnimate) {
static_cast<GameScene *>(scene())->registerAnimationItem(this);
} else {

View file

@ -23,10 +23,13 @@ class PlayerLogic;
class CardInfo;
class QPainter;
class QPoint;
class QPropertyAnimation;
class AbstractCardItem : public ArrowTarget, public IAnimatedItem
{
Q_OBJECT
Q_PROPERTY(qreal cardScale READ getCardScale WRITE setCardScale)
Q_PROPERTY(qreal cardOpacity READ getCardOpacity WRITE setCardOpacity)
protected:
CardState *state;
int tapAngle;
@ -34,9 +37,12 @@ protected:
private:
bool isHovered;
bool isHoverHighlighted;
qreal realZValue;
bool pendingSelectionCollapse;
int selectionCollapseGeneration = 0; ///< Guards the deferred collapse timer against stale firings
QPropertyAnimation *hoverZoom = nullptr;
QPropertyAnimation *opacityAnim = nullptr;
private slots:
void pixmapUpdated();
void onCardInfoChanged();
@ -57,6 +63,19 @@ signals:
void playSelectedFaceDown(AbstractCardItem *card);
void hideSelected(AbstractCardItem *card);
void selectionChanged(AbstractCardItem *card, bool selected);
void tappedChanged(bool tapped);
void faceDownChanged(bool faceDown);
/** @brief Emitted when the hover shrink-out animation runs to completion while unhovered. */
void hoverShrinkFinished(AbstractCardItem *card);
/**
* @brief Emitted when the hover zoom changes this card's scene footprint.
*
* Zones (and anything else that dodges the zoomed card) draw from the live footprint at
* paint time but are cached: they need this to invalidate, or a stale hole is left behind.
* Also emitted once when the hover ends, with both rects equal, because the hole
* disappears without the card changing size.
*/
void hoverFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint);
public:
enum
@ -116,6 +135,23 @@ public:
}
void setRealZValue(qreal _zValue);
void setHovered(bool _hovered);
/**
* @brief Shows the hover outline and stacking lift, plus the historical 1.1x hover
* scale whenever no zoom trigger is configured.
*
* The board zoom is trigger-gated; the hover feedback (card info, outline, raised
* stacking) still follows the cursor immediately on contact. With the zoom trigger
* off and the panel not on hover, the old 1.1x enlargement (gated by scaleCards)
* stays in effect so upgrading does not silently drop it.
*/
void setHoverHighlighted(bool highlighted);
qreal getCardScale() const;
void setCardScale(qreal scale);
qreal getCardOpacity() const;
void setCardOpacity(qreal opacity);
/** @brief Fades the card out under the hover panel, or back in when it closes. */
void fadeCardOut();
void fadeCardIn();
bool getIsHovered() const
{
return isHovered;

View file

@ -117,6 +117,11 @@ void CardItem::deleteLater()
void CardItem::setZone(CardZoneLogic *_zone)
{
state->setZone(_zone);
// A card faded out under the open hover panel must come back as soon as it changes
// zones; otherwise it stays invisible at its destination until the panel closes.
if (opacity() < 1.0) {
fadeCardIn();
}
}
void CardItem::retranslateUi()

View file

@ -2,6 +2,7 @@
#include "../client/settings/cache_settings.h"
#include "../interface/theme_manager.h"
#include "../interface/widgets/cards/card_hover_widget.h"
#include "animated_item.h"
#include "board/abstract_card_item.h"
#include "board/arrow_item.h"
@ -11,16 +12,21 @@
#include "player/menu/player_menu.h"
#include "player/player_graphics_item.h"
#include "player/player_target.h"
#include "z_values.h"
#include "zones/card_zone.h"
#include "zones/select_zone.h"
#include "zones/table_zone.h"
#include "zones/view_zone.h"
#include "zones/view_zone_widget.h"
#include <QBasicTimer>
#include <QCursor>
#include <QDebug>
#include <QEvent>
#include <QGraphicsItem>
#include <QGraphicsObject>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>
#include <QGraphicsView>
#include <QListIterator>
#include <QMenu>
@ -29,9 +35,11 @@
#include <QObject>
#include <QPoint>
#include <QRectF>
#include <QScrollBar>
#include <QSet>
#include <QSharedPointer>
#include <QtMath>
#include <QTimer>
#include <QtGlobal>
#include <algorithm>
#include <functional>
#include <libcockatrice/game/abstract_game.h>
@ -43,6 +51,7 @@
#include <libcockatrice/game/player/player_logic.h>
#include <libcockatrice/game/zones/card_zone_logic.h>
#include <libcockatrice/game/zones/view_zone_logic.h>
#include <libcockatrice/settings/cards_display_settings.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/utility/zone_names.h>
#include <numeric>
@ -75,6 +84,22 @@ GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
}
});
// Card hover popup (cardHoverWidget is created lazily on first show)
hoverActivateTimer = new QTimer(this);
hoverActivateTimer->setSingleShot(true);
hoverActivateTimer->setInterval(500);
connect(hoverActivateTimer, &QTimer::timeout, this, &GameScene::onHoverActivateTimeout);
hoverPanelTimer = new QTimer(this);
hoverPanelTimer->setSingleShot(true);
hoverPanelTimer->setInterval(200);
connect(hoverPanelTimer, &QTimer::timeout, this, &GameScene::onHoverPanelTimeout);
hoverGraceTimer = new QTimer(this);
hoverGraceTimer->setSingleShot(true);
hoverGraceTimer->setInterval(200);
connect(hoverGraceTimer, &QTimer::timeout, this, &GameScene::onHoverGraceTimeout);
rearrange();
}
@ -93,6 +118,9 @@ GameScene::~GameScene()
delete animationTimer;
animationTimer = nullptr;
delete hoverActivateTimer;
delete hoverPanelTimer;
delete hoverGraceTimer;
// Delete all ArrowItems before QGraphicsScene's base destructor runs.
// QGraphicsScene::~QGraphicsScene() destroys items in arbitrary order.
@ -239,6 +267,23 @@ void GameScene::onCardRightClicked(AbstractCardItem *abstractCard, QPoint screen
return;
}
// The zoom and panel triggers are independently bindable: a right-click fires
// whichever phases listen to it. When the panel is the trigger it carries every
// action itself, so the context menu stays suppressed; when right-click only zooms,
// the menu still opens, since nothing else would summon it.
auto &display = SettingsCache::instance().cardsDisplay();
const bool zoomFired = display.getHoverZoomTrigger() == CardsDisplaySettings::HoverPanelTriggerRightClick;
const bool panelFired = display.getHoverPanelTrigger() == CardsDisplaySettings::HoverPanelTriggerRightClick;
if (zoomFired || panelFired) {
fireTriggers(card, zoomFired, panelFired);
if (panelFired) {
return;
}
}
// Hide the hover popup when the context menu opens
hideCardHoverPopup();
setActiveCard(card);
if (auto *menu = view->getPlayerMenu()->updateCardMenu(card->getState())) {
@ -690,7 +735,6 @@ void GameScene::requestArrowDeletion(int playerId, int arrowId)
emit arrowDeletionRequested(playerId, arrowId);
}
}
void GameScene::onCardZoneChanged(CardState *card, bool sameZone)
{
auto *item = qobject_cast<CardItem *>(card->parent());
@ -710,6 +754,11 @@ void GameScene::onCardZoneChanged(CardState *card, bool sameZone)
for (auto *arrow : toDelete) {
deleteArrow(arrow->getCreatorId(), arrow->getId());
}
// The hover panel stays open on a moved card: follow it instead of stranding.
if (!sameZone && cardHoverWidget && cardHoverWidget->getCardItem() == item) {
positionCardHoverPopup();
}
}
void GameScene::onCardViewRefreshRequested(CardState *card, bool zoneChanged, PlayerLogic *newOwner)
@ -746,27 +795,137 @@ void GameScene::clearArrowsForPlayerLocally(int playerId)
}
}
}
// ---------- Hover Handling ----------
CardItem *GameScene::getHoveredCard() const
{
return hoveredCard;
}
void GameScene::updateHover(const QPointF &scenePos)
{
auto itemList = items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
updateHoveredCard(pickCardAt(scenePos));
}
CardItem *GameScene::pickCardAt(const QPointF &scenePos)
{
auto itemList = items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
CardZone *zone = findTopmostZone(itemList);
CardItem *topCard = zone ? findTopmostCardInZone(itemList, zone) : nullptr;
updateHoveredCard(topCard);
if (!topCard && hoveredCard) {
const QRectF guard = hoveredCard->sceneBoundingRect().adjusted(-8, -8, 8, 8);
if (guard.contains(scenePos)) {
// The zoomed card overflows onto neighboring zones, where naive topmost-zone
// picking attributes the cursor to the zone underneath. While the cursor is
// still over the zoomed footprint (with hysteresis for edge jiggle), keep it.
// A genuinely different topmost card still takes over.
return hoveredCard;
}
}
return topCard;
}
void GameScene::updateHoveredCard(CardItem *newCard)
{
// Safety: if the popup's card was destroyed, hide the popup immediately
if (cardHoverWidget && cardHoverWidget->isVisible() && !cardHoverWidget->hasCard()) {
hideCardHoverPopup();
}
// The hovered card may have been destroyed without ending the hover: its QPointer
// nulled itself, but the ancestor lift is still outstanding. Restore it now.
if (!hoveredCard && !hoverLiftedAncestors.isEmpty()) {
restoreHoverLift();
}
// Hovering alone never starts anything anymore: the trigger (dwell, click, wheel,
// shortcut) resolves first, then the zoom follows. This keeps the feature calm.
bool wasHoveringCard = (hoveredCard != nullptr);
if (hoveredCard && (newCard != hoveredCard)) {
endCardHover(hoveredCard);
hoveredCard = nullptr;
}
if (newCard && (newCard != hoveredCard)) {
beginCardHover(newCard);
// The hover outline and the card info follow the cursor on contact: only the board
// zoom and the panel wait for their trigger. A highlight-only card has no zoom to
// unwind, so it is dropped directly instead of through endCardHover().
if (hoverHighlightCard && hoverHighlightCard != newCard) {
hoverHighlightCard->setHoverHighlighted(false);
}
hoverHighlightCard = newCard;
if (newCard) {
newCard->setHoverHighlighted(true);
}
auto &display = SettingsCache::instance().cardsDisplay();
const int zoomTrigger = display.getHoverZoomTrigger();
const int panelTrigger = display.getHoverPanelTrigger();
const bool doubleConfirm = display.getHoverPanelDoubleConfirm() && zoomTrigger == panelTrigger;
if (newCard) {
// Cancel any pending grace timer (mouse is back on a card)
hoverGracePending = false;
hoverGraceTimer->stop();
if (newCard == hoveredCard) {
// Steady state: zoom already up. Refresh an open panel, otherwise nothing —
// in particular this must not re-fire an armed double-confirm.
if (cardHoverWidget && cardHoverWidget->isVisible() && cardHoverWidget->getCardItem() == newCard) {
cardHoverWidget->refreshDisplay();
}
return;
}
if (cardHoverWidget && cardHoverWidget->isVisible() && !cardHoverWidget->isClosing() &&
cardHoverWidget->getCardItem() == newCard) {
// Panel open but zoom dropped (e.g. survived a Leave) — zoom back and refresh.
beginCardHover(newCard);
hoveredCard = newCard;
cardHoverWidget->refreshDisplay();
return;
}
if (cardHoverWidget && cardHoverWidget->isVisible() && !cardHoverWidget->isClosing()) {
// A different card is hovered while the panel is up: close the old panel
// first, then fall through to first contact so the new card follows the
// normal dwell instead of the old panel trailing the cursor.
hideCardHoverPopup();
confirmArmedCard.clear();
}
if (zoomTrigger != CardsDisplaySettings::HoverPanelTriggerHover &&
panelTrigger != CardsDisplaySettings::HoverPanelTriggerHover) {
// Mouse contact alone drives neither phase in this config.
return;
}
if (doubleConfirm && confirmArmedCard == newCard) {
// Repeat hover on an armed card: zoom and show at once, no second dwell.
beginCardHover(newCard);
hoveredCard = newCard;
confirmArmedCard.clear();
showCardHoverPopup(newCard);
return;
}
if (newCard != hoverPopupTarget) {
// First contact (or a new card): dwell, then resolve on timeout.
hoverPopupTarget = newCard;
hoverActivateTimer->start(display.getHoverZoomDelayMs());
}
} else {
// No card hovered: drop any pending dwell/panel timers (kills stale shows) and start
// the grace timer only when the mouse just left a card with the panel open.
hoverPopupTarget = nullptr;
hoverPanelTarget = nullptr;
hoverActivateTimer->stop();
hoverPanelTimer->stop();
// Non-hover zoom arms only make sense while approaching the card: leaving
// re-arms the zoom for the next explicit trigger instead of showing the panel.
// (Hover-trigger arms survive the leave so re-entering completes the repeat.)
if (zoomTrigger != CardsDisplaySettings::HoverPanelTriggerHover) {
confirmArmedCard.clear();
}
if (wasHoveringCard && cardHoverWidget && cardHoverWidget->isVisible() &&
!cardHoverWidget->isMouseOverWidget() && !hoverGracePending) {
hoverGracePending = true;
hoverGraceTimer->start();
}
}
hoveredCard = newCard;
}
void GameScene::beginCardHover(CardItem *card)
@ -775,16 +934,340 @@ void GameScene::beginCardHover(CardItem *card)
if (auto *zone = SelectZone::findOwningSelectZone(card)) {
zone->escapeClipForHover(card);
}
// Lift the whole ancestor chain above their siblings: the zoomed card overflows its
// own zone, and Qt orders whole subtrees level by level, so no single z-value wins
// every comparison on its own. Harmless elsewhere (areas and zones tile without
// overlapping; arrows, zone views and drag items keep their higher layers).
// Restore first: if a previous hover never ended (its card was destroyed mid-hover),
// its chain is still outstanding and must land before a new one is recorded.
restoreHoverLift();
QGraphicsItem *ancestor = card->parentItem();
while (ancestor) {
// The chain is QGraphicsObject-derived in practice; a plain QGraphicsItem
// ancestor cannot be guarded, so it keeps its z-value instead of risking an
// unrestorable lift.
if (QGraphicsObject *ancestorObject = ancestor->toGraphicsObject()) {
hoverLiftedAncestors.append({QPointer<QGraphicsObject>(ancestorObject), ancestor->zValue()});
ancestor->setZValue(ZValues::HOVERED_AREA);
}
ancestor = ancestor->parentItem();
}
liftOwner = card;
connect(card, &AbstractCardItem::hoverShrinkFinished, this, &GameScene::onHoverShrinkFinished,
Qt::UniqueConnection);
connect(card, &AbstractCardItem::hoverFootprintChanged, this, &GameScene::onHoverFootprintChanged,
Qt::UniqueConnection);
}
void GameScene::endCardHover(CardItem *card)
{
if (auto *zone = SelectZone::findOwningSelectZone(card)) {
zone->restoreClipAfterHover(card);
}
// Only the zoom-out starts here: the z-value, the clip escape and the ancestor
// lift stay put until the shrink finishes (onHoverShrinkFinished), so siblings and
// the clip container cannot cut through the still-enlarged card.
card->setHovered(false);
}
void GameScene::onHoverShrinkFinished(AbstractCardItem *card)
{
auto *cardItem = qobject_cast<CardItem *>(card);
if (!cardItem) {
return;
}
// Per-card and idempotent: always settle, even if a newer hover owns the lift.
if (auto *zone = SelectZone::findOwningSelectZone(cardItem)) {
zone->restoreClipAfterHover(cardItem);
}
if (liftOwner != cardItem) {
// A newer hover already owns the lift (or nothing does): leave it alone.
return;
}
restoreHoverLift();
}
void GameScene::onHoverFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint)
{
const QRectF dirty = oldFootprint.united(newFootprint);
if (dirty.isEmpty()) {
return;
}
// TableZone cuts the hovered card out of its own paint, but it is cached: the card
// changing size does not dirty the zone, so the previous hole would stay transparent in
// the cache — an uncovered black rectangle under the zoom whenever the card grows across
// a zone boundary. Nudge only the zones the footprint touches; the scene repaint itself
// is already scheduled by the card.
const auto overlapping = items(dirty, Qt::IntersectsItemBoundingRect);
for (QGraphicsItem *item : overlapping) {
if (auto *zone = qobject_cast<TableZone *>(item->toGraphicsObject())) {
zone->update();
}
}
}
void GameScene::restoreHoverLift()
{
for (const auto &[lifted, zValue] : hoverLiftedAncestors) {
if (lifted) {
lifted->setZValue(zValue);
}
}
hoverLiftedAncestors.clear();
liftOwner.clear();
}
// ---------- Card Hover Popup ----------
void GameScene::showCardHoverPopup(CardItem *card)
{
if (!card || !card->getOwner()) {
return;
}
PlayerGraphicsItem *playerView = playerViews.value(card->getOwner()->getPlayerInfo()->getId());
if (!playerView) {
return;
}
hoverActivateTimer->stop();
hoverPanelTimer->stop();
hoverGracePending = false;
hoverGraceTimer->stop();
hoverPopupTarget = card;
hoverPanelTarget = nullptr;
confirmArmedCard.clear();
if (!cardHoverWidget) {
auto *viewport = views().isEmpty() ? nullptr : views().first()->viewport();
cardHoverWidget = new CardHoverWidget(viewport);
connect(cardHoverWidget, &CardHoverWidget::hoverEntered, this, &GameScene::onHoverWidgetEntered);
connect(cardHoverWidget, &CardHoverWidget::hoverLeft, this, &GameScene::onHoverWidgetLeft);
connect(cardHoverWidget, &CardHoverWidget::dismissRequested, this, &GameScene::hideCardHoverPopup);
// Keep the popup anchored to its card while the view scrolls, zooms, or resizes
if (!views().isEmpty()) {
auto *view = views().first();
connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, this, &GameScene::positionCardHoverPopup);
connect(view->verticalScrollBar(), &QScrollBar::valueChanged, this, &GameScene::positionCardHoverPopup);
if (viewport) {
viewport->installEventFilter(this);
}
}
}
// Crossfade: the opaque panel picture sits exactly over the zoomed card, so fade
// the board card out underneath it (masks any residual size/corner mismatch) and
// fade any previously shown card back in.
CardItem *oldCard = cardHoverWidget->hasCard() ? cardHoverWidget->getCardItem() : nullptr;
cardHoverWidget->setCard(card, playerView);
positionCardHoverPopup();
cardHoverWidget->showAnimated();
if (oldCard && oldCard != card) {
oldCard->fadeCardIn();
}
card->fadeCardOut();
}
void GameScene::hideCardHoverPopup()
{
// Hiding is terminal: drop all pending hover timing with it, or a dwell/panel
// timer that resolves afterwards pops the panel back up (e.g. over the context
// menu that hideCardHoverPopup was just called for).
hoverActivateTimer->stop();
hoverPanelTimer->stop();
hoverGracePending = false;
hoverGraceTimer->stop();
if (cardHoverWidget) {
// The panel is gone: whatever card it covered must come back.
if (CardItem *coveredCard = cardHoverWidget->getCardItem()) {
coveredCard->fadeCardIn();
}
if (cardHoverWidget->isVisible()) {
cardHoverWidget->hideAnimated();
}
}
hoverPopupTarget = nullptr;
hoverPanelTarget = nullptr;
}
void GameScene::positionCardHoverPopup()
{
if (!cardHoverWidget || !cardHoverWidget->hasCard()) {
return;
}
auto *viewport = views().isEmpty() ? nullptr : views().first()->viewport();
if (!viewport) {
return;
}
QRectF sceneRect = cardHoverWidget->getCardItem()->sceneBoundingRect();
QTransform vpTransform = getViewportTransform();
cardHoverWidget->positionNextTo(sceneRect, vpTransform, viewport);
}
void GameScene::onHoverActivateTimeout()
{
// Dwell resolved: the hover drives whichever phases listen to it. The cursor must
// still be over the pending card (rect test, not a fresh pick, so pick flakiness
// cannot veto it); otherwise this was a stale timer.
CardItem *target = hoverPopupTarget;
hoverPopupTarget = nullptr;
if (!target || views().isEmpty()) {
return;
}
auto *view = views().first();
const QPointF cursorScene = view->mapToScene(view->viewport()->mapFromGlobal(QCursor::pos()));
if (!target->sceneBoundingRect().contains(cursorScene)) {
return;
}
auto &display = SettingsCache::instance().cardsDisplay();
const bool zoomPhase = display.getHoverZoomTrigger() == CardsDisplaySettings::HoverPanelTriggerHover;
const bool panelPhase = display.getHoverPanelTrigger() == CardsDisplaySettings::HoverPanelTriggerHover;
const bool effectiveDouble =
display.getHoverPanelDoubleConfirm() && display.getHoverZoomTrigger() == display.getHoverPanelTrigger();
if (hoveredCard && hoveredCard != target) {
endCardHover(hoveredCard);
}
if (zoomPhase) {
if (hoveredCard != target) {
beginCardHover(target);
hoveredCard = target;
}
if (effectiveDouble) {
confirmArmedCard = target;
}
}
if (panelPhase && !effectiveDouble) {
hoverPanelTarget = target;
hoverPanelTimer->start(display.getHoverPanelDelayMs());
}
}
void GameScene::onHoverPanelTimeout()
{
// Panel delay resolved: show, but only if the target card is still the one under
// the cursor (same cheap rect check — no dependence on pick stability).
CardItem *target = hoverPanelTarget;
hoverPanelTarget = nullptr;
if (!target || views().isEmpty()) {
return;
}
auto *view = views().first();
const QPointF cursorScene = view->mapToScene(view->viewport()->mapFromGlobal(QCursor::pos()));
if (!target->sceneBoundingRect().contains(cursorScene)) {
return;
}
ensureZoomed(target);
showCardHoverPopup(target);
}
void GameScene::onHoverGraceTimeout()
{
hoverGracePending = false;
if (cardHoverWidget && cardHoverWidget->isVisible() && cardHoverWidget->isMouseOverWidget()) {
return;
}
hideCardHoverPopup();
}
void GameScene::summonHoverPanel()
{
// Summon for whatever is under the cursor right now; hovering is not required.
if (views().isEmpty()) {
return;
}
auto *view = views().first();
const QPointF cursorScene = view->mapToScene(view->viewport()->mapFromGlobal(QCursor::pos()));
if (CardItem *card = pickCardAt(cursorScene)) {
auto &display = SettingsCache::instance().cardsDisplay();
fireTriggers(card, display.getHoverZoomTrigger() == CardsDisplaySettings::HoverPanelTriggerShortcut,
display.getHoverPanelTrigger() == CardsDisplaySettings::HoverPanelTriggerShortcut);
}
}
void GameScene::ensureZoomed(CardItem *card)
{
if (hoveredCard != card) {
if (hoveredCard) {
endCardHover(hoveredCard);
}
beginCardHover(card);
hoveredCard = card;
}
}
void GameScene::fireTriggers(CardItem *card, bool zoomFired, bool panelFired)
{
if (!card || !card->getOwner()) {
return;
}
if (cardHoverWidget && cardHoverWidget->isVisible() && !cardHoverWidget->isClosing() &&
cardHoverWidget->getCardItem() == card) {
cardHoverWidget->refreshDisplay();
return;
}
// Explicit triggers preempt any pending hover timing.
hoverPopupTarget = nullptr;
hoverPanelTarget = nullptr;
hoverActivateTimer->stop();
hoverPanelTimer->stop();
auto &display = SettingsCache::instance().cardsDisplay();
const bool effectiveDouble =
display.getHoverPanelDoubleConfirm() && display.getHoverZoomTrigger() == display.getHoverPanelTrigger();
if (zoomFired && panelFired) {
// Both phases on one action: one-step zooms and shows at once (the crossfade
// covers it); double-confirm arms on first fire and shows on repeat.
if (effectiveDouble) {
if (confirmArmedCard == card) {
confirmArmedCard.clear();
ensureZoomed(card);
showCardHoverPopup(card);
} else {
confirmArmedCard = card;
ensureZoomed(card);
}
} else {
ensureZoomed(card);
showCardHoverPopup(card);
}
return;
}
if (zoomFired) {
ensureZoomed(card);
}
if (panelFired) {
ensureZoomed(card);
showCardHoverPopup(card);
}
}
void GameScene::onHoverWidgetEntered()
{
hoverGracePending = false;
hoverGraceTimer->stop();
}
void GameScene::onHoverWidgetLeft()
{
if (!hoveredCard && cardHoverWidget && cardHoverWidget->isVisible() && !hoverGracePending) {
hoverGracePending = true;
hoverGraceTimer->start();
}
}
bool GameScene::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::Resize) {
positionCardHoverPopup();
}
return QGraphicsScene::eventFilter(watched, event);
}
CardZone *GameScene::findTopmostZone(const QList<QGraphicsItem *> &items)
{
for (QGraphicsItem *item : items) {
@ -940,7 +1423,50 @@ bool GameScene::event(QEvent *event)
{
if (event->type() == QEvent::GraphicsSceneMouseMove) {
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
} else if (event->type() == QEvent::GraphicsSceneWheel) {
// Wheel trigger: wheeling over a card fires whichever phases listen to it
// instead of scrolling. Fully consumed here: forwarding to the base dispatcher
// as well would double-deliver it to items under the cursor (e.g. zone views,
// which scroll on wheel). Scrolling up instead reverts an active zoom/panel —
// backing out of the gesture undoes it; with nothing to revert the event falls
// through to normal scrolling.
auto &display = SettingsCache::instance().cardsDisplay();
const bool zoomFired = display.getHoverZoomTrigger() == CardsDisplaySettings::HoverPanelTriggerWheel;
const bool panelFired = display.getHoverPanelTrigger() == CardsDisplaySettings::HoverPanelTriggerWheel;
if (zoomFired || panelFired) {
auto *wheelEvent = static_cast<QGraphicsSceneWheelEvent *>(event);
// QGraphicsSceneWheelEvent carries delta()/pixelDelta(), not angleDelta().
const int wheelUp = !wheelEvent->pixelDelta().isNull()
? wheelEvent->pixelDelta().y()
: (wheelEvent->orientation() == Qt::Vertical ? wheelEvent->delta() : 0);
if (wheelUp > 0) {
if ((cardHoverWidget && cardHoverWidget->isVisible()) || hoveredCard) {
hoverPopupTarget = nullptr;
hoverPanelTarget = nullptr;
confirmArmedCard.clear();
hideCardHoverPopup();
if (hoveredCard) {
endCardHover(hoveredCard);
hoveredCard = nullptr;
}
event->accept();
return true;
}
} else if (CardItem *card = pickCardAt(wheelEvent->scenePos())) {
fireTriggers(card, zoomFired, panelFired);
event->accept();
return true;
}
}
} else if (event->type() == QEvent::Leave) {
// The hover panel opens directly over the zoomed card under the cursor, which the
// scene observes as a Leave. The cursor never actually left: if it is over the open
// panel, keep the hover (dropping it here shrinks the card from under the panel and
// starves the popup logic, so the menu never shows). A genuine leave of the window
// misses the panel and still ends the hover as before.
if (cardHoverWidget && cardHoverWidget->isVisible() && cardHoverWidget->isMouseOverWidget()) {
return QGraphicsScene::event(event);
}
updateHoveredCard(nullptr);
}

View file

@ -11,8 +11,10 @@
#include <QLoggingCategory>
#include <QMap>
#include <QMetaObject>
#include <QPair>
#include <QPointF>
#include <QPointer>
#include <QRectF>
#include <QSize>
#include <QSizeF>
#include <QString>
@ -30,6 +32,7 @@
class CardZoneLogic;
class IAnimatedItem;
class QGraphicsItem;
class QGraphicsObject;
class QPoint;
struct ArrowData;
template <class T> class QSharedPointer;
@ -48,6 +51,8 @@ class ServerInfo_Card;
class PhasesToolbar;
class QBasicTimer;
class QObject;
class QTimer;
class CardHoverWidget;
/**
* @class GameScene
@ -73,16 +78,41 @@ private:
ArrowRegistry arrowRegistry; ///< ID registry for arrow graphics items
QList<ZoneViewWidget *> zoneViews; ///< Active zone view widgets
QSize viewSize; ///< Current view size
QPointer<CardItem> hoveredCard; ///< Currently hovered card
QPointer<CardItem> activeCard; ///< Card the currently open context menu targets
QBasicTimer *animationTimer; ///< Timer for scene animations
QHash<QObject *, IAnimatedItem *> animatedItems; ///< Items currently animating
QPointer<CardItem> hoveredCard; ///< Currently hovered card (zoomed)
/// Card the cursor is resting on. It carries the hover outline and the card-info
/// update immediately, independently of the zoom/panel triggers.
QPointer<CardItem> hoverHighlightCard;
QPointer<CardItem> activeCard; ///< Card the currently open context menu targets
/// Card armed for double-confirm panel summon (first trigger zooms, repeat shows).
QPointer<CardItem> confirmArmedCard;
/// Ancestor chain of the hovered card with pre-hover Z-values. Lifted while hovering
/// because Qt orders subtrees level by level: the card z alone cannot beat a sibling
/// zone, and the top ancestor alone cannot beat same-area sibling zones either — every
/// level from the zone up must win its own comparison. Guarded pointers: if the card
/// is destroyed mid-hover (or an ancestor goes away first), the guards null out and
/// the next restore skips them instead of touching freed memory. An orphaned lift is
/// invisible — areas and zones tile without overlapping and all UI layers still win —
/// and any outstanding lift is restored by the next hover transition.
QList<QPair<QPointer<QGraphicsObject>, qreal>> hoverLiftedAncestors;
/// Card whose ancestor chain is currently lifted (cleared together with the chain).
QPointer<CardItem> liftOwner;
QBasicTimer *animationTimer; ///< Timer for scene animations
QHash<QObject *, IAnimatedItem *> animatedItems; ///< Items currently animating
QHash<QObject *, QMetaObject::Connection>
animationItemConnections; ///< destroyed->removeAnimatedItem handles per animated item
int playerRotation; ///< Rotation offset for player layout
bool rearranging = false; ///< Guard against re-entrant rearrange
bool needsReArrange = false; ///< Pending rearrange requested during a pass
// Card hover popup
QPointer<CardHoverWidget> cardHoverWidget; ///< The hover popup widget
QTimer *hoverActivateTimer; ///< Dwell delay before the hover zoom kicks in
QTimer *hoverPanelTimer; ///< Delay after the zoom before the tab panel shows
QTimer *hoverGraceTimer; ///< Grace period before hiding popup (200ms)
QPointer<CardItem> hoverPopupTarget; ///< Card the popup is intended for
QPointer<CardItem> hoverPanelTarget; ///< Card the panel timer will show
bool hoverGracePending = false; ///< Grace timer armed (mouse left a card or the popup)
/**
* @brief Updates which card is currently hovered based on scene coordinates.
* @param scenePos Scene position of the cursor.
@ -96,6 +126,23 @@ private:
void beginCardHover(CardItem *card);
/** @brief Deactivates hover state and restores the card to its clip container. */
void endCardHover(CardItem *card);
/** @brief Restores every lifted ancestor to its pre-hover Z-value and drops the chain. */
void restoreHoverLift();
/** @brief Settles a finished shrink-out: clip container and ancestor lift restore. */
void onHoverShrinkFinished(AbstractCardItem *card);
/**
* @brief Repaints the zones that dodge the zoomed card when its footprint moves.
*
* Those zones cut the hovered card out of their paint, but they are cached: another
* item's geometry change does not dirty them, so without this the previous hole stays
* transparent in the cache and a black rectangle shows under the zoom.
*/
void onHoverFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint);
// Card hover popup methods
void showCardHoverPopup(CardItem *card);
void hideCardHoverPopup();
void positionCardHoverPopup();
public:
/**
@ -227,6 +274,21 @@ public:
/** @brief Updates hovered card highlighting. */
void updateHoveredCard(CardItem *newCard);
/** @brief Topmost card at a scene position, without side effects. */
CardItem *pickCardAt(const QPointF &scenePos);
/**
* @brief Fires the zoom and/or panel trigger for a card (one explicit user action).
* When both fire on one action, double-confirm arms on first fire and shows on repeat.
*/
void fireTriggers(CardItem *card, bool zoomFired, bool panelFired);
/** @brief Starts the hover zoom for a card without touching panel state. */
void ensureZoomed(CardItem *card);
/** @brief The currently hovered card, if any (used by zones to dodge it while painting). */
CardItem *getHoveredCard() const;
/**
* @brief Registers an item for animation updates with the shared scene timer.
*
@ -293,10 +355,22 @@ public slots:
*/
void onCardViewRefreshRequested(CardState *card, bool zoneChanged, PlayerLogic *newOwner);
// Card hover popup slots
void onHoverActivateTimeout();
void onHoverPanelTimeout();
void onHoverGraceTimeout();
void onHoverWidgetEntered();
void onHoverWidgetLeft();
/** @brief Summons the hover panel for the currently hovered card, if any. */
void summonHoverPanel();
protected:
/** @brief Handles hover updates. */
bool event(QEvent *event) override;
/** @brief Repositions the hover popup when the viewport resizes. */
bool eventFilter(QObject *watched, QEvent *event) override;
/** @brief Handles animation timer updates. */
void timerEvent(QTimerEvent *event) override;

View file

@ -87,6 +87,10 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par
connect(aCloseMostRecentZoneView, &QAction::triggered, scene, &GameScene::closeMostRecentZoneView);
addAction(aCloseMostRecentZoneView);
aShowHoverPanel = new QAction(this);
connect(aShowHoverPanel, &QAction::triggered, scene, &GameScene::summonHoverPanel);
addAction(aShowHoverPanel);
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
&GameView::refreshShortcuts);
refreshShortcuts();
@ -246,6 +250,7 @@ void GameView::refreshShortcuts()
{
aCloseMostRecentZoneView->setShortcuts(
SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView"));
aShowHoverPanel->setShortcuts(SettingsCache::instance().shortcuts().getShortcut("Player/aShowHoverPanel"));
}
void GameView::clearTallyLabels()

View file

@ -29,6 +29,7 @@ class GameView : public QGraphicsView
Q_OBJECT
private:
QAction *aCloseMostRecentZoneView;
QAction *aShowHoverPanel;
QRubberBand *rubberBand;
QLabel *dragCountLabel;
QLabel *totalCountLabel;

View file

@ -34,6 +34,10 @@ constexpr qreal OVERLAY_BASE = ZValueLayerManager::OVERLAY_BASE;
// Overlay layer Z-values for items that should appear above normal cards
constexpr qreal HOVERED_CARD = ZValueLayerManager::overlayZValue(1.0);
// Lifts the hovered card's whole player area above sibling areas (and their zone
// decorations) while hovering. One level only: Qt compares subtrees at their highest
// differing ancestor, so the top ancestor decides. Below arrows/views/drags on purpose.
constexpr qreal HOVERED_AREA = ZValueLayerManager::overlayZValue(2.0);
constexpr qreal ARROWS = ZValueLayerManager::overlayZValue(3.0);
constexpr qreal ZONE_VIEW_WIDGET = ZValueLayerManager::overlayZValue(4.0);
constexpr qreal DRAG_ITEM = ZValueLayerManager::overlayZValue(5.0);

View file

@ -19,6 +19,7 @@
#include <QList>
#include <QListIterator>
#include <QPainter>
#include <QPainterPath>
#include <QRectF>
#include <QSharedPointer>
#include <QString>
@ -34,6 +35,7 @@
#include <libcockatrice/game/zones/table_zone_logic.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/utility/zone_names.h>
#include <optional>
#include <string>
namespace google
@ -118,6 +120,19 @@ bool TableZone::isInverted() const
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
// The hovered (zoomed) card may spill over this zone: cut it out of every layer
// below so washes, indicators, dimming and the land divider never paint over it,
// whatever the stacking order is.
const std::optional<QPainterPath> hoverHole = hoveredCardHole();
const bool clipped = hoverHole.has_value();
if (clipped && hoverHole->isEmpty()) {
// The zoom covers this zone entirely: there is nothing left of it to paint.
return;
}
if (clipped) {
painter->setClipPath(*hoverHole);
}
if (playmatActive) {
// Subtle overlay to distinguish table zone from stack zone
painter->fillRect(boundingRect(), QColor(0, 0, 0, 60));
@ -142,6 +157,39 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
}
paintLandDivider(painter);
if (clipped) {
painter->setClipping(false);
}
}
/**
* @brief This zone's paint area minus the hovered card's painted outline, in zone coordinates.
*
* @c std::nullopt when no card is hovered or it does not overlap this zone; an *empty* path when
* the zoom covers this zone entirely, which means nothing of it is left to paint. Lets every
* paint layer dodge the zoomed card instead of painting over it.
*/
std::optional<QPainterPath> TableZone::hoveredCardHole() const
{
auto *scene = qobject_cast<GameScene *>(this->scene());
if (!scene) {
return std::nullopt;
}
CardItem *hovered = scene->getHoveredCard();
if (!hovered) {
return std::nullopt;
}
// Cut out the card's painted outline, not its bounding rectangle: the rectangle's corners
// are never covered by the artwork (rounded corners, antialiased edges), so they would stay
// black around the zoom.
const QPainterPath cardOutline = sceneTransform().inverted().map(hovered->sceneTransform().map(hovered->shape()));
if (!cardOutline.boundingRect().intersects(boundingRect())) {
return std::nullopt;
}
QPainterPath zoneArea;
zoneArea.addRect(boundingRect());
return zoneArea.subtracted(cardOutline);
}
void TableZone::onPlaymatChanged(bool active)

View file

@ -18,6 +18,7 @@
#include <QPointF>
#include <QtGlobal>
#include <libcockatrice/game/zones/table_zone_logic.h>
#include <optional>
#include <qtmetamacros.h>
class CardDragItem;
@ -26,6 +27,7 @@ class CardZoneLogic;
class QColor;
class QGraphicsItem;
class QPainter;
class QPainterPath;
template <typename T> class QList;
/**
@ -221,6 +223,13 @@ private:
void paintZoneOutline(QPainter *painter);
void paintLandDivider(QPainter *painter);
/**
* @brief This zone's paint area minus the hovered card's painted outline, in zone coordinates.
*
* @c std::nullopt when no card is hovered or it does not overlap this zone; an *empty* path when
* the hovered card covers this zone entirely, in which case nothing of the zone is visible.
*/
[[nodiscard]] std::optional<QPainterPath> hoveredCardHole() const;
/*
Calculates card stack widths so mapping functions work properly

View file

@ -94,8 +94,10 @@ ZoneViewWidget::ZoneViewWidget(PlayerLogic *_player,
searchEdit.setFocusPolicy(Qt::ClickFocus);
searchEdit.setPlaceholderText(tr("Search by card name (or search expressions)"));
searchEdit.setClearButtonEnabled(true);
searchEdit.addAction(loadThemedIcon(QStringLiteral("icons/search")), QLineEdit::LeadingPosition);
auto help = searchEdit.addAction(loadThemedIcon(QStringLiteral("icons/info")), QLineEdit::TrailingPosition);
searchEdit.addAction(loadThemedIcon(QStringLiteral("icons/search"), IconTint::quiet()),
QLineEdit::LeadingPosition);
auto help = searchEdit.addAction(loadThemedIcon(QStringLiteral("icons/info"), IconTint::quiet()),
QLineEdit::TrailingPosition);
connect(help, &QAction::triggered, this, [this] { createSearchSyntaxHelpWindow(&searchEdit); });