[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

@ -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);
}