From 0aeb3e8926c222d1fe694ced669153d84a3933ac Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Feb 2022 17:21:43 +0200 Subject: [PATCH] Add hove color for a layout piece. --- src/app/puzzle/scene/vpgraphicspiece.cpp | 18 ++++++++++++++++-- src/app/puzzle/scene/vpgraphicspiece.h | 19 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 1e97fe524..59539b88d 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -191,6 +191,20 @@ void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsPiece::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_hoverMode = true; + QGraphicsObject::hoverEnterEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsPiece::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + m_hoverMode = false; + QGraphicsObject::hoverLeaveEvent(event); +} + //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { @@ -397,8 +411,8 @@ void VPGraphicsPiece::InitPieceLabel(const QVector &labelShape, const V //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::PaintPiece(QPainter *painter) { - QBrush noBrush(Qt::NoBrush); - QBrush selectionBrush(QColor(255,160,160,60)); + QBrush noBrush = m_hoverMode ? QBrush(QColor(199, 244, 249, 60)) : QBrush(Qt::NoBrush); + QBrush selectionBrush(QColor(255, 160, 160, 60)); m_seamLine = QPainterPath(); m_cuttingLine = QPainterPath(); diff --git a/src/app/puzzle/scene/vpgraphicspiece.h b/src/app/puzzle/scene/vpgraphicspiece.h index 3fdcd80d9..952bf11f8 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.h +++ b/src/app/puzzle/scene/vpgraphicspiece.h @@ -35,14 +35,18 @@ #include "scenedef.h" #include "../layout/layoutdef.h" +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) +#include "../vmisc/defglobal.h" +#endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0) + class VTextManager; class VPGraphicsPiece : public QGraphicsObject { - Q_OBJECT + Q_OBJECT // NOLINT public: explicit VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent = nullptr); - ~VPGraphicsPiece() = default; + ~VPGraphicsPiece() override = default; /** * @brief GetPiece Returns the piece that corresponds to the graphics piece @@ -50,7 +54,7 @@ public: */ auto GetPiece() -> VPPiecePtr; - virtual int type() const override {return Type;} + auto type() const -> int override {return Type;} enum { Type = UserType + static_cast(PGraphicsItem::Piece)}; void SetStickyPoints(const QVector &newStickyPoint); @@ -74,12 +78,15 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + auto itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; private: - Q_DISABLE_COPY(VPGraphicsPiece) + Q_DISABLE_COPY_MOVE(VPGraphicsPiece) // NOLINT VPPieceWeakPtr m_piece; QPainterPath m_cuttingLine{}; @@ -103,6 +110,8 @@ private: bool m_textAsPaths{false}; + bool m_hoverMode{false}; + QVector m_labelPathItems{}; QVector m_labelTextItems{}; @@ -112,7 +121,7 @@ private: void GroupMove(const QPointF &pos); - QColor PieceColor() const; + auto PieceColor() const -> QColor; }; #endif // VPGRAPHICSPIECE_H