Compare commits
3 Commits
2e2d89b80c
...
c6a6b68687
Author | SHA1 | Date |
---|---|---|
白封羽 | c6a6b68687 | |
白封羽 | 59ca15dcb9 | |
wuyize | d6a3d3555d |
|
@ -130,16 +130,16 @@
|
|||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\ElementManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\LayerManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\LayerWrapper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\PreviewWindow.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Renderer\Painting\LineTree.cpp">
|
||||
<Filter>Source Files\Renderer\Painting</Filter>
|
||||
|
@ -174,7 +174,7 @@
|
|||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\PreviewWindow.h">
|
||||
<Filter>Header Files</Filter>
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -293,17 +293,17 @@
|
|||
<ClInclude Include="src\Editor\GraphicElement.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\ElementManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
<ClInclude Include="src\Editor\LayerStyle.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\LayerManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\LayerStyle.h">
|
||||
<Filter>Header Files</Filter>
|
||||
<ClInclude Include="src\Editor\ElementManager.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\LayerWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Renderer\Painting\LineTree.h">
|
||||
<Filter>Header Files\Renderer\Painting</Filter>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,30">
|
||||
<item>
|
||||
<widget class="QLabel" name="title">
|
||||
<property name="text">
|
||||
|
@ -46,7 +46,7 @@
|
|||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>PreviewWindow</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<extends>QOpenGLWidget</extends>
|
||||
<header>PreviewWindow.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
|
@ -4,16 +4,18 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
|||
{
|
||||
ui.setupUi(this);
|
||||
previewWindow = ui.Preview;
|
||||
QJsonArray elements;
|
||||
QJsonArray layers;
|
||||
elementManager = new ElementManager(elements);
|
||||
layerManager = new LayerManager(layers, elementManager);
|
||||
elementManager->initialize(layerManager);
|
||||
previewWindow->initialize(layerManager);
|
||||
}
|
||||
|
||||
EditorWidget::~EditorWidget()
|
||||
{
|
||||
}
|
||||
#include "QGraphicsItem.h"
|
||||
#include "QGraphicsScene.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
void EditorWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
previewWindow->show();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "GraphicElement.h"
|
||||
#include "ElementManager.h"
|
||||
#include "LayerManager.h"
|
||||
#include "PreviewWindow.h"
|
||||
#include "ui_EditorWidget.h"
|
||||
#include <QPainter>
|
||||
|
@ -10,12 +11,14 @@ class EditorWidget : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Ui::EditorWidgetClass ui;
|
||||
PreviewWindow *previewWindow;
|
||||
ElementManager *elementManager;
|
||||
LayerManager *layerManager;
|
||||
|
||||
public:
|
||||
EditorWidget(QWidget *parent = nullptr);
|
||||
~EditorWidget();
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
Ui::EditorWidgetClass ui;
|
||||
PreviewWindow *previewWindow;
|
||||
};
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
#include "ElementManager.h"
|
||||
ElementManager *ElementManager::getInstance()
|
||||
ElementManager::ElementManager(QJsonArray jsonElementArray)
|
||||
{
|
||||
return nullptr;
|
||||
elements.resize(jsonElementArray.size());
|
||||
}
|
||||
|
||||
void ElementManager::initialize(LayerManager *layerManager)
|
||||
{
|
||||
}
|
||||
|
||||
void ElementManager::addElement(GraphicElement *element)
|
||||
{
|
||||
}
|
||||
|
||||
void ElementManager::removeElement(GraphicElement *pElement)
|
||||
{
|
||||
}
|
||||
GraphicElement *ElementManager::getElementById(int index)
|
||||
|
||||
GraphicElement **ElementManager::getElementById(int index)
|
||||
{
|
||||
if (index <= elements.size())
|
||||
return &elements[index];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
#pragma once
|
||||
#include "GraphicElement.h"
|
||||
#include "LayerManager.h"
|
||||
#include <QJsonArray>
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
class LayerManager;
|
||||
|
||||
class ElementManager
|
||||
{
|
||||
private:
|
||||
static ElementManager *INSTANCE;
|
||||
vector<GraphicElement> mElements;
|
||||
vector<GraphicElement *> elements;
|
||||
|
||||
public:
|
||||
static ElementManager *getInstance();
|
||||
ElementManager(QJsonArray jsonElementArray);
|
||||
void initialize(LayerManager *layerManager);
|
||||
void addElement(GraphicElement *element);
|
||||
void removeElement(GraphicElement *pElement);
|
||||
/**
|
||||
* only used in initialization
|
||||
*/
|
||||
GraphicElement *getElementById(int index);
|
||||
GraphicElement **getElementById(int index);
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@ ElementType ElementTypeStringValue::enumType(std::string elementType)
|
|||
}
|
||||
QPainterPath SimpleElement::getPaintObject() const
|
||||
{
|
||||
return mPainterPath;
|
||||
return painterPath;
|
||||
}
|
||||
void SimpleElement::pathOperate(QJsonArray paths)
|
||||
{
|
||||
|
@ -31,39 +31,51 @@ void SimpleElement::polygonOperate(QJsonArray points)
|
|||
{
|
||||
polygon.append(QPointF(point.toObject().value("x").toDouble(), point.toObject().value("y").toDouble()));
|
||||
}
|
||||
mPainterPath.addPolygon(polygon);
|
||||
painterPath.addPolygon(polygon);
|
||||
}
|
||||
void SimpleElement::roundOperate(QJsonObject json)
|
||||
{
|
||||
double xAxis = json.value("x-axis").toDouble();
|
||||
double yAxis = json.value("y-axis").toDouble();
|
||||
double angle = json.value("angle").toDouble();
|
||||
mPainterPath.arcMoveTo(xAxis * -0.5, yAxis * -0.5, xAxis, yAxis, 0);
|
||||
mPainterPath.arcTo(xAxis * -0.5, yAxis * -0.5, xAxis, yAxis, 0, angle);
|
||||
painterPath.arcMoveTo(xAxis * -0.5, yAxis * -0.5, xAxis, yAxis, 0);
|
||||
painterPath.arcTo(xAxis * -0.5, yAxis * -0.5, xAxis, yAxis, 0, angle);
|
||||
}
|
||||
SimpleElement::SimpleElement(QJsonObject jsonSource) : mJsonSource(jsonSource)
|
||||
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
|
||||
{
|
||||
mPainterPath.clear();
|
||||
mElementType = ElementTypeStringValue::enumType(mJsonSource.value("type").toString().toStdString());
|
||||
switch (mElementType)
|
||||
painterPath.clear();
|
||||
elementType = ElementTypeStringValue::enumType(jsonSource.value("type").toString().toStdString());
|
||||
switch (elementType)
|
||||
{
|
||||
case ElementType::undefined:
|
||||
break;
|
||||
case ElementType::path: {
|
||||
QJsonArray paths = mJsonSource.value("data").toObject().value("operations").toArray();
|
||||
QJsonArray paths = jsonSource.value("data").toObject().value("operations").toArray();
|
||||
pathOperate(paths);
|
||||
break;
|
||||
}
|
||||
case ElementType::polygon: {
|
||||
QJsonArray points = mJsonSource.value("data").toObject().value("points").toArray();
|
||||
QJsonArray points = jsonSource.value("data").toObject().value("points").toArray();
|
||||
polygonOperate(points);
|
||||
break;
|
||||
}
|
||||
case ElementType::round: {
|
||||
roundOperate(mJsonSource.value("data").toObject());
|
||||
roundOperate(jsonSource.value("data").toObject());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GroupElement::GroupElement(FolderLayerWrapper *sourceLayer)
|
||||
{
|
||||
this->sourceLayer = sourceLayer;
|
||||
}
|
||||
QPainterPath GroupElement::getPaintObject() const
|
||||
{
|
||||
if (sourceLayer != nullptr)
|
||||
return sourceLayer->getCache();
|
||||
else
|
||||
return QPainterPath();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
#pragma once
|
||||
#include "LayerWrapper.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QPainterPath>
|
||||
#include <string>
|
||||
class LayerWrapper;
|
||||
class LeafLayerWrapper;
|
||||
class FolderLayerWrapper;
|
||||
|
||||
enum class ElementType
|
||||
{
|
||||
undefined = 0,
|
||||
|
@ -28,9 +33,9 @@ class GraphicElement
|
|||
class SimpleElement : public GraphicElement
|
||||
{
|
||||
private:
|
||||
QJsonObject mJsonSource;
|
||||
QPainterPath mPainterPath;
|
||||
ElementType mElementType;
|
||||
QJsonObject jsonSource;
|
||||
QPainterPath painterPath;
|
||||
ElementType elementType;
|
||||
void pathOperate(QJsonArray paths);
|
||||
void polygonOperate(QJsonArray points);
|
||||
void roundOperate(QJsonObject json);
|
||||
|
@ -40,14 +45,13 @@ class SimpleElement : public GraphicElement
|
|||
~SimpleElement() = default;
|
||||
QPainterPath getPaintObject() const override;
|
||||
};
|
||||
// class GroupElement : public GraphicElement
|
||||
//{
|
||||
// private:
|
||||
// FolderLayerWrapper *mSourceLayer;
|
||||
//
|
||||
// public:
|
||||
// GroupElement(QJsonObject jsonSource);
|
||||
// GroupElement(FolderLayerWrapper *mSourceLayer);
|
||||
// ~GroupElement() = default;
|
||||
// QPainterPath getPaintObject() const override;
|
||||
// };
|
||||
class GroupElement : public GraphicElement
|
||||
{
|
||||
private:
|
||||
FolderLayerWrapper *sourceLayer;
|
||||
|
||||
public:
|
||||
GroupElement(FolderLayerWrapper *mSourceLayer);
|
||||
~GroupElement() = default;
|
||||
QPainterPath getPaintObject() const override;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "LayerManager.h"
|
||||
|
||||
LayerManager::LayerManager(QJsonArray layers, ElementManager *elementManager)
|
||||
{
|
||||
}
|
||||
void LayerManager::paint(QPainter *painter) const
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
#pragma once
|
||||
#include "ElementManager.h"
|
||||
#include "LayerWrapper.h"
|
||||
#include <QJsonArray>
|
||||
#include <QPainter>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
using std::pair;
|
||||
using std::vector;
|
||||
class ElementManager;
|
||||
|
||||
class LayerManager
|
||||
{
|
||||
private:
|
||||
using LayerPtrs = vector<LayerWrapper *>;
|
||||
LayerWrapper root;
|
||||
LayerWrapper *root;
|
||||
LayerPtrs selectedLayers;
|
||||
LayerPtrs involvedLeafLayersCache;
|
||||
|
||||
public:
|
||||
LayerManager(QJsonArray layers, ElementManager *elementManager);
|
||||
void paint(QPainter *painter) const;
|
||||
};
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "LayerWrapper.h"
|
||||
|
||||
void LayerWrapper::applyStyles(SimpleElement &element)
|
||||
{
|
||||
}
|
||||
void FolderLayerWrapper::addChild(LayerWrapper *child)
|
||||
{
|
||||
}
|
||||
|
||||
void FolderLayerWrapper::removeChild(LayerWrapper *child)
|
||||
{
|
||||
}
|
||||
|
||||
QPainterPath LayerWrapper::getCache() const
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
#pragma once
|
||||
#include "GraphicElement.h"
|
||||
#include "LayerStyle.h"
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsScene>
|
||||
#include <QLine>
|
||||
#include <QPoint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
using std::shared_ptr;
|
||||
using std::vector;
|
||||
class GraphicElement;
|
||||
class SimpleElement;
|
||||
class GroupElement;
|
||||
|
||||
class LayerWrapper
|
||||
{
|
||||
protected:
|
||||
|
@ -16,7 +23,7 @@ class LayerWrapper
|
|||
QPainterPath cache;
|
||||
|
||||
public:
|
||||
void applyStyles(SimpleElement &element); // invoke by manager, then invoke parent's applyStyles
|
||||
QPainterPath getCache() const; // invoke by manager, then invoke parent's applyStyles
|
||||
// todo: provide atomic operations for Events
|
||||
};
|
||||
|
||||
|
|
|
@ -1,27 +1,51 @@
|
|||
#include "PreviewWindow.h"
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent) : QGraphicsView(parent)
|
||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||
{
|
||||
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
mainScene = new QGraphicsScene(this);
|
||||
this->setScene(mainScene);
|
||||
QSurfaceFormat surfaceFormat;
|
||||
surfaceFormat.setSamples(16);
|
||||
setFormat(surfaceFormat);
|
||||
painter = new QPainter(this);
|
||||
layerManager = nullptr;
|
||||
}
|
||||
|
||||
void PreviewWindow::initialize(LayerManager *layerManager)
|
||||
{
|
||||
this->layerManager = layerManager;
|
||||
}
|
||||
|
||||
void PreviewWindow::show()
|
||||
{
|
||||
mainScene->clear();
|
||||
QFile settingFile;
|
||||
settingFile.setFileName("../data.json");
|
||||
|
||||
settingFile.open(QFile::ReadOnly);
|
||||
QByteArray setting = settingFile.readAll().trimmed();
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting));
|
||||
auto jElements = jsonDoc.object().value("elements").toArray();
|
||||
|
||||
for (auto &&ele : jElements)
|
||||
{
|
||||
SimpleElement element(ele.toObject());
|
||||
QGraphicsPathItem *item = new QGraphicsPathItem(element.getPaintObject());
|
||||
mainScene->addItem(item);
|
||||
painter->drawPath(element.getPaintObject());
|
||||
}
|
||||
|
||||
QGraphicsView::show();
|
||||
}
|
||||
|
||||
void PreviewWindow::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
glClearColor(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
void PreviewWindow::paintGL()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
painter->begin(this);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
layerManager->paint(painter);
|
||||
painter->end();
|
||||
}
|
||||
|
||||
void PreviewWindow::resizeGL(int w, int h)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
#pragma once
|
||||
#include "GraphicElement.h"
|
||||
#include "QGraphicsItem.h"
|
||||
#include "QGraphicsView.h"
|
||||
#include "LayerManager.h"
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
class PreviewWindow : public QGraphicsView
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLWidget>
|
||||
class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QGraphicsScene *mainScene;
|
||||
QPainter *painter;
|
||||
LayerManager *layerManager;
|
||||
|
||||
public:
|
||||
PreviewWindow(QWidget *parent = 0);
|
||||
PreviewWindow(QWidget *parent = nullptr);
|
||||
void initialize(LayerManager *layerManager);
|
||||
void show();
|
||||
void initializeGL() override;
|
||||
void paintGL() override;
|
||||
void resizeGL(int w, int h) override;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue