Compare commits
2 Commits
df71b04e4c
...
71588dc72c
Author | SHA1 | Date |
---|---|---|
wuyize | 71588dc72c | |
wuyize | b7dc0f75fa |
|
@ -32,12 +32,12 @@
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
||||||
<QtInstall>5.15.2_msvc2019_64</QtInstall>
|
<QtInstall>5.15.2_msvc2019_64</QtInstall>
|
||||||
<QtModules>core;xml;gui;svg;widgets;core-private;gui-private;widgets-private</QtModules>
|
<QtModules>core;xml;gui;svg;widgets;concurrent;core-private;gui-private;widgets-private</QtModules>
|
||||||
<QtBuildConfig>debug</QtBuildConfig>
|
<QtBuildConfig>debug</QtBuildConfig>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||||
<QtInstall>5.15.2_msvc2019_64</QtInstall>
|
<QtInstall>5.15.2_msvc2019_64</QtInstall>
|
||||||
<QtModules>core;xml;gui;svg;widgets;core-private;gui-private;widgets-private</QtModules>
|
<QtModules>core;xml;gui;svg;widgets;concurrent;core-private;gui-private;widgets-private</QtModules>
|
||||||
<QtBuildConfig>release</QtBuildConfig>
|
<QtBuildConfig>release</QtBuildConfig>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
|
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
|
||||||
|
@ -140,9 +140,11 @@
|
||||||
<ClCompile Include="src\Editor\util\PainterPathUtil.cpp" />
|
<ClCompile Include="src\Editor\util\PainterPathUtil.cpp" />
|
||||||
<ClCompile Include="src\Editor\util\PaintingUtil.cpp" />
|
<ClCompile Include="src\Editor\util\PaintingUtil.cpp" />
|
||||||
<ClCompile Include="src\Editor\util\SvgFileLoader.cpp" />
|
<ClCompile Include="src\Editor\util\SvgFileLoader.cpp" />
|
||||||
|
<ClCompile Include="src\FlowLayout.cpp" />
|
||||||
<ClCompile Include="src\FluentMenu.cpp" />
|
<ClCompile Include="src\FluentMenu.cpp" />
|
||||||
<ClCompile Include="src\FluentMenuButton.cpp" />
|
<ClCompile Include="src\FluentMenuButton.cpp" />
|
||||||
<ClCompile Include="src\gl.c" />
|
<ClCompile Include="src\gl.c" />
|
||||||
|
<ClCompile Include="src\Library\LibraryWidget.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
<ClCompile Include="src\MainWindow.cpp" />
|
<ClCompile Include="src\MainWindow.cpp" />
|
||||||
<ClCompile Include="src\NavigationBarWidget.cpp" />
|
<ClCompile Include="src\NavigationBarWidget.cpp" />
|
||||||
|
@ -176,7 +178,9 @@
|
||||||
<QtUic Include="EditorSettingWidget.ui" />
|
<QtUic Include="EditorSettingWidget.ui" />
|
||||||
<QtUic Include="EditorWidget.ui" />
|
<QtUic Include="EditorWidget.ui" />
|
||||||
<QtUic Include="EditorWidgetItem.ui" />
|
<QtUic Include="EditorWidgetItem.ui" />
|
||||||
|
<QtUic Include="LibraryWidget.ui" />
|
||||||
<QtUic Include="MainWindow.ui" />
|
<QtUic Include="MainWindow.ui" />
|
||||||
|
<QtUic Include="PaintingItem.ui" />
|
||||||
<QtUic Include="RendererWidget.ui" />
|
<QtUic Include="RendererWidget.ui" />
|
||||||
<QtUic Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.ui" />
|
<QtUic Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.ui" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -247,7 +251,9 @@
|
||||||
<ClInclude Include="src\Editor\util\PaintingUtil.h" />
|
<ClInclude Include="src\Editor\util\PaintingUtil.h" />
|
||||||
<ClInclude Include="src\Editor\util\SvgFileLoader.h" />
|
<ClInclude Include="src\Editor\util\SvgFileLoader.h" />
|
||||||
<QtMoc Include="src\FluentMenu.h" />
|
<QtMoc Include="src\FluentMenu.h" />
|
||||||
|
<ClInclude Include="src\FlowLayout.h" />
|
||||||
<ClInclude Include="src\FluentMenuButton.h" />
|
<ClInclude Include="src\FluentMenuButton.h" />
|
||||||
|
<QtMoc Include="src\Library\LibraryWidget.h" />
|
||||||
<ClInclude Include="src\Renderer\IblUtils.h" />
|
<ClInclude Include="src\Renderer\IblUtils.h" />
|
||||||
<ClInclude Include="src\Renderer\Painting\BaseStyle.h" />
|
<ClInclude Include="src\Renderer\Painting\BaseStyle.h" />
|
||||||
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" />
|
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" />
|
||||||
|
|
|
@ -100,6 +100,12 @@
|
||||||
<QtUic Include="EditorLayerInfoWidget.ui">
|
<QtUic Include="EditorLayerInfoWidget.ui">
|
||||||
<Filter>Form Files</Filter>
|
<Filter>Form Files</Filter>
|
||||||
</QtUic>
|
</QtUic>
|
||||||
|
<QtUic Include="LibraryWidget.ui">
|
||||||
|
<Filter>Form Files</Filter>
|
||||||
|
</QtUic>
|
||||||
|
<QtUic Include="PaintingItem.ui">
|
||||||
|
<Filter>Form Files</Filter>
|
||||||
|
</QtUic>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\Editor\EditorWidgetItem.cpp">
|
<ClCompile Include="src\Editor\EditorWidgetItem.cpp">
|
||||||
|
@ -291,6 +297,12 @@
|
||||||
<ClCompile Include="src\Editor\Properties\MaterialReplaceDialog.cpp">
|
<ClCompile Include="src\Editor\Properties\MaterialReplaceDialog.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Library\LibraryWidget.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\FlowLayout.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||||
|
@ -365,6 +377,9 @@
|
||||||
<QtMoc Include="src\Editor\Properties\MaterialReplaceDialog.h">
|
<QtMoc Include="src\Editor\Properties\MaterialReplaceDialog.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="src\Library\LibraryWidget.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\data.json" />
|
<None Include="..\data.json" />
|
||||||
|
@ -588,6 +603,9 @@
|
||||||
<ClInclude Include="src\Editor\util\JsonMerger.h">
|
<ClInclude Include="src\Editor\util\JsonMerger.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\FlowLayout.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="res\MainWindow.qrc">
|
<QtRcc Include="res\MainWindow.qrc">
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>LibraryWidgetClass</class>
|
||||||
|
<widget class="QWidget" name="LibraryWidgetClass">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1124</width>
|
||||||
|
<height>695</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="classComboBox">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="amountLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</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>
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Plain</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="flowWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1106</width>
|
||||||
|
<height>639</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -43,6 +43,7 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QStackedWidget" name="stackedWidget">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<widget class="EditorWidget" name="editorWidget"/>
|
<widget class="EditorWidget" name="editorWidget"/>
|
||||||
|
<widget class="Library::LibraryWidget" name="libraryWidget"/>
|
||||||
<widget class="Renderer::RendererWidget" name="rendererWidget"/>
|
<widget class="Renderer::RendererWidget" name="rendererWidget"/>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -62,6 +63,12 @@
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>Editor/EditorWidget.h</header>
|
<header>Editor/EditorWidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>Library::LibraryWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>Library/LibraryWidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Form</class>
|
||||||
|
<widget class="QWidget" name="Form">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||||
|
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -13,6 +13,7 @@ struct ProjectData
|
||||||
EditorWidgetItem* item;
|
EditorWidgetItem* item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// 没用
|
||||||
class ProjectDataManager
|
class ProjectDataManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -122,7 +122,9 @@ void EditorWidget::initFileMenu()
|
||||||
});
|
});
|
||||||
connect(actionMerge, &QAction::triggered, this, [this] {
|
connect(actionMerge, &QAction::triggered, this, [this] {
|
||||||
auto files = QFileDialog::getOpenFileNames(this, QStringLiteral("打开需要合并的项目文件"), "", QStringLiteral("JSON文件(*.json)"));
|
auto files = QFileDialog::getOpenFileNames(this, QStringLiteral("打开需要合并的项目文件"), "", QStringLiteral("JSON文件(*.json)"));
|
||||||
|
if (files.empty()) return;
|
||||||
auto target = QFileDialog::getSaveFileName(this, QStringLiteral("保存至"), "", QStringLiteral("JSON文件(*.json)"));
|
auto target = QFileDialog::getSaveFileName(this, QStringLiteral("保存至"), "", QStringLiteral("JSON文件(*.json)"));
|
||||||
|
if (target.isEmpty()) return;
|
||||||
auto load = [&](QString path) {
|
auto load = [&](QString path) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
|
|
|
@ -274,11 +274,6 @@ void EditorWidgetItem::handleCanvasMetallicChange(const float& metallic)
|
||||||
previewWindow->canvasMetallic = metallic;
|
previewWindow->canvasMetallic = metallic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidgetItem::handleMaterialReplace(const Renderer::Material& origin, const Renderer::Material& target)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize EditorWidgetItem::getCanvasReferSize() const
|
QSize EditorWidgetItem::getCanvasReferSize() const
|
||||||
{
|
{
|
||||||
return previewWindow->referSize;
|
return previewWindow->referSize;
|
||||||
|
|
|
@ -50,7 +50,6 @@ class EditorWidgetItem : public QWidget
|
||||||
void handleCanvasSizeChange(const QSize& size);
|
void handleCanvasSizeChange(const QSize& size);
|
||||||
void handleCanvasRoughnessChange(const float& roughness);
|
void handleCanvasRoughnessChange(const float& roughness);
|
||||||
void handleCanvasMetallicChange(const float& metallic);
|
void handleCanvasMetallicChange(const float& metallic);
|
||||||
void handleMaterialReplace(const Renderer::Material& origin, const Renderer::Material& target);
|
|
||||||
QSize getCanvasReferSize() const;
|
QSize getCanvasReferSize() const;
|
||||||
float getCanvasRoughness() const;
|
float getCanvasRoughness() const;
|
||||||
float getCanvasMetallic() const;
|
float getCanvasMetallic() const;
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
#include "FlowLayout.h"
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
|
FlowLayout::FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing)
|
||||||
|
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||||
|
{
|
||||||
|
setContentsMargins(margin, margin, margin, margin);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
|
||||||
|
: m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||||
|
{
|
||||||
|
setContentsMargins(margin, margin, margin, margin);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlowLayout::~FlowLayout()
|
||||||
|
{
|
||||||
|
QLayoutItem* item;
|
||||||
|
while ((item = takeAt(0)))
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlowLayout::addItem(QLayoutItem* item)
|
||||||
|
{
|
||||||
|
itemList.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::horizontalSpacing() const
|
||||||
|
{
|
||||||
|
if (m_hSpace >= 0) {
|
||||||
|
return m_hSpace;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::verticalSpacing() const
|
||||||
|
{
|
||||||
|
if (m_vSpace >= 0) {
|
||||||
|
return m_vSpace;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::count() const
|
||||||
|
{
|
||||||
|
return itemList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLayoutItem* FlowLayout::itemAt(int index) const
|
||||||
|
{
|
||||||
|
return itemList.value(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
QLayoutItem* FlowLayout::takeAt(int index)
|
||||||
|
{
|
||||||
|
if (index >= 0 && index < itemList.size())
|
||||||
|
return itemList.takeAt(index);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::Orientations FlowLayout::expandingDirections() const
|
||||||
|
{
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlowLayout::hasHeightForWidth() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::heightForWidth(int width) const
|
||||||
|
{
|
||||||
|
int height = doLayout(QRect(0, 0, width, 0), true);
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlowLayout::setGeometry(const QRect& rect)
|
||||||
|
{
|
||||||
|
QLayout::setGeometry(rect);
|
||||||
|
doLayout(rect, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize FlowLayout::sizeHint() const
|
||||||
|
{
|
||||||
|
return minimumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize FlowLayout::minimumSize() const
|
||||||
|
{
|
||||||
|
QSize size;
|
||||||
|
for (const QLayoutItem* item : qAsConst(itemList))
|
||||||
|
size = size.expandedTo(item->minimumSize());
|
||||||
|
|
||||||
|
const QMargins margins = contentsMargins();
|
||||||
|
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::doLayout(const QRect& rect, bool testOnly) const
|
||||||
|
{
|
||||||
|
int left, top, right, bottom;
|
||||||
|
getContentsMargins(&left, &top, &right, &bottom);
|
||||||
|
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
|
||||||
|
int x = effectiveRect.x();
|
||||||
|
int y = effectiveRect.y();
|
||||||
|
int lineHeight = 0;
|
||||||
|
|
||||||
|
for (QLayoutItem* item : qAsConst(itemList)) {
|
||||||
|
const QWidget* wid = item->widget();
|
||||||
|
int spaceX = horizontalSpacing();
|
||||||
|
if (spaceX == -1)
|
||||||
|
spaceX = wid->style()->layoutSpacing(
|
||||||
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
||||||
|
int spaceY = verticalSpacing();
|
||||||
|
if (spaceY == -1)
|
||||||
|
spaceY = wid->style()->layoutSpacing(
|
||||||
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
||||||
|
|
||||||
|
int nextX = x + item->sizeHint().width() + spaceX;
|
||||||
|
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
||||||
|
x = effectiveRect.x();
|
||||||
|
y = y + lineHeight + spaceY;
|
||||||
|
nextX = x + item->sizeHint().width() + spaceX;
|
||||||
|
lineHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!testOnly)
|
||||||
|
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||||
|
|
||||||
|
x = nextX;
|
||||||
|
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
||||||
|
}
|
||||||
|
return y + lineHeight - rect.y() + bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
||||||
|
{
|
||||||
|
QObject* parent = this->parent();
|
||||||
|
if (!parent) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (parent->isWidgetType()) {
|
||||||
|
QWidget* pw = static_cast<QWidget*>(parent);
|
||||||
|
return pw->style()->pixelMetric(pm, nullptr, pw);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return static_cast<QLayout*>(parent)->spacing();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
#include <QLayout>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
|
class FlowLayout : public QLayout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FlowLayout(QWidget* parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||||
|
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||||
|
~FlowLayout();
|
||||||
|
|
||||||
|
void addItem(QLayoutItem* item) override;
|
||||||
|
int horizontalSpacing() const;
|
||||||
|
int verticalSpacing() const;
|
||||||
|
Qt::Orientations expandingDirections() const override;
|
||||||
|
bool hasHeightForWidth() const override;
|
||||||
|
int heightForWidth(int) const override;
|
||||||
|
int count() const override;
|
||||||
|
QLayoutItem* itemAt(int index) const override;
|
||||||
|
QSize minimumSize() const override;
|
||||||
|
void setGeometry(const QRect& rect) override;
|
||||||
|
QSize sizeHint() const override;
|
||||||
|
QLayoutItem* takeAt(int index) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int doLayout(const QRect& rect, bool testOnly) const;
|
||||||
|
int smartSpacing(QStyle::PixelMetric pm) const;
|
||||||
|
|
||||||
|
QList<QLayoutItem*> itemList;
|
||||||
|
int m_hSpace;
|
||||||
|
int m_vSpace;
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
#include "LibraryWidget.h"
|
||||||
|
#include "../FlowLayout.h"
|
||||||
|
#include "../Renderer/Preview/PaintingRenderer.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include "../util/PaintingUtil.h"
|
||||||
|
|
||||||
|
using namespace Library;
|
||||||
|
|
||||||
|
LibraryWidget::LibraryWidget(QWidget* parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
ui.setupUi(this);
|
||||||
|
FlowLayout* layout = new FlowLayout(ui.flowWidget);
|
||||||
|
ui.flowWidget->setLayout(layout);
|
||||||
|
for (const auto& dir : libraryDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
|
||||||
|
ui.classComboBox->addItem(dir.fileName());
|
||||||
|
|
||||||
|
connect(ui.classComboBox, &QComboBox::textActivated, this, &LibraryWidget::onClassChanged);
|
||||||
|
|
||||||
|
Renderer::PaintingRenderer::instance();
|
||||||
|
|
||||||
|
onClassChanged(ui.classComboBox->currentText());
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize LibraryWidget::getPaintingAdjustedSize(const QString& path)
|
||||||
|
{
|
||||||
|
QFile file(path);
|
||||||
|
file.open(QFile::ReadOnly);
|
||||||
|
QByteArray setting = file.readAll().trimmed();
|
||||||
|
QJsonParseError jError;
|
||||||
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
|
||||||
|
auto width = jsonDoc.object().value("width").toDouble();
|
||||||
|
auto height = jsonDoc.object().value("height").toDouble();
|
||||||
|
return QSize(round(width / height * kItemHeight), kItemHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library::LibraryWidget::loadIcons(std::stop_token stop)
|
||||||
|
{
|
||||||
|
while (!loadingQueue.empty() && !stop.stop_requested())
|
||||||
|
{
|
||||||
|
auto item = loadingQueue.front();
|
||||||
|
loadingQueue.pop();
|
||||||
|
QString path = static_cast<PaintingItem*>(item->userData(Qt::UserRole))->path;
|
||||||
|
auto painting = PaintingUtil::transfromToPainting(path);
|
||||||
|
auto image = Renderer::PaintingRenderer::instance().renderPainting(painting, item->iconSize() * devicePixelRatioF());
|
||||||
|
QTimer::singleShot(0, this, [item, image, stop] {
|
||||||
|
if (!stop.stop_requested())
|
||||||
|
item->setIcon(QIcon(QPixmap::fromImage(image)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library::LibraryWidget::onClassChanged(const QString& name)
|
||||||
|
{
|
||||||
|
if (loadingThread)
|
||||||
|
{
|
||||||
|
loadingThread->request_stop();
|
||||||
|
loadingThread->join();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir classDir(libraryDir.filePath(name));
|
||||||
|
auto layout = static_cast<FlowLayout*>(ui.flowWidget->layout());
|
||||||
|
|
||||||
|
while (auto child = layout->takeAt(0))
|
||||||
|
{
|
||||||
|
if (child->widget())
|
||||||
|
{
|
||||||
|
child->widget()->setParent(nullptr);
|
||||||
|
delete child->widget();
|
||||||
|
}
|
||||||
|
delete child;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadingQueue = std::queue<QToolButton*>();
|
||||||
|
|
||||||
|
QPixmap pixmap(QSize(1, 1));
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
|
for (const auto& dir : classDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
|
||||||
|
for (const auto& file : QDir(dir.filePath()).entryInfoList(QDir::Files))
|
||||||
|
{
|
||||||
|
if (file.suffix() != "json") continue;
|
||||||
|
|
||||||
|
auto size = getPaintingAdjustedSize(file.filePath());
|
||||||
|
auto item = new QToolButton(ui.flowWidget);
|
||||||
|
item->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||||
|
item->setIcon(QIcon(pixmap));
|
||||||
|
item->setIconSize(size);
|
||||||
|
item->setText(file.baseName());
|
||||||
|
auto data = new PaintingItem(file.filePath());
|
||||||
|
item->setUserData(Qt::UserRole, data);
|
||||||
|
|
||||||
|
connect(item, &QToolButton::clicked, this, [this] {
|
||||||
|
emit openPaintingFile(static_cast<PaintingItem*>(qobject_cast<QToolButton*>(sender())->userData(Qt::UserRole))->path);
|
||||||
|
});
|
||||||
|
|
||||||
|
loadingQueue.push(item);
|
||||||
|
layout->addWidget(item);
|
||||||
|
}
|
||||||
|
ui.amountLabel->setText(QStringLiteral("¹² %1 Ïî").arg(layout->count()));
|
||||||
|
|
||||||
|
loadingThread = std::jthread([this](std::stop_token stop) {loadIcons(stop); });
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
#pragma once
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QDir>
|
||||||
|
#include <queue>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
#include "ui_LibraryWidget.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Library
|
||||||
|
{
|
||||||
|
|
||||||
|
class PaintingItem : public QObjectUserData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString path;
|
||||||
|
PaintingItem(const QString& path = "") : path(path) {}
|
||||||
|
PaintingItem(const PaintingItem& p) : path(p.path) {}
|
||||||
|
};
|
||||||
|
Q_DECLARE_METATYPE(PaintingItem);
|
||||||
|
|
||||||
|
class LibraryWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
const QDir libraryDir = QDir("Paintings");
|
||||||
|
constexpr static int kItemHeight = 240;
|
||||||
|
|
||||||
|
LibraryWidget(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void openPaintingFile(QString path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::LibraryWidgetClass ui;
|
||||||
|
std::queue<QToolButton*> loadingQueue;
|
||||||
|
std::mutex mutex;
|
||||||
|
std::optional<std::jthread> loadingThread;
|
||||||
|
|
||||||
|
void onClassChanged(const QString& name);
|
||||||
|
QSize getPaintingAdjustedSize(const QString& path);
|
||||||
|
void loadIcons(std::stop_token stop);
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "Renderer/RendererGLWidget.h"
|
#include "Renderer/RendererGLWidget.h"
|
||||||
#include "Editor/EditorWidget.h"
|
#include "Editor/EditorWidget.h"
|
||||||
|
#include "Library/LibraryWidget.h"
|
||||||
#include "qslider.h"
|
#include "qslider.h"
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
@ -25,6 +26,11 @@ CentralWidget::CentralWidget(QWidget* parent) : QWidget(parent)
|
||||||
ui.stackedWidget->setCurrentWidget(ui.editorWidget);
|
ui.stackedWidget->setCurrentWidget(ui.editorWidget);
|
||||||
ui.editorWidget->handleOpenPaintingFile(path);
|
ui.editorWidget->handleOpenPaintingFile(path);
|
||||||
});
|
});
|
||||||
|
QObject::connect(ui.libraryWidget, &Library::LibraryWidget::openPaintingFile, [&, navigationBarWidget](QString path) {
|
||||||
|
navigationBarWidget->tabs->setCurrentTab(0);
|
||||||
|
ui.stackedWidget->setCurrentWidget(ui.editorWidget);
|
||||||
|
ui.editorWidget->handleOpenPaintingFile(path);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CentralWidget::~CentralWidget()
|
CentralWidget::~CentralWidget()
|
||||||
|
|
|
@ -8,6 +8,7 @@ NavigationBarWidget::NavigationBarWidget(QWidget *parent)
|
||||||
, tabs(new QtMaterialTabs)
|
, tabs(new QtMaterialTabs)
|
||||||
{
|
{
|
||||||
tabs->addTab(QStringLiteral("纹理编辑"));
|
tabs->addTab(QStringLiteral("纹理编辑"));
|
||||||
|
tabs->addTab(QStringLiteral("匼第踱"));
|
||||||
tabs->addTab(QStringLiteral("场景渲染"));
|
tabs->addTab(QStringLiteral("场景渲染"));
|
||||||
tabs->setHaloVisible(false);
|
tabs->setHaloVisible(false);
|
||||||
tabs->setBackgroundColor(Qt::transparent);
|
tabs->setBackgroundColor(Qt::transparent);
|
||||||
|
|
|
@ -8,18 +8,24 @@ Renderer::PaintingRenderer& Renderer::PaintingRenderer::instance()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::PaintingRenderer::exportPainting(const QString& path, Painting& painting, const QSize& size, float supersampling)
|
bool Renderer::PaintingRenderer::exportPainting(const QString& path, Painting& painting, const QSize& size, float supersampling)
|
||||||
|
{
|
||||||
|
auto image = renderPainting(painting, size, supersampling);
|
||||||
|
image.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).save(path, "PNG", 100);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage Renderer::PaintingRenderer::renderPainting(Painting& painting, const QSize& size, float supersampling)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(drawMutex);
|
std::unique_lock<std::mutex> lock(drawMutex);
|
||||||
draw.wait(lock, [&] {return drawFinished; });
|
draw.wait(lock, [&] {return drawFinished; });
|
||||||
drawFinished = false;
|
drawFinished = false;
|
||||||
this->path = path;
|
|
||||||
this->painting = &painting;
|
this->painting = &painting;
|
||||||
this->size = size;
|
this->size = size;
|
||||||
this->supersampling = supersampling;
|
this->supersampling = supersampling;
|
||||||
needDraw = true;
|
needDraw = true;
|
||||||
draw.notify_all();
|
draw.notify_all();
|
||||||
draw.wait(lock, [&] {return drawFinished; });
|
draw.wait(lock, [&] {return drawFinished; });
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::PaintingRenderer::PaintingRenderer()
|
Renderer::PaintingRenderer::PaintingRenderer()
|
||||||
|
@ -67,8 +73,7 @@ Renderer::PaintingRenderer::PaintingRenderer()
|
||||||
gl->glBindImageTexture(1, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
|
gl->glBindImageTexture(1, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
|
||||||
gl->glDispatchCompute((GLuint)ceil(renderSize.width() / 8.), (GLuint)ceil(renderSize.height() / 8.), 1);
|
gl->glDispatchCompute((GLuint)ceil(renderSize.width() / 8.), (GLuint)ceil(renderSize.height() / 8.), 1);
|
||||||
shader->release();
|
shader->release();
|
||||||
auto image = fbo.toImage(true);
|
result = fbo.toImage(true);
|
||||||
image.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).save(path, "PNG", 100);
|
|
||||||
gl->glDeleteBuffers(7, painting->buffers.data());
|
gl->glDeleteBuffers(7, painting->buffers.data());
|
||||||
drawFinished = true;
|
drawFinished = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Renderer
|
||||||
public:
|
public:
|
||||||
static PaintingRenderer& instance();
|
static PaintingRenderer& instance();
|
||||||
bool exportPainting(const QString& path, Painting& painting, const QSize& size, float supersampling = 2.f);
|
bool exportPainting(const QString& path, Painting& painting, const QSize& size, float supersampling = 2.f);
|
||||||
|
QImage renderPainting(Painting& painting, const QSize& size, float supersampling = 2.f);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<QOpenGLShaderProgram> shader;
|
std::unique_ptr<QOpenGLShaderProgram> shader;
|
||||||
std::jthread thread;
|
std::jthread thread;
|
||||||
|
@ -23,10 +25,10 @@ namespace Renderer
|
||||||
std::condition_variable draw;
|
std::condition_variable draw;
|
||||||
std::mutex drawMutex;
|
std::mutex drawMutex;
|
||||||
Painting* painting;
|
Painting* painting;
|
||||||
QString path;
|
|
||||||
QSize size;
|
QSize size;
|
||||||
float supersampling;
|
float supersampling;
|
||||||
std::pair<QImage, QPointF> result;
|
|
||||||
|
QImage result;
|
||||||
|
|
||||||
PaintingRenderer();
|
PaintingRenderer();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue