From 81bb1b4b86fc0b6e8c46d3213af6ecdb071732c3 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Thu, 16 Mar 2023 20:22:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[editor/style]=20=E5=AE=8C=E6=88=90StrokeSt?= =?UTF-8?q?yle=E7=9A=84=E5=BA=8F=E5=88=97=E5=8C=96=E5=92=8C=E5=8F=8D?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=20[stroke]=20=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=88=9B=E5=BB=BAStrokeStyle=E6=97=B6=E7=9A=84=E5=88=9D?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 1 + ...rchitectureColoredPainting.vcxproj.filters | 3 ++ .../StrokeStyleWidget.cpp | 12 +++-- .../src/Editor/LayerStyle.cpp | 44 +++++++++++++++---- .../src/Editor/LayerStyle.h | 16 +++++-- .../src/Editor/LayerWrapper.cpp | 5 +++ .../src/Editor/util/EncodeUtil.hpp | 25 +++++++++++ 7 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 ArchitectureColoredPainting/src/Editor/util/EncodeUtil.hpp diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 91c9f62..6b49ff0 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -197,6 +197,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 71f1e04..d32b61b 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -480,6 +480,9 @@ Header Files\Editor\util + + Header Files\Editor\util + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index 00283ca..7e014db 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -10,7 +10,6 @@ constexpr int COLUMN_METALLIC = 2; constexpr int COLUMN_ROUGHNESS = 3; constexpr int COLUMN_OPERATIONS = 4; -// FIXME: Material的控件有显示bug StrokeStyleWidget::StrokeStyleWidget( std::shared_ptr stroke, QWidget* parent @@ -122,7 +121,7 @@ void StrokeStyleWidget::initTable(std::shared_ptrrbegin(); newWidth = lastPair->first + 0.01; } - Renderer::Material newMaterial = { QColor::fromRgb(0,0,0), 0.f, .8f }; + Renderer::Material newMaterial(QColor::fromRgb(0, 0, 0)); (*materialMap)[newWidth] = newMaterial; int newRow = this->strokeTable->rowCount() - 1; this->strokeTable->insertRow(newRow); @@ -153,18 +152,17 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma }); QTableWidgetItem* metallicItem = new QTableWidgetItem; - metallicItem->setData(Qt::EditRole, material.metallic); + metallicItem->setData(Qt::EditRole, material.metallicF()); strokeTable->setItem(row, COLUMN_METALLIC, metallicItem); QTableWidgetItem* roughnessItem = new QTableWidgetItem; - roughnessItem->setData(Qt::EditRole, material.roughness); + roughnessItem->setData(Qt::EditRole, material.roughnessF()); strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem); QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", strokeTable); removeButton->setFixedSize(20, 20); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { - if (this->strokeTable->rowCount() <= 1) return; radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat()); this->strokeTable->removeRow(row); }); @@ -204,12 +202,12 @@ void StrokeStyleWidget::onCellChanged(int row, int column) } case COLUMN_METALLIC: { - radialStroke(stroke)->materialMap[changedWidth].metallic = changedItemValue; + radialStroke(stroke)->materialMap[changedWidth].setMetallicF(changedItemValue); break; } case COLUMN_ROUGHNESS: { - radialStroke(stroke)->materialMap[changedWidth].roughness = changedItemValue; + radialStroke(stroke)->materialMap[changedWidth].setRoughnessF(changedItemValue); break; } } diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 9b65355..215ec15 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -1,6 +1,6 @@ #include "LayerStyle.h" #include "./EditorWidgetComponent/StrokeStyleWidget.h" -#include "./util/JsonUtil.hpp" +#include "./util/EncodeUtil.hpp" #include #include #include @@ -51,7 +51,6 @@ QWidget* StrokeElementLayerStyle::getInputWidget() if (this->strokePair.first == nullptr) { auto materialMap = std::map(); - materialMap[1.0] = Renderer::Material{ QColor(0, 0, 0), 0.f, .8f }; this->strokePair.first = std::shared_ptr(new Renderer::MaterialStyleStroke( 15, Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat, @@ -63,7 +62,6 @@ QWidget* StrokeElementLayerStyle::getInputWidget() if (this->strokePair.second == nullptr) { auto materialMap = std::map(); - materialMap[1.0] = Renderer::Material{ QColor(0, 0, 0), 0.f, .8f }; this->strokePair.second = std::shared_ptr(new Renderer::MaterialStyleStroke( 15, Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat, @@ -108,6 +106,14 @@ QWidget* StrokeElementLayerStyle::getListDisplayWidget() const return w; } +StrokeElementLayerStyle::StrokeElementLayerStyle(PMaterialStyleStroke left, PMaterialStyleStroke right) +{ + this->strokePair.first = left; + this->strokePair.second = right ? right : std::dynamic_pointer_cast( + std::shared_ptr(std::move(left->clone())) + ); +} + StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& other) { strokePair.first = std::dynamic_pointer_cast( @@ -121,11 +127,12 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& QJsonObject StrokeElementLayerStyle::toJson() const { + // todo: 修改打开逻辑 QJsonObject json; - json.insert("type", "stroke"); - json.insert("enableEachSideIndependent", enableEachSideIndependent); - json.insert("left", JsonUtil::toQJsonArray(strokePair.first->encoded())); - json.insert("right", JsonUtil::toQJsonArray(strokePair.second->encoded())); + json["type"] = getTypeName(); + json["enableEachSideIndependent"] = enableEachSideIndependent; + json["left"] = EncodeUtil::toBase64(strokePair.first->encoded()); + json["right"] = EncodeUtil::toBase64(strokePair.second->encoded()); return json; } @@ -184,5 +191,26 @@ std::unique_ptr FillElementLayerStyle::clone() const std::unique_ptr LayerStyle::fromJson(const QJsonObject& json) { - return std::unique_ptr(); + QString type = json["type"].toString(); + if (type == StrokeElementLayerStyle::getTypeName()) + { + auto ptr = std::make_unique( + std::dynamic_pointer_cast( + std::shared_ptr(std::move(Renderer::MaterialStyle::decoded(EncodeUtil::fromBase64(json["left"].toString())))) + ), + std::dynamic_pointer_cast( + std::shared_ptr(std::move(Renderer::MaterialStyle::decoded(EncodeUtil::fromBase64(json["right"].toString())))) + ) + ); + ptr->enableEachSideIndependent = json["enableEachSideIndependent"].toBool(); + return ptr; + } + else if (type == FillElementLayerStyle::getTypeName()) + { + return std::make_unique(); + } + else + { + return nullptr; + } } diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 6717299..636201d 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -13,6 +13,8 @@ using Renderer::MaterialStyle; using Renderer::MaterialStyleStroke; +#define STYLE_TYPENAME(name) static QString getTypeName() { return name; } + /** * 在进行Style的添加时,首先创建空对象,然后直接调用getInputWidget()方法 * 在进行Style的修改时,直接调用getInputWidget()方法 @@ -36,17 +38,22 @@ public: class StrokeElementLayerStyle : public LayerStyle { + using PMaterialStyleStroke = std::shared_ptr; private: - std::pair, std::shared_ptr> strokePair; + std::pair strokePair; public: + STYLE_TYPENAME("stroke") + + StrokeElementLayerStyle() = default; + StrokeElementLayerStyle(PMaterialStyleStroke left, PMaterialStyleStroke right = nullptr); + StrokeElementLayerStyle(const StrokeElementLayerStyle& other); + ~StrokeElementLayerStyle() = default; + std::vector toBaseStyles() const override; QString getStyleName() const override; QWidget* getInputWidget() override; QWidget* getListDisplayWidget() const override; - StrokeElementLayerStyle() = default; - StrokeElementLayerStyle(const StrokeElementLayerStyle& other); - ~StrokeElementLayerStyle() = default; QJsonObject toJson() const override; std::unique_ptr clone() const override; @@ -56,6 +63,7 @@ public: class FillElementLayerStyle : public LayerStyle { public: + STYLE_TYPENAME("fill") std::vector toBaseStyles() const override; QString getStyleName() const override; QWidget* getInputWidget() override; diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index d5229e9..febc24a 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -79,6 +79,11 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana qDebug() << json.value("name").toString() << " " << this; int elementIndex = json.value("element").toInt(); wrappedElement = elementManager->getElementById(elementIndex); + QJsonArray stylesArray = json.value("styles").toArray(); + for (const auto& style : stylesArray) + { + styles.push_back(LayerStyle::fromJson(style.toObject())); + } } void LayerWrapper::SimpleProperty::apply(PixelPath&cache) diff --git a/ArchitectureColoredPainting/src/Editor/util/EncodeUtil.hpp b/ArchitectureColoredPainting/src/Editor/util/EncodeUtil.hpp new file mode 100644 index 0000000..d9a5d01 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/util/EncodeUtil.hpp @@ -0,0 +1,25 @@ +#pragma once +#include + +namespace EncodeUtil +{ +#include + template + QString toBase64(const std::vector& vec) + { + QByteArray ba; + ba.resize(vec.size() * sizeof(S)); + memcpy_s(ba.data(), ba.size(), vec.data(), vec.size() * sizeof(S)); + return ba.toBase64(); + } + + template + std::vector fromBase64(const QString& str) + { + QByteArray ba = QByteArray::fromBase64(str.toUtf8()); + std::vector vec; + vec.resize(ba.size() / sizeof(T)); + memcpy_s(vec.data(), vec.size() * sizeof(T), ba.data(), ba.size()); + return vec; + } +} From 2569b07233b96d8b886d7698cdc4c92e6b71bde9 Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 17 Mar 2023 11:54:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Renderer=E9=83=A8=E5=88=86Painting=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AE=BE=E7=BD=AE=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArchitectureColoredPainting/res/Shaders/painting.comp | 7 ++++++- ArchitectureColoredPainting/src/Renderer/Model.cpp | 3 ++- .../src/Renderer/Painting/Painting.cpp | 7 +++++-- .../src/Renderer/Painting/Painting.h | 5 +++-- .../src/Renderer/VirtualTextureManager.cpp | 4 +++- .../src/Renderer/VirtualTextureManager.h | 2 +- ArchitectureColoredPainting/src/main.cpp | 4 ++++ 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index 3e8ede4..7324942 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -4,6 +4,11 @@ layout(local_size_x = 8, local_size_y = 8) in; layout(location = 0) uniform ivec2 pixelOffset; +layout(std140, binding = 1) uniform ubo +{ + vec3 backgroundColor; +}; + layout(rgba8, binding = 0) uniform image2D gBaseColor; layout(rg8, binding = 1) uniform image2D gMetallicRoughness; @@ -1353,7 +1358,7 @@ void main() vec3 debugBVH = vec3(0); // bool debugHit = false; //vec4 color = vec4(0.76, 0.33, 0.15, -1); - vec4 color = vec4(1,1,1, -1); + vec4 color = vec4(backgroundColor, -1); vec2 metallicRoughness = vec2(0, 0.8); stack.top = 0; uint index = 0, visitTime = 0; diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 4f62c3b..e96d36a 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -273,7 +273,8 @@ GLuint Renderer::Model::loadPainting(std::string path) } else if (path == "1.json") { - float widths[] = { 0.43, 0.43 * 0.25 / 0.15, 0.43 * 0.25 / 0.15 }; + painting.backgroundColor = QColor(196, 81, 35); + float widths[] = { 0.22, 0.22 * 0.25 / 0.15, 0.22 * 0.25 / 0.15 }; QPainterPath painterPaths[6]; for (int i = 0; i < 6; i++) if (!SvgFileLoader().loadSvgFile(QString(std::format("../svg/{}.svg", i + 1).c_str()), painterPaths[i])) diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp index 3d1fb2a..afd7e04 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp @@ -9,7 +9,7 @@ using namespace Renderer; constexpr int kMaxLineCount = 20; -Painting::Painting() +Painting::Painting(QColor backgroundColor) : backgroundColor(backgroundColor) { } @@ -171,18 +171,21 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc) //std::cout << std::format("{} {} {} {}\n", contourBuffer->bvhOffset, stylePool[i.first->style], contourBuffer->pointsOffset, contourBuffer->linesOffset); } - glFunc->glCreateBuffers(5, buffers.data()); + glFunc->glCreateBuffers(6, buffers.data()); GLuint& bvhSSBO = buffers[0]; GLuint& bvhBoundSSBO = buffers[1]; GLuint& elementOffsetSSBO = buffers[2]; GLuint& elementIndexSSBO = buffers[3]; GLuint& elementDataSSBO = buffers[4]; + GLuint& backgroundColorUBO = buffers[5]; glFunc->glNamedBufferData(buffers[0], bvhChildren.size() * sizeof(bvhChildren[0]), bvhChildren.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[1], bvhBounds.size() * sizeof(bvhBounds[0]), bvhBounds.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[2], elementOffsets.size() * sizeof(elementOffsets[0]), elementOffsets.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[3], elementIndex.size() * sizeof(elementIndex[0]), elementIndex.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[4], elementData.size() * sizeof(elementData[0]), elementData.data(), GL_STATIC_READ); + glm::vec3 color(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF()); + glFunc->glNamedBufferData(buffers[5], sizeof(glm::vec3), &color, GL_STATIC_READ); } GLuint Renderer::Painting::getElementCount() diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h index ab8f31a..9194040 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h @@ -64,9 +64,10 @@ namespace Renderer std::vector elementIndex; std::vector elementData; int paintingId = 0; - std::array buffers; + std::array buffers; + QColor backgroundColor; - Painting(); + Painting(QColor backgroundColor = Qt::white); void addElement(const Element& element, const ElementTransform& transform); void addElement(std::shared_ptr element, QVector4D bound, float rotation, int zIndex); void generateBuffers(QOpenGLFunctions_4_5_Core* glFunc); diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp index eeba398..b926ad4 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp @@ -126,6 +126,7 @@ std::uint16_t Renderer::VirtualTextureManager::createVirtualTexture(Painting pai for (int i = 0; i < 5; i++) glMain->BindBufferBase(GL_SHADER_STORAGE_BUFFER, i, painting.buffers[i]); + glMain->BindBufferBase(GL_UNIFORM_BUFFER, 1, painting.buffers[5]); for (auto level = levels - 1; level < levels; ++level) { @@ -143,7 +144,7 @@ std::uint16_t Renderer::VirtualTextureManager::createVirtualTexture(Painting pai GL_TRUE); program.bind(); - glMain->Uniform2i(gl->GetUniformLocation(program.programId(), "pixelOffset"), static_cast(pageSize) * i, static_cast(pageSize) * j); + glMain->Uniform2i(0 /*pixelOffset*/, static_cast(pageSize) * i, static_cast(pageSize) * j); glMain->BindImageTexture(0, baseColor, level, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8); glMain->BindImageTexture(1, metallicRoughness, level, GL_FALSE, 0, GL_READ_WRITE, GL_RG8); glMain->DispatchCompute(pageSize / 8, pageSize / 8, 1); @@ -190,6 +191,7 @@ void Renderer::VirtualTextureManager::pageCommitmentById(const glm::u16vec2& pag program.bind(); for (int i = 0; i < 5; i++) gl->BindBufferBase(GL_SHADER_STORAGE_BUFFER, i, painting.buffers[i]); + glMain->BindBufferBase(GL_UNIFORM_BUFFER, 1, painting.buffers[5]); gl->Uniform2i(gl->GetUniformLocation(program.programId(), "pixelOffset"), static_cast(pageSize) * page.x, static_cast(pageSize) * page.y); gl->BindImageTexture(0, painting.baseColor, level, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8); gl->BindImageTexture(1, painting.metallicRoughness, level, GL_FALSE, 0, GL_READ_WRITE, GL_RG8); diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h index e1d3a03..520800b 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h @@ -15,7 +15,7 @@ namespace Renderer { GLuint baseColor; GLuint metallicRoughness; - std::array buffers; + std::array buffers; }; class VirtualTextureManager diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 6ef683c..5bf6bbe 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include "consoleapi2.h" +#include extern "C" { @@ -50,6 +51,9 @@ int main(int argc, char* argv[]) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication a(argc, argv); Q_INIT_RESOURCE(resources); + QtMaterialTheme theme; + theme.setColor("primary1", QColor(0, 90, 158)); + QtMaterialStyle::instance().setTheme(&theme); //FramelessHelper::Core::setApplicationOSThemeAware(); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); //FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); From 6a09bdd32c2b59456fa353937dd4dbfcd8f1d2bc Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 17 Mar 2023 12:29:31 +0800 Subject: [PATCH 3/4] =?UTF-8?q?FIX:=20GraphicElement=E4=B8=ADpixelRatio?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/GraphicElement.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 6823669..f515210 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -92,7 +92,7 @@ QJsonObject GroupElement::toJson() const return result; } -void SimpleElement::paint(QPainter* painter, QTransform transform, const vector> &styles) +void SimpleElement::paint(QPainter* painter, QTransform transform, const vector>& styles) { painter->save(); painter->setTransform(transform); @@ -102,12 +102,15 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector< } else { - Renderer::ElementStyleStrokeDemo demo(2); std::shared_ptr style; style = styles[0]; - QVector2D scale(transform.m11(), transform.m22()); - scale /= transform.m33(); - double maxScale = std::max(scale.x(), scale.y()); + + double angle = atan(transform.m12() / transform.m11()); + double maxScale; + if (fabs(cos(angle))>1e-5) + maxScale = std::max(fabs(transform.m11() / cos(angle)), fabs(transform.m22() / cos(angle))); + else + maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle))); double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, *style, pixelRatio); transform.translate(mov.x(), mov.y()); @@ -117,7 +120,7 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector< painter->restore(); } -void GroupElement::paint(QPainter* painter, QTransform transform, const vector> &styles) +void GroupElement::paint(QPainter* painter, QTransform transform, const vector>& styles) { sourceLayer->paint(painter, transform); } @@ -125,7 +128,7 @@ void GroupElement::paint(QPainter* painter, QTransform transform, const vectorpaint(&painter, QTransform(), true); painter.end(); - QRect rect (cache.getBoundingRect().toRect()); + QRect rect(cache.getBoundingRect().toRect()); rect.setTopLeft(rect.topLeft() - QPoint(5, 5)); rect.setBottomRight(rect.bottomRight() + QPoint(5, 5)); result = result.copy(rect); From 9e4cdb3a63c1a9c56a275b69d13be258799bb7e8 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Fri, 17 Mar 2023 14:14:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=92=8C=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 3 + ...rchitectureColoredPainting.vcxproj.filters | 9 +++ ArchitectureColoredPainting/EditorSetting.ui | 32 ++++++++++ .../EditorSettingWidget.ui | 63 +++++++++++++++++++ .../EditorWidgetItem.ui | 13 +++- .../src/Editor/EditorWidget.cpp | 8 +++ .../src/Editor/EditorWidget.h | 2 +- .../src/Editor/EditorWidgetItem.cpp | 34 ++++++++++ .../src/Editor/EditorWidgetItem.h | 11 +++- .../src/Editor/PreviewWindow.cpp | 9 ++- .../src/Editor/PreviewWindow.h | 2 + .../Editor/RightBar/EditorSettingWidget.cpp | 21 +++++++ .../src/Editor/RightBar/EditorSettingWidget.h | 21 +++++++ data.json | 2 + 14 files changed, 226 insertions(+), 4 deletions(-) create mode 100644 ArchitectureColoredPainting/EditorSetting.ui create mode 100644 ArchitectureColoredPainting/EditorSettingWidget.ui create mode 100644 ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.h diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 6b49ff0..ac1871e 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -104,6 +104,7 @@ + @@ -154,6 +155,7 @@ + @@ -197,6 +199,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index d32b61b..f60bea2 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -82,6 +82,9 @@ Form Files + + Form Files + @@ -234,6 +237,9 @@ Source Files\Editor + + Source Files + @@ -281,6 +287,9 @@ Header Files\Editor + + Header Files + diff --git a/ArchitectureColoredPainting/EditorSetting.ui b/ArchitectureColoredPainting/EditorSetting.ui new file mode 100644 index 0000000..3680069 --- /dev/null +++ b/ArchitectureColoredPainting/EditorSetting.ui @@ -0,0 +1,32 @@ + + + EditorSettingWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + 璁剧疆鑳屾櫙棰滆壊 + + + + + + + + + + diff --git a/ArchitectureColoredPainting/EditorSettingWidget.ui b/ArchitectureColoredPainting/EditorSettingWidget.ui new file mode 100644 index 0000000..fc73390 --- /dev/null +++ b/ArchitectureColoredPainting/EditorSettingWidget.ui @@ -0,0 +1,63 @@ + + + EditorSettingWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + 0 + 0 + + + + + 120 + 16777215 + + + + 璁剧疆鑳屾櫙棰滆壊 + + + + + + + + 0 + 0 + + + + + 120 + 16777215 + + + + 璁剧疆椤圭洰鍚嶇О + + + + + + + + + + diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index 73f9357..63fbd7d 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -147,7 +147,7 @@ - 1 + 2 @@ -159,6 +159,11 @@ 鍥惧厓姹 + + + 璁剧疆 + + @@ -229,6 +234,12 @@
ElementPoolWidget.h
1 + + EditorSettingWidget + QWidget +
EditorSettingWidget.h
+ 1 +
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp index b51987b..97898fb 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp @@ -47,3 +47,11 @@ EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent) }); } +void EditorWidget::renameTab(QWidget* target, QString name) +{ + int index = this->tabWidget->indexOf(target); + if (index != -1) + { + this->tabWidget->setTabText(index, name); + } +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidget.h index b0cfe2f..0986609 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.h @@ -18,6 +18,6 @@ private: public: EditorWidget(QWidget* parent = nullptr); ~EditorWidget()=default; - + void renameTab(QWidget* target, QString name); }; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 41d175f..8f6afc9 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -1,8 +1,11 @@ #include "EditorWidgetItem.h" +#include "EditorWidget.h" +#include EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent) { QImage x; + this->parent = parent; displayLayer = nullptr; displayElement = nullptr; ui.setupUi(this); @@ -12,9 +15,12 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p this->filePath = filePath; layerInfoDisplayWidget = dynamic_cast(tabWidget->widget(0)); elementInfoDisplayWidget = dynamic_cast(tabWidget->widget(1)); + editorSettingWidget = dynamic_cast(tabWidget->widget(2)); elementInfoDisplayWidget->enableEdit(); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; + connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange); + connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange); connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged); @@ -53,6 +59,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p treeWidget->refresh(); treeWidget->addTopLevelItem(treeWidget->root->getQTreeItem()); } + this->backgroundColor = source.value("background-color").toVariant().value(); + this->projectName = source.value("project-name").toString(); + qDebug() << this->backgroundColor; + qDebug() << this->projectName; + QTimer::singleShot(300, this, [this]() { + handleBackgroundColorChange(this->backgroundColor); + handleProjectNameChange(this->projectName); + }); + } EditorWidgetItem::~EditorWidgetItem() @@ -100,9 +115,28 @@ void EditorWidgetItem::saveImpl(QString filePath) const json.insert("height", 1080); json.insert("root-layer", source1.value("root-layer")); json.insert("elements", source2.value("elements")); + json.insert("project-name", this->projectName); + json.insert("background-color", QJsonValue::fromVariant(QVariant::fromValue(this->backgroundColor))); QJsonDocument doc(json); QFile file(filePath); file.open(QIODevice::WriteOnly); file.write(doc.toJson()); file.close(); +} + +void EditorWidgetItem::handleBackgroundColorChange(QColor color) +{ + this->backgroundColor = color; + previewWindow->setBackgroundColor(color); +} + +void EditorWidgetItem::handleProjectNameChange(QString name) +{ + this->projectName = name; + auto parent = dynamic_cast(this->parent); + qDebug() << name << " " << parent<<" "<renameTab(this, name); + } } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h index 9fc5be8..409374a 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.h @@ -6,6 +6,7 @@ #include "LayerManager.h" #include "LayerTreeWidget.h" #include "PreviewWindow.h" +#include "EditorSettingWidget.h" #include "ui_EditorWidgetItem.h" #include #include @@ -26,11 +27,17 @@ class EditorWidgetItem : public QWidget QTabWidget *tabWidget; InfoDisplayWidget* layerInfoDisplayWidget; ElementPoolWidget* elementInfoDisplayWidget; + EditorSettingWidget* editorSettingWidget; // QT DATA PART LayerWrapper *displayLayer; GraphicElement *displayElement; - QString filePath; + QWidget* parent; void saveImpl(QString filePath)const; +public: + // PROJECT INFO + QString filePath; + QString projectName; + QColor backgroundColor; public: EditorWidgetItem(QString filePath, QWidget *parent = nullptr); @@ -38,6 +45,8 @@ class EditorWidgetItem : public QWidget void paintEvent(QPaintEvent *event) override; void save() const; void saveAs(QString filePath)const; + void handleBackgroundColorChange(QColor color); + void handleProjectNameChange(QString name); private slots: void onLayerChange(LayerWrapper *layer); diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 05b05e5..c4a03b5 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -13,6 +13,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent) painter->setRenderHint(QPainter::HighQualityAntialiasing); layerManager = nullptr; currentLayer = nullptr; + backgroundColor = QColor(255, 255, 255, 255); } void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize) @@ -44,7 +45,7 @@ void PreviewWindow::initializeGL() void PreviewWindow::paintGL() { - glClearColor(1.0, 1.0, 1.0, 1.0); + glClearColor(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(), backgroundColor.alphaF()); glClear(GL_COLOR_BUFFER_BIT); painter->begin(this); painter->setRenderHint(QPainter::Antialiasing); @@ -112,4 +113,10 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) void PreviewWindow::mouseReleaseEvent(QMouseEvent* event) { emit layerInfoChanged(); +} + +void PreviewWindow::setBackgroundColor(QColor color) +{ + this->backgroundColor = color; + this->repaint(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h index 70a033b..9f9d07c 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h @@ -23,6 +23,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions QRectF viewportRect; LayerWrapper* currentLayer; QPointF m_lastPos; + QColor backgroundColor; void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; @@ -35,6 +36,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions void paintGL() override; void resizeGL(int w, int h) override; Renderer::ElementRenderer* const getRenderer()const; + void setBackgroundColor(QColor color); public slots: void currentLayerChanged(LayerWrapper*); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp new file mode 100644 index 0000000..2f54a22 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp @@ -0,0 +1,21 @@ +#include "EditorSettingWidget.h" +#include +#include +#include + +EditorSettingWidget::EditorSettingWidget(QWidget* parent) + : QWidget(parent) +{ + ui.setupUi(this); + connect(ui.backgroundColorButton, &QPushButton::clicked, this, [this]() { + QColor color = QColorDialog::getColor(Qt::white, this, QString::fromLocal8Bit("选择背景颜色")); + if (color.isValid()) + { + emit backgroundColorChanged(color); + } + }); + connect(ui.renameButton, &QPushButton::clicked, this, [this]() { + QString name = QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("请输入新的项目名称")); + emit projectNameChanged(name); + }); +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.h new file mode 100644 index 0000000..ba0166c --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "ui_EditorSettingWidget.h" + +class EditorSettingWidget : + public QWidget +{ + Q_OBJECT; + + private: + Ui::EditorSettingWidget ui; + + public: + EditorSettingWidget(QWidget* parent = nullptr); + + signals: + void backgroundColorChanged(QColor); + void projectNameChanged(QString); + +}; + diff --git a/data.json b/data.json index 4f381cb..93398a4 100644 --- a/data.json +++ b/data.json @@ -1,4 +1,6 @@ { + "project-name": "鏍蜂緥1", + "background-color": "#ffffff", "height": 1080, "width": 1080, "elements": [