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