You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
C++
95 lines
2.5 KiB
C++
#include "MyQGraphicsEllipseItem.h"
|
|
|
|
MyQGraphicsEllipseItem::~MyQGraphicsEllipseItem()
|
|
{
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::SetCircleAttr(double x1, double y1, double width, double height)
|
|
{
|
|
m_circleX = x1 / 100.00;
|
|
m_circleY = y1 / 100.00;
|
|
m_diameter = width / 100.00;
|
|
|
|
//设置当前线位置
|
|
setPos(QPointF(x1, y1));
|
|
|
|
//设置ID
|
|
m_id = GlobalDefine::GetInstance()->GetItemId();
|
|
|
|
m_translteType = NONE;
|
|
|
|
m_backupDiameter = width / 100.00;
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::SetCircleInterfaceAttr(double x1, double y1, double dia)
|
|
{
|
|
m_circleX = x1;
|
|
m_circleY = y1;
|
|
m_diameter = dia;//设置当前线位置
|
|
this->setRect(QRectF(0, 0, m_diameter * DIE_SCALE, m_diameter * DIE_SCALE));
|
|
setPos(QPointF(m_circleX * DIE_SCALE, m_circleY * DIE_SCALE));
|
|
this->setScale(m_initScale);
|
|
m_translteType = NONE;
|
|
m_backupDiameter = dia / 100.00;
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
{
|
|
QGraphicsEllipseItem::paint(painter, option, widget);
|
|
|
|
QPen pen;
|
|
pen.setWidth(FEATURE_POINT_LINE_WIDTH);
|
|
painter->setPen(pen);
|
|
painter->setBrush(FEATURE_POINT_COLOR);
|
|
//圆心
|
|
painter->drawEllipse(QPointF(rect().width() / 2, rect().width() / 2), FEATURE_POINT_SIZE / 5, FEATURE_POINT_SIZE / 5);
|
|
//右侧用于按住需要缩放的点
|
|
painter->drawEllipse(QPointF(rect().width() - 2, rect().width() / 2), FEATURE_POINT_SIZE / 5, FEATURE_POINT_SIZE / 5);
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton)
|
|
{
|
|
emit signal_select(m_id);
|
|
m_mousePressDownPos = event->scenePos();
|
|
|
|
if (abs(event->scenePos().x() - (m_circleX + m_diameter) * DIE_SCALE) <= FEATURE_POINT_SIZE &&
|
|
abs(event->scenePos().y() - (m_circleY + m_diameter / 2) * DIE_SCALE) <= FEATURE_POINT_SIZE)
|
|
{
|
|
m_translteType = SCALE;
|
|
}
|
|
else
|
|
{
|
|
m_translteType = MOVE;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (m_translteType == MOVE)
|
|
{
|
|
setPos(event->scenePos().x(), event->scenePos().y());
|
|
m_circleX = (double)this->scenePos().x() / 100.00;
|
|
m_circleY = (double)this->scenePos().y() / 100.00;
|
|
}
|
|
else if (m_translteType == SCALE)
|
|
{
|
|
auto& nowMouseCoord = event->scenePos();
|
|
double prop = ((double)event->scenePos().x() - (double)m_mousePressDownPos.x()) / 150.00;
|
|
double scaleNum = m_initScale + prop;
|
|
m_nowScale = scaleNum;
|
|
this->setScale(m_nowScale);
|
|
m_diameter = m_backupDiameter * scaleNum;
|
|
|
|
}
|
|
}
|
|
|
|
void MyQGraphicsEllipseItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (m_translteType == SCALE) {
|
|
m_initScale = m_nowScale;
|
|
}
|
|
}
|