[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()}; return {ColorHelper::instance().getPrimary1()};
} }
inline bool isClosedStroke(const std::shared_ptr<MaterialStyleStroke>& stroke)
{
return stroke->endType == Renderer::StrokeEndType::kClosed;
}
StrokeStyleWidget::StrokeStyleWidget( StrokeStyleWidget::StrokeStyleWidget(
const std::shared_ptr<MaterialStyleStroke>& stroke, const std::shared_ptr<MaterialStyleStroke>& stroke,
QWidget* parent QWidget* parent
@ -39,7 +44,10 @@ StrokeStyleWidget::StrokeStyleWidget(
strokeProperties->setLayout(strokePropertiesLayout); strokeProperties->setLayout(strokePropertiesLayout);
strokePropertiesLayout->addWidget(enableGradual); strokePropertiesLayout->addWidget(enableGradual);
if (!isClosedStroke(stroke))
{
strokePropertiesLayout->addWidget(endTypeBox); strokePropertiesLayout->addWidget(endTypeBox);
}
viewLayout->addWidget(strokeProperties); viewLayout->addWidget(strokeProperties);
viewLayout->addWidget(widthField); viewLayout->addWidget(widthField);
@ -62,6 +70,8 @@ void StrokeStyleWidget::initStrokeSettings()
radialStroke(this->stroke)->gradual = checked; radialStroke(this->stroke)->gradual = checked;
}); });
if (!isClosedStroke(stroke))
{
this->endTypeBox = new QComboBox(this); this->endTypeBox = new QComboBox(this);
for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys) for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys)
{ {
@ -72,6 +82,11 @@ void StrokeStyleWidget::initStrokeSettings()
const auto& [displayName, endType] = MaterialStyleStroke::strokeEndTypeNames[index]; const auto& [displayName, endType] = MaterialStyleStroke::strokeEndTypeNames[index];
this->stroke->endType = endType; this->stroke->endType = endType;
}); });
}
else
{
this->endTypeBox = nullptr;
}
this->widthField = new QtMaterialTextField(this); this->widthField = new QtMaterialTextField(this);
widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È")); widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È"));

View File

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

View File

@ -46,7 +46,7 @@ public:
STYLE_NAME("Ãè±ß", "stroke") STYLE_NAME("Ãè±ß", "stroke")
static std::unique_ptr<StrokeElementLayerStyle> fromJson(const QJsonObject& json); static std::unique_ptr<StrokeElementLayerStyle> fromJson(const QJsonObject& json);
StrokeElementLayerStyle(); StrokeElementLayerStyle(bool isClosed);
StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right = nullptr); StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right = nullptr);
StrokeElementLayerStyle(const StrokeElementLayerStyle& other); StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
~StrokeElementLayerStyle() override = default; ~StrokeElementLayerStyle() override = default;
@ -88,17 +88,23 @@ public:
class LayerStyleContainer : public Renderer::ElementStyle class LayerStyleContainer : public Renderer::ElementStyle
{ {
using DisplayNameWithSupplier = std::map<QString, std::function<std::unique_ptr<LayerStyle>()>>; using DisplayNameWithSupplier = std::map<QString, std::function<std::unique_ptr<LayerStyle>()>>;
private:
inline const static DisplayNameWithSupplier commonStyles = { { private:
StrokeElementLayerStyle::displayName(), inline const static DisplayNameWithSupplier commonStyles = { };
[] { return std::make_unique<StrokeElementLayerStyle>(); } inline const static DisplayNameWithSupplier closedOnlyStyles = {
} }; {
inline const static DisplayNameWithSupplier closedOnlyStyles = { {
FillElementLayerStyle::displayName(), FillElementLayerStyle::displayName(),
[] { return std::make_unique<FillElementLayerStyle>(); } [] { 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>(false); }
} }; } };
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { };
DisplayNameWithSupplier unusedStyles; DisplayNameWithSupplier unusedStyles;
DisplayNameWithSupplier usedStyles; DisplayNameWithSupplier usedStyles;