From 587c09115aaef9fc460fb004118c95e63355026b Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Sun, 19 Mar 2023 14:43:25 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[editor/style]=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=8C=BA=E5=88=86=E5=B0=81=E9=97=AD=E4=B8=8E=E9=9D=9E?= =?UTF-8?q?=E5=B0=81=E9=97=AD=E5=9B=BE=E5=85=83=20|=20#12=20=20*=20LayerSt?= =?UTF-8?q?yleContainer=E7=9A=84=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86isClosedElement=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rchitectureColoredPainting.vcxproj.filters | 6 ++ .../src/Editor/LayerStyle.cpp | 30 ++++--- .../src/Editor/LayerStyle.h | 83 +++++++++++-------- .../src/Editor/LayerWrapper.cpp | 10 +-- .../src/Editor/LayerWrapper.h | 1 - 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 5610888..e198184 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -255,6 +255,9 @@ Source Files\Editor\Layer + + Source Files + @@ -308,6 +311,9 @@ Header Files\Editor\Layer + + Header Files + diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 7240d46..3351b34 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -90,9 +90,9 @@ void LayerStyleContainer::computeNewHash() } } -LayerStyleContainer LayerStyleContainer::fromJson(const QJsonArray& jsonArray) +LayerStyleContainer LayerStyleContainer::fromJson(bool isClosedElement, const QJsonArray& jsonArray) { - LayerStyleContainer container; + LayerStyleContainer container(isClosedElement); for (const auto& style : jsonArray) { container.useStyle(LayerStyle::fromJson(style.toObject())); @@ -100,16 +100,26 @@ LayerStyleContainer LayerStyleContainer::fromJson(const QJsonArray& jsonArray) return container; } -LayerStyleContainer::LayerStyleContainer() : hash(0) +LayerStyleContainer::LayerStyleContainer(bool isClosedElement) : hash(0) { - unusedStyles = { { - StrokeElementLayerStyle::displayName(), - [] { return std::make_unique(); } - }, + for (const auto& style : commonStyles) { - FillElementLayerStyle::displayName(), - [] { return std::make_unique(); } - } }; + unusedStyles.insert(style); + } + if (isClosedElement) + { + for (const auto& style : closedOnlyStyles) + { + unusedStyles.insert(style); + } + } + else + { + for (const auto& style : unclosedOnlyStyles) + { + unusedStyles.insert(style); + } + } } std::vector LayerStyleContainer::toBaseStyles() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 3d9b023..9274732 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -38,42 +38,6 @@ public: virtual std::unique_ptr clone() const = 0; }; -/** - * LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新 - */ -class LayerStyleContainer : public Renderer::ElementStyle -{ - using DisplayNameWithSupplier = std::map()>>; -private: - DisplayNameWithSupplier unusedStyles; - DisplayNameWithSupplier usedStyles; - std::map> styles; - size_t hash; -public: - static LayerStyleContainer fromJson(const QJsonArray& jsonArray); - - LayerStyleContainer(); - std::vector toBaseStyles() const override; - QJsonArray toJson() const; - - bool empty() const; - bool full() const; - std::map>::iterator begin(); - std::map>::iterator end(); - - QStringList unusedStyleNames() const; - std::unique_ptr makeUnusedStyle(const QString& styleName) const; - bool useStyle(const std::shared_ptr& style); - bool dropStyle(const QString& styleName); - float boundingBoxAffectValue() const; - size_t getHash() const; - - /** - * 需要在每次更改后手动调用 - */ - void computeNewHash(); -}; - class StrokeElementLayerStyle : public LayerStyle { using PMaterialStyleStroke = std::shared_ptr; @@ -116,4 +80,51 @@ public: std::unique_ptr clone() const override; PMaterialStyleFill fillMaterialStyle; +}; + +/** + * LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新 + */ +class LayerStyleContainer : public Renderer::ElementStyle +{ + using DisplayNameWithSupplier = std::map()>>; +private: + + inline const static DisplayNameWithSupplier commonStyles = { { + StrokeElementLayerStyle::displayName(), + [] { return std::make_unique(); } + } }; + inline const static DisplayNameWithSupplier closedOnlyStyles = { { + FillElementLayerStyle::displayName(), + [] { return std::make_unique(); } + } }; + inline const static DisplayNameWithSupplier unclosedOnlyStyles = { }; + + DisplayNameWithSupplier unusedStyles; + DisplayNameWithSupplier usedStyles; + std::map> styles; + size_t hash; +public: + static LayerStyleContainer fromJson(bool isClosedElement, const QJsonArray& jsonArray); + + LayerStyleContainer(bool isClosedElement); + std::vector toBaseStyles() const override; + QJsonArray toJson() const; + + bool empty() const; + bool full() const; + std::map>::iterator begin(); + std::map>::iterator end(); + + QStringList unusedStyleNames() const; + std::unique_ptr makeUnusedStyle(const QString& styleName) const; + bool useStyle(const std::shared_ptr& style); + bool dropStyle(const QString& styleName); + float boundingBoxAffectValue() const; + size_t getHash() const; + + /** + * 需要在每次更改后手动调用 + */ + void computeNewHash(); }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index e83ae7e..f131f27 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -73,14 +73,12 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element } } -LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) - : LayerWrapper(json, parent) +LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementManager, FolderLayerWrapper* parent) + : LayerWrapper(json, parent), + wrappedElement(elementManager->getElementById(json.value("element").toInt())), + styles(LayerStyleContainer::fromJson(wrappedElement->isClosed(), json.value("styles").toArray())) { qDebug() << json.value("name").toString() << " " << this; - int elementIndex = json.value("element").toInt(); - wrappedElement = elementManager->getElementById(elementIndex); - QJsonArray stylesArray = json.value("styles").toArray(); - styles = LayerStyleContainer::fromJson(stylesArray); } void LayerWrapper::SimpleProperty::apply(PixelPath&cache) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index b767d35..3b82b86 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -107,7 +107,6 @@ class LeafLayerWrapper : public LayerWrapper public: ~LeafLayerWrapper() = default; void refresh(LayerWrapper* layer = nullptr) override; - LeafLayerWrapper() = default; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); QJsonObject toJson() const override; void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; From 3904ff0b61ad2d86ab2dab5198a3dfafc460b719 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Sun, 19 Mar 2023 15:33:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=A3=80=E6=B5=8B=20|=20#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/ElementPoolWidget.cpp | 1 + .../src/Editor/GraphicElement.h | 1 + .../src/Editor/LayerWrapper.cpp | 45 +++++++++++++++++++ .../src/Editor/LayerWrapper.h | 6 ++- .../src/Editor/RightBar/LayerTreeWidget.cpp | 14 +++--- 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp index 17ec55a..ff166f0 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp @@ -120,6 +120,7 @@ void ElementPoolWidget::popMenu(const QPoint& pos) this->elementManager->removeElement(currentElement); refresh(); }); + menu->actions().last()->setDisabled(currentElement->referencedCount > 0); } else { diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index 377b9e5..8ce9bf2 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -20,6 +20,7 @@ class ComposedPainterPath; class GraphicElement { public: + size_t referencedCount = 0; Renderer::ElementRenderer *renderer; QString name = ""; int index; diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index f131f27..770c45d 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -79,6 +79,14 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementMana styles(LayerStyleContainer::fromJson(wrappedElement->isClosed(), json.value("styles").toArray())) { qDebug() << json.value("name").toString() << " " << this; + if(wrappedElement != nullptr) + wrappedElement->referencedCount++; +} + +LeafLayerWrapper::~LeafLayerWrapper() +{ + if (wrappedElement != nullptr) + wrappedElement->referencedCount--; } void LayerWrapper::SimpleProperty::apply(PixelPath&cache) @@ -368,4 +376,41 @@ void FolderLayerWrapper::refreshTreeItem() this->qTreeWidgetItem->setText(1, "<< " + ele->name); this->qTreeWidgetItem->setTextColor(1, Qt::darkGreen); } + if (this->referencedCount() > 0) + { + this->qTreeWidgetItem->setToolTip(0,QString::fromLocal8Bit("子树被引用计数:") + QString::number(this->referencedCount(true)) + "\n" + + QString::fromLocal8Bit("当前节点被引用计数:") + QString::number(this->getReferencedBy() != -1)); + } + else + { + this->qTreeWidgetItem->setToolTip(0, ""); + } } + +size_t LayerWrapper::referencedCount(bool excludeSelf) const +{ + return 0; +} + +size_t FolderLayerWrapper::referencedCount(bool excludeSelf) const +{ + size_t count = 0; + for (auto& child : children) + count += child->referencedCount(); + if (!excludeSelf && this->getReferencedBy() != -1) + count++; + return count; +} + +bool LayerWrapper::deleteable(bool excludeSubTree) const +{ + return true; +} + +bool FolderLayerWrapper::deleteable(bool excludeSubTree) const +{ + if (excludeSubTree) + return this->getReferencedBy() == -1; + else + return this->referencedCount() == 0; +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 3b82b86..b62d685 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -71,6 +71,8 @@ class LayerWrapper virtual void collectUpReachable(std::set& reachable); virtual void collectDownReachable(std::set& reachable); virtual void refreshTreeItem(); + virtual size_t referencedCount(bool excludeSelf = false) const; + virtual bool deleteable(bool excludeSubTree = false) const; }; class FolderLayerWrapper : public LayerWrapper @@ -96,6 +98,8 @@ class FolderLayerWrapper : public LayerWrapper void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; void collectDownReachable(std::set& reachable) override; void refreshTreeItem() override; + size_t referencedCount(bool excludeSelf = false) const override; + bool deleteable(bool excludeSubTree = false) const override; }; class LeafLayerWrapper : public LayerWrapper @@ -105,7 +109,7 @@ class LeafLayerWrapper : public LayerWrapper LayerStyleContainer styles; public: - ~LeafLayerWrapper() = default; + ~LeafLayerWrapper(); void refresh(LayerWrapper* layer = nullptr) override; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); QJsonObject toJson() const override; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index 69a67b9..dba5943 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -78,16 +78,20 @@ void LayerTreeWidget::popMenu(const QPoint &pos) emit requireRefreshPreview(); emit requireRefreshElementWidget(); }); + menu.actions().last()->setEnabled(layer->deleteable()); menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); if(typeid(*layer) == typeid(FolderLayerWrapper)) + { menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() { auto layer = this->selectedItem->data(0, Qt::UserRole).value(); - layer->delSelf(); - layer->getParent()->removeChild(layer); - this->refresh(); - emit requireRefreshPreview(); - emit requireRefreshElementWidget(); + layer->delSelf(); + layer->getParent()->removeChild(layer); + this->refresh(); + emit requireRefreshPreview(); + emit requireRefreshElementWidget(); }); + menu.actions().last()->setEnabled(layer->deleteable(true)); + } } if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) { menu.addAction(QString::fromLocal8Bit("创建组合元素"), this, [this]() { From 8bf6835c234cced8f7efe0401685d66efef3915b Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Sun, 19 Mar 2023 15:48:42 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0LayerWrapper=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerWrapper.cpp | 15 +++++++++++++++ .../src/Editor/LayerWrapper.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 770c45d..bf0222b 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -413,4 +413,19 @@ bool FolderLayerWrapper::deleteable(bool excludeSubTree) const return this->getReferencedBy() == -1; else return this->referencedCount() == 0; +} + +bool LayerWrapper::referencingGroupElement() const +{ + return false; +} + +bool LeafLayerWrapper::referencingGroupElement() const +{ + return typeid(*wrappedElement) == typeid(GroupElement); +} + +bool LayerWrapper::canApplyStyles() const +{ + return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index b62d685..947d90c 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -73,6 +73,8 @@ class LayerWrapper virtual void refreshTreeItem(); virtual size_t referencedCount(bool excludeSelf = false) const; virtual bool deleteable(bool excludeSubTree = false) const; + virtual bool referencingGroupElement() const; + bool canApplyStyles() const; }; class FolderLayerWrapper : public LayerWrapper @@ -117,6 +119,7 @@ class LeafLayerWrapper : public LayerWrapper void collectDownReachable(std::set& reachable) override; QTreeWidgetItem* getQTreeItem() override; void refreshTreeItem() override; + bool referencingGroupElement() const override; }; Q_DECLARE_METATYPE(LayerWrapper *) From b3bbf6c1bee75caeaaad05e7f4c300125c4f6f93 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Sun, 19 Mar 2023 16:07:35 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=87=8D=E5=86=99=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E5=8F=8A=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 9 +++++ .../src/Editor/ElementPoolWidget.cpp | 7 ++-- .../src/Editor/ElementPoolWidget.h | 1 + .../src/Editor/RightBar/InfoDisplayWidget.cpp | 36 ++++++++----------- .../src/Editor/RightBar/InfoDisplayWidget.h | 4 ++- .../src/Editor/RightBar/LayerTreeWidget.cpp | 16 +++------ .../src/Editor/RightBar/LayerTreeWidget.h | 1 + 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index bef3c7c..eb5f228 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -19,6 +19,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p elementInfoDisplayWidget->enableEdit(); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; + auto centralRefresh = [this]() { + layerInfoDisplayWidget->refresh(); + elementInfoDisplayWidget->refresh(); + treeWidget->refresh(); + previewWindow->refresh(); + }; + connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh); + connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh); + connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh); connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange); connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange); connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp index ff166f0..74453d0 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp @@ -67,7 +67,6 @@ void ElementPoolWidget::setElementManager(ElementManager* element) void ElementPoolWidget::refresh() { this->setElementList(this->elementManager->elements); - emit refreshLayerTree(); // update(); } @@ -113,12 +112,12 @@ void ElementPoolWidget::popMenu(const QPoint& pos) if (bOk && !sName.isEmpty()) { currentElement->name = sName; - refresh(); + emit triggerCentralRefresh(); } }); menu->addAction(QString::fromLocal8Bit("删除"), this, [this, currentElement]() { this->elementManager->removeElement(currentElement); - refresh(); + emit triggerCentralRefresh(); }); menu->actions().last()->setDisabled(currentElement->referencedCount > 0); } @@ -130,7 +129,7 @@ void ElementPoolWidget::popMenu(const QPoint& pos) QString fileName = fileInfo.fileName(); qDebug() << fileName << " " << filePath; this->elementManager->createSimpleElement(fileName, filePath); - refresh(); + emit triggerCentralRefresh(); }); } menu->popup(mapToGlobal(pos)); diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h index 82ee0ff..472b1ba 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h @@ -26,6 +26,7 @@ public: signals: void elementSelected(GraphicElement* element); void refreshLayerTree(); + void triggerCentralRefresh(); public slots: int pictureItemClicked(QListWidgetItem* item); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 1db2940..6869729 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -45,32 +45,27 @@ void InfoDisplayWidget::generateLayerForm() rotation->setValidator(new QIntValidator(-10000, 10000, this)); connect(rotation, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.rotation = content.toDouble(); - emit requireRefreshElementWidget(); - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); offsetX->setValidator(new QIntValidator(-10000, 10000, this)); connect(offsetX, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()}; - emit requireRefreshElementWidget(); - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); offsetY->setValidator(new QIntValidator(-10000, 10000, this)); connect(offsetY, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()}; - emit requireRefreshElementWidget(); - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); connect(scaleX, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()}; - emit requireRefreshElementWidget(); - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); connect(scaleY, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()}; - emit requireRefreshElementWidget(); - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); layout->addRow("layer name:", name); @@ -108,10 +103,7 @@ void InfoDisplayWidget::generateLayerForm() { leafP->styles.useStyle(dialog->layerStyle); leafP->styles.computeNewHash(); - - emit requireRefreshPreview(); - emit requireSelfRefresh(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); } }); } @@ -153,10 +145,7 @@ void InfoDisplayWidget::generateLayerForm() { styleIterator->second = dialog->layerStyle; styles->computeNewHash(); - - emit requireRefreshPreview(); - emit requireSelfRefresh(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); } }); @@ -165,10 +154,7 @@ void InfoDisplayWidget::generateLayerForm() { styles->dropStyle(styleIterator->first); styles->computeNewHash(); - - emit requireRefreshPreview(); - emit requireSelfRefresh(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); }); QWidget* styleDisplayWidget = styleIterator->second->getListDisplayWidget(); @@ -190,6 +176,12 @@ void InfoDisplayWidget::generateLayerForm() } void InfoDisplayWidget::triggerSelfRefresh() +{ + if (this->displayLayer != nullptr) + this->generateLayerForm(); +} + +void InfoDisplayWidget::refresh() { if (this->displayLayer != nullptr) this->generateLayerForm(); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h index 37b259c..da314f5 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h @@ -16,11 +16,13 @@ class InfoDisplayWidget : public QWidget public: void setLayer(LayerWrapper *layer); void generateLayerForm(); + void refresh(); public slots: void triggerSelfRefresh(); - signals: +signals: + void triggerCentralRefresh(); void requireRefreshPreview(); void requireSelfRefresh(); void requireRefreshElementWidget(); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index dba5943..a8ba44e 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -24,7 +24,7 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent) else { emit displayLayerChange(nullptr); } - emit requireRefreshPreview(); + emit triggerCentralRefresh(); }); // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked); } @@ -62,9 +62,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos) folderLayer->addChild(std::shared_ptr(newLayer)); folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem()); qDebug() << jsonObj<<"----------------------"; - this->refresh(); - emit requireRefreshPreview(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); }); dialog->exec(); }); @@ -74,9 +72,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos) auto layer = this->selectedItem->data(0, Qt::UserRole).value(); layer->del(); layer->getParent()->removeChild(layer); - this->refresh(); - emit requireRefreshPreview(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); }); menu.actions().last()->setEnabled(layer->deleteable()); menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); @@ -86,9 +82,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos) auto layer = this->selectedItem->data(0, Qt::UserRole).value(); layer->delSelf(); layer->getParent()->removeChild(layer); - this->refresh(); - emit requireRefreshPreview(); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); }); menu.actions().last()->setEnabled(layer->deleteable(true)); } @@ -103,7 +97,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos) "", &ok); if (ok && !name.isEmpty()) { elementManager->createGroupElement(name, layer); - emit requireRefreshElementWidget(); + emit triggerCentralRefresh(); } } }); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h index e7472dd..a7f4c93 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h @@ -21,6 +21,7 @@ class LayerTreeWidget : public QTreeWidget // void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0); signals: + void triggerCentralRefresh(); void displayLayerChange(LayerWrapper *); void requireRefreshPreview(); void requireRefreshElementWidget(); From b6e79ee6de4f653aa4ae4418ecc0c038b55b5352 Mon Sep 17 00:00:00 2001 From: wuyize Date: Mon, 20 Mar 2023 00:26:50 +0800 Subject: [PATCH 5/5] =?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 +}