From b6e79ee6de4f653aa4ae4418ecc0c038b55b5352 Mon Sep 17 00:00:00 2001 From: wuyize Date: Mon, 20 Mar 2023 00:26:50 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=80=9A=E8=BF=87json?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9E=84=E9=80=A0Painting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerStyle.cpp | 6 +- .../src/Editor/util/PaintingUtil.cpp | 249 ++++++++---------- .../src/Editor/util/PaintingUtil.h | 7 +- .../src/FluentMenu.cpp | 7 +- ArchitectureColoredPainting/src/FluentMenu.h | 1 + .../src/Renderer/Model.cpp | 3 +- .../src/Renderer/Painting/BvhTree.cpp | 4 +- .../src/Renderer/RendererWidget.cpp | 2 +- test.json | 131 +++++++++ 9 files changed, 255 insertions(+), 155 deletions(-) create mode 100644 test.json diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 3351b34..16ff56c 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -206,11 +206,11 @@ bool LayerStyleContainer::dropStyle(const QString& styleName) float LayerStyleContainer::boundingBoxAffectValue() const { float maxLineWidth = 0; - const auto strokeStyle = styles.at(StrokeElementLayerStyle::displayName()); - if (strokeStyle != nullptr) + const auto strokeStyle = styles.find(StrokeElementLayerStyle::displayName()); + if (strokeStyle != styles.end()) { if (const auto strokeElementLayerStyle = - std::dynamic_pointer_cast(strokeStyle); + std::dynamic_pointer_cast(strokeStyle->second); strokeElementLayerStyle != nullptr) { const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first; diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index aea42d4..ce93afb 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -5,7 +5,7 @@ #include using Renderer::Painting; -using Renderer::Element; +using Renderer::BaseElement; using Renderer::ElementTransform; using glm::bvec2; using std::max; @@ -17,161 +17,124 @@ using std::queue; const double PaintingUtil::pi = acos(-1); struct LayerNode { - LayerWrapper* nowLayer; - QTransform transfrom; - bvec2 flip; + LayerWrapper* nowLayer; + QTransform transfrom; }; QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) { - QFile jsonFile(jsonFilePath); - jsonFile.open(QFile::ReadOnly); - QByteArray fileContent = jsonFile.readAll().trimmed(); - jsonFile.close(); - QJsonParseError jError; - QJsonDocument jsonDoc(QJsonDocument::fromJson(fileContent, &jError)); - return jsonDoc.object(); + QFile jsonFile(jsonFilePath); + qDebug() << jsonFilePath; + jsonFile.open(QFile::ReadOnly); + QByteArray fileContent = jsonFile.readAll().trimmed(); + jsonFile.close(); + QJsonParseError jError; + QJsonDocument jsonDoc(QJsonDocument::fromJson(fileContent, &jError)); + return jsonDoc.object(); } Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { - Painting painting; - glm::bvec2 flip(0, 0); - QJsonObject jsonObj = readJsonFile(jsonFilePath); - qDebug() << jsonObj; - shared_ptr elementManager = make_shared(jsonObj, Renderer::ElementRenderer::instance()); - shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); - //qDebug() << elementManager->toJson(); - //qDebug() << layerManager->toJson(); + Painting painting; + glm::bvec2 flip(0, 0); + QJsonObject jsonObj = readJsonFile(jsonFilePath); + qDebug() << jsonObj; + shared_ptr elementManager = make_shared(jsonObj, Renderer::ElementRenderer::instance()); + shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); + //qDebug() << elementManager->toJson(); + //qDebug() << layerManager->toJson(); //qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath; - //qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath; - queue layerQueue; - LayerWrapper* root = layerManager->getRoot(); - root->getCache(); - layerQueue.push({ root, root->property.transform, flip }); - while (!layerQueue.empty()) { - auto layerNode = layerQueue.front(); - layerQueue.pop(); - FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, layerNode.transfrom, layerNode.flip, painting); - if (nowLayer != nullptr) { - for (auto sonLayer : nowLayer->children) { - layerQueue.push({ sonLayer.get(), layerNode.transfrom, layerNode.flip}); - } - } - } - - return painting; + //qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath; + //qDebug() << elementManager->toJson(); + //qDebug() << layerManager->toJson(); + //qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath; + //qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath; + queue layerQueue; + LayerWrapper* root = layerManager->getRoot(); + root->getCache(); + //double maxLineWidth = getMaxLineWidth(root); + layerQueue.push({ root, root->property.transform }); + while (!layerQueue.empty()) { + auto layerNode = layerQueue.front(); + layerQueue.pop(); + FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, layerNode.transfrom, painting); + if (nowLayer != nullptr) { + for (auto sonLayer : nowLayer->children) { + layerQueue.push({ sonLayer.get(), layerNode.transfrom }); + } + } + } + + return painting; } -FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, bvec2& flip, Painting& painting) { - LeafLayerWrapper* leafLayer = dynamic_cast(nowLayer); - flip ^= bvec2(nowLayer->property.flipHorizontally, nowLayer->property.flipVertically); +FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, Painting& painting) { + LeafLayerWrapper* leafLayer = dynamic_cast(nowLayer); - transform = nowLayer->property.transform * transform; + transform = nowLayer->property.transform * transform; - if (leafLayer != nullptr) { + if (leafLayer != nullptr) { - GroupElement* wrapperElement = dynamic_cast(leafLayer->wrappedElement); - if (wrapperElement != nullptr) { - transform = wrapperElement->sourceLayer->property.transform * transform; - return wrapperElement->sourceLayer; - } + GroupElement* wrapperElement = dynamic_cast(leafLayer->wrappedElement); + if (wrapperElement != nullptr) { + transform = wrapperElement->sourceLayer->property.transform * transform; + return wrapperElement->sourceLayer; + } - PixelPath pixelPath = nowLayer->getCache(); - QPainterPath painterPath = pixelPath.getPainterPath(); - QRectF bound = painterPath.boundingRect(); - //qDebug() << leafLayer<<"------" << painterPath; - //qDebug() << transform; - Element element; - ElementTransform elementTrans; - element.ratio = bound.width() / bound.height(); - // transform to initial painterPath - // transfrom to -1, 1 - QTransform trans; - trans.scale(1 / bound.width(), 1 / bound.height()); - trans.translate(-bound.center().x(), -bound.center().y()); - - qDebug() << trans.map(painterPath); - element.contour = std::make_shared >>(PainterPathUtil::transformToLines(trans.map(painterPath))); - QSize screenSize = QSize(1024, 1024); - element.style = std::make_shared(0.06); - - - painterPath = transform.map(painterPath); - qDebug() << painterPath; - bound = painterPath.boundingRect(); - qDebug() << bound; + PixelPath pixelPath = nowLayer->getCache(); + QPainterPath painterPath = pixelPath.getPainterPath(); + QRectF bound = painterPath.boundingRect(); + //qDebug() << leafLayer<<"------" << painterPath; + //qDebug() << transform; + // transform to initial painterPath + // transfrom to -1, 1 + QTransform trans; + double maxLen = std::max(bound.width(), bound.height()); + qDebug() << maxLen << bound; + trans.scale(1 / maxLen, 1 / maxLen); + trans.translate(-bound.center().x(), -bound.center().y()); - // TODO 改用矩阵 + painterPath = trans.map(painterPath); + shared_ptr >> contour = std::make_shared >>(PainterPathUtil::transformToLines(painterPath)); + QSize screenSize = QSize(1024, 1024); - /* elementTrans.center = glm::vec2( - (2 * bound.center().x() - screenSize.width()) / screenSize.width(), - (2 * bound.center().y() - screenSize.height()) / screenSize.height() - ); - qDebug() << elementTrans.center.x << elementTrans.center.y; - decomposeTransform(transform, elementTrans.rotation, elementTrans.scale); - elementTrans.scale = glm::vec2( - bound.width() * 2 / screenSize.width(), - bound.height() * 2 / screenSize.height() - ); - elementTrans.flip = glm::bvec2( - nowLayer->property.flipHorizontally, - nowLayer->property.flipVertically - ); - qDebug() << elementTrans.scale.x << elementTrans.scale.y; - painting.addElement(element, elementTrans);*/ - return nullptr; - } - - FolderLayerWrapper* folderLayer = dynamic_cast(nowLayer); - return folderLayer; -} -void PaintingUtil::decomposeTransform(QTransform trans, float& angle, glm::vec2& scale) { - //qDebug() << trans; - trans.setMatrix( - trans.m11(), trans.m12(), trans.m13(), - trans.m21(), trans.m22(), trans.m23(), - 0, 0, 1); - //qDebug() << trans.dx() << trans.dy(); - int count = 0; - double norm = 0, n = 0; - QTransform R = trans, Rit, Rnext; - do { - ++count; - Rit = R.transposed().inverted(); - Rnext.setMatrix( - (R.m11() + Rit.m11()) / 2, - (R.m12() + Rit.m12()) / 2, - (R.m13() + Rit.m13()) / 2, - (R.m21() + Rit.m21()) / 2, - (R.m22() + Rit.m22()) / 2, - (R.m23() + Rit.m23()) / 2, - (R.m31() + Rit.m31()) / 2, - (R.m32() + Rit.m32()) / 2, - (R.m33() + Rit.m33()) / 2 - ); - norm = 0; - norm = max(norm, - fabs(R.m11() - Rnext.m11()) - + fabs(R.m12() - Rnext.m12()) - + fabs(R.m13() - Rnext.m13())); - norm = max(norm, - fabs(R.m21() - Rnext.m21()) - + fabs(R.m22() - Rnext.m22()) - + fabs(R.m23() - Rnext.m23())); - norm = max(norm, - fabs(R.m31() - Rnext.m31()) - + fabs(R.m32() - Rnext.m32()) - + fabs(R.m33() - Rnext.m33())); - R = Rnext; - } while (count < 100 && norm > 0.0001); - double cosValue = max(-1.0, min(R.m11(), 1.0)); - double sinValue = max(-1.0, min(R.m12(), 1.0)); - angle = acos(cosValue) * 180 / pi; - if (sinValue < 0) { - angle = 360 - angle; - } - qDebug() << angle; - //R = R.inverted() * trans; - //scale = glm::vec2(R.m11(), R.m22()); - //qDebug() << scale.x << scale.y; - return; + ElementTransform elementTransform; + transform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1); + + auto baseStyles = leafLayer->styles.toBaseStyles(); + Renderer::BaseElement element; + element.contour = contour; + for (auto baseStyle : baseStyles) { + double lineWidth = 0; + if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) { + auto material = dynamic_cast(baseStyle.material.get()); + material->halfWidth = material->halfWidth / maxLen; + lineWidth = material->halfWidth; + qDebug() << material->halfWidth; + } + QRectF rect = painterPath.boundingRect(); + rect.setX(-lineWidth + rect.x()); + rect.setY(-lineWidth + rect.y()); + rect.setWidth(lineWidth * 2 + rect.width()); + rect.setHeight(lineWidth * 2 + rect.height()); + QPainterPath path; + path.addRect(rect); + rect = transform.map(path).boundingRect(); + elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); + qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z; + transform = transform.inverted(); + elementTransform.transform = glm::mat3x2( + transform.m11(), transform.m12(), transform.m21(), + transform.m22(), transform.m31(), transform.m32() + ); + qDebug() << transform; + elementTransform.zIndex = 0; + + element.style = baseStyle.material; + painting.addElement(element, elementTransform); + } + + return nullptr; + } + + FolderLayerWrapper* folderLayer = dynamic_cast(nowLayer); + return folderLayer; } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h index 77e6ea2..850bfc0 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h @@ -7,10 +7,9 @@ class PaintingUtil private: static const double pi; static QJsonObject readJsonFile(QString jsonFilePath); - static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, glm::bvec2& flip, Renderer::Painting& painting); -public: + static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, Renderer::Painting& painting); + //static double getMaxLineWidth(LayerWrapper* root); +public: static Renderer::Painting transfromToPainting(QString jsonFilePath); - static void decomposeTransform(QTransform trans, float& angle, glm::vec2& scale); - }; diff --git a/ArchitectureColoredPainting/src/FluentMenu.cpp b/ArchitectureColoredPainting/src/FluentMenu.cpp index 42b0f7d..2119311 100644 --- a/ArchitectureColoredPainting/src/FluentMenu.cpp +++ b/ArchitectureColoredPainting/src/FluentMenu.cpp @@ -21,4 +21,9 @@ void ::FluentMenu::paintEvent(QPaintEvent* event) painter.drawRoundedRect(QRectF(shadowRadius - i, shadowRadius - i, width() - (shadowRadius - i) * 2, height() - (shadowRadius - i) * 2), borderRadius + i, borderRadius + i); } QMenu::paintEvent(event); -} \ No newline at end of file +} + +QAction* FluentMenu::exec(const QPoint& pos, QAction* at) +{ + return QMenu::exec(parentWidget()->mapToGlobal(parentWidget()->mapFromGlobal(pos) + QPoint(-shadowRadius, -shadowRadius)), at); +} diff --git a/ArchitectureColoredPainting/src/FluentMenu.h b/ArchitectureColoredPainting/src/FluentMenu.h index 480f6e2..f0ac3fe 100644 --- a/ArchitectureColoredPainting/src/FluentMenu.h +++ b/ArchitectureColoredPainting/src/FluentMenu.h @@ -7,6 +7,7 @@ class FluentMenu : public QMenu public: explicit FluentMenu(QWidget* parent = nullptr); void paintEvent(QPaintEvent* event) override; + QAction* exec(const QPoint& pos, QAction* at = nullptr); int shadowRadius = 16; int borderRadius = 6; int itemBorderRadius = 4; diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 3510ed7..9251d9c 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -244,8 +244,9 @@ GLuint Renderer::Model::loadPainting(std::string path) return iter->second; Painting painting; + path = "../test.json"; if (auto file = QFileInfo(QString(path.c_str())); file.isFile()) - painting = PaintingUtil::transfromToPainting(file.path()); + painting = PaintingUtil::transfromToPainting(file.filePath()); else { qDebug() << path.c_str() << "Not Found, Using Default Painting"; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp index 82edf94..000fec3 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp @@ -20,12 +20,12 @@ QVector4D BvhTree::Union(QVector4D a, QVector4D b) { QVector4D BvhTree::merge(BvhPtr lp, BvhPtr rp) { QVector4D a = lp->bound, b = rp->bound; - if (lp->isLeaf) { + /*if (lp->isLeaf) { a = BvhTreeData::boundWithRotation(a, lp->getRightSon()); } if (rp->isLeaf) { b = BvhTreeData::boundWithRotation(b, rp->getRightSon()); - } + }*/ return Union(a, b); } diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp index d0df771..7e1e03a 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp @@ -29,7 +29,7 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent) ui.openButton->setChecked(false); }); QObject::connect(ui.openButton, &QPushButton::clicked, [&, menu]() { - menu->exec(ui.openButton->mapToGlobal(QPoint(-menu->shadowRadius, ui.openButton->height() - menu->shadowRadius))); + menu->exec(ui.openButton->mapToGlobal(QPoint(0, ui.openButton->height()))); }); QObject::connect(ui.horizontalSlider, &QSlider::valueChanged, diff --git a/test.json b/test.json new file mode 100644 index 0000000..15441e2 --- /dev/null +++ b/test.json @@ -0,0 +1,131 @@ +{ + "background-color": "#ffffff", + "elements": [ + { + "data": { + "include": "../svg/2.svg" + }, + "name": "ababa", + "type": "svg-file" + }, + { + "data": { + "reference-layer": "0.0" + }, + "name": "ababa-group", + "type": "group" + }, + { + "data": { + "include": "../svg/0.svg" + }, + "name": "ababa2", + "type": "svg-file" + } + ], + "height": 1080, + "project-name": "鏍蜂緥1", + "root-layer": { + "children": [ + { + "children": [ + { + "element": 0, + "is-folder": false, + "name": "Leaf1", + "styles": [ + { + "enableEachSideIndependent": false, + "left": "AAAAQAEAIZwAf///qqr//w==", + "right": "AADgQAAACJw=", + "type": "stroke" + } + ], + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 0, + "is-folder": false, + "name": "Leaf2", + "styles": [ + { + "enableEachSideIndependent": false, + "left": "AAAAQAEAIZwAf////1UA/w==", + "right": "AADgQAAACJw=", + "type": "stroke" + } + ], + "transform": { + "offset": { + "x": 150, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1.5, + "y": 1.5 + } + } + } + ], + "is-folder": true, + "name": "GroupFolderExample", + "referenced-by": 1, + "transform": { + "offset": { + "x": 50, + "y": 50 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 1, + "is-folder": false, + "name": "ReferencingGroupLayer", + "styles": [ + ], + "transform": { + "offset": { + "x": 100, + "y": 0 + }, + "rotation": 45, + "scale": { + "x": 1, + "y": 1 + } + } + } + ], + "is-folder": true, + "name": "root", + "referenced-by": null, + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + "width": 1080 +} From 855dd2e075f9fbc7e5a380459250a4d1e56fd875 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 02:48:52 +0800 Subject: [PATCH 2/9] =?UTF-8?q?[editor]=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=9A=E5=AF=BC=E8=87=B4warning=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20|=20#15=20=20*=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86ColorHelper=20=20*=20LayerStyleDialog=E9=87=8D?= =?UTF-8?q?=E5=A4=8DsetLayer=E5=AF=BC=E8=87=B4=E7=9A=84warning=20=20*=20QC?= =?UTF-8?q?olorDialog::getColor=E6=97=B6=E7=94=B1=E4=BA=8EQt=E7=9A=84bug?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E8=AE=BE=E7=BD=AE=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 1 + ...rchitectureColoredPainting.vcxproj.filters | 3 ++ .../src/ColorHelper.hpp | 49 +++++++++++++++++++ .../EditorWidgetComponent/ColorPicker.cpp | 6 +-- .../EditorWidgetComponent/ColorPicker.h | 3 +- .../EditorWidgetComponent/FillStyleWidget.cpp | 2 +- .../LayerStyleDialog.cpp | 25 +++++----- .../EditorWidgetComponent/LayerStyleDialog.h | 4 +- .../StrokeStyleWidget.cpp | 20 ++++---- .../EditorWidgetComponent/StrokeStyleWidget.h | 4 +- .../src/Editor/LayerStyle.cpp | 3 +- .../Editor/RightBar/EditorSettingWidget.cpp | 4 +- ArchitectureColoredPainting/src/main.cpp | 6 +-- 13 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 ArchitectureColoredPainting/src/ColorHelper.hpp diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index c403fad..7414c08 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -202,6 +202,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index e198184..835a354 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -519,6 +519,9 @@ Header Files\Editor\Layer + + Header Files + diff --git a/ArchitectureColoredPainting/src/ColorHelper.hpp b/ArchitectureColoredPainting/src/ColorHelper.hpp new file mode 100644 index 0000000..f337382 --- /dev/null +++ b/ArchitectureColoredPainting/src/ColorHelper.hpp @@ -0,0 +1,49 @@ +#pragma once +#include +#include +#include + +class ColorHelper +{ + QtMaterialTheme theme; + QColor primary1; +public: + + void setPrimary1(const QColor& color) + { + theme.setColor("primary1", color); + primary1 = color; + } + + [[nodiscard]] QColor getPrimary1() const + { + return primary1; + } + + ColorHelper() + { + setPrimary1(QColor::fromRgb(0, 90, 158)); + QtMaterialStyle::instance().setTheme(&theme); + } + + static ColorHelper& instance() + { + static ColorHelper instance; + return instance; + } + + static QColor execColorDialog( + const QColor& initial = instance().getPrimary1(), + QWidget* parent = nullptr, + const QString& title = "" + ) { + auto dialog = QColorDialog(initial, parent); + if (!title.isEmpty()) + { + dialog.setWindowTitle(title); + } + dialog.adjustSize(); + dialog.exec(); + return dialog.selectedColor(); + } +}; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp index 7010ae4..4ccb504 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp @@ -1,5 +1,6 @@ #include "ColorPicker.h" #include +#include QString getStyleSheet(const QColor& color) { @@ -26,9 +27,8 @@ QColor ColorPicker::getColor() const void ColorPicker::onClicked() { - QColorDialog dialog(this->color, this); - dialog.exec(); - QColor newColor = dialog.selectedColor(); + //const QColor newColor = QColorDialog::getColor(this->color, this); + const QColor newColor = ColorHelper::execColorDialog(this->color, this); if (newColor.isValid() && this->color != newColor) { this->color = newColor; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h index a8edd67..50c1c34 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h @@ -1,4 +1,5 @@ #pragma once +#include "../ColorHelper.hpp" #include class ColorPicker : public QPushButton { @@ -6,7 +7,7 @@ class ColorPicker : public QPushButton private: QColor color; public: - ColorPicker(const QColor& color = QColor::fromRgb(0, 0, 0), QWidget* parent = nullptr); + ColorPicker(const QColor& color = ColorHelper::instance().getPrimary1(), QWidget* parent = nullptr); QColor getColor() const; public slots: void onClicked(); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp index bf78dbc..662ff47 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp @@ -4,7 +4,7 @@ #include #include -FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent) +FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent) : QWidget(parent), fill(fill) { auto* layout = new QGridLayout(this); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp index 33a3568..40c2555 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp @@ -1,28 +1,25 @@ #include "LayerStyleDialog.h" #include #include -#include #include LayerStyleDialog::LayerStyleDialog( LayerStyleContainer& styles, - std::shared_ptr existedStyle, + const std::shared_ptr& existedStyle, QWidget* parent ) : QDialog(parent), styles(&styles) { - auto* dialogLayout = new QVBoxLayout(this); + dialogLayout = new QGridLayout; dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); this->setLayout(dialogLayout); if (existedStyle) { this->modifyingStyle = existedStyle->clone(); - - this->styleContainer = nullptr; + this->styleWidget = modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - dialogLayout->addWidget(styleWidget); - // do something + dialogLayout->addWidget(styleWidget, 1, 0); } else { @@ -34,13 +31,12 @@ LayerStyleDialog::LayerStyleDialog( typeSelector->addItems(unusedStyleNames); this->modifyingStyle = std::move(styles.makeUnusedStyle(unusedStyleNames[0])); - dialogLayout->addWidget(typeSelector); - this->styleContainer = new QGridLayout(this); - dialogLayout->addLayout(styleContainer); + dialogLayout->addWidget(typeSelector, 0, 0); + this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - this->styleContainer->addWidget(styleWidget); + this->dialogLayout->addWidget(styleWidget, 1, 0); connect(typeSelector, &QComboBox::currentTextChanged, this, &LayerStyleDialog::onStyleTypeSelectorChanged); } @@ -48,7 +44,8 @@ LayerStyleDialog::LayerStyleDialog( auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(buttonBox, &QDialogButtonBox::accepted, this, &LayerStyleDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &LayerStyleDialog::reject); - dialogLayout->addWidget(buttonBox); + dialogLayout->addWidget(buttonBox, 2, 0); + this->adjustSize(); } void LayerStyleDialog::accept() @@ -61,14 +58,14 @@ void LayerStyleDialog::onStyleTypeSelectorChanged(const QString& current) { if (this->styleWidget) { - this->styleContainer->removeWidget(this->styleWidget); + this->dialogLayout->removeWidget(this->styleWidget); this->styleWidget->setParent(nullptr); delete styleWidget; } this->modifyingStyle = std::move(styles->makeUnusedStyle(current)); this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - this->styleContainer->addWidget(styleWidget, 0, 0, 1, 1); + this->dialogLayout->addWidget(styleWidget, 1, 0); this->styleWidget->adjustSize(); this->adjustSize(); } diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h index b703e80..485b58c 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h @@ -8,13 +8,13 @@ class LayerStyleDialog : public QDialog Q_OBJECT private: QWidget* styleWidget; - QGridLayout* styleContainer; + QGridLayout* dialogLayout; LayerStyleContainer* styles; std::unique_ptr modifyingStyle; public: LayerStyleDialog( LayerStyleContainer& styles, - std::shared_ptr existedStyle = nullptr, + const std::shared_ptr& existedStyle = nullptr, QWidget* parent = nullptr ); std::shared_ptr layerStyle; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index e2c9ce7..e9999bb 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -1,8 +1,8 @@ #include "StrokeStyleWidget.h" #include "ColorPicker.h" +#include "../ColorHelper.hpp" #include #include -#include constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; @@ -105,8 +105,8 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetBackgroundColor(QtMaterialStyle::instance().themeColor("primary1")); + auto* addButton = new QtMaterialRaisedButton("+", strokeTable); + addButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); strokeTable->setSpan(row, 0, 1, 5); strokeTable->setCellWidget(row, 0, addButton); strokeTable->setMinimumHeight(strokeTable->rowHeight(row) * 5); @@ -114,18 +114,18 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetFixedHeight(strokeTable->rowHeight(row)); connect(addButton, &QtMaterialRaisedButton::clicked, [this]() { handlingRowInsert = true; - auto materialMap = &(radialStroke(this->stroke)->materialMap); - float newWidth = 0; - if (materialMap->size() == 0) + auto materialMap = &radialStroke(this->stroke)->materialMap; + float newWidth; + if (materialMap->empty()) { newWidth = 0.1; } else { - auto lastPair = materialMap->rbegin(); + const auto lastPair = materialMap->rbegin(); newWidth = lastPair->first + 0.01; } - Renderer::Material newMaterial(QColor::fromRgb(0, 0, 0)); + const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1()); (*materialMap)[newWidth] = newMaterial; int newRow = this->strokeTable->rowCount() - 1; this->strokeTable->insertRow(newRow); @@ -143,7 +143,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma widthItem->setData(Qt::EditRole, width); strokeTable->setItem(row, COLUMN_WIDTH, widthItem); - QColor* colorPtr = &(material.color); + QColor* colorPtr = &material.color; auto* colorItem = new QTableWidgetItem; colorItem->setData(Qt::DisplayRole, *colorPtr); strokeTable->setItem(row, COLUMN_COLOR, colorItem); @@ -163,7 +163,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem); auto* removeButton = new QtMaterialRaisedButton("-", strokeTable); - removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1")); + removeButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); removeButton->setFixedSize(20, 20); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index 6d5dbdd..67af3ee 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -23,8 +23,8 @@ private: void setTableRow(int row, float width, Renderer::Material& material); public: - StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr); - std::shared_ptr stroke; + StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr); + std::shared_ptr stroke; protected slots: void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 16ff56c..292d0ca 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -2,6 +2,7 @@ #include "./EditorWidgetComponent/StrokeStyleWidget.h" #include "./EditorWidgetComponent/FillStyleWidget.h" #include "./util/EncodeUtil.hpp" +#include "../ColorHelper.hpp" #include #include #include @@ -334,7 +335,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater if (!fillMaterialStyle) { this->fillMaterialStyle = std::make_shared( - std::make_shared(Renderer::Material(QColor::fromRgb(0, 0, 0))) + std::make_shared(ColorHelper::instance().getPrimary1()) ); } } diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp index 2f54a22..979af0b 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp @@ -1,6 +1,6 @@ #include "EditorSettingWidget.h" +#include "../ColorHelper.hpp" #include -#include #include EditorSettingWidget::EditorSettingWidget(QWidget* parent) @@ -8,7 +8,7 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent) { ui.setupUi(this); connect(ui.backgroundColorButton, &QPushButton::clicked, this, [this]() { - QColor color = QColorDialog::getColor(Qt::white, this, QString::fromLocal8Bit("选择背景颜色")); + QColor color = ColorHelper::execColorDialog(Qt::white, this, QString::fromLocal8Bit("选择背景颜色")); if (color.isValid()) { emit backgroundColorChanged(color); diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 5bf6bbe..0e3d73b 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -1,11 +1,11 @@ #include "MainWindow.h" +#include "ColorHelper.hpp" #include #include #include #include #include #include "consoleapi2.h" -#include extern "C" { @@ -51,9 +51,7 @@ 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); + ColorHelper::instance(); //FramelessHelper::Core::setApplicationOSThemeAware(); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); //FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); From f06fbbaef6a238066323c4360a7dbdf0ac778530 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 14:44:36 +0800 Subject: [PATCH 3/9] =?UTF-8?q?FIX:=20=E6=9A=82=E6=97=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E5=B1=82=E5=B1=9E=E6=80=A7=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 17 +++++++++-------- .../src/Editor/PreviewWindow.cpp | 5 ++--- .../src/Editor/PreviewWindow.h | 1 + .../src/Editor/RightBar/InfoDisplayWidget.cpp | 5 ++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index eb5f228..b9930ab 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -25,6 +25,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p treeWidget->refresh(); previewWindow->refresh(); }; + connect(previewWindow, &PreviewWindow::triggerCentralRefresh, centralRefresh); connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh); connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh); connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh); @@ -33,15 +34,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged); - connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); - connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); + //connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); + // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange); - connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, - &EditorWidgetItem::triggerRefreshPreview); - connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this, - &EditorWidgetItem::triggerRefreshPreview); - connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); - connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh); + // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, + // &EditorWidgetItem::triggerRefreshPreview); + // connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this, + // &EditorWidgetItem::triggerRefreshPreview); + //connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); + // connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh); // &EditorWidget::triggerRefreshPreview); // test QFile settingFile; diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index c4a03b5..dbe317c 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -100,19 +100,18 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) auto index = -1; if (typeid(*layer) == typeid(FolderLayerWrapper)) index = dynamic_cast(layer)->getReferencedBy(); - if (index != -1) - emit refreshElementPreviewByIndex(index); layer = layer->getParent(); } } // 更新上一次的位置 + emit triggerCentralRefresh(); m_lastPos = event->pos(); this->repaint(); } void PreviewWindow::mouseReleaseEvent(QMouseEvent* event) { - emit layerInfoChanged(); + //emit layerInfoChanged(); } void PreviewWindow::setBackgroundColor(QColor color) diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h index 9f9d07c..4fd002d 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h @@ -46,4 +46,5 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions void layerInfoChanged(); void refreshElementPreview(GraphicElement*); void refreshElementPreviewByIndex(int); + void triggerCentralRefresh(); }; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 6869729..56e46b4 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -21,12 +21,11 @@ void InfoDisplayWidget::generateLayerForm() { while (this->layout()->count() > 0 && (item = this->layout()->takeAt(0)) != nullptr) { - delete item->widget(); - delete item; + item->widget()->deleteLater(); + delete item; } delete this->layout(); } - QFormLayout *layout = new QFormLayout(); layout->setRowWrapPolicy(QFormLayout::WrapAllRows); if (this->displayLayer == nullptr) From 8a34f57251647a80fbed0d0b97f0a0161ae6b213 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 15:52:27 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=98=BE=E7=A4=BA/?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=9B=BE=E5=B1=82=E5=8A=9F=E8=83=BD=20|=20#1?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditorWidgetItem.ui | 11 +++++++ .../src/Editor/EditorWidgetItem.cpp | 3 +- .../src/Editor/GraphicElement.cpp | 2 +- .../src/Editor/LayerWrapper.cpp | 32 +++++++++---------- .../src/Editor/LayerWrapper.h | 7 ++-- .../src/Editor/RightBar/LayerTreeWidget.cpp | 5 +++ 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index e269e9d..b8eb51c 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -180,6 +180,12 @@ + + + 10 + 10 + + 鍥惧眰鍚 @@ -190,6 +196,11 @@ 鍏宠仈鍥惧厓 + + + 鍙 + + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index b9930ab..2693b45 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -74,9 +74,10 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p this->projectName = source.value("project-name").toString(); qDebug() << this->backgroundColor; qDebug() << this->projectName; - QTimer::singleShot(300, this, [this]() { + QTimer::singleShot(300, this, [this, centralRefresh]() { handleBackgroundColorChange(this->backgroundColor); handleProjectNameChange(this->projectName); + centralRefresh(); }); } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 4cc2ef3..01f6df5 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -127,7 +127,7 @@ bool SimpleElement::isClosed() const void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) { - sourceLayer->paint(painter, transform); + sourceLayer->paint(painter, transform, true); } bool GroupElement::isClosed() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index bf0222b..1240eb2 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -47,6 +47,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM transformJson.value("scale").toObject().value("y").toDouble()}; property.rotation = {transformJson.value("rotation").toDouble()}; selected = false; + hidden = false; } FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) @@ -199,6 +200,7 @@ void FolderLayerWrapper::delSelf() { QTreeWidgetItem* LayerWrapper::getQTreeItem() { this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this)); + this->qTreeWidgetItem->setCheckState(0, Qt::Checked); return this->qTreeWidgetItem; } @@ -280,31 +282,27 @@ int FolderLayerWrapper::getReferencedBy()const return -1; } -void LayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - if (!ignoreSelected && this->selected) - { - painter->save(); - painter->setTransform(transform, ignoreSelected); - painter->setPen(QPen(Qt::gray, 2)); - painter->setPen(Qt::DashLine); - painter->drawRect(cache.getBoundingRect()); - painter->restore(); - } + } -void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - LayerWrapper::paint(painter, transform, ignoreSelected); + if (hidden && !force) + return; + LayerWrapper::paint(painter, transform, force); transform = property.transform * transform; //qDebug() << transform; for (auto& child : children) - child->paint(painter, transform, ignoreSelected); + child->paint(painter, transform, force); } -void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - LayerWrapper::paint(painter, transform, ignoreSelected); + if (hidden && !force) + return; + LayerWrapper::paint(painter, transform, force); transform = property.transform * transform; //qDebug() << transform; if (wrappedElement != nullptr) @@ -347,11 +345,12 @@ void FolderLayerWrapper::collectDownReachable(std::set& reachable void LayerWrapper::refreshTreeItem() { - + hidden = qTreeWidgetItem->checkState(0) == Qt::Unchecked; } void LeafLayerWrapper::refreshTreeItem() { + LayerWrapper::refreshTreeItem(); if (typeid(*wrappedElement) == typeid(GroupElement)) { this->qTreeWidgetItem->setText(0, "@ " + this->property.name); @@ -366,6 +365,7 @@ void LeafLayerWrapper::refreshTreeItem() void FolderLayerWrapper::refreshTreeItem() { + LayerWrapper::refreshTreeItem(); for (auto& child : this->children) { child->refreshTreeItem(); } diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 947d90c..6312f12 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -37,6 +37,7 @@ class LayerWrapper public: QTreeWidgetItem* qTreeWidgetItem; bool selected; + bool hidden; struct SimpleProperty { QString name = ""; @@ -58,7 +59,7 @@ class LayerWrapper FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr); LayerWrapper() = default; - virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool ignoreSelected = false); + virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool force = false); // TODO : export Function // virtual LayerWrapper *addChild() = 0; // Leaf Child Only // virtual LayerWrapper *addParent() = 0; // Folder Parent Only @@ -97,7 +98,7 @@ class FolderLayerWrapper : public LayerWrapper QTreeWidgetItem* getQTreeItem() override; QJsonObject toJson() const override; int getReferencedBy()const; - void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; + void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override; void collectDownReachable(std::set& reachable) override; void refreshTreeItem() override; size_t referencedCount(bool excludeSelf = false) const override; @@ -115,7 +116,7 @@ class LeafLayerWrapper : public LayerWrapper void refresh(LayerWrapper* layer = nullptr) override; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); QJsonObject toJson() const override; - void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; + void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override; void collectDownReachable(std::set& reachable) override; QTreeWidgetItem* getQTreeItem() override; void refreshTreeItem() override; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index a8ba44e..5090342 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -2,6 +2,7 @@ #include #include #include "./EditorWidgetComponent/LayerCreateWidget.h" +#include LayerTreeWidget::LayerTreeWidget(QWidget *parent) { @@ -26,6 +27,10 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent) } emit triggerCentralRefresh(); }); + connect(this, &QTreeWidget::itemChanged, this, [=]() { + emit triggerCentralRefresh(); + }); + // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked); } From f25f2d2a81f4b0129713a90796b4097740dec961 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 17:35:33 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=AB=98=E4=BA=AE?= =?UTF-8?q?=E9=80=89=E4=B8=ADLayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerManager.cpp | 13 ++++++++++ .../src/Editor/LayerWrapper.cpp | 26 ++++++++++++++++++- .../src/Editor/LayerWrapper.h | 1 + .../src/Editor/PixelPath.cpp | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp index 06f0170..b1d2e60 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp @@ -13,8 +13,21 @@ LayerWrapper *LayerManager::getRoot() const } void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const { + painter->save(); root->getCache(); root->paint(painter); + painter->restore(); + painter->save(); + // painter->setBrush(QBrush(Qt::white)); + //painter->setCompositionMode(QPainter::CompositionMode_Difference); + if (selecetedLayer != nullptr) + { + painter->setPen(QPen(Qt::gray, 2, Qt::DashLine)); + selecetedLayer->paintVisualBounding(painter); + //painter->setPen(QPen(Qt::gray, 2, Qt::DashDotLine)); + //selecetedLayer->paintVisualBounding(painter); + } + painter->restore(); } bool LayerManager::singleSelectedCheck() const { diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 1240eb2..d2f1453 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -284,7 +284,14 @@ int FolderLayerWrapper::getReferencedBy()const void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - + // if (this->selected) + // { + // painter->save(); + //painter->setPen(QPen(Qt::red, 2)); + //painter->setTransform(transform); + //painter->drawRect(this->cache.getBoundingRect()); + //painter->restore(); + // } } void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) @@ -428,4 +435,21 @@ bool LeafLayerWrapper::referencingGroupElement() const bool LayerWrapper::canApplyStyles() const { return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement(); +} + +void LayerWrapper::paintVisualBounding(QPainter* painter) const +{ + if (hidden) + return; + QTransform transform; + auto layer = this->parent; + while (layer != nullptr) + { + transform = transform * layer->property.transform; + layer = layer->parent; + } + painter->save(); + painter->setTransform(transform); + painter->drawRect(cache.getBoundingRect()); + painter->restore(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 6312f12..c45ec21 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -75,6 +75,7 @@ class LayerWrapper virtual size_t referencedCount(bool excludeSelf = false) const; virtual bool deleteable(bool excludeSubTree = false) const; virtual bool referencingGroupElement() const; + virtual void paintVisualBounding(QPainter* painter) const; bool canApplyStyles() const; }; diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp index 3087f39..e673504 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp @@ -78,7 +78,8 @@ PixelPath PixelPath::trans(QTransform& mat)const painter.setTransform(mat); painter.drawPixmap(0, 0, pixmap); result.painterPath.addPath(this->painterPath); - result.boundingRect = mat.mapRect(boundingRect); + result.painterPath = mat.map(result.painterPath); + result.boundingRect = result.painterPath.boundingRect(); return result; } From ae641bb87c0bfd434d81a097a32cb90e2a1c51ea Mon Sep 17 00:00:00 2001 From: wuyize Date: Mon, 20 Mar 2023 17:48:18 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86StrokeEndType::k?= =?UTF-8?q?Closed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/Shaders/element.comp | 25 ++++++++++++++-- .../src/Editor/util/PaintingUtil.cpp | 25 +++++++--------- .../Renderer/Painting/MaterialStyleStroke.cpp | 13 +++++++-- .../Renderer/Painting/MaterialStyleStroke.h | 3 +- UnitTest/ElementRendererTest.cpp | 29 ++++++++++++++++--- UnitTest/UnitTest.cpp | 16 +--------- test.json | 2 +- 7 files changed, 72 insertions(+), 41 deletions(-) diff --git a/ArchitectureColoredPainting/res/Shaders/element.comp b/ArchitectureColoredPainting/res/Shaders/element.comp index fd09af8..511c470 100644 --- a/ArchitectureColoredPainting/res/Shaders/element.comp +++ b/ArchitectureColoredPainting/res/Shaders/element.comp @@ -1093,6 +1093,7 @@ void main() bool onVeryBegin = false; bool onVeryEnd = false; vec2 tangentEndLast; + vec2 tangentFirstBegin; uint lastHitIndex = 0; bool lastHitElement = false; hitElement = false; @@ -1108,7 +1109,19 @@ void main() pBegin = path[++pathIndex]; p3Last = pBegin; p2Last = pBegin; - onVeryBegin = true; + if(endType == 4) + { + //onVeryBegin = false; + vec2 lastP1 = path[pathSize-3]; + vec2 lastP2 = path[pathSize-2]; + vec2 lastP3 = path[pathSize-1]; + if (lastP3 != lastP2) + tangentEndLast = normalize(lastP3 - lastP2); + else + tangentEndLast = normalize(lastP3 - lastP1); + } + else + onVeryBegin = true; continue; } mat4x2 p = mat4x2(p3Last, pTemp, path[++pathIndex], path[++pathIndex]); @@ -1119,7 +1132,13 @@ void main() vec2 pTemp = path[pathIndex + 1]; if (isinf(pTemp.x)) { - onVeryEnd = true; + if(endType == 4) + { + //onVeryEnd = false; + tangentBeginNext = tangentFirstBegin; + } + else + onVeryEnd = true; } else { @@ -1180,6 +1199,8 @@ void main() } } tangentEndLast = tangentEnd; + if(pathIndex == 0) + tangentFirstBegin = tangentBegin; } p3Last = p[3]; p2Last = p[2]; diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index ce93afb..aa23ce6 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -83,9 +83,7 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr QPainterPath painterPath = pixelPath.getPainterPath(); QRectF bound = painterPath.boundingRect(); //qDebug() << leafLayer<<"------" << painterPath; - //qDebug() << transform; - // transform to initial painterPath - // transfrom to -1, 1 + // transform to -1, 1 QTransform trans; double maxLen = std::max(bound.width(), bound.height()); qDebug() << maxLen << bound; @@ -102,22 +100,19 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr auto baseStyles = leafLayer->styles.toBaseStyles(); Renderer::BaseElement element; element.contour = contour; - for (auto baseStyle : baseStyles) { + for (auto& baseStyle : baseStyles) { double lineWidth = 0; if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) { - auto material = dynamic_cast(baseStyle.material.get()); - material->halfWidth = material->halfWidth / maxLen; + auto material = std::static_pointer_cast(baseStyle.material); + material->halfWidth /= maxLen; lineWidth = material->halfWidth; qDebug() << material->halfWidth; } - QRectF rect = painterPath.boundingRect(); - rect.setX(-lineWidth + rect.x()); - rect.setY(-lineWidth + rect.y()); - rect.setWidth(lineWidth * 2 + rect.width()); - rect.setHeight(lineWidth * 2 + rect.height()); - QPainterPath path; - path.addRect(rect); - rect = transform.map(path).boundingRect(); + QPainterPathStroker stroker; + stroker.setWidth(lineWidth); + stroker.setCapStyle(Qt::RoundCap); + QPainterPath strokePath = stroker.createStroke(painterPath); + auto rect = transform.map(strokePath).boundingRect(); elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z; transform = transform.inverted(); @@ -125,7 +120,7 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr transform.m11(), transform.m12(), transform.m21(), transform.m22(), transform.m31(), transform.m32() ); - qDebug() << transform; + //qDebug() << transform; elementTransform.zIndex = 0; element.style = baseStyle.material; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp index 0d72542..9919f73 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp @@ -1,5 +1,6 @@ #include "MaterialStyleStroke.h" #include +#include using namespace Renderer; @@ -105,8 +106,8 @@ std::unique_ptr Renderer::MaterialStyleStroke::clone() const bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const { - return type() == m.type() - && halfWidth == static_cast(m).halfWidth + return type() == m.type() + && halfWidth == static_cast(m).halfWidth && strokeType == static_cast(m).strokeType && endType == static_cast(m).endType && *materialStroke == *static_cast(m).materialStroke; @@ -117,4 +118,10 @@ float Renderer::MaterialStyleStroke::getHalfWidth() const return halfWidth; } - +#define endTypeBoxLabel(start, end) QStringLiteral(start##" -> "##end) +const std::array, 4> Renderer::MaterialStyleStroke::strokeEndTypeNames = { + std::pair{endTypeBoxLabel("圆头", "圆头"), StrokeEndType::kRound}, + std::pair{endTypeBoxLabel("平头", "圆头"), StrokeEndType::kFlatRound}, + std::pair{endTypeBoxLabel("圆头", "平头"), StrokeEndType::kRoundFlat}, + std::pair{endTypeBoxLabel("平头", "平头"), StrokeEndType::kFlat} +}; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h index 29fd55b..e6bf8af 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h @@ -43,7 +43,7 @@ namespace Renderer }; enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 }; - enum class StrokeEndType { kRound = 0b00, kFlat = 0b11, kRoundFlat = 0b10, kFlatRound = 0b01 }; + enum class StrokeEndType { kRound = 0b00, kFlat = 0b11, kRoundFlat = 0b10, kFlatRound = 0b01, kClosed = 0b100/*用于封闭图形*/ }; class MaterialStyleStroke : public MaterialStyle { @@ -59,5 +59,6 @@ namespace Renderer StrokeType strokeType; StrokeEndType endType; std::shared_ptr materialStroke; + static const std::array, 4> strokeEndTypeNames; }; } diff --git a/UnitTest/ElementRendererTest.cpp b/UnitTest/ElementRendererTest.cpp index aba0474..5760980 100644 --- a/UnitTest/ElementRendererTest.cpp +++ b/UnitTest/ElementRendererTest.cpp @@ -42,17 +42,38 @@ namespace UnitTest { virtual std::vector toBaseStyles() const override { - return { BaseStyle(std::make_shared(), - std::make_shared( - std::make_shared(Material(QColor(255,255,0))))) }; + std::make_shared(std::make_shared(Material(QColor(255,255,0))))) }; + } + } style; + TestGLWidget w(style, path); + w.show(); + a.exec(); + } + TEST_METHOD(TestFillPlainAndStrokeRadialGradient) + { + QApplication a(argc, argv); + class Style : public Renderer::ElementStyle + { + virtual std::vector toBaseStyles() const override + { + std::map materialMap = { + {0.20, Material{QColor(255,255,255)}}, + {0.60, Material{QColor(165,176,207)}}, + {1.00, Material{QColor(58,64,151)}} + }; + return { BaseStyle(std::make_shared(), + std::make_shared( + std::make_shared(Material(QColor(255,255,0))))), + BaseStyle(std::make_shared(), + std::make_shared(10, StrokeType::kBothSides, StrokeEndType::kRound, + std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } - }; TEST_CLASS(ElementRendererStokeTypeTest) diff --git a/UnitTest/UnitTest.cpp b/UnitTest/UnitTest.cpp index 25bcf67..0005c41 100644 --- a/UnitTest/UnitTest.cpp +++ b/UnitTest/UnitTest.cpp @@ -122,20 +122,6 @@ namespace UnitTest }; TEST_CLASS(PaintingUtilTest) { - TEST_METHOD(TransfromTest) - { - qInstallMessageHandler(messageHandler); - QPainterPath path; - path.addRect(0, 0, 20, 20); - QTransform trans; - qDebug() << path.boundingRect(); - //qDebug() << trans; - //qDebug() << acos(-0.707107); - glm::vec2 scale; - float rotate; - PaintingUtil::decomposeTransform(trans, rotate, scale); - qDebug() << rotate; - qDebug() << scale.x << scale.y; - } + }; } diff --git a/test.json b/test.json index 15441e2..ce11428 100644 --- a/test.json +++ b/test.json @@ -59,7 +59,7 @@ "name": "Leaf2", "styles": [ { - "enableEachSideIndependent": false, + "enableEachSideIndependent": true, "left": "AAAAQAEAIZwAf////1UA/w==", "right": "AADgQAAACJw=", "type": "stroke" From 6a1c64a4267a84f958ea44eb8da6ab8bd47e6b6a Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 18:03:54 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Ctrl+=E5=B7=A6=E9=94=AE?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E7=BC=A9=E6=94=BE=EF=BC=8CC+S+=E5=B7=A6?= =?UTF-8?q?=E9=94=AE=E7=AD=89=E6=AF=94=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/PreviewWindow.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index dbe317c..410b8af 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -1,4 +1,5 @@ #include "PreviewWindow.h" +#include PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent) { @@ -84,7 +85,17 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) int dx = event->x() - m_lastPos.x(); int dy = event->y() - m_lastPos.y(); if (currentLayer != nullptr) { - if (event->buttons() & Qt::LeftButton) { + if (QApplication::keyboardModifiers() == Qt::ControlModifier && (event->buttons() & Qt::LeftButton)) + { + currentLayer->property.scale.setX(std::max(0.0, currentLayer->property.scale.x() + dx / 50.0)); + currentLayer->property.scale.setY(std::max(0.0, currentLayer->property.scale.y() + dy / 50.0)); + } + else if (QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && (event->buttons() & Qt::LeftButton)) + { + currentLayer->property.scale.setX(std::max(0.0, currentLayer->property.scale.x() * (1.0 + dx / 50.0))); + currentLayer->property.scale.setY(std::max(0.0, currentLayer->property.scale.y() * (1.0 + dx / 50.0))); + } + else if (event->buttons() & Qt::LeftButton) { // 如果按下的是左键,那么平移图形 currentLayer->property.offset.setX(currentLayer->property.offset.x() + dx); currentLayer->property.offset.setY(currentLayer->property.offset.y() + dy); From 4b2776d4297df8e4ce49dfa77c26505becde97bf Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 19:03:15 +0800 Subject: [PATCH 8/9] =?UTF-8?q?[editor/style]=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86Stroke=E7=9A=84=E6=B7=BB=E5=8A=A0=E4=BA=A4=E4=BA=92=20?= =?UTF-8?q?|=20#17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrokeStyleWidget.cpp | 62 ++++++++++++------- .../EditorWidgetComponent/StrokeStyleWidget.h | 3 + 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index e9999bb..3984076 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -3,6 +3,7 @@ #include "../ColorHelper.hpp" #include #include +#include constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; @@ -10,11 +11,22 @@ constexpr int COLUMN_METALLIC = 2; constexpr int COLUMN_ROUGHNESS = 3; constexpr int COLUMN_OPERATIONS = 4; +inline Renderer::Material newMaterial() +{ + return {ColorHelper::instance().getPrimary1()}; +} + StrokeStyleWidget::StrokeStyleWidget( std::shared_ptr stroke, QWidget* parent ) : QWidget(parent), stroke(stroke) { + auto& materialMap = radialStroke(stroke)->materialMap; + if (materialMap.empty()) + { + materialMap[1.f] = newMaterial(); + } + auto* viewLayout = new QVBoxLayout(this); this->setLayout(viewLayout); @@ -30,8 +42,12 @@ StrokeStyleWidget::StrokeStyleWidget( viewLayout->addWidget(strokeProperties); viewLayout->addWidget(widthField); - initTable(std::dynamic_pointer_cast(stroke->materialStroke)); + initTable(radialStroke(stroke)); viewLayout->addWidget(strokeTable); + + initAddButton(); + viewLayout->addWidget(addButton); + this->adjustSize(); } @@ -83,13 +99,12 @@ void StrokeStyleWidget::initStrokeSettings() }); } -// TODO: 新增时参数校验 void StrokeStyleWidget::initTable(std::shared_ptr materialStroke) { this->strokeTable = new QTableWidget(this); strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); strokeTable->setColumnCount(5); - strokeTable->setRowCount(materialStroke->materialMap.size() + 1); + strokeTable->setRowCount(materialStroke->materialMap.size()); QStringList headers; headers << QStringLiteral("离心距离占比") << QStringLiteral("颜色") @@ -97,44 +112,45 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetHorizontalHeaderLabels(headers); + strokeTable->setMinimumHeight(strokeTable->rowHeight(0) * 5); + strokeTable->setMinimumWidth(strokeTable->sizeHint().width()); int row = 0; // 内容 - for (auto & strokePair : materialStroke->materialMap) + for (auto& [width, material] : std::views::reverse(materialStroke->materialMap)) { - setTableRow(row, strokePair.first, strokePair.second); + setTableRow(row, width, material); row++; } - // 新增按钮 - auto* addButton = new QtMaterialRaisedButton("+", strokeTable); + connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged); + connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged); +} + +void StrokeStyleWidget::initAddButton() +{ + this->addButton = new QtMaterialRaisedButton("+", strokeTable); + addButton->setFixedHeight(this->strokeTable->rowHeight(0)); addButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); - strokeTable->setSpan(row, 0, 1, 5); - strokeTable->setCellWidget(row, 0, addButton); - strokeTable->setMinimumHeight(strokeTable->rowHeight(row) * 5); - strokeTable->setMinimumWidth(strokeTable->sizeHint().width()); - addButton->setFixedHeight(strokeTable->rowHeight(row)); - connect(addButton, &QtMaterialRaisedButton::clicked, [this]() { + connect(addButton, &QtMaterialRaisedButton::clicked, [this] { handlingRowInsert = true; auto materialMap = &radialStroke(this->stroke)->materialMap; float newWidth; if (materialMap->empty()) { - newWidth = 0.1; + newWidth = 1.f; } else { - const auto lastPair = materialMap->rbegin(); - newWidth = lastPair->first + 0.01; + const auto firstPair = materialMap->begin(); + newWidth = firstPair->first / 2; } const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1()); (*materialMap)[newWidth] = newMaterial; - int newRow = this->strokeTable->rowCount() - 1; + int newRow = this->strokeTable->rowCount(); this->strokeTable->insertRow(newRow); setTableRow(newRow, newWidth, (*materialMap)[newWidth]); this->strokeTable->update(); handlingRowInsert = false; }); - connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged); - connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged); } void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& material) @@ -166,7 +182,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma removeButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); removeButton->setFixedSize(20, 20); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); - connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { + connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row] { radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat()); this->strokeTable->removeRow(row); }); @@ -199,9 +215,13 @@ void StrokeStyleWidget::onCellChanged(int row, int column) { float oldWidth = this->currentItemValue.toFloat(); auto node = radialStroke(stroke)->materialMap.extract(oldWidth); + if (node.empty()) + { + break; + } node.key() = changedWidth; radialStroke(stroke)->materialMap.insert(std::move(node)); - strokeTable->sortItems(COLUMN_WIDTH); + strokeTable->sortItems(COLUMN_WIDTH, Qt::DescendingOrder); break; } case COLUMN_METALLIC: diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index 67af3ee..d0bd250 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -6,6 +6,7 @@ #include #include #include +#include class StrokeStyleWidget : public QWidget { Q_OBJECT @@ -16,10 +17,12 @@ private: QComboBox* endTypeBox; QtMaterialTextField* widthField; QTableWidget* strokeTable; + QtMaterialRaisedButton* addButton; bool handlingRowInsert = false; void initStrokeSettings(); void initTable(std::shared_ptr materialStroke); + void initAddButton(); void setTableRow(int row, float width, Renderer::Material& material); public: From bf71d17b5d31abe029fa35e38ad21e55b70936ed Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 19:58:02 +0800 Subject: [PATCH 9/9] =?UTF-8?q?[editor/style]=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E4=BA=86=E6=96=B0=E7=9A=84StrokeEndType=20|=20#18=20=20*=20[st?= =?UTF-8?q?roke]=20=E9=80=82=E9=85=8D=E4=BA=86=E6=96=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9A=84StrokeEndType::kClosed=20=20*=20[stroke]=20=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E4=BA=86Renderer=E6=96=B9=E9=9D=A2=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=9A=84=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrokeStyleWidget.cpp | 75 ++++++++++--------- .../EditorWidgetComponent/StrokeStyleWidget.h | 4 +- .../src/Editor/LayerStyle.cpp | 8 +- .../src/Editor/LayerStyle.h | 24 +++--- 4 files changed, 60 insertions(+), 51 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index 3984076..7422763 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -3,7 +3,9 @@ #include "../ColorHelper.hpp" #include #include +#include #include +#include constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; @@ -16,8 +18,13 @@ inline Renderer::Material newMaterial() return {ColorHelper::instance().getPrimary1()}; } +inline bool isClosedStroke(const std::shared_ptr& stroke) +{ + return stroke->endType == Renderer::StrokeEndType::kClosed; +} + StrokeStyleWidget::StrokeStyleWidget( - std::shared_ptr stroke, + const std::shared_ptr& stroke, QWidget* parent ) : QWidget(parent), stroke(stroke) { @@ -37,7 +44,10 @@ StrokeStyleWidget::StrokeStyleWidget( strokeProperties->setLayout(strokePropertiesLayout); strokePropertiesLayout->addWidget(enableGradual); - strokePropertiesLayout->addWidget(endTypeBox); + if (!isClosedStroke(stroke)) + { + strokePropertiesLayout->addWidget(endTypeBox); + } viewLayout->addWidget(strokeProperties); viewLayout->addWidget(widthField); @@ -60,30 +70,23 @@ void StrokeStyleWidget::initStrokeSettings() radialStroke(this->stroke)->gradual = checked; }); -#define endTypeBoxLabel(start, end) QStringLiteral(start##" -> "##end) - this->endTypeBox = new QComboBox(this); - endTypeBox->addItem(endTypeBoxLabel("圆头", "圆头")); // kRound - endTypeBox->addItem(endTypeBoxLabel("平头", "圆头")); // kFlatRound - endTypeBox->addItem(endTypeBoxLabel("圆头", "平头")); // kRoundFlat - endTypeBox->addItem(endTypeBoxLabel("平头", "平头")); // kFlat - endTypeBox->setCurrentIndex(static_cast(this->stroke->endType)); - connect(endTypeBox, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { - switch (index) + if (!isClosedStroke(stroke)) + { + this->endTypeBox = new QComboBox(this); + for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys) { - case 0: - this->stroke->endType = Renderer::StrokeEndType::kRound; - break; - case 1: - this->stroke->endType = Renderer::StrokeEndType::kFlatRound; - break; - case 2: - this->stroke->endType = Renderer::StrokeEndType::kRoundFlat; - break; - case 3: - this->stroke->endType = Renderer::StrokeEndType::kFlat; - break; + endTypeBox->addItem(displayName); } - }); + endTypeBox->setCurrentIndex(static_cast(this->stroke->endType)); + connect(endTypeBox, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { + const auto& [displayName, endType] = MaterialStyleStroke::strokeEndTypeNames[index]; + this->stroke->endType = endType; + }); + } + else + { + this->endTypeBox = nullptr; + } this->widthField = new QtMaterialTextField(this); widthField->setLabel(QStringLiteral("本侧描边宽度")); @@ -99,7 +102,7 @@ void StrokeStyleWidget::initStrokeSettings() }); } -void StrokeStyleWidget::initTable(std::shared_ptr materialStroke) +void StrokeStyleWidget::initTable(const std::shared_ptr& materialStroke) { this->strokeTable = new QTableWidget(this); strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); @@ -132,22 +135,22 @@ void StrokeStyleWidget::initAddButton() addButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); connect(addButton, &QtMaterialRaisedButton::clicked, [this] { handlingRowInsert = true; - auto materialMap = &radialStroke(this->stroke)->materialMap; + auto& materialMap = radialStroke(this->stroke)->materialMap; float newWidth; - if (materialMap->empty()) + if (materialMap.empty()) { newWidth = 1.f; } else { - const auto firstPair = materialMap->begin(); + const auto firstPair = materialMap.begin(); newWidth = firstPair->first / 2; } const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1()); - (*materialMap)[newWidth] = newMaterial; - int newRow = this->strokeTable->rowCount(); + materialMap[newWidth] = newMaterial; + const int newRow = this->strokeTable->rowCount(); this->strokeTable->insertRow(newRow); - setTableRow(newRow, newWidth, (*materialMap)[newWidth]); + setTableRow(newRow, newWidth, materialMap[newWidth]); this->strokeTable->update(); handlingRowInsert = false; }); @@ -166,7 +169,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma auto* colorPicker = new ColorPicker(*colorPtr, strokeTable); strokeTable->setCellWidget(row, COLUMN_COLOR, colorPicker); connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) { - *colorPtr = color; + *colorPtr = std::move(color); this->strokeTable->update(); }); @@ -191,7 +194,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) { if (!current) return; - int column = current->column(); + const int column = current->column(); if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS) { this->currentItemValue = current->data(Qt::EditRole); @@ -201,14 +204,14 @@ void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWi void StrokeStyleWidget::onCellChanged(int row, int column) { if (handlingRowInsert) return; - auto changedItem = strokeTable->item(row, column); - auto changedItemValue = changedItem->text().toFloat(); + const auto changedItem = strokeTable->item(row, column); + const auto changedItemValue = changedItem->text().toFloat(); if (changedItemValue < 0 || 1 < changedItemValue) { changedItem->setData(Qt::EditRole, this->currentItemValue.toFloat()); return; } - auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->data(Qt::EditRole).toFloat(); + const auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->data(Qt::EditRole).toFloat(); switch (column) { case COLUMN_WIDTH: diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index d0bd250..c4d1bfc 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -21,12 +21,12 @@ private: bool handlingRowInsert = false; void initStrokeSettings(); - void initTable(std::shared_ptr materialStroke); + void initTable(const std::shared_ptr& materialStroke); void initAddButton(); void setTableRow(int row, float width, Renderer::Material& material); public: - StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr); + StrokeStyleWidget(const std::shared_ptr& stroke, QWidget* parent = nullptr); std::shared_ptr stroke; protected slots: diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 292d0ca..d8bbae3 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -78,7 +78,7 @@ QWidget* StrokeElementLayerStyle::getListDisplayWidget() const void LayerStyleContainer::computeNewHash() { hash = 0; - for (auto& f : styles + for (auto& f : styles | std::views::values | std::views::transform(&LayerStyle::toBaseStyles) | std::views::join @@ -248,18 +248,18 @@ std::unique_ptr StrokeElementLayerStyle::fromJson(const return ptr; } -StrokeElementLayerStyle::StrokeElementLayerStyle() +StrokeElementLayerStyle::StrokeElementLayerStyle(bool isClosed) { const auto materialMap = std::map(); this->strokePair.first = std::make_shared( 7, - Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat, + Renderer::StrokeType::kLeftSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat, std::make_shared(materialMap, false) ); this->strokePair.second = std::make_shared( 7, - Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat, + Renderer::StrokeType::kRightSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat, std::make_shared(materialMap, false) ); diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 9274732..3eba1ad 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -46,7 +46,7 @@ public: STYLE_NAME("描边", "stroke") static std::unique_ptr fromJson(const QJsonObject& json); - StrokeElementLayerStyle(); + StrokeElementLayerStyle(bool isClosed); StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right = nullptr); StrokeElementLayerStyle(const StrokeElementLayerStyle& other); ~StrokeElementLayerStyle() override = default; @@ -88,17 +88,23 @@ public: class LayerStyleContainer : public Renderer::ElementStyle { using DisplayNameWithSupplier = std::map()>>; -private: - inline const static DisplayNameWithSupplier commonStyles = { { +private: + inline const static DisplayNameWithSupplier commonStyles = { }; + inline const static DisplayNameWithSupplier closedOnlyStyles = { + { + FillElementLayerStyle::displayName(), + [] { return std::make_unique(); } + }, + { + StrokeElementLayerStyle::displayName(), + [] { return std::make_unique(true); } + } + }; + inline const static DisplayNameWithSupplier unclosedOnlyStyles = { { StrokeElementLayerStyle::displayName(), - [] { return std::make_unique(); } + [] { return std::make_unique(false); } } }; - inline const static DisplayNameWithSupplier closedOnlyStyles = { { - FillElementLayerStyle::displayName(), - [] { return std::make_unique(); } - } }; - inline const static DisplayNameWithSupplier unclosedOnlyStyles = { }; DisplayNameWithSupplier unusedStyles; DisplayNameWithSupplier usedStyles;