PlotterHMI/datafile/view/mygraphicsscene.cpp
huahaiyan 3ce55cebbd 20240308
1、梳理代码,修改绘制会绘制两次的bug;
2、增加正向旋转功能,线宽设置功能;
3、测试压缩算法,完成;
2024-03-08 16:33:05 +08:00

116 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mygraphicsscene.h"
MyGraphicsScene::MyGraphicsScene()
{
m_myGraphicsItem= new MyGraphicsItem();
}
MyGraphicsScene::~MyGraphicsScene()
{
if(m_myGraphicsItem != NULL)
{
delete m_myGraphicsItem;
m_myGraphicsItem = NULL;
}
}
void MyGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
return QGraphicsScene::mousePressEvent(mouseEvent);
}
void MyGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
return QGraphicsScene::mouseMoveEvent(mouseEvent);
}
void MyGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
return QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
void MyGraphicsScene::createScenePathAndPic(QPainterPath path, QPicture pic)
{
if(m_myGraphicsItem != NULL)
{
this->clear();
m_myGraphicsItem->setPaintPathAndPic(path,pic);
this->addItem(m_myGraphicsItem);
}
}
void MyGraphicsScene::addItemToScene()
{
//绘制留边
this->setSceneRect(0,0,m_myGraphicsItem->boundingRect().width()+DRAWMARGINS,m_myGraphicsItem->boundingRect().height()+DRAWMARGINS);
//如果scene未超过graphicsView的范围图形就是居中显示的
this->addItem(m_myGraphicsItem);
m_myGraphicsItem->moveBy(DRAWMARGINS/2.0,DRAWMARGINS/2.0);//item居中显示
}
void MyGraphicsScene::cleanScene()
{
if(m_myGraphicsItem != NULL)
{
this->removeItem(m_myGraphicsItem);
}
}
QPicture MyGraphicsScene::getPictureByDat(Marker marker,int penWidth)
{
QPicture pic;
if(m_myGraphicsItem != NULL)
{
pic = m_myGraphicsItem->getPictureByDat(marker,penWidth);
}
return pic;
}
QPicture MyGraphicsScene::getPictureByBmp(QPixmap pixmap,int penWidth)
{
QPicture pic;
if(m_myGraphicsItem != NULL)
{
pic = m_myGraphicsItem->getPictureByBmp(pixmap,penWidth);
}
return pic;
}
QPainterPath MyGraphicsScene::getDrawPath()
{
QPainterPath path;
if(m_myGraphicsItem != NULL)
{
path = m_myGraphicsItem->getDrawPath();
}
return path;
}
void MyGraphicsScene::swithSceneByPic(QPicture pic)
{
if(m_myGraphicsItem != NULL)
{
this->clear();
m_myGraphicsItem->setPicture(pic);
this->addItem(m_myGraphicsItem);
}
}
void MyGraphicsScene::swithSceneByPath(QPainterPath path)
{
if(m_myGraphicsItem != NULL)
{
this->clear();
m_myGraphicsItem->setPaintPath(path);
this->addItem(m_myGraphicsItem);
}
}
void MyGraphicsScene::ReflushBlockScene(QPoint p)
{
if(m_myGraphicsItem != NULL)
{
m_myGraphicsItem->reflushBlockPos(p);
}
}