From dd37676f2aedc80cb82c606674712d8314599b55 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Tue, 27 Aug 2024 17:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=89=E4=B8=AD=E6=A1=86?= =?UTF-8?q?=E5=92=8C=E5=8F=98=E6=8D=A2=E4=B8=AD=E5=BF=83=E7=82=B9=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/graphicsItem/graphicsBaseItem.h | 3 +++ source/graphicsItem/graphicsPolygonItem.cpp | 13 +++++++++++++ source/graphicsItem/graphicsRectItem.cpp | 15 ++++++++++++--- source/graphicsItem/itemControlHandle.cpp | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/graphicsItem/graphicsBaseItem.h b/include/graphicsItem/graphicsBaseItem.h index b6d10e6..9604b73 100644 --- a/include/graphicsItem/graphicsBaseItem.h +++ b/include/graphicsItem/graphicsBaseItem.h @@ -235,6 +235,8 @@ public: break; } } + + m_boundingRect_selected = boundRect.adjusted(-nMargin, -nMargin, nMargin, nMargin); } virtual QRectF boundingRect() const { return m_boundingRect; } @@ -250,6 +252,7 @@ protected: double m_dWidth; double m_dHeight; QRectF m_boundingRect; + QRectF m_boundingRect_selected;//选中矩形框 QGraphicsPathItem* m_pOperationCopy; //图元移动和旋转时的操作副本 QPointF m_movingIniPos; //移动副本开始移动初始点 diff --git a/source/graphicsItem/graphicsPolygonItem.cpp b/source/graphicsItem/graphicsPolygonItem.cpp index ef41539..b95b5cf 100644 --- a/source/graphicsItem/graphicsPolygonItem.cpp +++ b/source/graphicsItem/graphicsPolygonItem.cpp @@ -2,6 +2,7 @@ #include "graphicsItem/itemControlHandle.h" #include +#include GraphicPolygonItem::GraphicPolygonItem(QGraphicsItem *parent) : GraphicsBaseItem(parent) @@ -65,6 +66,18 @@ void GraphicPolygonItem::paint(QPainter* painter, const QStyleOptionGraphicsItem painter->setPen(m_pen); painter->setBrush(m_brush); painter->drawPolygon(m_points); + //绘制变换原点 + QPointF originPoint = transformOriginPoint(); + painter->setBrush(Qt::red); + painter->drawEllipse(originPoint, 4, 4); + + if (option->state & QStyle::State_Selected) //是选中状态,绘制选中框 + { + int nPenWidth = 1; + painter->setPen(QPen(QColor(70,70,70), nPenWidth, Qt::DashLine)); //蓝色的外框 + painter->setBrush(Qt::NoBrush); + painter->drawRect(m_boundingRect_selected); + } } void GraphicPolygonItem::resize(int nHandle,double dSX, double dSY, const QPointF& basePoint) diff --git a/source/graphicsItem/graphicsRectItem.cpp b/source/graphicsItem/graphicsRectItem.cpp index 42b09e6..43f439e 100644 --- a/source/graphicsItem/graphicsRectItem.cpp +++ b/source/graphicsItem/graphicsRectItem.cpp @@ -2,6 +2,7 @@ #include "graphicsItem/itemControlHandle.h" #include +#include GraphicsRectItem::GraphicsRectItem(const QRect &rect, bool isRound, QGraphicsItem *parent) : GraphicsBaseItem(parent), m_bIsRound(isRound), m_dRatioX(1 / 10.0), m_dRatioY(1 / 10.0) @@ -104,9 +105,17 @@ void GraphicsRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* painter->drawRect(m_boundingRect); //绘制变换原点 - // QPointF originPoint = transformOriginPoint(); - // painter->setPen(Qt::red); - // painter->drawEllipse(originPoint, 5, 5); + QPointF originPoint = transformOriginPoint(); + painter->setBrush(Qt::red); + painter->drawEllipse(originPoint, 4, 4); + + if (option->state & QStyle::State_Selected) //是选中状态,绘制选中框 + { + int nPenWidth = 1; + painter->setPen(QPen(QColor(70,70,70), nPenWidth, Qt::DashLine)); //蓝色的外框 + painter->setBrush(Qt::NoBrush); + painter->drawRect(m_boundingRect_selected); + } } void GraphicsRectItem::resize(int nHandle,double dSX, double dSY, const QPointF& basePoint) diff --git a/source/graphicsItem/itemControlHandle.cpp b/source/graphicsItem/itemControlHandle.cpp index 5313d2b..f67cf5f 100644 --- a/source/graphicsItem/itemControlHandle.cpp +++ b/source/graphicsItem/itemControlHandle.cpp @@ -1,7 +1,7 @@ #include "graphicsItem/itemControlHandle.h" #include -#define HNDLE_SIZE 6 +#define HNDLE_SIZE 8 ItemControlHandle::ItemControlHandle(QGraphicsItem *parent) : QGraphicsRectItem(-HNDLE_SIZE / 2,