Compare commits
3 Commits
c2dd8271e3
...
25eec60e5c
Author | SHA1 | Date |
---|---|---|
karlis | 25eec60e5c | |
karlis | 6f8bfa1558 | |
karlis | ef990cd4b4 |
|
@ -104,6 +104,7 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidget.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidgetItem.cpp" />
|
||||
<ClCompile Include="src\Editor\ElementManager.cpp" />
|
||||
|
@ -154,6 +155,7 @@
|
|||
<QtUic Include="EditorWidgetItem.ui" />
|
||||
<QtUic Include="MainWindow.ui" />
|
||||
<QtUic Include="RendererWidget.ui" />
|
||||
<QtUic Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.ui" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\data.json" />
|
||||
|
@ -188,6 +190,7 @@
|
|||
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
|
||||
<QtMoc Include="src\MainWindow.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidget.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h" />
|
||||
<ClInclude Include="src\Editor\ElementManager.h" />
|
||||
<QtMoc Include="src\Editor\ElementPoolWidget.h" />
|
||||
<ClInclude Include="src\Editor\GraphicElement.h" />
|
||||
|
|
|
@ -73,6 +73,9 @@
|
|||
<QtUic Include="EditorWidget.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Editor\EditorWidgetItem.cpp">
|
||||
|
@ -213,6 +216,9 @@
|
|||
<ClCompile Include="src\Editor\util\PaintingUtil.cpp">
|
||||
<Filter>Source Files\Editor\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||
|
@ -248,6 +254,9 @@
|
|||
<QtMoc Include="src\FluentMenu.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\data.json" />
|
||||
|
@ -441,9 +450,6 @@
|
|||
<ClInclude Include="src\Renderer\VirtualTextureManager.h">
|
||||
<Filter>Header Files\Renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\util\PaintingUtil.h">
|
||||
<Filter>Header Files\Editor\util</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#include "LayerCreateWidget.h"
|
||||
#include <QComboBox>
|
||||
|
||||
LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, QWidget* parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
||||
elementPool = new ElementPoolWidget(ui.elementPool);
|
||||
elementPool->setElementList(elementManager->elements);
|
||||
}
|
||||
|
||||
LayerCreateWidget::~LayerCreateWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void LayerCreateWidget::accept()
|
||||
{
|
||||
QJsonObject jsonObj;
|
||||
jsonObj.insert("name", ui.name->text());
|
||||
if (ui.comboBox->currentIndex() == 0) {
|
||||
jsonObj.insert("is-folder", false);
|
||||
jsonObj.insert("element", elementPool->currentIndex);
|
||||
}
|
||||
else {
|
||||
jsonObj.insert("is-folder", true);
|
||||
jsonObj.insert("children", QJsonArray());
|
||||
}
|
||||
jsonObj.insert("tranform", "{\"offset\":{\"x\":0,\"y\":0},\"scale\":{\"x\":1,\"y\":1},\"rotation\":0}");
|
||||
jsonObj.insert("referenced-by", QJsonValue());
|
||||
emit LayerInfoReturned(jsonObj);
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void LayerCreateWidget::onCurrentIndexChanged(int index) {
|
||||
if (index == 0) {// leaf layer
|
||||
elementPool->setVisible(true);
|
||||
}
|
||||
else {// folder layer
|
||||
elementPool->setVisible(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <QDialog>
|
||||
#include <QJsonObject>
|
||||
#include "ElementPoolWidget.h"
|
||||
#include "ElementManager.h"
|
||||
#include "ui_LayerCreateWidget.h"
|
||||
|
||||
class LayerCreateWidget :
|
||||
public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Ui::LayerCreateWidget ui;
|
||||
ElementPoolWidget* elementPool;
|
||||
|
||||
|
||||
public:
|
||||
LayerCreateWidget(ElementManager* elementManager,QWidget* parent = nullptr);
|
||||
~LayerCreateWidget();
|
||||
void accept() override;
|
||||
|
||||
public slots:
|
||||
void onCurrentIndexChanged(int index);
|
||||
|
||||
signals:
|
||||
void LayerInfoReturned(QJsonObject jsonObj);
|
||||
};
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LayerCreateWidget</class>
|
||||
<widget class="QWidget" name="LayerCreateWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>326</width>
|
||||
<height>355</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,5,1,0">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maxVisibleItems">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="maxCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>叶子节点</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>组合节点</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<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>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>11</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>图层名:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="elementPool" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<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>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -36,6 +36,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
elementManager = new ElementManager(source,previewWindow->getRenderer());
|
||||
layerManager = new LayerManager(source, elementManager);
|
||||
elementInfoDisplayWidget->setElementManager(elementManager);
|
||||
treeWidget->elementManager = elementManager;
|
||||
qDebug() << layerManager->toJson();
|
||||
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
|
|||
pItem->setSizeHint(QSize(iconWidth, iconHeight));
|
||||
pictureList->insertItem(index, pItem);
|
||||
}
|
||||
if(elements.size() > 0)
|
||||
pictureList->setCurrentRow(0),
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
ElementPoolWidget::~ElementPoolWidget() {
|
||||
|
@ -61,6 +64,7 @@ ElementPoolWidget::~ElementPoolWidget() {
|
|||
|
||||
int ElementPoolWidget::pictureItemClicked(QListWidgetItem* item) {
|
||||
//qDebug() << pictureList->currentRow();
|
||||
currentIndex = pictureList->currentRow();
|
||||
emit elementSelected(this->elements[pictureList->currentRow()]);
|
||||
return pictureList->currentRow();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ private:
|
|||
ElementManager* elementManager;
|
||||
|
||||
public:
|
||||
int currentIndex = -1;
|
||||
ElementPoolWidget(QWidget* parent = nullptr);
|
||||
void setElementList(std::vector<GraphicElement*> elementList);
|
||||
void setElementManager(ElementManager* element);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "LayerTreeWidget.h"
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include "./EditorWidgetComponent/LayerCreateWidget.h"
|
||||
|
||||
LayerTreeWidget::LayerTreeWidget(QWidget *parent)
|
||||
{
|
||||
emit displayLayerChange(nullptr);
|
||||
|
@ -35,32 +37,47 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
QMenu menu;
|
||||
QTreeWidgetItem *item = itemAt(pos);
|
||||
this->selectedItem = item;
|
||||
// TODO
|
||||
menu.addAction(QString::fromLocal8Bit("创建子节点"), this, &LayerTreeWidget::onRenameEvent);
|
||||
//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*>();
|
||||
if (item != nullptr) {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
if (layer != nullptr) {
|
||||
if (typeid(*layer) == typeid(FolderLayerWrapper)) {
|
||||
menu.addAction(QString::fromLocal8Bit("创建子节点"), this, [this, layer]() {
|
||||
auto dialog = new LayerCreateWidget(elementManager, this);
|
||||
connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) {
|
||||
auto folderLayer = dynamic_cast<FolderLayerWrapper*>(layer);
|
||||
LayerWrapper* newLayer;
|
||||
if(jsonObj.value("is-folder").toBool())
|
||||
newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||
else
|
||||
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
|
||||
folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem());
|
||||
qDebug() << jsonObj<<"----------------------";
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
dialog->exec();
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||
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]() {
|
||||
if (this->selectedItem == nullptr)
|
||||
return;
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->del();
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
//}
|
||||
});
|
||||
}
|
||||
if (layer != root) {
|
||||
menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->del();
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "LayerWrapper.h"
|
||||
#include "ElementManager.h"
|
||||
#include <QPoint>
|
||||
#include <QTreeWidget>
|
||||
class LayerTreeWidget : public QTreeWidget
|
||||
|
@ -10,6 +11,7 @@ class LayerTreeWidget : public QTreeWidget
|
|||
LayerWrapper *copiedItem;
|
||||
|
||||
public:
|
||||
ElementManager* elementManager;
|
||||
LayerWrapper* root;
|
||||
LayerTreeWidget(QWidget *parent = nullptr);
|
||||
void onRenameEvent();
|
||||
|
|
Loading…
Reference in New Issue