更新了Preview窗口类
parent
722b4bfacd
commit
4b97ece85d
|
@ -103,6 +103,7 @@
|
||||||
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
||||||
<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\IconWidget.cpp" />
|
<ClCompile Include="src\IconWidget.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
<ClCompile Include="src\MainWindow.cpp" />
|
<ClCompile Include="src\MainWindow.cpp" />
|
||||||
|
@ -159,6 +160,7 @@
|
||||||
<ClInclude Include="src\Editor\LayerManager.h" />
|
<ClInclude Include="src\Editor\LayerManager.h" />
|
||||||
<ClInclude Include="src\Editor\LayerStyle.h" />
|
<ClInclude Include="src\Editor\LayerStyle.h" />
|
||||||
<ClInclude Include="src\Editor\LayerWrapper.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\Element.h" />
|
||||||
<ClInclude Include="src\Renderer\Painting\Painting.h" />
|
<ClInclude Include="src\Renderer\Painting\Painting.h" />
|
||||||
<ClInclude Include="src\SvgParser.h" />
|
<ClInclude Include="src\SvgParser.h" />
|
||||||
|
|
|
@ -138,6 +138,9 @@
|
||||||
<ClCompile Include="src\Editor\LayerWrapper.cpp">
|
<ClCompile Include="src\Editor\LayerWrapper.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Editor\PreviewWindow.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||||
|
@ -164,6 +167,9 @@
|
||||||
<QtMoc Include="src\MainWindow.h">
|
<QtMoc Include="src\MainWindow.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="src\Editor\PreviewWindow.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Shaders\shader.frag">
|
<None Include="Shaders\shader.frag">
|
||||||
|
|
|
@ -27,18 +27,29 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>纹理编辑</string>
|
<widget class="QLabel" name="title">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="alignment">
|
<string>纹理编辑</string>
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="PreviewWindow" name="Preview"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PreviewWindow</class>
|
||||||
|
<extends>QGraphicsView</extends>
|
||||||
|
<header>PreviewWindow.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -3,28 +3,17 @@
|
||||||
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
previewWindow = ui.Preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorWidget::~EditorWidget()
|
EditorWidget::~EditorWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
#include "QGraphicsItem.h"
|
||||||
|
#include "QGraphicsScene.h"
|
||||||
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
void EditorWidget::paintEvent(QPaintEvent *event)
|
void EditorWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter pt;
|
previewWindow->show();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GraphicElement.h"
|
#include "GraphicElement.h"
|
||||||
|
#include "PreviewWindow.h"
|
||||||
#include "ui_EditorWidget.h"
|
#include "ui_EditorWidget.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <QFile>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonValue>
|
|
||||||
class EditorWidget : public QWidget
|
class EditorWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -21,4 +17,5 @@ class EditorWidget : public QWidget
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::EditorWidgetClass ui;
|
Ui::EditorWidgetClass ui;
|
||||||
|
PreviewWindow *previewWindow;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
};
|
Loading…
Reference in New Issue