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,