增加了QPainterPath转为vector<>

dev-VirtualTexture
yang.yongquan 2023-02-04 20:20:40 +08:00
parent 9e1ec3f848
commit 2af2464745
8 changed files with 73 additions and 9 deletions

View File

@ -110,6 +110,7 @@
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp" />
<ClCompile Include="src\Editor\ThirdPartyLib\qquick\qquicksvgparser.cpp" />
<ClCompile Include="src\Editor\ThirdPartyLib\SvgHelper.cpp" />
<ClCompile Include="src\Editor\util\PainterPathUtil.cpp" />
<ClCompile Include="src\Editor\util\SvgFileLoader.cpp" />
<ClCompile Include="src\IconWidget.cpp" />
<ClCompile Include="src\main.cpp" />
@ -180,6 +181,7 @@
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal.h" />
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal_p.h" />
<ClInclude Include="src\Editor\ThirdPartyLib\SvgHelper.h" />
<ClInclude Include="src\Editor\util\PainterPathUtil.h" />
<ClInclude Include="src\Editor\util\SvgFileLoader.h" />
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" />
<ClInclude Include="src\Renderer\Painting\Element.h" />

View File

@ -192,6 +192,9 @@
<ClCompile Include="src\Editor\util\SvgFileLoader.cpp">
<Filter>Source Files\Editor\util</Filter>
</ClCompile>
<ClCompile Include="src\Editor\util\PainterPathUtil.cpp">
<Filter>Source Files\Editor\util</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -360,9 +363,6 @@
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h">
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\ElementStyle.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
@ -387,12 +387,12 @@
<ClInclude Include="src\Renderer\Painting\MaterialStyleFill.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\BaseStyle.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\MaterialStyleStroke.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Editor\util\PainterPathUtil.h">
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="MainWindow.qrc">

View File

@ -1,5 +1,5 @@
#include "GraphicElement.h"
#include "third-party modules/util/SvgFileLoader.h"
#include <util/SvgFileLoader.h>
using namespace std;
QPainterPath SimpleElement::getPaintObject() const
{

View File

@ -0,0 +1,41 @@
#include "PainterPathUtil.h"
#include <QDebug>
using Renderer::Point;
using std::vector;
vector<vector<Point> > PainterPathUtil::transformToLines(QPainterPath& painterPath) {
vector<Point> line; line.clear();
vector<vector<Point> > lines; lines.clear();
QPointF startPoint(0, 0);
Point point(0, 0);
for (int elementIndex = 0; elementIndex < painterPath.elementCount(); elementIndex++) {
auto element = painterPath.elementAt(elementIndex);
point = element;
qDebug() << element;
if (element.isMoveTo()) {
if (line.size() >= 2) {
lines.push_back(line);
}
line.clear();
line.push_back(point);
}
else {
line.push_back(point);
if (element.isLineTo()) {
lines.push_back(line);
}
if (element.isCurveTo()) {
point = painterPath.elementAt(++elementIndex);
line.push_back(point);
point = painterPath.elementAt(++elementIndex);
line.push_back(point);
lines.push_back(line);
}
line.clear();
line.push_back(point);
}
}
line.clear();
return lines;
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <vector>
#include <QPainterPath>
#include "../Renderer/Painting/Line.h"
using Renderer::Point;
class PainterPathUtil
{
public:
static std::vector<std::vector<Point> > transformToLines(QPainterPath& painterPath);
};

View File

@ -151,7 +151,8 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) {
}
}
qDebug() << labelStyle;
addEllipse(cx, cy, r, r, painterPath);
//addEllipse(cx, cy, r, r, painterPath);
painterPath.addEllipse(cx, cy, r, r);
}
void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) {
@ -174,7 +175,8 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) {
}
}
qDebug() << labelStyle;
addEllipse(cx, cy, rx, ry, painterPath);
//addEllipse(cx, cy, rx, ry, painterPath);
painterPath.addEllipse(cx, cy, rx, ry);
}
void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) {

View File

@ -23,4 +23,5 @@ private:
void handleLabelEllipse(QPainterPath& painterPath);
void handleLabelPolyline(QPainterPath& painterPath);
void handleLabelPolygon(QPainterPath& painterPath);
};

View File

@ -25,6 +25,11 @@ namespace Renderer
bool operator< (const Point& a) const {
return fabs(x - a.x) <= eps ? y < a.y : x < a.x;
}
Point& operator= (const QPointF p){
x = p.x();
y = p.y();
return *this;
}
operator glm::dvec2() {
return glm::dvec2(x, y);
}