[editor/style] 实现了FillElementLayerStyle | #2
parent
69422ba96a
commit
0e62672b58
|
@ -104,6 +104,7 @@
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp" />
|
||||||
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp" />
|
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp" />
|
||||||
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
|
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
|
||||||
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp" />
|
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp" />
|
||||||
|
@ -200,6 +201,7 @@
|
||||||
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h" />
|
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h" />
|
||||||
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
|
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
|
||||||
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
|
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
|
||||||
|
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
|
||||||
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
|
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
|
||||||
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />
|
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />
|
||||||
<ClInclude Include="src\Editor\ElementManager.h" />
|
<ClInclude Include="src\Editor\ElementManager.h" />
|
||||||
|
|
|
@ -240,6 +240,9 @@
|
||||||
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp">
|
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||||
|
@ -290,6 +293,9 @@
|
||||||
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h">
|
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\data.json" />
|
<None Include="..\data.json" />
|
||||||
|
|
|
@ -6,7 +6,7 @@ class ColorPicker : public QPushButton
|
||||||
private:
|
private:
|
||||||
QColor color;
|
QColor color;
|
||||||
public:
|
public:
|
||||||
ColorPicker(const QColor& color, QWidget* parent = nullptr);
|
ColorPicker(const QColor& color = QColor::fromRgb(0, 0, 0), QWidget* parent = nullptr);
|
||||||
QColor getColor() const;
|
QColor getColor() const;
|
||||||
public slots:
|
public slots:
|
||||||
void onClicked();
|
void onClicked();
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include "FillStyleWidget.h"
|
||||||
|
#include "ColorPicker.h"
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <qtmaterialtextfield.h>
|
||||||
|
|
||||||
|
FillStyleWidget::FillStyleWidget(std::shared_ptr<Renderer::MaterialStyleFill> fill, QWidget* parent)
|
||||||
|
: QWidget(parent), fill(fill)
|
||||||
|
{
|
||||||
|
auto* layout = new QGridLayout(this);
|
||||||
|
this->setLayout(layout);
|
||||||
|
|
||||||
|
// ÑÕÉ«
|
||||||
|
auto* material = &plainFill(fill)->material;
|
||||||
|
auto* colorLabel = new QLabel(QStringLiteral("ÑÕÉ«"), this);
|
||||||
|
layout->addWidget(colorLabel, 0, 0);
|
||||||
|
auto* colorPicker = new ColorPicker(material->color);
|
||||||
|
connect(colorPicker, &ColorPicker::colorChanged,
|
||||||
|
[material](QColor color)
|
||||||
|
{
|
||||||
|
material->color = color;
|
||||||
|
});
|
||||||
|
layout->addWidget(colorPicker, 0, 1);
|
||||||
|
|
||||||
|
// ½ðÊô¶È
|
||||||
|
auto* metallicLabel = new QLabel(QStringLiteral("½ðÊô¶È"), this);
|
||||||
|
layout->addWidget(metallicLabel, 1, 0);
|
||||||
|
auto* metallicInput = new QtMaterialTextField(this);
|
||||||
|
metallicInput->setText(QString::number(material->metallicF(), 'g', 3));
|
||||||
|
connect(metallicInput, &QtMaterialTextField::textChanged,
|
||||||
|
[material](const QString& text)
|
||||||
|
{
|
||||||
|
material->setMetallicF(text.toFloat());
|
||||||
|
});
|
||||||
|
layout->addWidget(metallicInput, 1, 1);
|
||||||
|
|
||||||
|
// ´Ö²Ú¶È
|
||||||
|
auto* roughnessLabel = new QLabel(QStringLiteral("´Ö²Ú¶È"), this);
|
||||||
|
layout->addWidget(roughnessLabel, 2, 0);
|
||||||
|
auto* roughnessInput = new QtMaterialTextField(this);
|
||||||
|
roughnessInput->setText(QString::number(material->roughnessF(), 'g', 3));
|
||||||
|
connect(roughnessInput, &QtMaterialTextField::textChanged,
|
||||||
|
[material](const QString& text)
|
||||||
|
{
|
||||||
|
material->setRoughnessF(text.toFloat());
|
||||||
|
});
|
||||||
|
layout->addWidget(roughnessInput, 2, 1);
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
#include "../Renderer/Painting/MaterialStyleFill.h"
|
||||||
|
#include "LayerStyle.h"
|
||||||
|
#include <QWidget>
|
||||||
|
class FillStyleWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FillStyleWidget(std::shared_ptr<Renderer::MaterialStyleFill> fill, QWidget* parent = nullptr);
|
||||||
|
std::shared_ptr<Renderer::MaterialStyleFill> fill;
|
||||||
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ constexpr int COLUMN_ROUGHNESS = 3;
|
||||||
constexpr int COLUMN_OPERATIONS = 4;
|
constexpr int COLUMN_OPERATIONS = 4;
|
||||||
|
|
||||||
StrokeStyleWidget::StrokeStyleWidget(
|
StrokeStyleWidget::StrokeStyleWidget(
|
||||||
std::shared_ptr<Renderer::MaterialStyleStroke> stroke,
|
std::shared_ptr<MaterialStyleStroke> stroke,
|
||||||
QWidget* parent
|
QWidget* parent
|
||||||
) : QWidget(parent), stroke(stroke)
|
) : QWidget(parent), stroke(stroke)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#include "LayerStyle.h"
|
#include "LayerStyle.h"
|
||||||
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
|
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
|
||||||
|
#include "./EditorWidgetComponent/FillStyleWidget.h"
|
||||||
#include "./util/EncodeUtil.hpp"
|
#include "./util/EncodeUtil.hpp"
|
||||||
#include <qtmaterialcheckbox.h>
|
#include <qtmaterialcheckbox.h>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#define _USE_JOIN_VIEW_INPUT_RANGE
|
#define _USE_JOIN_VIEW_INPUT_RANGE
|
||||||
|
@ -20,21 +19,19 @@ std::vector<Renderer::BaseStyle> StrokeElementLayerStyle::toBaseStyles() const
|
||||||
{
|
{
|
||||||
if (!radialStroke(strokePair.first)->materialMap.empty())
|
if (!radialStroke(strokePair.first)->materialMap.empty())
|
||||||
{
|
{
|
||||||
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(),
|
baseStyles.push_back({ std::make_shared<Renderer::TransformStyle>(), strokePair.first });
|
||||||
strokePair.first));
|
|
||||||
}
|
}
|
||||||
if (!radialStroke(strokePair.second)->materialMap.empty())
|
if (!radialStroke(strokePair.second)->materialMap.empty())
|
||||||
{
|
{
|
||||||
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(),
|
baseStyles.push_back({ std::make_shared<Renderer::TransformStyle>(), strokePair.second });
|
||||||
strokePair.second));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!radialStroke(strokePair.first)->materialMap.empty())
|
else if (!radialStroke(strokePair.first)->materialMap.empty())
|
||||||
{
|
{
|
||||||
const auto material = std::shared_ptr(std::move(strokePair.first->clone()));
|
const auto material = std::shared_ptr(std::move(strokePair.first->clone()));
|
||||||
std::dynamic_pointer_cast<MaterialStyleStroke>(material)->strokeType = Renderer::StrokeType::kBothSides;
|
std::static_pointer_cast<MaterialStyleStroke>(material)->strokeType = Renderer::StrokeType::kBothSides;
|
||||||
|
|
||||||
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(), material));
|
baseStyles.push_back({ std::make_shared<Renderer::TransformStyle>(), material });
|
||||||
}
|
}
|
||||||
return baseStyles;
|
return baseStyles;
|
||||||
}
|
}
|
||||||
|
@ -197,18 +194,23 @@ bool LayerStyleContainer::dropStyle(const QString& styleName)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float LayerStyleContainer::boundingBoxAffectValue() {
|
float LayerStyleContainer::boundingBoxAffectValue() const {
|
||||||
float maxLineWidth = 0;
|
float maxLineWidth = 0;
|
||||||
auto strokeStyle = styles[StrokeElementLayerStyle::displayName()];
|
const auto strokeStyle = styles.at(StrokeElementLayerStyle::displayName());
|
||||||
if (strokeStyle != nullptr) {
|
if (strokeStyle != nullptr)
|
||||||
auto strokeElementLayerStyle = dynamic_cast<StrokeElementLayerStyle*>(strokeStyle.get());
|
{
|
||||||
if (strokeElementLayerStyle != nullptr) {
|
if (const auto strokeElementLayerStyle =
|
||||||
auto leftStyleStroke = strokeElementLayerStyle->strokePair.first;
|
std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle);
|
||||||
auto rightStyleStroke = strokeElementLayerStyle->strokePair.second;
|
strokeElementLayerStyle != nullptr)
|
||||||
if (leftStyleStroke != nullptr) {
|
{
|
||||||
|
const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first;
|
||||||
|
const auto& rightStyleStroke = strokeElementLayerStyle->strokePair.second;
|
||||||
|
if (leftStyleStroke != nullptr)
|
||||||
|
{
|
||||||
maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth);
|
maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth);
|
||||||
}
|
}
|
||||||
if (rightStyleStroke != nullptr) {
|
if (rightStyleStroke != nullptr)
|
||||||
|
{
|
||||||
maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth);
|
maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,11 +218,25 @@ float LayerStyleContainer::boundingBoxAffectValue() {
|
||||||
return maxLineWidth;
|
return maxLineWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t LayerStyleContainer::getHash() const
|
size_t LayerStyleContainer::getHash() const
|
||||||
{
|
{
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<StrokeElementLayerStyle> StrokeElementLayerStyle::fromJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
auto ptr = std::make_unique<StrokeElementLayerStyle>(
|
||||||
|
std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["left"].toString()))))
|
||||||
|
),
|
||||||
|
std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["right"].toString()))))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
ptr->enableEachSideIndependent = json["enableEachSideIndependent"].toBool();
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
StrokeElementLayerStyle::StrokeElementLayerStyle()
|
StrokeElementLayerStyle::StrokeElementLayerStyle()
|
||||||
{
|
{
|
||||||
const auto materialMap = std::map<float, Renderer::Material>();
|
const auto materialMap = std::map<float, Renderer::Material>();
|
||||||
|
@ -238,7 +254,7 @@ StrokeElementLayerStyle::StrokeElementLayerStyle()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StrokeElementLayerStyle::StrokeElementLayerStyle(PMaterialStyleStroke left, PMaterialStyleStroke right)
|
StrokeElementLayerStyle::StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right)
|
||||||
{
|
{
|
||||||
this->strokePair.first = left;
|
this->strokePair.first = left;
|
||||||
this->strokePair.second = right ? right : std::static_pointer_cast<MaterialStyleStroke>(
|
this->strokePair.second = right ? right : std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
@ -259,8 +275,7 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
|
||||||
|
|
||||||
QJsonObject StrokeElementLayerStyle::toJson() const
|
QJsonObject StrokeElementLayerStyle::toJson() const
|
||||||
{
|
{
|
||||||
QJsonObject json;
|
auto json = LayerStyle::toJson();
|
||||||
json["type"] = typeName();
|
|
||||||
json["enableEachSideIndependent"] = enableEachSideIndependent;
|
json["enableEachSideIndependent"] = enableEachSideIndependent;
|
||||||
json["left"] = EncodeUtil::toBase64<GLfloat>(strokePair.first->encoded());
|
json["left"] = EncodeUtil::toBase64<GLfloat>(strokePair.first->encoded());
|
||||||
json["right"] = EncodeUtil::toBase64<GLfloat>(strokePair.second->encoded());
|
json["right"] = EncodeUtil::toBase64<GLfloat>(strokePair.second->encoded());
|
||||||
|
@ -272,18 +287,24 @@ std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
|
||||||
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<FillElementLayerStyle> FillElementLayerStyle::fromJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
auto ptr = std::make_unique<FillElementLayerStyle>(
|
||||||
|
std::static_pointer_cast<MaterialStyleFill>(
|
||||||
|
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["material"].toString()))))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
|
std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
|
||||||
{
|
{
|
||||||
// TODO: implement
|
return { {std::make_shared<Renderer::TransformStyle>(), fillMaterialStyle} };
|
||||||
return std::vector<Renderer::BaseStyle>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* FillElementLayerStyle::getInputWidget()
|
QWidget* FillElementLayerStyle::getInputWidget()
|
||||||
{
|
{
|
||||||
// TODO
|
return new FillStyleWidget(fillMaterialStyle);
|
||||||
auto* name = new QLineEdit;
|
|
||||||
name->setText(QStringLiteral("Ìî³ä"));
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* FillElementLayerStyle::getListDisplayWidget() const
|
QWidget* FillElementLayerStyle::getListDisplayWidget() const
|
||||||
|
@ -297,18 +318,29 @@ QWidget* FillElementLayerStyle::getListDisplayWidget() const
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMaterialStyle)
|
||||||
|
: fillMaterialStyle(fillMaterialStyle)
|
||||||
|
{
|
||||||
|
if (!fillMaterialStyle)
|
||||||
|
{
|
||||||
|
this->fillMaterialStyle = std::make_shared<MaterialStyleFill>(
|
||||||
|
std::make_shared<Renderer::FillPlain>(Renderer::Material(QColor::fromRgb(0, 0, 0)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
|
FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
|
||||||
{
|
{
|
||||||
materialStyles = std::vector<std::shared_ptr<Renderer::MaterialStyleFill>>(other.materialStyles.size());
|
this->fillMaterialStyle = std::static_pointer_cast<MaterialStyleFill>(
|
||||||
for (size_t i = 0; i < other.materialStyles.size(); i++)
|
std::shared_ptr(std::move(other.fillMaterialStyle->clone()))
|
||||||
{
|
);
|
||||||
materialStyles[i] = std::make_shared<Renderer::MaterialStyleFill>(*other.materialStyles[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject FillElementLayerStyle::toJson() const
|
QJsonObject FillElementLayerStyle::toJson() const
|
||||||
{
|
{
|
||||||
return QJsonObject();
|
auto json = LayerStyle::toJson();
|
||||||
|
json["material"] = EncodeUtil::toBase64<GLfloat>(fillMaterialStyle->encoded());
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<LayerStyle> FillElementLayerStyle::clone() const
|
std::unique_ptr<LayerStyle> FillElementLayerStyle::clone() const
|
||||||
|
@ -321,23 +353,18 @@ std::unique_ptr<LayerStyle> LayerStyle::fromJson(const QJsonObject& json)
|
||||||
QString type = json["type"].toString();
|
QString type = json["type"].toString();
|
||||||
if (type == StrokeElementLayerStyle::typeName())
|
if (type == StrokeElementLayerStyle::typeName())
|
||||||
{
|
{
|
||||||
auto ptr = std::make_unique<StrokeElementLayerStyle>(
|
return StrokeElementLayerStyle::fromJson(json);
|
||||||
std::static_pointer_cast<MaterialStyleStroke>(
|
|
||||||
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["left"].toString()))))
|
|
||||||
),
|
|
||||||
std::static_pointer_cast<MaterialStyleStroke>(
|
|
||||||
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["right"].toString()))))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
ptr->enableEachSideIndependent = json["enableEachSideIndependent"].toBool();
|
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
else if (type == FillElementLayerStyle::typeName())
|
if (type == FillElementLayerStyle::typeName())
|
||||||
{
|
{
|
||||||
return std::make_unique<FillElementLayerStyle>();
|
return FillElementLayerStyle::fromJson(json);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject LayerStyle::toJson() const
|
||||||
|
{
|
||||||
|
QJsonObject json;
|
||||||
|
json["type"] = this->getTypeName();
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,26 +12,35 @@
|
||||||
|
|
||||||
using Renderer::MaterialStyle;
|
using Renderer::MaterialStyle;
|
||||||
using Renderer::MaterialStyleStroke;
|
using Renderer::MaterialStyleStroke;
|
||||||
|
using Renderer::MaterialStyleFill;
|
||||||
|
|
||||||
#define STYLE_NAME(display_name, type_name) \
|
#define STYLE_NAME(display_name, type_name) \
|
||||||
static QString displayName() { return QStringLiteral(display_name); } \
|
static QString displayName() { return QStringLiteral(display_name); } \
|
||||||
QString getDisplayName() const override { return QStringLiteral(display_name); } \
|
QString getDisplayName() const override { return QStringLiteral(display_name); } \
|
||||||
static QString typeName() { return type_name; }
|
static QString typeName() { return type_name; } \
|
||||||
|
QString getTypeName() const override { return type_name; }
|
||||||
#define radialStroke(stroke) std::static_pointer_cast<Renderer::StrokeRadialGradient>(stroke->materialStroke)
|
#define radialStroke(stroke) std::static_pointer_cast<Renderer::StrokeRadialGradient>(stroke->materialStroke)
|
||||||
|
#define plainFill(fill) std::static_pointer_cast<Renderer::FillPlain>(fill->materialFill)
|
||||||
|
|
||||||
class LayerStyle : public Renderer::ElementStyle
|
class LayerStyle : public Renderer::ElementStyle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<LayerStyle> fromJson(const QJsonObject& json);
|
static std::unique_ptr<LayerStyle> fromJson(const QJsonObject& json);
|
||||||
|
virtual ~LayerStyle() = default;
|
||||||
|
|
||||||
virtual QString getDisplayName() const = 0;
|
virtual QString getDisplayName() const = 0;
|
||||||
|
virtual QString getTypeName() const = 0;
|
||||||
|
|
||||||
virtual QWidget* getInputWidget() = 0;
|
virtual QWidget* getInputWidget() = 0;
|
||||||
virtual QWidget* getListDisplayWidget() const = 0;
|
virtual QWidget* getListDisplayWidget() const = 0;
|
||||||
virtual ~LayerStyle() = default;
|
|
||||||
virtual QJsonObject toJson() const = 0;
|
virtual QJsonObject toJson() const;
|
||||||
virtual std::unique_ptr<LayerStyle> clone() const = 0;
|
virtual std::unique_ptr<LayerStyle> clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新
|
||||||
|
*/
|
||||||
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>()>>;
|
||||||
|
@ -56,7 +65,7 @@ public:
|
||||||
std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const;
|
std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const;
|
||||||
bool useStyle(const std::shared_ptr<LayerStyle>& style);
|
bool useStyle(const std::shared_ptr<LayerStyle>& style);
|
||||||
bool dropStyle(const QString& styleName);
|
bool dropStyle(const QString& styleName);
|
||||||
float boundingBoxAffectValue();
|
float boundingBoxAffectValue() const;
|
||||||
size_t getHash() const;
|
size_t getHash() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,9 +80,10 @@ class StrokeElementLayerStyle : public LayerStyle
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STYLE_NAME("Ãè±ß", "stroke")
|
STYLE_NAME("Ãè±ß", "stroke")
|
||||||
|
static std::unique_ptr<StrokeElementLayerStyle> fromJson(const QJsonObject& json);
|
||||||
|
|
||||||
StrokeElementLayerStyle();
|
StrokeElementLayerStyle();
|
||||||
StrokeElementLayerStyle(PMaterialStyleStroke left, 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;
|
||||||
|
|
||||||
|
@ -89,16 +99,21 @@ public:
|
||||||
|
|
||||||
class FillElementLayerStyle : public LayerStyle
|
class FillElementLayerStyle : public LayerStyle
|
||||||
{
|
{
|
||||||
|
using PMaterialStyleFill = std::shared_ptr<MaterialStyleFill>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STYLE_NAME("Ìî³ä", "fill")
|
STYLE_NAME("Ìî³ä", "fill")
|
||||||
|
static std::unique_ptr<FillElementLayerStyle> fromJson(const QJsonObject& json);
|
||||||
|
|
||||||
|
FillElementLayerStyle(const PMaterialStyleFill& fillMaterialStyle = nullptr);
|
||||||
|
FillElementLayerStyle(const FillElementLayerStyle& other);
|
||||||
|
~FillElementLayerStyle() override = default;
|
||||||
|
|
||||||
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
||||||
QWidget* getInputWidget() override;
|
QWidget* getInputWidget() override;
|
||||||
QWidget* getListDisplayWidget() const override;
|
QWidget* getListDisplayWidget() const override;
|
||||||
FillElementLayerStyle() = default;
|
|
||||||
FillElementLayerStyle(const FillElementLayerStyle& other);
|
|
||||||
~FillElementLayerStyle() override = default;
|
|
||||||
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
|
|
||||||
QJsonObject toJson() const override;
|
QJsonObject toJson() const override;
|
||||||
std::unique_ptr<LayerStyle> clone() const override;
|
std::unique_ptr<LayerStyle> clone() const override;
|
||||||
|
|
||||||
|
PMaterialStyleFill fillMaterialStyle;
|
||||||
};
|
};
|
|
@ -102,7 +102,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connect(addStyleButton, &QPushButton::clicked, [&, leafP] {
|
connect(addStyleButton, &QPushButton::clicked, [&, leafP] {
|
||||||
auto* dialog = new LayerStyleDialog(leafP->styles);
|
auto* dialog = new LayerStyleDialog(leafP->styles, nullptr, this);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
if (dialog->layerStyle)
|
if (dialog->layerStyle)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,6 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
emit requireSelfRefresh();
|
emit requireSelfRefresh();
|
||||||
emit requireRefreshElementWidget();
|
emit requireRefreshElementWidget();
|
||||||
}
|
}
|
||||||
dialog->deleteLater();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,60 +124,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
header->setFlags(Qt::NoItemFlags);
|
header->setFlags(Qt::NoItemFlags);
|
||||||
styleList->addItem(header);
|
styleList->addItem(header);
|
||||||
styleList->setItemWidget(header, headerWidget);
|
styleList->setItemWidget(header, headerWidget);
|
||||||
//static vector<QString> styleNames = { "样例1", "样例2", "样例3" };
|
|
||||||
// auto createStyleItem = [this, styleList](int index) {
|
|
||||||
// QListWidgetItem* item = new QListWidgetItem;
|
|
||||||
// QWidget* w = new QWidget;
|
|
||||||
// item->setSizeHint(QSize(50, 40));
|
|
||||||
// QHBoxLayout* layout = new QHBoxLayout;
|
|
||||||
// QPushButton* deleteButton = new QPushButton(w);
|
|
||||||
// QPushButton* detailButton = new QPushButton(w);
|
|
||||||
// QLabel* name = new QLabel(w);
|
|
||||||
// name->setText(styleNames[index]);
|
|
||||||
// detailButton->setText("...");
|
|
||||||
// detailButton->setFixedSize(QSize(20, 20));
|
|
||||||
// deleteButton->setText("×");
|
|
||||||
// deleteButton->setFixedSize(QSize(20, 20));
|
|
||||||
// connect(detailButton, &QPushButton::clicked, [styleList, item, this, index]() {
|
|
||||||
// QDialog dlg(this);
|
|
||||||
// dlg.setWindowTitle("样式详情");
|
|
||||||
// dlg.resize(400, 200);
|
|
||||||
// QGridLayout *contentLayout = new QGridLayout(&dlg);
|
|
||||||
// QLineEdit* name = new QLineEdit(styleNames[index], &dlg);
|
|
||||||
// auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
|
||||||
// contentLayout->addWidget(buttonBox);
|
|
||||||
// connect(buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept);
|
|
||||||
// connect(buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject);
|
|
||||||
// bool updateStyle = dlg.exec();
|
|
||||||
// if (updateStyle) {
|
|
||||||
// styleNames[index] = name->text();
|
|
||||||
// qDebug() << name->text();
|
|
||||||
// // 在此处修改新样式信息至内存
|
|
||||||
// emit requireRefreshPreview();
|
|
||||||
// emit requireSelfRefresh();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// connect(deleteButton, &QPushButton::clicked, [styleList,item,this]() {
|
|
||||||
// styleList->removeItemWidget(item);
|
|
||||||
// delete item;
|
|
||||||
// // 删除layer对应样式
|
|
||||||
// emit requireRefreshPreview();
|
|
||||||
// emit requireSelfRefresh();
|
|
||||||
// });
|
|
||||||
// layout->addWidget(name);
|
|
||||||
// layout->addWidget(detailButton);
|
|
||||||
// layout->addWidget(deleteButton);
|
|
||||||
// w->setLayout(layout);
|
|
||||||
// styleList->addItem(item);
|
|
||||||
// styleList->setItemWidget(item, w);
|
|
||||||
// };
|
|
||||||
// for (int i = 0; i < styleNames.size(); i++)
|
|
||||||
// createStyleItem(i);
|
|
||||||
|
|
||||||
/*if (leafP->styles.empty())
|
|
||||||
{
|
|
||||||
leafP->styles.push_back(std::shared_ptr<LayerStyle>(new StrokeElementLayerStyle()));
|
|
||||||
}*/
|
|
||||||
auto* styles = &leafP->styles;
|
auto* styles = &leafP->styles;
|
||||||
for (auto styleIterator = styles->begin(); styleIterator != styles->end(); ++styleIterator)
|
for (auto styleIterator = styles->begin(); styleIterator != styles->end(); ++styleIterator)
|
||||||
{
|
{
|
||||||
|
@ -200,7 +146,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
[this, styles, styleIterator]
|
[this, styles, styleIterator]
|
||||||
{
|
{
|
||||||
auto* dialog =
|
auto* dialog =
|
||||||
new LayerStyleDialog(*styles, styleIterator->second);
|
new LayerStyleDialog(*styles, styleIterator->second, this);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
if (dialog->layerStyle)
|
if (dialog->layerStyle)
|
||||||
|
@ -212,7 +158,6 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
emit requireSelfRefresh();
|
emit requireSelfRefresh();
|
||||||
emit requireRefreshElementWidget();
|
emit requireRefreshElementWidget();
|
||||||
}
|
}
|
||||||
dialog->deleteLater();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(removeButton, &QPushButton::clicked, this,
|
connect(removeButton, &QPushButton::clicked, this,
|
||||||
|
|
Loading…
Reference in New Issue