PowerDesigner/source/graphicsItem/graphicsBaseItem.cpp

106 lines
3.1 KiB
C++
Raw Normal View History

2024-08-16 11:39:30 +08:00
#include "graphicsItem/graphicsBaseItem.h"
#include <QGraphicsScene>
GraphicsBaseItem::GraphicsBaseItem(QGraphicsItem *parent)
: AbstractShapeType<QGraphicsItem>(parent)
{
m_type = T_item;
2024-08-16 11:39:30 +08:00
//初始化缩放操作用的handle
m_vecHanle.reserve(H_left);
for(int i = H_leftTop; i <= H_left; i++)
{
ItemControlHandle* pHandle = new ItemControlHandle(this);
pHandle->setType(T_resize);
pHandle->setTag(i);
m_vecHanle.push_back(pHandle);
}
for(int i = H_rotate_leftTop; i <= H_rotate_leftBottom; i++)
{
ItemControlHandle* pHandle = new ItemControlHandle(this);
pHandle->setType(T_rotate);
pHandle->setTag(i);
m_vecHanle.push_back(pHandle);
}
2024-08-16 11:39:30 +08:00
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setAcceptHoverEvents(true);
}
GraphicsBaseItem::~GraphicsBaseItem()
{
}
void GraphicsBaseItem::createOperationCopy()
2024-08-16 11:39:30 +08:00
{
m_pOperationCopy = new QGraphicsPathItem(this->shape());
m_pOperationCopy->setPen(Qt::DashLine);
m_pOperationCopy->setPos(this->pos());
m_pOperationCopy->setTransformOriginPoint(this->transformOriginPoint());
m_pOperationCopy->setTransform(this->transform());
m_pOperationCopy->setRotation(this->rotation());
m_pOperationCopy->setScale(this->scale());
m_pOperationCopy->setZValue(this->zValue());
2024-08-16 11:39:30 +08:00
QGraphicsScene* scene = this->scene();
if(scene && m_pOperationCopy)
2024-08-16 11:39:30 +08:00
{
scene->addItem(m_pOperationCopy);
2024-08-16 11:39:30 +08:00
m_movingIniPos = this->pos();
}
}
void GraphicsBaseItem::removeOperationCopy()
2024-08-16 11:39:30 +08:00
{
QGraphicsScene* scene = this->scene();
if(scene && m_pOperationCopy)
2024-08-16 11:39:30 +08:00
{
if(this->pos() != m_pOperationCopy->pos())
this->setPos(m_pOperationCopy->pos()); //本体移动到副本的位置
if(this->rotation() != m_pOperationCopy->rotation())
this->setRotation(m_pOperationCopy->rotation()); //本体旋转至副本的角度
scene->removeItem(m_pOperationCopy);
delete m_pOperationCopy;
m_pOperationCopy = nullptr;
2024-08-16 11:39:30 +08:00
}
}
void GraphicsBaseItem::moveOperationCopy(const QPointF& distance)
2024-08-16 11:39:30 +08:00
{
if(m_pOperationCopy)
m_pOperationCopy->setPos(m_movingIniPos + distance);
2024-08-16 11:39:30 +08:00
}
void GraphicsBaseItem::rotateOperationCopy(const double& dAngle)
{
if(m_pOperationCopy)
m_pOperationCopy->setRotation(dAngle);
}
2024-08-16 11:39:30 +08:00
QVariant GraphicsBaseItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value)
{
if (change == QGraphicsItem::ItemSelectedHasChanged)
{
QGraphicsItemGroup *group = dynamic_cast<QGraphicsItemGroup *>(parentItem());
if(!group)
setHandleVisible(value.toBool());
else //在某一组群中,由组群展示是否选中,自身不做展示
{
setSelected(false);
return QVariant::fromValue<bool>(false);
}
}
return QGraphicsItem::itemChange(change, value);
}
void GraphicsBaseItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{
Q_UNUSED(event);
}