Use native hover events (#5722)

* Use native hover events

* Update cockatrice/src/game/cards/abstract_card_item.cpp

* Reorder

---------

Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
Basile Clement 2025-03-15 20:07:51 +01:00 committed by GitHub
parent b9900e67a6
commit e4f40a82a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 27 additions and 77 deletions

View file

@ -253,51 +253,6 @@ void GameScene::processViewSizeChange(const QSize &newSize)
}
}
void GameScene::updateHover(const QPointF &scenePos)
{
QList<QGraphicsItem *> itemList =
items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
// Search for the topmost zone and ignore all cards not belonging to that zone.
CardZone *zone = 0;
for (int i = 0; i < itemList.size(); ++i)
if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
break;
CardItem *maxZCard = 0;
if (zone) {
qreal maxZ = -1;
for (int i = 0; i < itemList.size(); ++i) {
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
if (!card)
continue;
if (card->getAttachedTo()) {
if (card->getAttachedTo()->getZone() != zone)
continue;
} else if (card->getZone() != zone)
continue;
if (card->getRealZValue() > maxZ) {
maxZ = card->getRealZValue();
maxZCard = card;
}
}
}
if (hoveredCard && (maxZCard != hoveredCard))
hoveredCard->setHovered(false);
if (maxZCard && (maxZCard != hoveredCard))
maxZCard->setHovered(true);
hoveredCard = maxZCard;
}
bool GameScene::event(QEvent *event)
{
if (event->type() == QEvent::GraphicsSceneMouseMove)
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
return QGraphicsScene::event(event);
}
void GameScene::timerEvent(QTimerEvent * /*event*/)
{
QMutableSetIterator<CardItem *> i(cardsToAnimate);