Compare commits

..

No commits in common. "301f5a149625c4c0da95e186623671cc1abdbb21" and "6a4a724f006a181e6c87dedfb181a643363d9af0" have entirely different histories.

18 changed files with 188 additions and 489 deletions

View File

@ -104,9 +104,9 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Editor\EditorWidget.cpp" /> <ClCompile Include="ElementPoolWidget.cpp" />
<ClCompile Include="src\CaptionButton.cpp" /> <ClCompile Include="src\CaptionButton.cpp" />
<ClCompile Include="src\Editor\EditorWidgetItem.cpp" /> <ClCompile Include="src\Editor\EditorWidget.cpp" />
<ClCompile Include="src\Editor\ElementManager.cpp" /> <ClCompile Include="src\Editor\ElementManager.cpp" />
<ClCompile Include="src\Editor\GraphicElement.cpp" /> <ClCompile Include="src\Editor\GraphicElement.cpp" />
<ClCompile Include="src\Editor\LayerManager.cpp" /> <ClCompile Include="src\Editor\LayerManager.cpp" />
@ -151,11 +151,8 @@
<ClCompile Include="src\SvgParser.cpp" /> <ClCompile Include="src\SvgParser.cpp" />
<ClCompile Include="src\TitleWidget.cpp" /> <ClCompile Include="src\TitleWidget.cpp" />
<QtUic Include="EditorWidget.ui" /> <QtUic Include="EditorWidget.ui" />
<QtUic Include="EditorWidgetItem.ui" />
<QtUic Include="FramelessWindow.ui" />
<QtUic Include="MainWindow.ui" /> <QtUic Include="MainWindow.ui" />
<QtUic Include="RendererWidget.ui" /> <QtUic Include="RendererWidget.ui" />
<QtUic Include="EditorWidget.ui" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\data.json" /> <None Include="..\data.json" />
@ -189,7 +186,6 @@
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" /> <QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" />
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" /> <QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
<QtMoc Include="src\MainWindow.h" /> <QtMoc Include="src\MainWindow.h" />
<QtMoc Include="src\Editor\EditorWidget.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="src\Editor\ElementManager.h" /> <ClInclude Include="src\Editor\ElementManager.h" />
<QtMoc Include="src\Editor\ElementPoolWidget.h" /> <QtMoc Include="src\Editor\ElementPoolWidget.h" />
@ -221,7 +217,7 @@
<QtMoc Include="src\CaptionButton.h" /> <QtMoc Include="src\CaptionButton.h" />
<QtMoc Include="src\NavigationBarWidget.h" /> <QtMoc Include="src\NavigationBarWidget.h" />
<QtMoc Include="src\Renderer\RendererWidget.h" /> <QtMoc Include="src\Renderer\RendererWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetItem.h" /> <QtMoc Include="src\Editor\EditorWidget.h" />
<ClInclude Include="src\Renderer\Painting\BvhTree.h" /> <ClInclude Include="src\Renderer\Painting\BvhTree.h" />
<ClInclude Include="src\Renderer\Camera.h" /> <ClInclude Include="src\Renderer\Camera.h" />
<ClInclude Include="src\Renderer\Painting\CubicBezier.h" /> <ClInclude Include="src\Renderer\Painting\CubicBezier.h" />

View File

@ -70,18 +70,9 @@
<QtUic Include="MainWindow.ui"> <QtUic Include="MainWindow.ui">
<Filter>Form Files</Filter> <Filter>Form Files</Filter>
</QtUic> </QtUic>
<QtUic Include="NavigationBarWidget.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="FramelessWindow.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="EditorWidget.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Editor\EditorWidgetItem.cpp"> <ClCompile Include="src\Editor\EditorWidget.cpp">
<Filter>Source Files\Editor</Filter> <Filter>Source Files\Editor</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Renderer\Camera.cpp"> <ClCompile Include="src\Renderer\Camera.cpp">
@ -219,15 +210,12 @@
<ClCompile Include="ElementPoolWidget.cpp"> <ClCompile Include="ElementPoolWidget.cpp">
<Filter>Source Files\Editor</Filter> <Filter>Source Files\Editor</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Editor\EditorWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h"> <QtMoc Include="src\Renderer\RendererGLWidget.h">
<Filter>Header Files\Renderer</Filter> <Filter>Header Files\Renderer</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="src\Editor\EditorWidgetItem.h"> <QtMoc Include="src\Editor\EditorWidget.h">
<Filter>Header Files\Editor</Filter> <Filter>Header Files\Editor</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="src\Renderer\RendererWidget.h"> <QtMoc Include="src\Renderer\RendererWidget.h">
@ -260,9 +248,6 @@
<QtMoc Include="src\Editor\ElementPoolWidget.h"> <QtMoc Include="src\Editor\ElementPoolWidget.h">
<Filter>Header Files\Editor</Filter> <Filter>Header Files\Editor</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="src\Editor\EditorWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\data.json" /> <None Include="..\data.json" />
@ -343,7 +328,7 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="EditorWidgetItem.ui"> <QtUic Include="EditorWidget.ui">
<Filter>Form Files</Filter> <Filter>Form Files</Filter>
</QtUic> </QtUic>
<QtUic Include="RendererWidget.ui"> <QtUic Include="RendererWidget.ui">

View File

@ -1,146 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>EditorWidget</class> <class>EditorWidgetClass</class>
<widget class="QWidget" name="EditorWidget"> <widget class="QWidget" name="EditorWidgetClass">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1139</width> <width>1124</width>
<height>685</height> <height>695</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>RendererWidget</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <property name="leftMargin">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1,20"> <number>0</number>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="createButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property> </property>
<property name="maximumSize"> <property name="topMargin">
<size> <number>0</number>
<width>80</width>
<height>16777215</height>
</size>
</property> </property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="MainWindow" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,30">
<item>
<widget class="QLabel" name="Title">
<property name="text"> <property name="text">
<string>新建</string> <string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="saveButton"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,18,5">
<property name="minimumSize"> <item>
<size> <widget class="QWidget" name="LeftBar" native="true"/>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>保存</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="saveAsButton"> <widget class="PreviewWindow" name="Preview"/>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>另存为</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="closeButton"> <widget class="QWidget" name="RightBar" native="true">
<property name="minimumSize"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="1,2">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>关闭</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <widget class="QTabWidget" name="DisplayTab">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="EditorWidgetItem" name="tab"> <widget class="InfoDisplayWidget" name="LayerDisplay">
<attribute name="title"> <attribute name="title">
<string>Tab 1</string> <string>Layer</string>
</attribute> </attribute>
</widget> </widget>
<widget class="EditorWidgetItem" name="tab_2"> <widget class="QWidget" name="ElementDisplay">
<attribute name="title"> <attribute name="title">
<string>Tab 2</string> <string>Element</string>
</attribute> </attribute>
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="LayerTreeWidget" name="LayerTree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>EditorWidgetItem</class> <class>PreviewWindow</class>
<extends>QOpenGLWidget</extends>
<header>PreviewWindow.h</header>
</customwidget>
<customwidget>
<class>LayerTreeWidget</class>
<extends>QTreeWidget</extends>
<header location="global">LayerTreeWidget.h</header>
</customwidget>
<customwidget>
<class>InfoDisplayWidget</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>EditorWidgetItem.h</header> <header location="global">InfoDisplayWidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

View File

@ -1,113 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditorWidgetItem</class>
<widget class="QWidget" name="EditorWidgetItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1124</width>
<height>695</height>
</rect>
</property>
<property name="windowTitle">
<string>RendererWidget</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="MainWindow" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,30">
<item>
<widget class="QLabel" name="Title">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,18,5">
<item>
<widget class="QWidget" name="LeftBar" native="true"/>
</item>
<item>
<widget class="PreviewWindow" name="Preview"/>
</item>
<item>
<widget class="QWidget" name="RightBar" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="1,2">
<item>
<widget class="QTabWidget" name="DisplayTab">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="InfoDisplayWidget" name="LayerDisplay">
<attribute name="title">
<string>Layer</string>
</attribute>
</widget>
<widget class="QWidget" name="ElementDisplay">
<attribute name="title">
<string>Element</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="LayerTreeWidget" name="LayerTree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>PreviewWindow</class>
<extends>QOpenGLWidget</extends>
<header>PreviewWindow.h</header>
</customwidget>
<customwidget>
<class>LayerTreeWidget</class>
<extends>QTreeWidget</extends>
<header location="global">LayerTreeWidget.h</header>
</customwidget>
<customwidget>
<class>InfoDisplayWidget</class>
<extends>QWidget</extends>
<header location="global">InfoDisplayWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -60,16 +60,16 @@
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"> <string notr="true">
QTabBar::tab.rendererWidget { QTabBar::tab {
height: 0px; height: 0px;
margin-top:0px; margin-top:0px;
} }
QTabWidget::tab-bar.rendererWidget QTabWidget::tab-bar
{ {
height: 0px; height: 0px;
top:0px; top:0px;
} }
QTabWidget::pane.rendererWidget { QTabWidget::pane {
border: 0px; border: 0px;
background-color: transparent; background-color: transparent;
} }

View File

@ -1,33 +1,62 @@
#include "EditorWidget.h" #include "EditorWidget.h"
#include "EditorWidgetItem.h"
#include <QMouseEvent>
#include <QInputDialog>
#include <QMenu>
EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent) EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
{ {
QImage x;
displayLayer = nullptr;
displayElement = nullptr;
ui.setupUi(this); ui.setupUi(this);
this->createButton = ui.createButton; previewWindow = ui.Preview;
this->closeButton = ui.closeButton; treeWidget = ui.LayerTree;
this->saveButton = ui.saveButton; tabWidget = ui.DisplayTab;
this->saveAsButton = ui.saveAsButton; layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
this->tabWidget = ui.tabWidget; elementInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(1));
while (this->tabWidget->count() > 0) connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidget::onLayerChange);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
&EditorWidget::triggerRefreshPreview);
connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
&EditorWidget::triggerRefreshPreview);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
// &EditorWidget::triggerRefreshPreview);
// test
QFile settingFile;
settingFile.setFileName("../data.json");
settingFile.open(QFile::ReadOnly);
QByteArray setting = settingFile.readAll().trimmed();
QJsonParseError jError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
qDebug() << jsonDoc.object().value("height").toDouble();
qDebug() << jError.errorString();
// end test
QJsonObject source = jsonDoc.object();
elementManager = new ElementManager(source,previewWindow->getRenderer());
layerManager = new LayerManager(source, elementManager);
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
if (layerManager->getRoot() != nullptr)
{ {
this->tabWidget->removeTab(0); treeWidget->root = layerManager->getRoot();
treeWidget->refresh();
treeWidget->addTopLevelItem(treeWidget->root->getQTreeItem());
} }
connect(this->createButton, &QPushButton::clicked, this, [this]() {
static int count = 0;
this->tabWidget->addTab(new EditorWidgetItem(this),"untitled"+QString::number(count++));
});
connect(this->closeButton, &QPushButton::clicked, this, [this]() {
this->tabWidget->removeTab(this->tabWidget->currentIndex());
});
connect(this->saveButton, &QPushButton::clicked, this, [this]() {
});
connect(this->saveAsButton, &QPushButton::clicked, this, [this]() {
});
} }
EditorWidget::~EditorWidget()
{
}
void EditorWidget::paintEvent(QPaintEvent *event)
{
}
void EditorWidget::onLayerChange(LayerWrapper *layer)
{
displayLayer = layer;
// TODO : notify InfoDisplayWidget and update
dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0))->setLayer(layer);
this->update();
}
void EditorWidget::triggerRefreshPreview()
{
previewWindow->update();
}

View File

@ -1,22 +1,39 @@
#pragma once #pragma once
#include <qwidget.h>
#include "ui_EditorWidget.h"
class EditorWidget : #include "ElementManager.h"
public QWidget #include "InfoDisplayWidget.h"
#include "LayerManager.h"
#include "LayerTreeWidget.h"
#include "PreviewWindow.h"
#include "ui_EditorWidget.h"
#include <QPainter>
#include <QTreeWidget>
#include <QWidget>
class EditorWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private:
Ui::EditorWidget ui;
QTabWidget* tabWidget;
QPushButton* createButton;
QPushButton* closeButton;
QPushButton* saveButton;
QPushButton* saveAsButton;
public: private:
EditorWidget(QWidget* parent = nullptr); // DATA PART
~EditorWidget()=default; PreviewWindow *previewWindow;
ElementManager *elementManager;
LayerManager *layerManager;
// QT GUI PART
Ui::EditorWidgetClass ui;
LayerTreeWidget *treeWidget;
QTabWidget *tabWidget;
InfoDisplayWidget *layerInfoDisplayWidget, *elementInfoDisplayWidget;
// QT DATA PART
LayerWrapper *displayLayer;
GraphicElement *displayElement;
public:
EditorWidget(QWidget *parent = nullptr);
~EditorWidget();
void paintEvent(QPaintEvent *event) override;
private slots:
void onLayerChange(LayerWrapper *layer);
void triggerRefreshPreview();
}; };

View File

@ -1,63 +0,0 @@
#include "EditorWidgetItem.h"
EditorWidgetItem::EditorWidgetItem(QWidget *parent) : QWidget(parent)
{
QImage x;
displayLayer = nullptr;
displayElement = nullptr;
ui.setupUi(this);
previewWindow = ui.Preview;
treeWidget = ui.LayerTree;
tabWidget = ui.DisplayTab;
layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
elementInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(1));
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
&EditorWidgetItem::triggerRefreshPreview);
connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
&EditorWidgetItem::triggerRefreshPreview);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
// &EditorWidget::triggerRefreshPreview);
// test
QFile settingFile;
settingFile.setFileName("../data.json");
settingFile.open(QFile::ReadOnly);
QByteArray setting = settingFile.readAll().trimmed();
QJsonParseError jError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
qDebug() << jsonDoc.object().value("height").toDouble();
qDebug() << jError.errorString();
// end test
QJsonObject source = jsonDoc.object();
elementManager = new ElementManager(source,previewWindow->getRenderer());
layerManager = new LayerManager(source, elementManager);
qDebug() << layerManager->toJson();
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
if (layerManager->getRoot() != nullptr)
{
treeWidget->root = layerManager->getRoot();
treeWidget->refresh();
treeWidget->addTopLevelItem(treeWidget->root->getQTreeItem());
}
}
EditorWidgetItem::~EditorWidgetItem()
{
}
void EditorWidgetItem::paintEvent(QPaintEvent *event)
{
}
void EditorWidgetItem::onLayerChange(LayerWrapper *layer)
{
displayLayer = layer;
// TODO : notify InfoDisplayWidget and update
dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0))->setLayer(layer);
this->update();
}
void EditorWidgetItem::triggerRefreshPreview()
{
previewWindow->update();
}

View File

@ -1,39 +0,0 @@
#pragma once
#include "ElementManager.h"
#include "InfoDisplayWidget.h"
#include "LayerManager.h"
#include "LayerTreeWidget.h"
#include "PreviewWindow.h"
#include "ui_EditorWidgetItem.h"
#include <QPainter>
#include <QTreeWidget>
#include <QWidget>
class EditorWidgetItem : public QWidget
{
Q_OBJECT
private:
// DATA PART
PreviewWindow *previewWindow;
ElementManager *elementManager;
LayerManager *layerManager;
// QT GUI PART
Ui::EditorWidgetItem ui;
LayerTreeWidget *treeWidget;
QTabWidget *tabWidget;
InfoDisplayWidget *layerInfoDisplayWidget, *elementInfoDisplayWidget;
// QT DATA PART
LayerWrapper *displayLayer;
GraphicElement *displayElement;
public:
EditorWidgetItem(QWidget *parent = nullptr);
~EditorWidgetItem();
void paintEvent(QPaintEvent *event) override;
private slots:
void onLayerChange(LayerWrapper *layer);
void triggerRefreshPreview();
};

View File

@ -3,7 +3,6 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
{ {
auto elementsJson = source.value("elements").toArray(); auto elementsJson = source.value("elements").toArray();
qDebug() << elementsJson.size(); qDebug() << elementsJson.size();
int index = 0;
for (auto elementJson : elementsJson) for (auto elementJson : elementsJson)
{ {
if (elementJson.toObject().value("type").toString() == "group") if (elementJson.toObject().value("type").toString() == "group")
@ -13,8 +12,6 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
(*elements.rbegin())->renderer = renderer; (*elements.rbegin())->renderer = renderer;
} }
for (auto element : elements)
element->index = index++;
} }
void ElementManager::addElement(GraphicElement *element) void ElementManager::addElement(GraphicElement *element)
@ -36,13 +33,3 @@ GraphicElement *ElementManager::getElementById(int index)
ElementManager::~ElementManager() ElementManager::~ElementManager()
{ {
} }
QJsonObject ElementManager::toJson() const
{
QJsonArray elementsJson;
for (auto element : elements)
elementsJson.push_back(element->toJson());
QJsonObject result;
result.insert("elements", elementsJson);
return result;
}

View File

@ -19,7 +19,6 @@ class ElementManager
~ElementManager(); ~ElementManager();
void addElement(GraphicElement *element); void addElement(GraphicElement *element);
void removeElement(GraphicElement *pElement); void removeElement(GraphicElement *pElement);
QJsonObject toJson()const;
/** /**
* only used in initialization * only used in initialization
*/ */

View File

@ -76,10 +76,3 @@ PixelPath GroupElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeD
// rawPath.addPath(path); // rawPath.addPath(path);
// } // }
//} //}
//TODO : Ìí¼Óϸ½Ú
QJsonObject GraphicElement::toJson() const
{
QJsonObject result;
result.insert("name", name);
return result;
}

View File

@ -22,9 +22,7 @@ class GraphicElement
public: public:
Renderer::ElementRenderer *renderer; Renderer::ElementRenderer *renderer;
QString name = ""; QString name = "";
int index;
// TODO: ¸ÄΪBitmapPath // TODO: ¸ÄΪBitmapPath
virtual QJsonObject toJson() const;
virtual PixelPath getPaintObject() const = 0; virtual PixelPath getPaintObject() const = 0;
virtual PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const = 0; virtual PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const = 0;
}; };

View File

@ -62,20 +62,11 @@ bool LayerManager::changeParent(FolderLayerWrapper *newParent) const
selectedLayers[0]->setParent(newParent); selectedLayers[0]->setParent(newParent);
return true; return true;
} }
void LayerManager::addLayer(LayerWrapper *layer) void LayerManager::addLayer(LayerWrapper *layer)
{ {
layerSet.insert(layer); layerSet.insert(layer);
} }
void LayerManager::removeLayer(LayerWrapper *layer) void LayerManager::removeLayer(LayerWrapper *layer)
{ {
layerSet.erase(layer); layerSet.erase(layer);
} }
QJsonObject LayerManager::toJson() const
{
QJsonObject result;
result.insert("root-layer", root->toJson());
return result;
}

View File

@ -31,7 +31,6 @@ class LayerManager
LayerWrapper *getRoot() const; LayerWrapper *getRoot() const;
LayerManager() = default; LayerManager() = default;
LayerManager(QJsonObject source, ElementManager* elementManager); LayerManager(QJsonObject source, ElementManager* elementManager);
QJsonObject toJson() const;
void paint(QPainter *painter, QSize size) const; void paint(QPainter *painter, QSize size) const;
bool rename(QString newName) const; bool rename(QString newName) const;
bool combine() const; bool combine() const;

View File

@ -53,7 +53,6 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
auto p = reinterpret_cast<GroupElement *>(elementManager->getElementById(referencedJson.toInt())); auto p = reinterpret_cast<GroupElement *>(elementManager->getElementById(referencedJson.toInt()));
if (p != nullptr) if (p != nullptr)
p->setSourceLayer(this); p->setSourceLayer(this);
this->referencedBy = referencedJson.toInt();
} }
for (auto childJson : childrenJson) for (auto childJson : childrenJson)
{ {
@ -96,6 +95,7 @@ void FolderLayerWrapper::refresh()
{ {
cache.clear(); cache.clear();
for (auto& child : children) { for (auto& child : children) {
qDebug() << child.get();
cache.addPath(child.get()->getCache()); cache.addPath(child.get()->getCache());
} }
LayerWrapper::refresh(); LayerWrapper::refresh();
@ -181,40 +181,3 @@ QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
} }
return LayerWrapper::getQTreeItem(); return LayerWrapper::getQTreeItem();
} }
//TODO: add effects
QJsonObject LayerWrapper::toJson() const
{
QJsonObject json;
json.insert("name", property.name);
QJsonObject transformJson;
transformJson.insert("offset", QJsonObject({ {"x", property.offset.x()}, {"y", property.offset.y()} }));
transformJson.insert("scale", QJsonObject({ {"x", property.scale.x()}, {"y", property.scale.y()} }));
transformJson.insert("rotation", property.rotation);
json.insert("transform", transformJson);
return json;
}
QJsonObject FolderLayerWrapper::toJson() const
{
QJsonObject json = LayerWrapper::toJson();
QJsonArray childrenJson;
for (auto& child : children)
childrenJson.push_back(child->toJson());
json.insert("children", childrenJson);
json.insert("is-folder", true);
if(this->referencedBy != -1)
json.insert("referenced-by", this->referencedBy);
else
json.insert("referenced-by", QJsonValue());
return json;
}
QJsonObject LeafLayerWrapper::toJson() const
{
QJsonObject json = LayerWrapper::toJson();
json.insert("element", wrappedElement->index);
json.insert("is-folder", false);
return json;
}

View File

@ -60,16 +60,13 @@ class LayerWrapper
// virtual void deleteAll() const = 0; // virtual void deleteAll() const = 0;
virtual void del(); virtual void del();
virtual void delSelf(); virtual void delSelf();
virtual QJsonObject toJson() const;
~LayerWrapper() = default; ~LayerWrapper() = default;
}; };
class FolderLayerWrapper : public LayerWrapper class FolderLayerWrapper : public LayerWrapper
{ {
public: public:
vector<shared_ptr<LayerWrapper>> children; vector<shared_ptr<LayerWrapper>> children;
int referencedBy = -1;
public: public:
@ -83,7 +80,6 @@ class FolderLayerWrapper : public LayerWrapper
void del() override; void del() override;
void delSelf() override; void delSelf() override;
QTreeWidgetItem* getQTreeItem() override; QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override;
}; };
class LeafLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper
@ -97,7 +93,6 @@ class LeafLayerWrapper : public LayerWrapper
void refresh() override; void refresh() override;
LeafLayerWrapper() = default; LeafLayerWrapper() = default;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
QJsonObject toJson() const override;
}; };
Q_DECLARE_METATYPE(LayerWrapper *) Q_DECLARE_METATYPE(LayerWrapper *)

View File

@ -34,7 +34,6 @@
"is-folder": true, "is-folder": true,
"referenced-by": null, "referenced-by": null,
"children": [ "children": [
{ {
"name": "GroupFolderExample", "name": "GroupFolderExample",
"transform": { "transform": {
@ -88,7 +87,6 @@
} }
] ]
}, },
{ {
"name": "ReferencingGroupLayer", "name": "ReferencingGroupLayer",
"transform": { "transform": {