完成layer信息展示和数据修改(部分)

dev-VirtualTexture
白封羽 2023-01-17 20:21:04 +08:00
parent 3d770ea92f
commit cee219409e
9 changed files with 146 additions and 2 deletions

View File

@ -105,6 +105,7 @@
<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\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" />
@ -163,6 +164,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" /> <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

@ -177,6 +177,9 @@
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp"> <ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h"> <QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -209,6 +212,9 @@
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h"> <QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</QtMoc> </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">

View File

@ -49,7 +49,24 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="RightBar" native="true"> <widget class="QWidget" name="RightBar" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4"> <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> <item>
<widget class="LayerTreeWidget" name="LayerTree"> <widget class="LayerTreeWidget" name="LayerTree">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
@ -79,6 +96,12 @@
<extends>QTreeWidget</extends> <extends>QTreeWidget</extends>
<header location="global">LayerTreeWidget.h</header> <header location="global">LayerTreeWidget.h</header>
</customwidget> </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

@ -2,9 +2,14 @@
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;
treeWidget = ui.LayerTree; treeWidget = ui.LayerTree;
tabWidget = ui.DisplayTab;
qDebug() << tabWidget;
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidget::onLayerChange);
qDebug() << "123"; qDebug() << "123";
// test // test
QFile settingFile; QFile settingFile;
@ -33,3 +38,11 @@ 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();
}

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ElementManager.h" #include "ElementManager.h"
#include "InfoDisplayWidget.h"
#include "LayerManager.h" #include "LayerManager.h"
#include "LayerTreeWidget.h" #include "LayerTreeWidget.h"
#include "PreviewWindow.h" #include "PreviewWindow.h"
@ -13,14 +14,23 @@ 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; LayerTreeWidget *treeWidget;
QTabWidget *tabWidget;
// 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);
}; };

View File

@ -0,0 +1,62 @@
#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);
name->setDisabled(true);
rotation->setValidator(new QIntValidator(-1000, 1000, this));
connect(rotation, &QLineEdit::textChanged,
[=](QString content) { this->displayLayer->property.rotation = content.toDouble(); });
offsetX->setValidator(new QIntValidator(-1000, 1000, this));
connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
});
offsetY->setValidator(new QIntValidator(-1000, 1000, this));
connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
;
});
layout->addRow("layer name:", name);
layout->addRow("rotation:", rotation);
layout->addRow("offset-X:", offsetX);
layout->addRow("offset-Y:", offsetY);
}
this->setLayout(layout);
}
void InfoDisplayWidget::generateElementForm()
{
}

View File

@ -1 +1,20 @@
#pragma once #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();
};

View File

@ -3,11 +3,16 @@
#include <QMenu> #include <QMenu>
LayerTreeWidget::LayerTreeWidget(QWidget *parent) LayerTreeWidget::LayerTreeWidget(QWidget *parent)
{ {
emit displayLayerChange(nullptr);
this->selectedItem = nullptr; this->selectedItem = nullptr;
this->copiedItem = nullptr; this->copiedItem = nullptr;
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
this->setHeaderLabel("Layer Content"); this->setHeaderLabel("Layer Content");
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu); 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); // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
} }
@ -50,4 +55,5 @@ void LayerTreeWidget::onRenameEvent()
this->selectedItem->setText(0, sName); this->selectedItem->setText(0, sName);
this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>()->property.name = sName; this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>()->property.name = sName;
} }
emit displayLayerChange(this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper *>());
} }

View File

@ -15,4 +15,7 @@ class LayerTreeWidget : public QTreeWidget
void popMenu(const QPoint &pos); void popMenu(const QPoint &pos);
// void mouseDoubleClickEvent(QMouseEvent *event) override; // void mouseDoubleClickEvent(QMouseEvent *event) override;
// void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0); // void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0);
signals:
void displayLayerChange(LayerWrapper *);
}; };