[stroke] 适配了新添加的StrokeEndType::kClosed

为封闭及非封闭图元的描边style初始化做了分化
dev-LayerStyle
ArgonarioD 2023-03-20 19:51:01 +08:00
parent 21aeb0832b
commit 0aa69195b3
3 changed files with 44 additions and 23 deletions

View File

@ -18,6 +18,11 @@ inline Renderer::Material newMaterial()
return {ColorHelper::instance().getPrimary1()};
}
inline bool isClosedStroke(const std::shared_ptr<MaterialStyleStroke>& stroke)
{
return stroke->endType == Renderer::StrokeEndType::kClosed;
}
StrokeStyleWidget::StrokeStyleWidget(
const std::shared_ptr<MaterialStyleStroke>& 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);
@ -62,16 +70,23 @@ void StrokeStyleWidget::initStrokeSettings()
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<int>(this->stroke->endType));
connect(endTypeBox, QOverload<int>::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<int>(this->stroke->endType));
connect(endTypeBox, QOverload<int>::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("±¾²àÃè±ß¿í¶È"));

View File

@ -248,18 +248,18 @@ std::unique_ptr<StrokeElementLayerStyle> StrokeElementLayerStyle::fromJson(const
return ptr;
}
StrokeElementLayerStyle::StrokeElementLayerStyle()
StrokeElementLayerStyle::StrokeElementLayerStyle(bool isClosed)
{
const auto materialMap = std::map<float, Renderer::Material>();
this->strokePair.first = std::make_shared<MaterialStyleStroke>(
7,
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
Renderer::StrokeType::kLeftSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat,
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
);
this->strokePair.second = std::make_shared<MaterialStyleStroke>(
7,
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
Renderer::StrokeType::kRightSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat,
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
);

View File

@ -46,7 +46,7 @@ public:
STYLE_NAME("Ãè±ß", "stroke")
static std::unique_ptr<StrokeElementLayerStyle> 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<QString, std::function<std::unique_ptr<LayerStyle>()>>;
private:
inline const static DisplayNameWithSupplier commonStyles = { {
private:
inline const static DisplayNameWithSupplier commonStyles = { };
inline const static DisplayNameWithSupplier closedOnlyStyles = {
{
FillElementLayerStyle::displayName(),
[] { return std::make_unique<FillElementLayerStyle>(); }
},
{
StrokeElementLayerStyle::displayName(),
[] { return std::make_unique<StrokeElementLayerStyle>(true); }
}
};
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { {
StrokeElementLayerStyle::displayName(),
[] { return std::make_unique<StrokeElementLayerStyle>(); }
[] { return std::make_unique<StrokeElementLayerStyle>(false); }
} };
inline const static DisplayNameWithSupplier closedOnlyStyles = { {
FillElementLayerStyle::displayName(),
[] { return std::make_unique<FillElementLayerStyle>(); }
} };
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { };
DisplayNameWithSupplier unusedStyles;
DisplayNameWithSupplier usedStyles;