Add hove color for a layout piece.

This commit is contained in:
Roman Telezhynskyi 2022-02-18 17:21:43 +02:00
parent 4508bd859f
commit 0aeb3e8926
2 changed files with 30 additions and 7 deletions

View file

@ -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<QPointF> &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();

View file

@ -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<int>(PGraphicsItem::Piece)};
void SetStickyPoints(const QVector<QPointF> &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<QGraphicsPathItem *> m_labelPathItems{};
QVector<QGraphicsSimpleTextItem *> m_labelTextItems{};
@ -112,7 +121,7 @@ private:
void GroupMove(const QPointF &pos);
QColor PieceColor() const;
auto PieceColor() const -> QColor;
};
#endif // VPGRAPHICSPIECE_H