分支合并

白封羽 2023-01-19 15:41:21 +08:00
commit 4eba93a4f7
24 changed files with 430 additions and 33 deletions

View File

@ -105,6 +105,8 @@
<ClCompile Include="src\Editor\LayerManager.cpp" /> <ClCompile Include="src\Editor\LayerManager.cpp" />
<ClCompile Include="src\Editor\LayerWrapper.cpp" /> <ClCompile Include="src\Editor\LayerWrapper.cpp" />
<ClCompile Include="src\Editor\PreviewWindow.cpp" /> <ClCompile Include="src\Editor\PreviewWindow.cpp" />
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp" />
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp" />
<ClCompile Include="src\Editor\third-party modules\qquick\qquicksvgparser.cpp" /> <ClCompile Include="src\Editor\third-party modules\qquick\qquicksvgparser.cpp" />
<ClCompile Include="src\Editor\third-party modules\util\SvgFileLoader.cpp" /> <ClCompile Include="src\Editor\third-party modules\util\SvgFileLoader.cpp" />
<ClCompile Include="src\IconWidget.cpp" /> <ClCompile Include="src\IconWidget.cpp" />
@ -162,6 +164,8 @@
<None Include="Shaders\ssgi.comp" /> <None Include="Shaders\ssgi.comp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" />
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
<ClInclude Include="src\Editor\third-party modules\qquick\qtquickglobal.h" /> <ClInclude Include="src\Editor\third-party modules\qquick\qtquickglobal.h" />
<ClInclude Include="src\Editor\third-party modules\qquick\qtquickglobal_p.h" /> <ClInclude Include="src\Editor\third-party modules\qquick\qtquickglobal_p.h" />
<ClInclude Include="src\Editor\third-party modules\qquick\qquicksvgparser_p.h" /> <ClInclude Include="src\Editor\third-party modules\qquick\qquicksvgparser_p.h" />

View File

@ -173,6 +173,13 @@
</ClCompile> </ClCompile>
<ClCompile Include="src\Editor\third-party modules\SvgHelper.cpp"> <ClCompile Include="src\Editor\third-party modules\SvgHelper.cpp">
<Filter>Source Files\Editor\third-party modules</Filter> <Filter>Source Files\Editor\third-party modules</Filter>
<Filter>Source Files\Editor\third-party modules</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Renderer\Painting\ElementStyle.cpp"> <ClCompile Include="src\Renderer\Painting\ElementStyle.cpp">
<Filter>Source Files\Renderer\Painting</Filter> <Filter>Source Files\Renderer\Painting</Filter>
@ -206,6 +213,12 @@
<QtMoc Include="src\Editor\PreviewWindow.h"> <QtMoc Include="src\Editor\PreviewWindow.h">
<Filter>Header Files\Editor</Filter> <Filter>Header Files\Editor</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Shaders\shader.frag"> <None Include="Shaders\shader.frag">
@ -333,9 +346,6 @@
<ClInclude Include="src\Editor\ElementManager.h"> <ClInclude Include="src\Editor\ElementManager.h">
<Filter>Header Files\Editor</Filter> <Filter>Header Files\Editor</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Editor\LayerWrapper.h">
<Filter>Header Files\Editor</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\LineTree.h"> <ClInclude Include="src\Renderer\Painting\LineTree.h">
<Filter>Header Files\Renderer\Painting</Filter> <Filter>Header Files\Renderer\Painting</Filter>
</ClInclude> </ClInclude>
@ -360,6 +370,13 @@
<ClInclude Include="src\Renderer\Painting\ElementStyle.h"> <ClInclude Include="src\Renderer\Painting\ElementStyle.h">
<Filter>Header Files\Renderer\Painting</Filter> <Filter>Header Files\Renderer\Painting</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Editor\LayerWrapper.h">
<Filter>Header Files\Editor</Filter>
<Filter>Header Files\Editor\third-party modules\qquick</Filter>
</ClInclude>
<ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h">
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtRcc Include="MainWindow.qrc"> <QtRcc Include="MainWindow.qrc">

View File

@ -27,18 +27,60 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,30"> <widget class="QWidget" name="MainWindow" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,30">
<item> <item>
<widget class="QLabel" name="title"> <widget class="QLabel" name="Title">
<property name="text"> <property name="text">
<string>纹理编辑</string> <string>纹理编辑</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,18,5">
<item>
<widget class="QWidget" name="LeftBar" native="true"/>
</item>
<item> <item>
<widget class="PreviewWindow" name="Preview"/> <widget class="PreviewWindow" name="Preview"/>
</item> </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>
</widget>
</item>
</layout> </layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -49,6 +91,17 @@
<extends>QOpenGLWidget</extends> <extends>QOpenGLWidget</extends>
<header>PreviewWindow.h</header> <header>PreviewWindow.h</header>
</customwidget> </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> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -876,6 +876,49 @@ void drawLine(in float d, in uint styleIndex, out vec4 elementColor, out vec2 me
} }
} }
void drawLine(in float d, in uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness)
{
elementColor = vec4(1);
metallicRoughness = vec2(0.8);
switch(int(elementData[styleIndex+3]))
{
case 0:
{
elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1);
metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]);
break;
}
case 1:
{
elementColor = vec4(mix(vec3(0), vec3(1), d), 1);
metallicRoughness = vec2(0,0.8);
break;
}
case 2:
{
float levels[] = {0.25,0.5,0.75};
vec3 colors[] = {vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(1,1,0)};
int i = 0;
while(i<3)
{
if(d<levels[i])
{
elementColor = vec4(colors[i], 1);
metallicRoughness = vec2(0,0.8);
break;
}
i++;
}
if(i==3)
{
elementColor = vec4(colors[i], 1);
metallicRoughness = vec2(0,0.8);
}
break;
}
}
}
bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metallicRoughness, inout vec3 debugBVH = vec3(0)) bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metallicRoughness, inout vec3 debugBVH = vec3(0))
{ {
bool hitElement = false; bool hitElement = false;

View File

@ -2,9 +2,18 @@
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent) EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
{ {
displayLayer = nullptr;
displayElement = nullptr;
ui.setupUi(this); ui.setupUi(this);
previewWindow = ui.Preview; previewWindow = ui.Preview;
qDebug() << "123"; 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);
// &EditorWidget::triggerRefreshPreview);
// test // test
QFile settingFile; QFile settingFile;
settingFile.setFileName("../data.json"); settingFile.setFileName("../data.json");
@ -19,6 +28,10 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
elementManager = new ElementManager(source); elementManager = new ElementManager(source);
layerManager = new LayerManager(source, elementManager); layerManager = new LayerManager(source, elementManager);
previewWindow->initialize(layerManager); previewWindow->initialize(layerManager);
if (layerManager->getRoot() != nullptr)
{
treeWidget->addTopLevelItem(layerManager->getRoot()->qTreeItem);
}
} }
EditorWidget::~EditorWidget() EditorWidget::~EditorWidget()
@ -28,3 +41,16 @@ EditorWidget::~EditorWidget()
void EditorWidget::paintEvent(QPaintEvent *event) 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,24 +1,38 @@
#pragma once #pragma once
#include "ElementManager.h" #include "ElementManager.h"
#include "InfoDisplayWidget.h"
#include "LayerManager.h" #include "LayerManager.h"
#include "LayerTreeWidget.h"
#include "PreviewWindow.h" #include "PreviewWindow.h"
#include "ui_EditorWidget.h" #include "ui_EditorWidget.h"
#include <QPainter> #include <QPainter>
#include <QTreeWidget>
#include <QWidget> #include <QWidget>
class EditorWidget : public QWidget class EditorWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::EditorWidgetClass ui; // DATA PART
PreviewWindow *previewWindow; PreviewWindow *previewWindow;
ElementManager *elementManager; ElementManager *elementManager;
LayerManager *layerManager; LayerManager *layerManager;
// QT GUI PART
Ui::EditorWidgetClass ui;
LayerTreeWidget *treeWidget;
QTabWidget *tabWidget;
InfoDisplayWidget *layerInfoDisplayWidget, *elementInfoDisplayWidget;
// QT DATA PART
LayerWrapper *displayLayer;
GraphicElement *displayElement;
public: public:
EditorWidget(QWidget *parent = nullptr); EditorWidget(QWidget *parent = nullptr);
~EditorWidget(); ~EditorWidget();
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
private slots:
void onLayerChange(LayerWrapper *layer);
void triggerRefreshPreview();
}; };

View File

@ -11,12 +11,14 @@ void SimpleElement::loadSvgFile(const QString& filePath)
// TODO ÑùʽÎÊÌâ // TODO ÑùʽÎÊÌâ
SvgFileLoader loader; SvgFileLoader loader;
loader.loadSvgFile(filePath, painterPath); loader.loadSvgFile(filePath, painterPath);
qDebug() << "load svg file success "<<painterPath.elementCount();
} }
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{ {
painterPath.clear(); painterPath.clear();
loadSvgFile(jsonSource.value("data").toObject().value("include").toString()); loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
//loadSvgFile(jsonSource.value("data").toObject().value("include").toString());
} }
GroupElement::GroupElement(FolderLayerWrapper *sourceLayer) GroupElement::GroupElement(FolderLayerWrapper *sourceLayer)

View File

@ -7,6 +7,10 @@ LayerManager::LayerManager(QJsonObject source, ElementManager *elementManager)
else else
root = new LeafLayerWrapper(rootJson, elementManager, nullptr); root = new LeafLayerWrapper(rootJson, elementManager, nullptr);
} }
LayerWrapper *LayerManager::getRoot() const
{
return root;
}
void LayerManager::paint(QPainter *painter) const void LayerManager::paint(QPainter *painter) const
{ {
painter->drawPath(root->getCache()); painter->drawPath(root->getCache());
@ -57,3 +61,11 @@ bool LayerManager::changeParent(FolderLayerWrapper *newParent) const
selectedLayers[0]->setParent(newParent); selectedLayers[0]->setParent(newParent);
return true; return true;
} }
void LayerManager::addLayer(LayerWrapper *layer)
{
layerSet.insert(layer);
}
void LayerManager::removeLayer(LayerWrapper *layer)
{
layerSet.erase(layer);
}

View File

@ -3,9 +3,11 @@
#include "LayerWrapper.h" #include "LayerWrapper.h"
#include <QJsonArray> #include <QJsonArray>
#include <QPainter> #include <QPainter>
#include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
using std::pair; using std::pair;
using std::set;
using std::vector; using std::vector;
class ElementManager; class ElementManager;
class LayerWrapper; class LayerWrapper;
@ -21,8 +23,13 @@ class LayerManager
LayerPtrs involvedLeafLayersCache; LayerPtrs involvedLeafLayersCache;
bool singleSelectedCheck() const; bool singleSelectedCheck() const;
bool multipleSelectedCheck() const; bool multipleSelectedCheck() const;
set<LayerWrapper *> layerSet;
public: public:
void addLayer(LayerWrapper *layer);
void removeLayer(LayerWrapper *layer);
LayerWrapper *getRoot() const;
LayerManager() = default;
LayerManager(QJsonObject source, ElementManager *elementManager); LayerManager(QJsonObject source, ElementManager *elementManager);
void paint(QPainter *painter) const; void paint(QPainter *painter) const;
bool rename(QString newName) const; bool rename(QString newName) const;

View File

@ -33,15 +33,23 @@ LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
{ {
this->parent = shared_ptr<LayerWrapper>(parent); this->parent = shared_ptr<LayerWrapper>(parent);
auto transformJson = json.value("transform").toObject(); auto transformJson = json.value("transform").toObject();
property.offset = { transformJson.value("offset").toObject().value("x").toDouble(), transformJson.value("offset").toObject().value("y").toDouble() }; property.name = json.value("name").toString();
property.scale = { transformJson.value("scale").toObject().value("x").toDouble(), transformJson.value("scale").toObject().value("y").toDouble() }; property.offset = {transformJson.value("offset").toObject().value("x").toDouble(),
property.rotation = { transformJson.value("rotation").toDouble()}; transformJson.value("offset").toObject().value("y").toDouble()};
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
transformJson.value("scale").toObject().value("y").toDouble()};
property.rotation = {transformJson.value("rotation").toDouble()};
qTreeItem = new QTreeWidgetItem();
qTreeItem->setText(0, property.name);
if (parent != nullptr)
parent->qTreeItem->addChild(qTreeItem);
qTreeItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
} }
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent) FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent) : LayerWrapper(json, parent)
{ {
qDebug() << json.value("name").toString()<<" "<<this; qDebug() << json.value("name").toString() << " " << this;
QJsonArray childrenJson = json.value("children").toArray(); QJsonArray childrenJson = json.value("children").toArray();
QJsonValue referencedJson = json.value("referenced-by"); QJsonValue referencedJson = json.value("referenced-by");
if (!referencedJson.isNull()) if (!referencedJson.isNull())
@ -71,16 +79,16 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const
{ {
QTransform trans; QTransform trans;
double delX = cache.boundingRect().width(); double centerX = cache.boundingRect().center().x();
double delY = cache.boundingRect().height(); double centerY = cache.boundingRect().center().y();
trans.translate(-delX,-delY); qDebug() << name << " " << cache.boundingRect().center();
qDebug() << name << " " << cache.boundingRect();
trans.translate(centerX, centerY);
trans.scale(scale.x(), scale.y()); trans.scale(scale.x(), scale.y());
trans.rotate(rotation); trans.rotate(rotation);
trans.translate(-centerX, -centerY);
trans.translate(offset.x(), offset.y());
cache = trans.map(cache); cache = trans.map(cache);
trans.reset();
trans.translate(delX+offset.x(), delY+offset.y());
cache = trans.map(cache);
// cache.translate(offset);
} }
void LayerWrapper::refresh() void LayerWrapper::refresh()
{ {
@ -98,7 +106,8 @@ void FolderLayerWrapper::refresh()
void LeafLayerWrapper::refresh() void LeafLayerWrapper::refresh()
{ {
cache.clear(); cache.clear();
if (wrappedElement != nullptr) { if (wrappedElement != nullptr)
{
cache.addPath(wrappedElement->getPaintObject()); cache.addPath(wrappedElement->getPaintObject());
} }
LayerWrapper::refresh(); LayerWrapper::refresh();
@ -113,3 +122,12 @@ void FolderLayerWrapper::removeAllChild()
{ {
children.clear(); children.clear();
} }
namespace LayerEvent
{
static void onDoubleClick(QTreeWidgetItem *qItem, LayerWrapper *layerWrapper)
{
}
} // namespace LayerEvent

View File

@ -7,7 +7,9 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QJSonObject> #include <QJSonObject>
#include <QLine> #include <QLine>
#include <QObject>
#include <QPoint> #include <QPoint>
#include <QTreeWidget>
#include <memory> #include <memory>
#include <vector> #include <vector>
using std::shared_ptr; using std::shared_ptr;
@ -19,6 +21,7 @@ class ElementManager;
class LayerWrapper class LayerWrapper
{ {
protected: protected:
shared_ptr<LayerWrapper> parent; shared_ptr<LayerWrapper> parent;
QPointF referencePoint; QPointF referencePoint;
@ -26,6 +29,7 @@ class LayerWrapper
QPainterPath cache; QPainterPath cache;
public: public:
QTreeWidgetItem *qTreeItem;
struct SimpleProperty struct SimpleProperty
{ {
QString name = ""; QString name = "";
@ -42,6 +46,11 @@ class LayerWrapper
LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, LayerWrapper *parent); LayerWrapper(QJsonObject json, LayerWrapper *parent);
LayerWrapper() = default; LayerWrapper() = default;
// TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
// virtual void deleteSelf() const = 0;
// virtual void deleteAll() const = 0;
}; };
class FolderLayerWrapper : public LayerWrapper class FolderLayerWrapper : public LayerWrapper
@ -68,3 +77,5 @@ class LeafLayerWrapper : public LayerWrapper
LeafLayerWrapper() = default; LeafLayerWrapper() = default;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent); LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent);
}; };
Q_DECLARE_METATYPE(LayerWrapper *)

View File

@ -0,0 +1,80 @@
#include "InfoDisplayWidget.h"
#include <QLineEdit>
#include <QTextBlock>
void InfoDisplayWidget::setLayer(LayerWrapper *layer)
{
this->displayLayer = layer;
generateLayerForm();
}
void InfoDisplayWidget::setElement(GraphicElement *element)
{
this->displayElement = element;
generateElementForm();
}
void InfoDisplayWidget::generateLayerForm()
{
QLayoutItem *item;
if (this->layout() != nullptr)
{
while ((item = this->layout()->takeAt(0)) != nullptr)
{
delete item->widget();
delete item;
}
delete this->layout();
}
QFormLayout *layout = new QFormLayout();
layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
if (this->displayLayer == nullptr)
{
layout->addRow("no selected layer", new QLabel());
}
else
{
QLineEdit *name = new QLineEdit(this->displayLayer->property.name, this);
QLineEdit *rotation = new QLineEdit(QString::number(this->displayLayer->property.rotation, 'f', 0), this);
QLineEdit *offsetX = new QLineEdit(QString::number(this->displayLayer->property.offset.x()), this);
QLineEdit *offsetY = new QLineEdit(QString::number(this->displayLayer->property.offset.y()), this);
QLineEdit *scaleX = new QLineEdit(QString::number(this->displayLayer->property.scale.x()), this);
QLineEdit *scaleY = new QLineEdit(QString::number(this->displayLayer->property.scale.y()), this);
name->setDisabled(true);
rotation->setValidator(new QIntValidator(-1000, 1000, this));
connect(rotation, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.rotation = content.toDouble();
emit requireRefreshPreview();
});
offsetX->setValidator(new QIntValidator(-1000, 1000, this));
connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
emit requireRefreshPreview();
});
offsetY->setValidator(new QIntValidator(-1000, 1000, this));
connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
emit requireRefreshPreview();
});
scaleX->setValidator(new QDoubleValidator(0.01, 100, 4, this));
connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
emit requireRefreshPreview();
});
scaleY->setValidator(new QDoubleValidator(0.01, 100, 4, this));
connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
emit requireRefreshPreview();
});
layout->addRow("layer name:", name);
layout->addRow("rotation:", rotation);
layout->addRow("offset-X:", offsetX);
layout->addRow("offset-Y:", offsetY);
layout->addRow("scale-X:", scaleX);
layout->addRow("scale-Y:", scaleY);
layout->setRowWrapPolicy(QFormLayout::DontWrapRows);
}
this->setLayout(layout);
}
void InfoDisplayWidget::generateElementForm()
{
}

View File

@ -0,0 +1,23 @@
#pragma once
#include "GraphicElement.h"
#include "LayerWrapper.h"
#include <QFormLayout>
#include <QLabel>
#include <QWidget>
class InfoDisplayWidget : public QWidget
{
Q_OBJECT
private:
LayerWrapper *displayLayer;
GraphicElement *displayElement;
public:
void setLayer(LayerWrapper *layer);
void setElement(GraphicElement *element);
void generateLayerForm();
void generateElementForm();
signals:
void requireRefreshPreview();
};

View File

@ -0,0 +1,59 @@
#include "LayerTreeWidget.h"
#include <QInputDialog>
#include <QMenu>
LayerTreeWidget::LayerTreeWidget(QWidget *parent)
{
emit displayLayerChange(nullptr);
this->selectedItem = nullptr;
this->copiedItem = nullptr;
this->setContextMenuPolicy(Qt::CustomContextMenu);
this->setHeaderLabel("Layer Content");
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
connect(this, &QTreeWidget::currentItemChanged, [=](QTreeWidgetItem *currentItem) {
this->selectedItem = currentItem;
emit displayLayerChange(this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>());
});
// connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
}
// void LayerTreeWidget::mouseDoubleClickEvent(QMouseEvent *event)
//{
// // stay empty to avoid the default behavior
// }
//
// void LayerTreeWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
//{
// this->selectedItem = item;
// // TODO
// }
void LayerTreeWidget::popMenu(const QPoint &pos)
{
QMenu menu;
QTreeWidgetItem *item = itemAt(pos);
this->selectedItem = item;
// TODO
menu.addAction("Add Child", this, &LayerTreeWidget::onRenameEvent);
menu.addAction("Rename", this, &LayerTreeWidget::onRenameEvent);
menu.addAction("Copy", this, &LayerTreeWidget::onRenameEvent);
if (item != nullptr && item->childCount() > 0)
menu.addAction("Delete (Self Only)", this, &LayerTreeWidget::onRenameEvent);
menu.addAction("Delete", this, &LayerTreeWidget::onRenameEvent);
menu.exec(mapToGlobal(pos));
}
void LayerTreeWidget::onRenameEvent()
{
if (this->selectedItem == nullptr)
return;
qDebug() << this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>()->property.name;
bool bOk = false;
QString sName =
QInputDialog::getText(this, "Rename", "New Name:", QLineEdit::Normal, this->selectedItem->text(0), &bOk);
if (bOk && !sName.isEmpty())
{
this->selectedItem->setText(0, sName);
this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>()->property.name = sName;
}
emit displayLayerChange(this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>());
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "LayerWrapper.h"
#include <QPoint>
#include <QTreeWidget>
class LayerTreeWidget : public QTreeWidget
{
Q_OBJECT
private:
QTreeWidgetItem *selectedItem;
LayerWrapper *copiedItem;
public:
LayerTreeWidget(QWidget *parent = nullptr);
void onRenameEvent();
void popMenu(const QPoint &pos);
// void mouseDoubleClickEvent(QMouseEvent *event) override;
// void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0);
signals:
void displayLayerChange(LayerWrapper *);
};

View File

@ -6,7 +6,7 @@
"name": "ababa", "name": "ababa",
"type": "svg-file", "type": "svg-file",
"data": { "data": {
"include": "./svg/ababa.svg" "include": "./svg/2.svg"
} }
}, },
{ {

1
svg/0.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 106.93 99.81"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>0</title><g id="图层_2" data-name="图层 2"><polyline class="cls-1" points="27.24 16.75 27.24 2.15 7.2 2.15 7.2 22.78 46.7 22.78"/></g><g id="图层_3" data-name="图层 3"><polyline class="cls-1" points="27.24 30.37 27.24 44.97 0 44.97"/></g><g id="图层_4" data-name="图层 4"><path class="cls-1" d="M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15" transform="translate(-287.18 -56.2)"/></g><g id="图层_5" data-name="图层 5"><path class="cls-1" d="M339.72,85.41V58.75a69.07,69.07,0,0,1,14.79,0c5.9.63,9.31,1,12.84,3.5,1.76,1.22,6.37,4.43,6.68,9.92.25,4.38-2.27,9.26-6.72,11-3.5,1.39-8.46,1-10.71-2.06-.14-.18-2-2.82-.92-5.46.63-1.51,2.34-3.23,4.28-2.92a3.76,3.76,0,0,1,2.33,1.55" transform="translate(-287.18 -56.2)"/></g><g id="图层_6" data-name="图层 6"><path class="cls-1" d="M301.38,145.93a8.21,8.21,0,0,1-.77,5.83c-.26.44-2.5,4.23-5.84,3.7a5,5,0,0,1-3.89-3.5c-.1-.35-1-3,.58-4.09a3.28,3.28,0,0,1,3.89.58" transform="translate(-287.18 -56.2)"/><path class="cls-1" d="M323.18,115.76a7.37,7.37,0,0,1,7.39-8.17c.49,0,4.07.12,5.65,2.92.19.34,1.52,2.7.19,4.67a4.33,4.33,0,0,1-4.67,1.56" transform="translate(-287.18 -56.2)"/></g><g id="图层_7" data-name="图层 7"><path class="cls-1" d="M352.17,86.57a14.23,14.23,0,0,0-4.67,2.73c-1.59,1.4-3.37,3-3.5,5.45a6.45,6.45,0,0,0,2.14,4.86c1.28,1.1,3.68,2.22,5.84,1.17,1.64-.8,3.31-3,2.53-4.67a3.6,3.6,0,0,0-3.31-1.75" transform="translate(-287.18 -56.2)"/><path class="cls-1" d="M382.34,66.53a17.27,17.27,0,0,0,3.89.39c2.16,0,3.53,0,4.86-1a6.15,6.15,0,0,0,2.34-3.89c.17-1,.53-2.93-.78-4.29a4.32,4.32,0,0,0-4.48-.77A3.62,3.62,0,0,0,386,58.75a3.75,3.75,0,0,0,.2,3.31" transform="translate(-287.18 -56.2)"/></g></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

1
svg/1.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_2" data-name="图层 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 21.63"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>1</title><polyline class="cls-1" points="20.54 15.1 20.54 0.5 0.5 0.5 0.5 21.13 40 21.13"/></svg>

After

Width:  |  Height:  |  Size: 284 B

1
svg/2.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_3" data-name="图层 3" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 27.74 15.09"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>2</title><polyline class="cls-1" points="27.24 0 27.24 14.6 0 14.6"/></svg>

After

Width:  |  Height:  |  Size: 265 B

1
svg/3.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_4" data-name="图层 4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29.07 30.28"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>3</title><path class="cls-1" d="M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15" transform="translate(-292.3 -107.25)"/></svg>

After

Width:  |  Height:  |  Size: 617 B

1
svg/4.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_5" data-name="图层 5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35.33 27.55"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>4</title><path class="cls-1" d="M339.72,85.41V58.75a69.07,69.07,0,0,1,14.79,0c5.9.63,9.31,1,12.84,3.5,1.76,1.22,6.37,4.43,6.68,9.92.25,4.38-2.27,9.26-6.72,11-3.5,1.39-8.46,1-10.71-2.06-.14-.18-2-2.82-.92-5.46.63-1.51,2.34-3.23,4.28-2.92a3.76,3.76,0,0,1,2.33,1.55" transform="translate(-339.22 -57.85)"/></svg>

After

Width:  |  Height:  |  Size: 499 B

1
svg/5.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_6" data-name="图层 6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 47.45 48.92"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>5</title><path class="cls-1" d="M301.38,145.93a8.21,8.21,0,0,1-.77,5.83c-.26.44-2.5,4.23-5.84,3.7a5,5,0,0,1-3.89-3.5c-.1-.35-1-3,.58-4.09a3.28,3.28,0,0,1,3.89.58" transform="translate(-290.04 -107.09)"/><path class="cls-1" d="M323.18,115.76a7.37,7.37,0,0,1,7.39-8.17c.49,0,4.07.12,5.65,2.92.19.34,1.52,2.7.19,4.67a4.33,4.33,0,0,1-4.67,1.56" transform="translate(-290.04 -107.09)"/></svg>

After

Width:  |  Height:  |  Size: 577 B

1
svg/6.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_7" data-name="图层 7" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50.62 45.5"><defs><style>.cls-1{fill:none;stroke:#00ff1c;stroke-miterlimit:10;}</style></defs><title>6</title><path class="cls-1" d="M352.17,86.57a14.23,14.23,0,0,0-4.67,2.73c-1.59,1.4-3.37,3-3.5,5.45a6.45,6.45,0,0,0,2.14,4.86c1.28,1.1,3.68,2.22,5.84,1.17,1.64-.8,3.31-3,2.53-4.67a3.6,3.6,0,0,0-3.31-1.75" transform="translate(-343.49 -56.2)"/><path class="cls-1" d="M382.34,66.53a17.27,17.27,0,0,0,3.89.39c2.16,0,3.53,0,4.86-1a6.15,6.15,0,0,0,2.34-3.89c.17-1,.53-2.93-.78-4.29a4.32,4.32,0,0,0-4.48-.77A3.62,3.62,0,0,0,386,58.75a3.75,3.75,0,0,0,.2,3.31" transform="translate(-343.49 -56.2)"/></svg>

After

Width:  |  Height:  |  Size: 686 B

BIN
svg/原图.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB