mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
This reverts commit e4f40a82a2.
This change had unintended consequences in the hover behavior, reverting
for now.
This commit is contained in:
parent
d03f5388d4
commit
be28d50997
9 changed files with 77 additions and 27 deletions
|
|
@ -10,7 +10,6 @@
|
|||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <algorithm>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(QGraphicsItem *parent,
|
||||
|
|
@ -19,7 +18,7 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent,
|
|||
Player *_owner,
|
||||
int _id)
|
||||
: ArrowTarget(_owner, parent), id(_id), name(_name), providerId(_providerId), tapped(false), facedown(false),
|
||||
tapAngle(0), bgColor(Qt::transparent), realZValue(0)
|
||||
tapAngle(0), bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
|
|
@ -27,8 +26,6 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent,
|
|||
|
||||
connect(&SettingsCache::instance(), &SettingsCache::displayCardNamesChanged, this, [this] { update(); });
|
||||
refreshCardInfo();
|
||||
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
AbstractCardItem::~AbstractCardItem()
|
||||
|
|
@ -160,7 +157,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /*widget*/)
|
||||
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
|
|
@ -169,7 +166,6 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
bool isHovered = option->state.testFlag(QStyle::State_MouseOver);
|
||||
if (isSelected() || isHovered) {
|
||||
QPen pen;
|
||||
if (isHovered)
|
||||
|
|
@ -212,24 +208,17 @@ void AbstractCardItem::setProviderId(const QString &_providerId)
|
|||
refreshCardInfo();
|
||||
}
|
||||
|
||||
void AbstractCardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
void AbstractCardItem::setHovered(bool _hovered)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
if (isHovered == _hovered)
|
||||
return;
|
||||
|
||||
emit hovered(this);
|
||||
setZValue(2000000004);
|
||||
setScale(SettingsCache::instance().getScaleCards() ? 1.1 : 1);
|
||||
setTransformOriginPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2);
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractCardItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
setZValue(realZValue);
|
||||
setScale(1);
|
||||
setTransformOriginPoint(0, 0);
|
||||
if (_hovered)
|
||||
processHoverEvent();
|
||||
isHovered = _hovered;
|
||||
setZValue(_hovered ? 2000000004 : realZValue);
|
||||
setScale(_hovered && SettingsCache::instance().getScaleCards() ? 1.1 : 1);
|
||||
setTransformOriginPoint(_hovered ? CARD_WIDTH / 2 : 0, _hovered ? CARD_HEIGHT / 2 : 0);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -325,6 +314,11 @@ void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
void AbstractCardItem::processHoverEvent()
|
||||
{
|
||||
emit hovered(this);
|
||||
}
|
||||
|
||||
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ protected:
|
|||
QColor bgColor;
|
||||
|
||||
private:
|
||||
bool isHovered;
|
||||
qreal realZValue;
|
||||
private slots:
|
||||
void pixmapUpdated();
|
||||
|
|
@ -85,6 +86,7 @@ public:
|
|||
return realZValue;
|
||||
}
|
||||
void setRealZValue(qreal _zValue);
|
||||
void setHovered(bool _hovered);
|
||||
QString getColor() const
|
||||
{
|
||||
return color;
|
||||
|
|
@ -100,6 +102,7 @@ public:
|
|||
return facedown;
|
||||
}
|
||||
void setFaceDown(bool _facedown);
|
||||
void processHoverEvent();
|
||||
void deleteCardInfoPopup()
|
||||
{
|
||||
emit deleteCardInfoPopup(name);
|
||||
|
|
@ -111,9 +114,6 @@ protected:
|
|||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||
void cacheBgColor();
|
||||
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -469,6 +469,7 @@ bool CardItem::animationEvent()
|
|||
.translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF)
|
||||
.rotate(tapAngle)
|
||||
.translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
return animationIncomplete;
|
||||
|
|
|
|||
|
|
@ -158,6 +158,12 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void DeckViewCard::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
processHoverEvent();
|
||||
}
|
||||
|
||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name) : QGraphicsItem(), name(_name), width(0), height(0)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
};
|
||||
|
||||
class DeckViewCardDragItem : public AbstractCardDragItem
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ private:
|
|||
QList<QList<Player *>> playersByColumn;
|
||||
QList<ZoneViewWidget *> zoneViews;
|
||||
QSize viewSize;
|
||||
QPointer<CardItem> hoveredCard;
|
||||
QBasicTimer *animationTimer;
|
||||
QSet<CardItem *> cardsToAnimate;
|
||||
int playerRotation;
|
||||
void updateHover(const QPointF &scenePos);
|
||||
|
||||
public:
|
||||
explicit GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = nullptr);
|
||||
|
|
@ -63,6 +65,7 @@ public slots:
|
|||
void rearrange();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
signals:
|
||||
void sigStartRubberBand(const QPointF &selectionOrigin);
|
||||
|
|
|
|||
|
|
@ -2386,6 +2386,7 @@ void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &
|
|||
card->setFaceDown(event.face_down());
|
||||
if (startZone != targetZone) {
|
||||
card->setBeingPointedAt(false);
|
||||
card->setHovered(false);
|
||||
|
||||
const QList<CardItem *> &attachedCards = card->getAttachedCards();
|
||||
for (auto attachedCard : attachedCards) {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|||
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!cards.isEmpty())
|
||||
emit cards[0]->hovered(cards[0]);
|
||||
|
||||
cards[0]->processHoverEvent();
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue