diff --git a/cockatrice/src/game_graphics/board/abstract_card_item.cpp b/cockatrice/src/game_graphics/board/abstract_card_item.cpp index f2c0966e4..37d639653 100644 --- a/cockatrice/src/game_graphics/board/abstract_card_item.cpp +++ b/cockatrice/src/game_graphics/board/abstract_card_item.cpp @@ -57,7 +57,7 @@ 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), isHoverHighlighted(false), realZValue(0) + bgColor(Qt::transparent), isHovered(false), isHoverZoomed(false), realZValue(0) { setCursor(Qt::OpenHandCursor); setFlag(ItemIsSelectable); @@ -82,10 +82,10 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef // 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) { + if (!isHoverZoomed) { // 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); + setZValue(isHovered ? 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()) { @@ -170,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 && !isHoverHighlighted) { + if (!isHovered && !isHoverZoomed) { setZValue(_zValue); } } @@ -268,9 +268,9 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * painter->setRenderHint(QPainter::Antialiasing, false); - if (isSelected() || isHovered || isHoverHighlighted) { + if (isSelected() || isHovered || isHoverZoomed) { QPen pen; - if (isHovered || isHoverHighlighted) { + if (isHovered || isHoverZoomed) { pen.setColor(Qt::yellow); } if (isSelected()) { @@ -284,13 +284,13 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * painter->restore(); } -void AbstractCardItem::setHovered(bool _hovered) +void AbstractCardItem::setHoverZoomed(bool _hoverZoomed) { - if (isHovered == _hovered) { + if (isHoverZoomed == _hoverZoomed) { return; } - if (_hovered) { + if (_hoverZoomed) { processHoverEvent(); } else { // Mark the hovered card's current scene footprint dirty so overlapped @@ -304,11 +304,11 @@ void AbstractCardItem::setHovered(bool _hovered) } } - isHovered = _hovered; + isHoverZoomed = _hoverZoomed; // 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) { + if (_hoverZoomed) { setZValue(ZValues::HOVERED_CARD); } // Scale about the center in both directions: at scale 1 the origin is moot, @@ -320,7 +320,7 @@ void AbstractCardItem::setHovered(bool _hovered) // 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()) { + if (_hoverZoomed && SettingsCache::instance().cardsDisplay().getScaleCards()) { const qreal w = boundingRect().width(); qreal viewScale = 1.0; if (scene() && !scene()->views().isEmpty()) { @@ -335,24 +335,24 @@ void AbstractCardItem::setHovered(bool _hovered) hoverZoom->stop(); hoverZoom->setStartValue(scale()); hoverZoom->setEndValue(target); - hoverZoom->setDuration(_hovered ? HOVER_ZOOM_IN_MS : HOVER_ZOOM_OUT_MS); + hoverZoom->setDuration(_hoverZoomed ? HOVER_ZOOM_IN_MS : HOVER_ZOOM_OUT_MS); hoverZoom->start(); update(); } -void AbstractCardItem::setHoverHighlighted(bool highlighted) +void AbstractCardItem::setHovered(bool _hovered) { - if (isHoverHighlighted == highlighted) { + if (isHovered == _hovered) { return; } - if (highlighted) { + if (_hovered) { // The card-info widget listens for this: hovering still updates it right away. processHoverEvent(); } - isHoverHighlighted = highlighted; - if (highlighted) { + isHovered = _hovered; + if (_hovered) { setZValue(ZValues::HOVERED_CARD); } @@ -368,10 +368,10 @@ void AbstractCardItem::setHoverHighlighted(bool highlighted) 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->setEndValue(_hovered ? LEGACY_HOVER_SCALE : 1.0); + hoverZoom->setDuration(_hovered ? HOVER_ZOOM_IN_MS : HOVER_ZOOM_OUT_MS); hoverZoom->start(); - } else if (!highlighted && !isHovered && hoverZoom->state() != QAbstractAnimation::Running) { + } else if (!_hovered && !isHoverZoomed && 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); diff --git a/cockatrice/src/game_graphics/board/abstract_card_item.h b/cockatrice/src/game_graphics/board/abstract_card_item.h index 82058f08a..06b9a90c7 100644 --- a/cockatrice/src/game_graphics/board/abstract_card_item.h +++ b/cockatrice/src/game_graphics/board/abstract_card_item.h @@ -37,7 +37,7 @@ protected: private: bool isHovered; - bool isHoverHighlighted; + bool isHoverZoomed; qreal realZValue; bool pendingSelectionCollapse; int selectionCollapseGeneration = 0; ///< Guards the deferred collapse timer against stale firings @@ -134,7 +134,6 @@ public: return realZValue; } 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. @@ -144,7 +143,8 @@ public: * 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); + void setHovered(bool _hovered); + void setHoverZoomed(bool _hoverZoomed); qreal getCardScale() const; void setCardScale(qreal scale); qreal getCardOpacity() const; @@ -152,9 +152,9 @@ public: /** @brief Fades the card out under the hover panel, or back in when it closes. */ void fadeCardOut(); void fadeCardIn(); - bool getIsHovered() const + bool getIsHoverZoomed() const { - return isHovered; + return isHoverZoomed; } [[nodiscard]] QString getColor() const { diff --git a/cockatrice/src/game_graphics/board/card_item.cpp b/cockatrice/src/game_graphics/board/card_item.cpp index 9cc57f2b6..82ff6d9a9 100644 --- a/cockatrice/src/game_graphics/board/card_item.cpp +++ b/cockatrice/src/game_graphics/board/card_item.cpp @@ -533,7 +533,7 @@ bool CardItem::animationEvent() .translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F) .rotate(tapAngle) .translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F)); - setHovered(false); + setHoverZoomed(false); update(); return animationIncomplete; diff --git a/cockatrice/src/game_graphics/game_scene.cpp b/cockatrice/src/game_graphics/game_scene.cpp index b4c6e1690..1388844fb 100644 --- a/cockatrice/src/game_graphics/game_scene.cpp +++ b/cockatrice/src/game_graphics/game_scene.cpp @@ -773,7 +773,7 @@ void GameScene::onCardViewRefreshRequested(CardState *card, bool zoneChanged, Pl item->deleteDragItem(); if (zoneChanged) { item->setBeingPointedAt(false); - item->setHovered(false); + item->setHoverZoomed(false); } if (newOwner) { item->setOwner(newOwner); @@ -797,9 +797,9 @@ void GameScene::clearArrowsForPlayerLocally(int playerId) } // ---------- Hover Handling ---------- -CardItem *GameScene::getHoveredCard() const +CardItem *GameScene::getHoverZoomedCard() const { - return hoveredCard; + return hoverZoomedCard; } void GameScene::updateHover(const QPointF &scenePos) @@ -812,14 +812,14 @@ 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; - if (!topCard && hoveredCard) { - const QRectF guard = hoveredCard->sceneBoundingRect().adjusted(-8, -8, 8, 8); + if (!topCard && hoverZoomedCard) { + const QRectF guard = hoverZoomedCard->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 hoverZoomedCard; } } return topCard; @@ -833,27 +833,27 @@ void GameScene::updateHoveredCard(CardItem *newCard) } // 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()) { + if (!hoverZoomedCard && !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; + bool wasHoveringCard = (hoverZoomedCard != nullptr); + if (hoverZoomedCard && (newCard != hoverZoomedCard)) { + endHoverZoom(hoverZoomedCard); + hoverZoomedCard = nullptr; } // 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); + if (hoveredCard && hoveredCard != newCard) { + hoveredCard->setHovered(false); } - hoverHighlightCard = newCard; + hoveredCard = newCard; if (newCard) { - newCard->setHoverHighlighted(true); + newCard->setHovered(true); } auto &display = SettingsCache::instance().cardsDisplay(); @@ -866,7 +866,7 @@ void GameScene::updateHoveredCard(CardItem *newCard) hoverGracePending = false; hoverGraceTimer->stop(); - if (newCard == hoveredCard) { + if (newCard == hoverZoomedCard) { // 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) { @@ -877,8 +877,8 @@ void GameScene::updateHoveredCard(CardItem *newCard) 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; + beginHoverZoom(newCard); + hoverZoomedCard = newCard; cardHoverWidget->refreshDisplay(); return; } @@ -896,8 +896,8 @@ void GameScene::updateHoveredCard(CardItem *newCard) } if (doubleConfirm && confirmArmedCard == newCard) { // Repeat hover on an armed card: zoom and show at once, no second dwell. - beginCardHover(newCard); - hoveredCard = newCard; + beginHoverZoom(newCard); + hoverZoomedCard = newCard; confirmArmedCard.clear(); showCardHoverPopup(newCard); return; @@ -928,9 +928,9 @@ void GameScene::updateHoveredCard(CardItem *newCard) } } -void GameScene::beginCardHover(CardItem *card) +void GameScene::beginHoverZoom(CardItem *card) { - card->setHovered(true); + card->setHoverZoomed(true); if (auto *zone = SelectZone::findOwningSelectZone(card)) { zone->escapeClipForHover(card); } @@ -953,21 +953,21 @@ void GameScene::beginCardHover(CardItem *card) ancestor = ancestor->parentItem(); } liftOwner = card; - connect(card, &AbstractCardItem::hoverShrinkFinished, this, &GameScene::onHoverShrinkFinished, + connect(card, &AbstractCardItem::hoverShrinkFinished, this, &GameScene::onHoverZoomShrinkFinished, Qt::UniqueConnection); - connect(card, &AbstractCardItem::hoverFootprintChanged, this, &GameScene::onHoverFootprintChanged, + connect(card, &AbstractCardItem::hoverFootprintChanged, this, &GameScene::onHoverZoomFootprintChanged, Qt::UniqueConnection); } -void GameScene::endCardHover(CardItem *card) +void GameScene::endHoverZoom(CardItem *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); + card->setHoverZoomed(false); } -void GameScene::onHoverShrinkFinished(AbstractCardItem *card) +void GameScene::onHoverZoomShrinkFinished(AbstractCardItem *card) { auto *cardItem = qobject_cast(card); if (!cardItem) { @@ -984,7 +984,7 @@ void GameScene::onHoverShrinkFinished(AbstractCardItem *card) restoreHoverLift(); } -void GameScene::onHoverFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint) +void GameScene::onHoverZoomFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint) { const QRectF dirty = oldFootprint.united(newFootprint); if (dirty.isEmpty()) { @@ -1126,13 +1126,13 @@ void GameScene::onHoverActivateTimeout() const bool panelPhase = display.getHoverPanelTrigger() == CardsDisplaySettings::HoverPanelTriggerHover; const bool effectiveDouble = display.getHoverPanelDoubleConfirm() && display.getHoverZoomTrigger() == display.getHoverPanelTrigger(); - if (hoveredCard && hoveredCard != target) { - endCardHover(hoveredCard); + if (hoverZoomedCard && hoverZoomedCard != target) { + endHoverZoom(hoverZoomedCard); } if (zoomPhase) { - if (hoveredCard != target) { - beginCardHover(target); - hoveredCard = target; + if (hoverZoomedCard != target) { + beginHoverZoom(target); + hoverZoomedCard = target; } if (effectiveDouble) { confirmArmedCard = target; @@ -1158,7 +1158,7 @@ void GameScene::onHoverPanelTimeout() if (!target->sceneBoundingRect().contains(cursorScene)) { return; } - ensureZoomed(target); + ensureHoverZoomed(target); showCardHoverPopup(target); } @@ -1186,14 +1186,14 @@ void GameScene::summonHoverPanel() } } -void GameScene::ensureZoomed(CardItem *card) +void GameScene::ensureHoverZoomed(CardItem *card) { - if (hoveredCard != card) { - if (hoveredCard) { - endCardHover(hoveredCard); + if (hoverZoomedCard != card) { + if (hoverZoomedCard) { + endHoverZoom(hoverZoomedCard); } - beginCardHover(card); - hoveredCard = card; + beginHoverZoom(card); + hoverZoomedCard = card; } } @@ -1225,23 +1225,23 @@ void GameScene::fireTriggers(CardItem *card, bool zoomFired, bool panelFired) if (effectiveDouble) { if (confirmArmedCard == card) { confirmArmedCard.clear(); - ensureZoomed(card); + ensureHoverZoomed(card); showCardHoverPopup(card); } else { confirmArmedCard = card; - ensureZoomed(card); + ensureHoverZoomed(card); } } else { - ensureZoomed(card); + ensureHoverZoomed(card); showCardHoverPopup(card); } return; } if (zoomFired) { - ensureZoomed(card); + ensureHoverZoomed(card); } if (panelFired) { - ensureZoomed(card); + ensureHoverZoomed(card); showCardHoverPopup(card); } } @@ -1254,7 +1254,7 @@ void GameScene::onHoverWidgetEntered() void GameScene::onHoverWidgetLeft() { - if (!hoveredCard && cardHoverWidget && cardHoverWidget->isVisible() && !hoverGracePending) { + if (!hoverZoomedCard && cardHoverWidget && cardHoverWidget->isVisible() && !hoverGracePending) { hoverGracePending = true; hoverGraceTimer->start(); } @@ -1440,14 +1440,14 @@ bool GameScene::event(QEvent *event) ? wheelEvent->pixelDelta().y() : (wheelEvent->orientation() == Qt::Vertical ? wheelEvent->delta() : 0); if (wheelUp > 0) { - if ((cardHoverWidget && cardHoverWidget->isVisible()) || hoveredCard) { + if ((cardHoverWidget && cardHoverWidget->isVisible()) || hoverZoomedCard) { hoverPopupTarget = nullptr; hoverPanelTarget = nullptr; confirmArmedCard.clear(); hideCardHoverPopup(); - if (hoveredCard) { - endCardHover(hoveredCard); - hoveredCard = nullptr; + if (hoverZoomedCard) { + endHoverZoom(hoverZoomedCard); + hoverZoomedCard = nullptr; } event->accept(); return true; diff --git a/cockatrice/src/game_graphics/game_scene.h b/cockatrice/src/game_graphics/game_scene.h index 9c8c422a3..d74aefdd5 100644 --- a/cockatrice/src/game_graphics/game_scene.h +++ b/cockatrice/src/game_graphics/game_scene.h @@ -78,11 +78,9 @@ private: ArrowRegistry arrowRegistry; ///< ID registry for arrow graphics items QList zoneViews; ///< Active zone view widgets QSize viewSize; ///< Current view size - QPointer 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 hoverHighlightCard; - QPointer activeCard; ///< Card the currently open context menu targets + QPointer hoveredCard; ///< Card the cursor is resting on + QPointer hoverZoomedCard; ///< Card that is currently being hover zoomed + QPointer activeCard; ///< Card the currently open context menu targets /// Card armed for double-confirm panel summon (first trigger zooms, repeat shows). QPointer confirmArmedCard; /// Ancestor chain of the hovered card with pre-hover Z-values. Lifted while hovering @@ -120,16 +118,16 @@ private: void updateHover(const QPointF &scenePos); /** - * @brief Activates hover state and escapes the card from its clip container + * @brief Activates hover zoom state and escapes the card from its clip container * so hover scaling is visible beyond zone bounds. */ - void beginCardHover(CardItem *card); - /** @brief Deactivates hover state and restores the card to its clip container. */ - void endCardHover(CardItem *card); + void beginHoverZoom(CardItem *card); + /** @brief Deactivates hover zoom state and restores the card to its clip container. */ + void endHoverZoom(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); + void onHoverZoomShrinkFinished(AbstractCardItem *card); /** * @brief Repaints the zones that dodge the zoomed card when its footprint moves. * @@ -137,7 +135,7 @@ private: * 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); + void onHoverZoomFootprintChanged(const QRectF &oldFootprint, const QRectF &newFootprint); // Card hover popup methods void showCardHoverPopup(CardItem *card); @@ -284,10 +282,10 @@ public: void fireTriggers(CardItem *card, bool zoomFired, bool panelFired); /** @brief Starts the hover zoom for a card without touching panel state. */ - void ensureZoomed(CardItem *card); + void ensureHoverZoomed(CardItem *card); - /** @brief The currently hovered card, if any (used by zones to dodge it while painting). */ - CardItem *getHoveredCard() const; + /** @brief The currently hover zoomed card, if any (used by zones to dodge it while painting). */ + CardItem *getHoverZoomedCard() const; /** * @brief Registers an item for animation updates with the shared scene timer. diff --git a/cockatrice/src/game_graphics/zones/select_zone.cpp b/cockatrice/src/game_graphics/zones/select_zone.cpp index ccac9decc..b8ebb1375 100644 --- a/cockatrice/src/game_graphics/zones/select_zone.cpp +++ b/cockatrice/src/game_graphics/zones/select_zone.cpp @@ -119,7 +119,7 @@ void SelectZone::restoreStaleEscapedCards() // A card parented to the zone (instead of the clip container) should // only occur while it is actively hovered. If hover cleanup was // missed, reparent it back so clipping resumes. - if (card && card->parentItem() == this && !card->getIsHovered()) { + if (card && card->parentItem() == this && !card->getIsHoverZoomed()) { card->setParentItem(cardClipContainer); } } diff --git a/cockatrice/src/game_graphics/zones/table_zone.cpp b/cockatrice/src/game_graphics/zones/table_zone.cpp index dd2b3e38e..60740d1ff 100644 --- a/cockatrice/src/game_graphics/zones/table_zone.cpp +++ b/cockatrice/src/game_graphics/zones/table_zone.cpp @@ -176,7 +176,7 @@ std::optional TableZone::hoveredCardHole() const if (!scene) { return std::nullopt; } - CardItem *hovered = scene->getHoveredCard(); + CardItem *hovered = scene->getHoverZoomedCard(); if (!hovered) { return std::nullopt; } diff --git a/cockatrice/src/interface/widgets/cards/card_hover_widget.cpp b/cockatrice/src/interface/widgets/cards/card_hover_widget.cpp index 27625db52..fca99b8e3 100644 --- a/cockatrice/src/interface/widgets/cards/card_hover_widget.cpp +++ b/cockatrice/src/interface/widgets/cards/card_hover_widget.cpp @@ -460,7 +460,7 @@ void CardHoverWidget::createPTOverlay() ptPillLabel->clear(); ptOverlay->resize(ptCompactSize); - // The whole subtree feeds the hover state: moving onto a button must not read as a leave. + // The whole subtree feeds the hover zoom state: moving onto a button must not read as a leave. ptOverlay->installEventFilter(this); const QList ptChildren = ptOverlay->findChildren(); for (QWidget *child : ptChildren) {