加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gsshapeitem.cpp 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
#include "gsshapeitem.h"
#include <QPainter>
#include <QDebug>
GsShapeItem::GsShapeItem(GsShapeType type, QRectF rectF,QGraphicsObject *parent):
m_boundRectF(rectF),
QGraphicsObject(parent)
{
// setCacheMode(ItemCoordinateCache);
setFlags(ItemIsMovable | ItemIsSelectable);
m_type = type;
}
GsShapeItem::~GsShapeItem()
{
}
QRectF GsShapeItem::boundingRect() const
{
return m_boundRectF;
}
int GsShapeItem::type() const
{
return Type_ShapeItem;
}
void GsShapeItem::drawShape(QPointF p1, QPointF p2)
{
m_firstPoint = p1;
m_lastPoint = p2;
update();
}
void GsShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setRenderHint(QPainter::Antialiasing);
QColor color = Qt::red;//(rand()%255,rand()%255,rand()%255);
painter->setBrush(color);
painter->setPen(QPen(color,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
switch (m_type) {
case Shape_Line:
painter->drawLine(m_firstPoint,m_lastPoint);
break;
case Shape_Rectange:
painter->drawRect(QRectF(m_firstPoint,m_lastPoint));
break;
case Shape_Circle:
painter->drawEllipse(m_firstPoint.x(),m_firstPoint.y(),
qAbs(m_lastPoint.y() - m_firstPoint.y()),
qAbs(m_lastPoint.y() - m_firstPoint.y()));
break;
case Shape_Oval:
painter->drawEllipse(QRectF(m_firstPoint,m_lastPoint));
break;
default:
break;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化