Compare commits
6 Commits
526f33ceba
...
edb7e37b91
Author | SHA1 | Date |
---|---|---|
karlis | edb7e37b91 | |
karlis | 06c96144e4 | |
karlis | 1031ba5808 | |
karlis | 33475f6f57 | |
karlis | 8ca036fafb | |
karlis | c1ad6a61f0 |
|
@ -104,8 +104,9 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\CaptionButton.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidget.cpp" />
|
||||
<ClCompile Include="src\CaptionButton.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidgetItem.cpp" />
|
||||
<ClCompile Include="src\Editor\ElementManager.cpp" />
|
||||
<ClCompile Include="src\Editor\ElementPoolWidget.cpp" />
|
||||
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
||||
|
@ -151,6 +152,7 @@
|
|||
<ClCompile Include="src\SvgParser.cpp" />
|
||||
<ClCompile Include="src\TitleWidget.cpp" />
|
||||
<QtUic Include="EditorWidget.ui" />
|
||||
<QtUic Include="EditorWidgetItem.ui" />
|
||||
<QtUic Include="MainWindow.ui" />
|
||||
<QtUic Include="RendererWidget.ui" />
|
||||
</ItemGroup>
|
||||
|
@ -187,6 +189,7 @@
|
|||
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
|
||||
<QtMoc Include="src\MainWindow.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidget.h" />
|
||||
<ClInclude Include="src\Editor\ElementManager.h" />
|
||||
<QtMoc Include="src\Editor\ElementPoolWidget.h" />
|
||||
<ClInclude Include="src\Editor\GraphicElement.h" />
|
||||
|
@ -217,7 +220,7 @@
|
|||
<QtMoc Include="src\CaptionButton.h" />
|
||||
<QtMoc Include="src\NavigationBarWidget.h" />
|
||||
<QtMoc Include="src\Renderer\RendererWidget.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidget.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidgetItem.h" />
|
||||
<ClInclude Include="src\Renderer\Painting\BvhTree.h" />
|
||||
<ClInclude Include="src\Renderer\Camera.h" />
|
||||
<ClInclude Include="src\Renderer\Painting\CubicBezier.h" />
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
</QtUic>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Editor\EditorWidget.cpp">
|
||||
<ClCompile Include="src\Editor\EditorWidgetItem.cpp">
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Renderer\Camera.cpp">
|
||||
|
@ -207,6 +207,9 @@
|
|||
<ClCompile Include="src\Editor\PixelPath.cpp">
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\EditorWidget.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\ElementPoolWidget.cpp">
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
|
@ -215,7 +218,7 @@
|
|||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||
<Filter>Header Files\Renderer</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\EditorWidget.h">
|
||||
<QtMoc Include="src\Editor\EditorWidgetItem.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Renderer\RendererWidget.h">
|
||||
|
@ -245,6 +248,9 @@
|
|||
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\EditorWidget.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\ElementPoolWidget.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</QtMoc>
|
||||
|
@ -328,7 +334,7 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="EditorWidget.ui">
|
||||
<QtUic Include="EditorWidgetItem.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="RendererWidget.ui">
|
||||
|
|
|
@ -1,113 +1,193 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditorWidgetClass</class>
|
||||
<widget class="QWidget" name="EditorWidgetClass">
|
||||
<class>EditorWidget</class>
|
||||
<widget class="QWidget" name="EditorWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1124</width>
|
||||
<height>695</height>
|
||||
<width>1139</width>
|
||||
<height>685</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>RendererWidget</string>
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,20">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</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>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,1,1,1,1,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="createButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新建</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>打开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveAsButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>另存为</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>关闭</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
<?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>
|
|
@ -1,62 +1,48 @@
|
|||
#include "EditorWidget.h"
|
||||
#include "EditorWidgetItem.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
|
||||
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
||||
EditorWidget::EditorWidget(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, &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)
|
||||
{
|
||||
treeWidget->root = layerManager->getRoot();
|
||||
treeWidget->refresh();
|
||||
treeWidget->addTopLevelItem(treeWidget->root->getQTreeItem());
|
||||
}
|
||||
ui.setupUi(this);
|
||||
this->createButton = ui.createButton;
|
||||
this->closeButton = ui.closeButton;
|
||||
this->saveButton = ui.saveButton;
|
||||
this->saveAsButton = ui.saveAsButton;
|
||||
this->openButton = ui.openButton;
|
||||
this->tabWidget = ui.tabWidget;
|
||||
while (this->tabWidget->count() > 0)
|
||||
{
|
||||
this->tabWidget->removeTab(0);
|
||||
}
|
||||
connect(this->createButton, &QPushButton::clicked, this, [this]() {
|
||||
static int count = 0;
|
||||
this->tabWidget->addTab(new EditorWidgetItem("../data.json",this), "untitled" + QString::number(count++));
|
||||
});
|
||||
connect(this->openButton, &QPushButton::clicked, this, [this]() {
|
||||
QString fileName = QFileDialog::getOpenFileName(this->saveAsButton, QString::fromLocal8Bit("´ò¿ª"), "", QString::fromLocal8Bit("JSONÎļþ(*.json)"));
|
||||
this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName);
|
||||
});
|
||||
connect(this->closeButton, &QPushButton::clicked, this, [this]() {
|
||||
this->tabWidget->removeTab(this->tabWidget->currentIndex());
|
||||
});
|
||||
connect(this->saveButton, &QPushButton::clicked, this, [this]() {
|
||||
EditorWidgetItem* item = dynamic_cast<EditorWidgetItem*>(this->tabWidget->currentWidget());
|
||||
if (item != nullptr)
|
||||
{
|
||||
//item->save();
|
||||
}
|
||||
});
|
||||
connect(this->saveAsButton, &QPushButton::clicked, this, [this]() {
|
||||
EditorWidgetItem* item = dynamic_cast<EditorWidgetItem*>(this->tabWidget->currentWidget());
|
||||
if (item != nullptr)
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this->saveAsButton, QString::fromLocal8Bit("Áí´æΪ"), "", QString::fromLocal8Bit("JSONÎļþ(*.json)"));
|
||||
item->saveAs(fileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -1,39 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "ElementManager.h"
|
||||
#include "InfoDisplayWidget.h"
|
||||
#include "LayerManager.h"
|
||||
#include "LayerTreeWidget.h"
|
||||
#include "PreviewWindow.h"
|
||||
#include <qwidget.h>
|
||||
#include "ui_EditorWidget.h"
|
||||
#include <QPainter>
|
||||
#include <QTreeWidget>
|
||||
#include <QWidget>
|
||||
|
||||
class EditorWidget : public QWidget
|
||||
class EditorWidget :
|
||||
public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Ui::EditorWidget ui;
|
||||
QTabWidget* tabWidget;
|
||||
QPushButton* createButton;
|
||||
QPushButton* closeButton;
|
||||
QPushButton* saveButton;
|
||||
QPushButton* saveAsButton;
|
||||
QPushButton* openButton;
|
||||
|
||||
private:
|
||||
// DATA PART
|
||||
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()=default;
|
||||
|
||||
public:
|
||||
EditorWidget(QWidget *parent = nullptr);
|
||||
~EditorWidget();
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onLayerChange(LayerWrapper *layer);
|
||||
void triggerRefreshPreview();
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
#include "EditorWidgetItem.h"
|
||||
|
||||
EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QImage x;
|
||||
displayLayer = nullptr;
|
||||
displayElement = nullptr;
|
||||
ui.setupUi(this);
|
||||
previewWindow = ui.Preview;
|
||||
treeWidget = ui.LayerTree;
|
||||
tabWidget = ui.DisplayTab;
|
||||
this->filePath = filePath;
|
||||
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.setFileName(filePath);
|
||||
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();
|
||||
}
|
||||
|
||||
void EditorWidgetItem::save() const
|
||||
{
|
||||
saveImpl(this->filePath);
|
||||
}
|
||||
|
||||
void EditorWidgetItem::saveAs(QString filePath) const
|
||||
{
|
||||
saveImpl(filePath);
|
||||
}
|
||||
|
||||
void EditorWidgetItem::saveImpl(QString filePath) const
|
||||
{
|
||||
QJsonObject source1 = layerManager->toJson();
|
||||
QJsonObject source2 = elementManager->toJson();
|
||||
QJsonObject json;
|
||||
json.insert("width", 1080);
|
||||
json.insert("height", 1080);
|
||||
json.insert("root-layer", source1.value("root-layer"));
|
||||
json.insert("elements", source2.value("elements"));
|
||||
QJsonDocument doc(json);
|
||||
QFile file(filePath);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(doc.toJson());
|
||||
file.close();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#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;
|
||||
QString filePath;
|
||||
void saveImpl(QString filePath)const;
|
||||
|
||||
public:
|
||||
EditorWidgetItem(QString filePath, QWidget *parent = nullptr);
|
||||
~EditorWidgetItem();
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void save() const;
|
||||
void saveAs(QString filePath)const;
|
||||
|
||||
private slots:
|
||||
void onLayerChange(LayerWrapper *layer);
|
||||
void triggerRefreshPreview();
|
||||
};
|
|
@ -3,6 +3,7 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
|||
{
|
||||
auto elementsJson = source.value("elements").toArray();
|
||||
qDebug() << elementsJson.size();
|
||||
int index = 0;
|
||||
for (auto elementJson : elementsJson)
|
||||
{
|
||||
if (elementJson.toObject().value("type").toString() == "group")
|
||||
|
@ -12,6 +13,8 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
|||
|
||||
(*elements.rbegin())->renderer = renderer;
|
||||
}
|
||||
for (auto element : elements)
|
||||
element->index = index++;
|
||||
}
|
||||
|
||||
void ElementManager::addElement(GraphicElement *element)
|
||||
|
@ -33,3 +36,13 @@ GraphicElement *ElementManager::getElementById(int index)
|
|||
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;
|
||||
}
|
|
@ -19,6 +19,7 @@ class ElementManager
|
|||
~ElementManager();
|
||||
void addElement(GraphicElement *element);
|
||||
void removeElement(GraphicElement *pElement);
|
||||
QJsonObject toJson()const;
|
||||
/**
|
||||
* only used in initialization
|
||||
*/
|
||||
|
|
|
@ -76,3 +76,10 @@ PixelPath GroupElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeD
|
|||
// rawPath.addPath(path);
|
||||
// }
|
||||
//}
|
||||
//TODO : Ìí¼Óϸ½Ú
|
||||
QJsonObject GraphicElement::toJson() const
|
||||
{
|
||||
QJsonObject result;
|
||||
result.insert("name", name);
|
||||
return result;
|
||||
}
|
|
@ -22,7 +22,9 @@ class GraphicElement
|
|||
public:
|
||||
Renderer::ElementRenderer *renderer;
|
||||
QString name = "";
|
||||
int index;
|
||||
// TODO: ¸ÄΪBitmapPath
|
||||
virtual QJsonObject toJson() const;
|
||||
virtual PixelPath getPaintObject() const = 0;
|
||||
virtual PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const = 0;
|
||||
};
|
||||
|
|
|
@ -62,11 +62,20 @@ bool LayerManager::changeParent(FolderLayerWrapper *newParent) const
|
|||
selectedLayers[0]->setParent(newParent);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LayerManager::addLayer(LayerWrapper *layer)
|
||||
{
|
||||
layerSet.insert(layer);
|
||||
}
|
||||
|
||||
void LayerManager::removeLayer(LayerWrapper *layer)
|
||||
{
|
||||
layerSet.erase(layer);
|
||||
}
|
||||
|
||||
QJsonObject LayerManager::toJson() const
|
||||
{
|
||||
QJsonObject result;
|
||||
result.insert("root-layer", root->toJson());
|
||||
return result;
|
||||
}
|
|
@ -31,6 +31,7 @@ class LayerManager
|
|||
LayerWrapper *getRoot() const;
|
||||
LayerManager() = default;
|
||||
LayerManager(QJsonObject source, ElementManager* elementManager);
|
||||
QJsonObject toJson() const;
|
||||
void paint(QPainter *painter, QSize size) const;
|
||||
bool rename(QString newName) const;
|
||||
bool combine() const;
|
||||
|
|
|
@ -53,6 +53,7 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
|
|||
auto p = reinterpret_cast<GroupElement *>(elementManager->getElementById(referencedJson.toInt()));
|
||||
if (p != nullptr)
|
||||
p->setSourceLayer(this);
|
||||
this->referencedBy = referencedJson.toInt();
|
||||
}
|
||||
for (auto childJson : childrenJson)
|
||||
{
|
||||
|
@ -95,7 +96,6 @@ void FolderLayerWrapper::refresh()
|
|||
{
|
||||
cache.clear();
|
||||
for (auto& child : children) {
|
||||
qDebug() << child.get();
|
||||
cache.addPath(child.get()->getCache());
|
||||
}
|
||||
LayerWrapper::refresh();
|
||||
|
@ -181,3 +181,40 @@ QTreeWidgetItem* FolderLayerWrapper::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;
|
||||
}
|
|
@ -60,13 +60,16 @@ class LayerWrapper
|
|||
// virtual void deleteAll() const = 0;
|
||||
virtual void del();
|
||||
virtual void delSelf();
|
||||
virtual QJsonObject toJson() const;
|
||||
~LayerWrapper() = default;
|
||||
|
||||
};
|
||||
|
||||
class FolderLayerWrapper : public LayerWrapper
|
||||
{
|
||||
public:
|
||||
vector<shared_ptr<LayerWrapper>> children;
|
||||
int referencedBy = -1;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -80,6 +83,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
void del() override;
|
||||
void delSelf() override;
|
||||
QTreeWidgetItem* getQTreeItem() override;
|
||||
QJsonObject toJson() const override;
|
||||
};
|
||||
|
||||
class LeafLayerWrapper : public LayerWrapper
|
||||
|
@ -93,6 +97,7 @@ class LeafLayerWrapper : public LayerWrapper
|
|||
void refresh() override;
|
||||
LeafLayerWrapper() = default;
|
||||
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||
QJsonObject toJson() const override;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(LayerWrapper *)
|
||||
|
|
|
@ -150,6 +150,6 @@ void InfoDisplayWidget::triggerSelfRefresh()
|
|||
{
|
||||
if (this->displayLayer != nullptr)
|
||||
this->generateLayerForm();
|
||||
else
|
||||
if (this->displayElement != nullptr)
|
||||
this->generateElementForm();
|
||||
}
|
|
@ -37,25 +37,30 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
this->selectedItem = item;
|
||||
// TODO
|
||||
menu.addAction(QString::fromLocal8Bit("´´½¨×Ó½Úµã"), this, &LayerTreeWidget::onRenameEvent);
|
||||
menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent);
|
||||
// menu.addAction("Copy", this, &LayerTreeWidget::onRenameEvent);
|
||||
if (item != nullptr && item->childCount() > 0)
|
||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
//if (item != root->getQTreeItem())
|
||||
//{
|
||||
menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent);
|
||||
// menu.addAction("Copy", this, &LayerTreeWidget::onRenameEvent);
|
||||
if (item != nullptr && item->childCount() > 0)
|
||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||
if (this->selectedItem == nullptr)
|
||||
return;
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->delSelf();
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() {
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() {
|
||||
if (this->selectedItem == nullptr)
|
||||
return;
|
||||
return;
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->del();
|
||||
layer->getParent()->removeChild(layer);
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
});
|
||||
//}
|
||||
menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"height": 1080,
|
||||
"width": 1080,
|
||||
"elements": [
|
||||
{
|
||||
"name": "ababa",
|
||||
"type": "svg-file",
|
||||
"data": {
|
||||
"include": "./svg/2.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ababa-group",
|
||||
"type": "group",
|
||||
"data": {
|
||||
"reference-layer": "0.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"root-layer": {
|
||||
"name": "root",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"scale": {
|
||||
"x": 1.0,
|
||||
"y": 1.0
|
||||
},
|
||||
"rotation": 0.0
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": true,
|
||||
"referenced-by": null,
|
||||
"children": [
|
||||
|
||||
{
|
||||
"name": "GroupFolderExample",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 50,
|
||||
"y": 50
|
||||
},
|
||||
"scale": {
|
||||
"x": 1.0,
|
||||
"y": 1.0
|
||||
},
|
||||
"rotation": 0.0
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": true,
|
||||
"referenced-by": 1,
|
||||
"children": [
|
||||
{
|
||||
"name": "Leaf1",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"scale": {
|
||||
"x": 1.0,
|
||||
"y": 1.0
|
||||
},
|
||||
"rotation": 0.0
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": false,
|
||||
"element": 0
|
||||
},
|
||||
{
|
||||
"name": "Leaf2",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 150,
|
||||
"y": 0
|
||||
},
|
||||
"scale": {
|
||||
"x": 1.5,
|
||||
"y": 1.5
|
||||
},
|
||||
"rotation": 0.0
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": false,
|
||||
"element": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "ReferencingGroupLayer",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 100,
|
||||
"y": 0
|
||||
},
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
},
|
||||
"rotation": 45
|
||||
},
|
||||
"effects": [],
|
||||
"is-folder": false,
|
||||
"element": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
{
|
||||
"elements": [
|
||||
{
|
||||
"name": ""
|
||||
},
|
||||
{
|
||||
"name": ""
|
||||
}
|
||||
],
|
||||
"height": 1080,
|
||||
"root-layer": {
|
||||
"children": [
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"element": 0,
|
||||
"is-folder": false,
|
||||
"name": "Leaf1",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 0,
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"element": 0,
|
||||
"is-folder": false,
|
||||
"name": "Leaf2",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 150,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 0,
|
||||
"scale": {
|
||||
"x": 1.5,
|
||||
"y": 1.5
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"is-folder": true,
|
||||
"name": "GroupFolderExample",
|
||||
"referenced-by": 1,
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 50,
|
||||
"y": 50
|
||||
},
|
||||
"rotation": 0,
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"element": 1,
|
||||
"is-folder": false,
|
||||
"name": "ReferencingGroupLayer",
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 100,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 45,
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"is-folder": true,
|
||||
"name": "root",
|
||||
"referenced-by": null,
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 0,
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"width": 1080
|
||||
}
|
Loading…
Reference in New Issue