[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 {