minor hover bug fix
This commit is contained in:
parent
c4cb0f6354
commit
c8779032c8
5 changed files with 15 additions and 13 deletions
|
@ -13,7 +13,7 @@
|
|||
#include <QTimer>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent)
|
||||
: ArrowTarget(_owner, parent), info(db->getCard(_name)), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false)
|
||||
: ArrowTarget(_owner, parent), info(db->getCard(_name)), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false), realZValue(0)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
|
@ -42,6 +42,12 @@ void AbstractCardItem::pixmapUpdated()
|
|||
update();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setRealZValue(qreal _zValue)
|
||||
{
|
||||
realZValue = _zValue;
|
||||
setZValue(_zValue);
|
||||
}
|
||||
|
||||
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
|
||||
{
|
||||
return QSizeF(
|
||||
|
@ -149,6 +155,7 @@ void AbstractCardItem::animationEvent()
|
|||
tapAngle += delta;
|
||||
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
|
||||
|
@ -167,6 +174,7 @@ void AbstractCardItem::setName(const QString &_name)
|
|||
void AbstractCardItem::setHovered(bool _hovered)
|
||||
{
|
||||
isHovered = _hovered;
|
||||
setZValue(_hovered ? 2000000004 : realZValue);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ protected:
|
|||
private:
|
||||
QTimer *animationTimer;
|
||||
bool isHovered;
|
||||
qreal realZValue;
|
||||
private slots:
|
||||
void animationEvent();
|
||||
void pixmapUpdated();
|
||||
|
@ -41,6 +42,8 @@ public:
|
|||
CardInfo *getInfo() const { return info; }
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name = QString());
|
||||
qreal getRealZValue() const { return realZValue; }
|
||||
void setRealZValue(qreal _zValue);
|
||||
void setHovered(bool _hovered);
|
||||
QString getColor() const { return color; }
|
||||
void setColor(const QString &_color);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "tab_game.h"
|
||||
|
||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, _owner, parent), id(_cardid), realZValue(0), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
: AbstractCardItem(_name, _owner, parent), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
{
|
||||
owner->addCard(this);
|
||||
|
||||
|
@ -154,12 +154,6 @@ void CardItem::retranslateUi()
|
|||
}
|
||||
}
|
||||
|
||||
void CardItem::setRealZValue(qreal _zValue)
|
||||
{
|
||||
realZValue = _zValue;
|
||||
setZValue(_zValue);
|
||||
}
|
||||
|
||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->save();
|
||||
|
|
|
@ -17,7 +17,6 @@ class CardItem : public AbstractCardItem {
|
|||
private:
|
||||
CardZone *zone;
|
||||
int id;
|
||||
qreal realZValue;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
QMap<int, int> counters;
|
||||
|
@ -48,8 +47,6 @@ public:
|
|||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
QPoint getGridPoint() const { return gridPoint; }
|
||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||
qreal getRealZValue() const { return realZValue; }
|
||||
void setRealZValue(qreal _zValue);
|
||||
QPoint getGridPos() const { return gridPoint; }
|
||||
Player *getOwner() const { return owner; }
|
||||
int getId() const { return id; }
|
||||
|
|
|
@ -149,7 +149,7 @@ bool GameScene::event(QEvent *event)
|
|||
for (int i = 0; i < oldItemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(oldItemList[i]);
|
||||
if (card)
|
||||
card->setZValue(card->getRealZValue());
|
||||
card->setHovered(false);
|
||||
}
|
||||
|
||||
QList<QGraphicsItem *> itemList = items(mouseEvent->scenePos());
|
||||
|
@ -176,7 +176,7 @@ bool GameScene::event(QEvent *event)
|
|||
}
|
||||
}
|
||||
for (int i = 0; i < cardList.size(); ++i)
|
||||
cardList[i]->setZValue(cardList[i] == maxZCard ? 2000000004 : cardList[i]->getRealZValue());
|
||||
cardList[i]->setHovered(cardList[i] == maxZCard);
|
||||
}
|
||||
}
|
||||
return QGraphicsScene::event(event);
|
||||
|
|
Loading…
Reference in a new issue