DiagramDesigner/diagramCavas/source/graphicsItem/handleRect.cpp

70 lines
1.7 KiB
C++
Raw Normal View History

#include "graphicsItem/handleRect.h"
#include <QPainter>
HandleRect::HandleRect(QGraphicsItem *parent)
:ItemControlHandle(parent)
{
}
HandleRect::~HandleRect()
{
}
QRectF HandleRect::boundingRect() const
{
// 设置边界矩形,这里我们返回一个从(10,10)开始宽度为100高度为50的矩形
return QRectF(-HNDLE_SIZE / 2,
-HNDLE_SIZE / 2,
HNDLE_SIZE,
HNDLE_SIZE);
}
void HandleRect::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->setPen(Qt::SolidLine);
painter->setRenderHint(QPainter::Antialiasing, true);
if(m_type==T_resize)
{
painter->setBrush(Qt::white);
painter->drawRect(boundingRect());
}
else if(m_type==T_rotate)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect());
}
else if(m_type==T_editShape)
{
painter->setBrush(Qt::green);
painter->drawEllipse(boundingRect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
}
else if(m_type==T_lineIn)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::green);
painter->drawEllipse(boundingRect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
}
else if(m_type==T_lineOut)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::red);
painter->drawEllipse(boundingRect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
}
}
void HandleRect::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
ItemControlHandle::hoverEnterEvent(event);
}
void HandleRect::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
ItemControlHandle::hoverLeaveEvent(event);
}