diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index 48a4a6a..e758dfc 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -1,33 +1,51 @@ #include "StrokeStyleWidget.h" #include "ColorPicker.h" #include +#include +#include +#define radialStroke(stroke) std::dynamic_pointer_cast(stroke->materialStroke) constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; constexpr int COLUMN_METALLIC = 2; constexpr int COLUMN_ROUGHNESS = 3; constexpr int COLUMN_OPERATIONS = 4; -// TODO: 加上新增行按钮和宽度设置 +// TODO: 加上新增行按钮 +// FIXME: Material的控件有显示bug StrokeStyleWidget::StrokeStyleWidget( - std::shared_ptr stroke, + std::shared_ptr stroke, QWidget* parent ) : QWidget(parent), stroke(stroke) { this->viewLayout = new QVBoxLayout(this); this->setLayout(viewLayout); - initTable(stroke); + 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(); + } + }); + viewLayout->addWidget(widthField); + + initTable(std::dynamic_pointer_cast(stroke->materialStroke)); viewLayout->addWidget(strokeTable); this->adjustSize(); } -void StrokeStyleWidget::initTable(std::shared_ptr& stroke) +void StrokeStyleWidget::initTable(std::shared_ptr materialStroke) { this->strokeTable = new QTableWidget(this); strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); strokeTable->setColumnCount(5); - strokeTable->setRowCount(stroke->materialMap.size()); + strokeTable->setRowCount(materialStroke->materialMap.size()); QStringList headers; headers << QStringLiteral("离心距离占比") << QStringLiteral("颜色") @@ -35,7 +53,7 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetHorizontalHeaderLabels(headers); - for (int row = 0; auto & strokePair : stroke->materialMap) + for (int row = 0; auto & strokePair : materialStroke->materialMap) { QTableWidgetItem* widthItem = new QTableWidgetItem; widthItem->setData(Qt::EditRole, strokePair.first); @@ -64,8 +82,8 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetFixedSize(20, 20); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { - this->stroke->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat()); - this->strokeTable->removeRow(row); + radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat()); + this->strokeTable->removeRow(row); }); row++; @@ -94,24 +112,25 @@ void StrokeStyleWidget::onCellChanged(int row, int column) return; } auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->text().toFloat(); - switch (row) + switch (column) { case COLUMN_WIDTH: { float oldWidth = this->currentItemValue.toFloat(); - auto node = stroke->materialMap.extract(oldWidth); + auto node = radialStroke(stroke)->materialMap.extract(oldWidth); node.key() = changedWidth; - stroke->materialMap.insert(std::move(node)); + radialStroke(stroke)->materialMap.insert(std::move(node)); + strokeTable->sortItems(COLUMN_WIDTH); break; } case COLUMN_METALLIC: { - stroke->materialMap[changedWidth].metallic = changedItemValue; + radialStroke(stroke)->materialMap[changedWidth].metallic = changedItemValue; break; } case COLUMN_ROUGHNESS: { - stroke->materialMap[changedWidth].roughness = changedItemValue; + radialStroke(stroke)->materialMap[changedWidth].roughness = changedItemValue; break; } } diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index c2a9179..96da6a5 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -12,11 +12,11 @@ private: QVBoxLayout* viewLayout; QTableWidget* strokeTable; - void initTable(std::shared_ptr& stroke); + void initTable(std::shared_ptr materialStroke); 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 bba4015..53e1498 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -1,6 +1,7 @@ #include "LayerStyle.h" #include "./EditorWidgetComponent/StrokeStyleWidget.h" #include +#include #include #include #include @@ -51,6 +52,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget() { auto materialMap = std::map(); materialMap[0.3] = Renderer::Material{ QColor(0,255,255), 0.f, .8f }; + materialMap[0.6] = Renderer::Material{ QColor(50,165,100), 0.f, .8f }; materialMap[1.0] = Renderer::Material{ QColor(80,25,255), 0.f, .8f }; this->strokePair.first = std::shared_ptr(new Renderer::MaterialStyleStroke( 15, @@ -79,9 +81,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget() QVBoxLayout* layout = new QVBoxLayout(w); layout->setMargin(0); - StrokeStyleWidget* leftStrokeView = new StrokeStyleWidget( - std::dynamic_pointer_cast(this->strokePair.first->materialStroke), w - ); + StrokeStyleWidget* leftStrokeView = new StrokeStyleWidget(this->strokePair.first, w); layout->addWidget(leftStrokeView); QtMaterialCheckBox* checkEachSideIndependent = new QtMaterialCheckBox(w); @@ -89,9 +89,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget() checkEachSideIndependent->setChecked(enableEachSideIndependent); layout->addWidget(checkEachSideIndependent); - StrokeStyleWidget* rightStrokeView = new StrokeStyleWidget( - std::dynamic_pointer_cast(this->strokePair.second->materialStroke), w - ); + StrokeStyleWidget* rightStrokeView = new StrokeStyleWidget(this->strokePair.second, w); layout->addWidget(rightStrokeView); rightStrokeView->setDisabled(!this->enableEachSideIndependent);