minor hover bug fix

This commit is contained in:
Max-Wilhelm Bruker 2010-11-10 02:04:40 +01:00
parent c4cb0f6354
commit c8779032c8
5 changed files with 15 additions and 13 deletions

View file

@ -13,7 +13,7 @@
#include <QTimer> #include <QTimer>
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent) 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); setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable); setFlag(ItemIsSelectable);
@ -42,6 +42,12 @@ void AbstractCardItem::pixmapUpdated()
update(); update();
} }
void AbstractCardItem::setRealZValue(qreal _zValue)
{
realZValue = _zValue;
setZValue(_zValue);
}
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
{ {
return QSizeF( return QSizeF(
@ -149,6 +155,7 @@ void AbstractCardItem::animationEvent()
tapAngle += delta; tapAngle += delta;
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); 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(); update();
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0))) if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
@ -167,6 +174,7 @@ void AbstractCardItem::setName(const QString &_name)
void AbstractCardItem::setHovered(bool _hovered) void AbstractCardItem::setHovered(bool _hovered)
{ {
isHovered = _hovered; isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue);
update(); update();
} }

View file

@ -23,6 +23,7 @@ protected:
private: private:
QTimer *animationTimer; QTimer *animationTimer;
bool isHovered; bool isHovered;
qreal realZValue;
private slots: private slots:
void animationEvent(); void animationEvent();
void pixmapUpdated(); void pixmapUpdated();
@ -41,6 +42,8 @@ public:
CardInfo *getInfo() const { return info; } CardInfo *getInfo() const { return info; }
QString getName() const { return name; } QString getName() const { return name; }
void setName(const QString &_name = QString()); void setName(const QString &_name = QString());
qreal getRealZValue() const { return realZValue; }
void setRealZValue(qreal _zValue);
void setHovered(bool _hovered); void setHovered(bool _hovered);
QString getColor() const { return color; } QString getColor() const { return color; }
void setColor(const QString &_color); void setColor(const QString &_color);

View file

@ -17,7 +17,7 @@
#include "tab_game.h" #include "tab_game.h"
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent) 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); 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) void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
painter->save(); painter->save();

View file

@ -17,7 +17,6 @@ class CardItem : public AbstractCardItem {
private: private:
CardZone *zone; CardZone *zone;
int id; int id;
qreal realZValue;
bool attacking; bool attacking;
bool facedown; bool facedown;
QMap<int, int> counters; QMap<int, int> counters;
@ -48,8 +47,6 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPoint getGridPoint() const { return gridPoint; } QPoint getGridPoint() const { return gridPoint; }
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; } void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
qreal getRealZValue() const { return realZValue; }
void setRealZValue(qreal _zValue);
QPoint getGridPos() const { return gridPoint; } QPoint getGridPos() const { return gridPoint; }
Player *getOwner() const { return owner; } Player *getOwner() const { return owner; }
int getId() const { return id; } int getId() const { return id; }

View file

@ -149,7 +149,7 @@ bool GameScene::event(QEvent *event)
for (int i = 0; i < oldItemList.size(); ++i) { for (int i = 0; i < oldItemList.size(); ++i) {
CardItem *card = qgraphicsitem_cast<CardItem *>(oldItemList[i]); CardItem *card = qgraphicsitem_cast<CardItem *>(oldItemList[i]);
if (card) if (card)
card->setZValue(card->getRealZValue()); card->setHovered(false);
} }
QList<QGraphicsItem *> itemList = items(mouseEvent->scenePos()); QList<QGraphicsItem *> itemList = items(mouseEvent->scenePos());
@ -176,7 +176,7 @@ bool GameScene::event(QEvent *event)
} }
} }
for (int i = 0; i < cardList.size(); ++i) 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); return QGraphicsScene::event(event);