更新了Preview窗口类

dev-VirtualTexture
白封羽 2022-11-19 17:17:07 +08:00
parent 722b4bfacd
commit 4b97ece85d
7 changed files with 79 additions and 29 deletions

View File

@ -103,6 +103,7 @@
<ClCompile Include="src\Editor\GraphicElement.cpp" />
<ClCompile Include="src\Editor\LayerManager.cpp" />
<ClCompile Include="src\Editor\LayerWrapper.cpp" />
<ClCompile Include="src\Editor\PreviewWindow.cpp" />
<ClCompile Include="src\IconWidget.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\MainWindow.cpp" />
@ -159,6 +160,7 @@
<ClInclude Include="src\Editor\LayerManager.h" />
<ClInclude Include="src\Editor\LayerStyle.h" />
<ClInclude Include="src\Editor\LayerWrapper.h" />
<QtMoc Include="src\Editor\PreviewWindow.h" />
<ClInclude Include="src\Renderer\Painting\Element.h" />
<ClInclude Include="src\Renderer\Painting\Painting.h" />
<ClInclude Include="src\SvgParser.h" />

View File

@ -138,6 +138,9 @@
<ClCompile Include="src\Editor\LayerWrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Editor\PreviewWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -164,6 +167,9 @@
<QtMoc Include="src\MainWindow.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\PreviewWindow.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<None Include="Shaders\shader.frag">

View File

@ -27,18 +27,29 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
<item>
<widget class="QLabel" name="title">
<property name="text">
<string>纹理编辑</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="PreviewWindow" name="Preview"/>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>PreviewWindow</class>
<extends>QGraphicsView</extends>
<header>PreviewWindow.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -3,28 +3,17 @@
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
previewWindow = ui.Preview;
}
EditorWidget::~EditorWidget()
{
}
#include "QGraphicsItem.h"
#include "QGraphicsScene.h"
#include <iostream>
using namespace std;
void EditorWidget::paintEvent(QPaintEvent *event)
{
QPainter pt;
pt.begin(this);
pt.setRenderHint(QPainter::Antialiasing);
QFile settingFile;
settingFile.setFileName("C:/Users/Karlis/Desktop/data.json");
settingFile.open(QFile::ReadOnly);
QByteArray setting = settingFile.readAll().trimmed();
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting));
auto jElements = jsonDoc.object().value("elements").toArray();
for (auto &&ele : jElements)
{
SimpleElement element(ele.toObject());
pt.drawPath(element.getPaintObject());
}
pt.end();
previewWindow->show();
}

View File

@ -1,15 +1,11 @@
#pragma once
#include "GraphicElement.h"
#include "PreviewWindow.h"
#include "ui_EditorWidget.h"
#include <QPainter>
#include <QWidget>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
class EditorWidget : public QWidget
{
Q_OBJECT
@ -21,4 +17,5 @@ class EditorWidget : public QWidget
private:
Ui::EditorWidgetClass ui;
PreviewWindow *previewWindow;
};

View File

@ -0,0 +1,26 @@
#include "PreviewWindow.h"
PreviewWindow::PreviewWindow(QWidget *parent) : QGraphicsView(parent)
{
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
mainScene = new QGraphicsScene(this);
this->setScene(mainScene);
}
void PreviewWindow::show()
{
mainScene->clear();
QFile settingFile;
settingFile.setFileName("C:/Users/Karlis/Desktop/data.json");
settingFile.open(QFile::ReadOnly);
QByteArray setting = settingFile.readAll().trimmed();
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting));
auto jElements = jsonDoc.object().value("elements").toArray();
for (auto &&ele : jElements)
{
SimpleElement element(ele.toObject());
QGraphicsPathItem *item = new QGraphicsPathItem(element.getPaintObject());
mainScene->addItem(item);
}
QGraphicsView::show();
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "GraphicElement.h"
#include "QGraphicsItem.h"
#include "QGraphicsView.h"
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
class PreviewWindow : public QGraphicsView
{
Q_OBJECT
private:
QGraphicsScene *mainScene;
public:
PreviewWindow(QWidget *parent = 0);
void show();
};