Commit 179f1fe1 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

added yellow border to cards being moused over

parent 55e7feee
...@@ -13,7 +13,7 @@ ...@@ -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) : ArrowTarget(_owner, parent), info(db->getCard(_name)), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false)
{ {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable); setFlag(ItemIsSelectable);
...@@ -132,6 +132,9 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * ...@@ -132,6 +132,9 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
if (isSelected()) { if (isSelected()) {
painter->setPen(Qt::red); painter->setPen(Qt::red);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1)); painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
} else if (isHovered) {
painter->setPen(Qt::yellow);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
} }
painter->restore(); painter->restore();
...@@ -209,9 +212,16 @@ void AbstractCardItem::processHoverEvent() ...@@ -209,9 +212,16 @@ void AbstractCardItem::processHoverEvent()
void AbstractCardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void AbstractCardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
processHoverEvent(); processHoverEvent();
isHovered = true;
QGraphicsItem::hoverEnterEvent(event); QGraphicsItem::hoverEnterEvent(event);
} }
void AbstractCardItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
isHovered = false;
QGraphicsItem::hoverLeaveEvent(event);
}
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == ItemSelectedHasChanged) { if (change == ItemSelectedHasChanged) {
......
...@@ -22,6 +22,7 @@ protected: ...@@ -22,6 +22,7 @@ protected:
QString color; QString color;
private: private:
QTimer *animationTimer; QTimer *animationTimer;
bool isHovered;
private slots: private slots:
void animationEvent(); void animationEvent();
void pixmapUpdated(); void pixmapUpdated();
...@@ -51,6 +52,7 @@ protected: ...@@ -51,6 +52,7 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment