From 7079b335cb6d8a559eac1f5903a07de7ef7e95e0 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Wed, 15 Mar 2023 15:09:55 +0800 Subject: [PATCH] =?UTF-8?q?[style/stroke]=20=E5=AE=8C=E6=88=90=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=AE=BE=E7=BD=AE=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrokeStyleWidget.cpp | 73 +++++++++++++++---- .../EditorWidgetComponent/StrokeStyleWidget.h | 8 +- .../src/Editor/LayerStyle.cpp | 1 - 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index e758dfc..f5ae10c 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -1,7 +1,6 @@ #include "StrokeStyleWidget.h" #include "ColorPicker.h" #include -#include #include #define radialStroke(stroke) std::dynamic_pointer_cast(stroke->materialStroke) @@ -18,21 +17,19 @@ StrokeStyleWidget::StrokeStyleWidget( QWidget* parent ) : QWidget(parent), stroke(stroke) { - this->viewLayout = new QVBoxLayout(this); + QVBoxLayout* viewLayout = new QVBoxLayout(this); this->setLayout(viewLayout); - QtMaterialTextField* widthField = new QtMaterialTextField(this); - widthField->setLabel(QStringLiteral("本侧描边宽度")); - widthField->setText(QString::number(stroke->halfWidth)); - QDoubleValidator* widthValidator = new QDoubleValidator(0.1, std::numeric_limits::max(), 3, widthField); - widthValidator->setNotation(QDoubleValidator::StandardNotation); - widthField->setValidator(widthValidator); - connect(widthField, &QtMaterialTextField::textChanged, [this, widthField](const QString& changed) { - if (widthField->hasAcceptableInput()) - { - this->stroke->halfWidth = changed.toFloat(); - } - }); + initStrokeSettings(); + QWidget* strokeProperties = new QWidget(this); + QHBoxLayout* strokePropertiesLayout = new QHBoxLayout(strokeProperties); + strokePropertiesLayout->setMargin(0); + + strokeProperties->setLayout(strokePropertiesLayout); + strokePropertiesLayout->addWidget(enableGradual); + strokePropertiesLayout->addWidget(endTypeBox); + + viewLayout->addWidget(strokeProperties); viewLayout->addWidget(widthField); initTable(std::dynamic_pointer_cast(stroke->materialStroke)); @@ -40,6 +37,54 @@ StrokeStyleWidget::StrokeStyleWidget( this->adjustSize(); } +void StrokeStyleWidget::initStrokeSettings() +{ + this->enableGradual = new QtMaterialCheckBox(this); + enableGradual->setText(QStringLiteral("启用渐变")); + enableGradual->setChecked(radialStroke(stroke)->gradual); + connect(enableGradual, &QtMaterialCheckBox::toggled, [this](bool checked) { + 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) + { + 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; + } + }); + + this->widthField = new QtMaterialTextField(this); + widthField->setLabel(QStringLiteral("本侧描边宽度")); + widthField->setText(QString::number(stroke->halfWidth)); + QDoubleValidator* widthValidator = new QDoubleValidator(0.1, std::numeric_limits::max(), 3, widthField); + widthValidator->setNotation(QDoubleValidator::StandardNotation); + widthField->setValidator(widthValidator); + connect(widthField, &QtMaterialTextField::textChanged, [this](const QString& changed) { + if (this->widthField->hasAcceptableInput()) + { + this->stroke->halfWidth = changed.toFloat(); + } + }); +} + void StrokeStyleWidget::initTable(std::shared_ptr materialStroke) { this->strokeTable = new QTableWidget(this); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index 96da6a5..b67b7dc 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -3,15 +3,21 @@ #include "../Renderer/Painting/MaterialStyleStroke.h" #include #include +#include +#include +#include class StrokeStyleWidget : public QWidget { Q_OBJECT private: QString currentItemValue; - QVBoxLayout* viewLayout; + QtMaterialCheckBox* enableGradual; + QComboBox* endTypeBox; + QtMaterialTextField* widthField; QTableWidget* strokeTable; + void initStrokeSettings(); void initTable(std::shared_ptr materialStroke); public: diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 53e1498..da4af88 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -1,7 +1,6 @@ #include "LayerStyle.h" #include "./EditorWidgetComponent/StrokeStyleWidget.h" #include -#include #include #include #include