Revert "Use native hover events (#5722)"

This reverts commit e4f40a82a2.

This change had unintended consequences in the hover behavior, reverting
for now.
This commit is contained in:
Basile Clément 2025-03-20 18:35:36 +01:00
parent 48123c8822
commit 46c93c4af8
No known key found for this signature in database
9 changed files with 77 additions and 27 deletions

View file

@ -253,6 +253,51 @@ 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);