添加选中框和变换中心点的实时绘制

This commit is contained in:
duanshengchao 2024-08-27 17:19:44 +08:00
parent f59af2bf9d
commit dd37676f2a
4 changed files with 29 additions and 4 deletions

View File

@ -235,6 +235,8 @@ public:
break; break;
} }
} }
m_boundingRect_selected = boundRect.adjusted(-nMargin, -nMargin, nMargin, nMargin);
} }
virtual QRectF boundingRect() const { return m_boundingRect; } virtual QRectF boundingRect() const { return m_boundingRect; }
@ -250,6 +252,7 @@ protected:
double m_dWidth; double m_dWidth;
double m_dHeight; double m_dHeight;
QRectF m_boundingRect; QRectF m_boundingRect;
QRectF m_boundingRect_selected;//选中矩形框
QGraphicsPathItem* m_pOperationCopy; //图元移动和旋转时的操作副本 QGraphicsPathItem* m_pOperationCopy; //图元移动和旋转时的操作副本
QPointF m_movingIniPos; //移动副本开始移动初始点 QPointF m_movingIniPos; //移动副本开始移动初始点

View File

@ -2,6 +2,7 @@
#include "graphicsItem/itemControlHandle.h" #include "graphicsItem/itemControlHandle.h"
#include <QPainter> #include <QPainter>
#include <QStyleOption>
GraphicPolygonItem::GraphicPolygonItem(QGraphicsItem *parent) GraphicPolygonItem::GraphicPolygonItem(QGraphicsItem *parent)
: GraphicsBaseItem(parent) : GraphicsBaseItem(parent)
@ -65,6 +66,18 @@ void GraphicPolygonItem::paint(QPainter* painter, const QStyleOptionGraphicsItem
painter->setPen(m_pen); painter->setPen(m_pen);
painter->setBrush(m_brush); painter->setBrush(m_brush);
painter->drawPolygon(m_points); 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) void GraphicPolygonItem::resize(int nHandle,double dSX, double dSY, const QPointF& basePoint)

View File

@ -2,6 +2,7 @@
#include "graphicsItem/itemControlHandle.h" #include "graphicsItem/itemControlHandle.h"
#include <QPainter> #include <QPainter>
#include <QStyleOption>
GraphicsRectItem::GraphicsRectItem(const QRect &rect, bool isRound, QGraphicsItem *parent) GraphicsRectItem::GraphicsRectItem(const QRect &rect, bool isRound, QGraphicsItem *parent)
: GraphicsBaseItem(parent), m_bIsRound(isRound), m_dRatioX(1 / 10.0), m_dRatioY(1 / 10.0) : 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); painter->drawRect(m_boundingRect);
//绘制变换原点 //绘制变换原点
// QPointF originPoint = transformOriginPoint(); QPointF originPoint = transformOriginPoint();
// painter->setPen(Qt::red); painter->setBrush(Qt::red);
// painter->drawEllipse(originPoint, 5, 5); 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) void GraphicsRectItem::resize(int nHandle,double dSX, double dSY, const QPointF& basePoint)

View File

@ -1,7 +1,7 @@
#include "graphicsItem/itemControlHandle.h" #include "graphicsItem/itemControlHandle.h"
#include <QPainter> #include <QPainter>
#define HNDLE_SIZE 6 #define HNDLE_SIZE 8
ItemControlHandle::ItemControlHandle(QGraphicsItem *parent) ItemControlHandle::ItemControlHandle(QGraphicsItem *parent)
: QGraphicsRectItem(-HNDLE_SIZE / 2, : QGraphicsRectItem(-HNDLE_SIZE / 2,