From 0aa69195b32a42296adc358ed642a23194848c3a Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 19:51:01 +0800 Subject: [PATCH] =?UTF-8?q?[stroke]=20=E9=80=82=E9=85=8D=E4=BA=86=E6=96=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9A=84StrokeEndType::kClosed=20=E4=B8=BA?= =?UTF-8?q?=E5=B0=81=E9=97=AD=E5=8F=8A=E9=9D=9E=E5=B0=81=E9=97=AD=E5=9B=BE?= =?UTF-8?q?=E5=85=83=E7=9A=84=E6=8F=8F=E8=BE=B9style=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=81=9A=E4=BA=86=E5=88=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrokeStyleWidget.cpp | 35 +++++++++++++------ .../src/Editor/LayerStyle.cpp | 8 ++--- .../src/Editor/LayerStyle.h | 24 ++++++++----- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index 60b65c8..7422763 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -18,6 +18,11 @@ inline Renderer::Material newMaterial() return {ColorHelper::instance().getPrimary1()}; } +inline bool isClosedStroke(const std::shared_ptr& stroke) +{ + return stroke->endType == Renderer::StrokeEndType::kClosed; +} + StrokeStyleWidget::StrokeStyleWidget( const std::shared_ptr& stroke, QWidget* parent @@ -39,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); @@ -61,17 +69,24 @@ void StrokeStyleWidget::initStrokeSettings() connect(enableGradual, &QtMaterialCheckBox::toggled, [this](bool checked) { radialStroke(this->stroke)->gradual = checked; }); - - this->endTypeBox = new QComboBox(this); - for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys) + + if (!isClosedStroke(stroke)) { - endTypeBox->addItem(displayName); + this->endTypeBox = new QComboBox(this); + for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys) + { + 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; } - 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; - }); this->widthField = new QtMaterialTextField(this); widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È")); 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;