[stroke] 基本完成添加单层描边功能
parent
7079b335cb
commit
3ceeba61b5
|
@ -10,7 +10,6 @@ constexpr int COLUMN_METALLIC = 2;
|
||||||
constexpr int COLUMN_ROUGHNESS = 3;
|
constexpr int COLUMN_ROUGHNESS = 3;
|
||||||
constexpr int COLUMN_OPERATIONS = 4;
|
constexpr int COLUMN_OPERATIONS = 4;
|
||||||
|
|
||||||
// TODO: ¼ÓÉÏÐÂÔöÐа´Å¥
|
|
||||||
// FIXME: Material的控件有显示bug
|
// FIXME: Material的控件有显示bug
|
||||||
StrokeStyleWidget::StrokeStyleWidget(
|
StrokeStyleWidget::StrokeStyleWidget(
|
||||||
std::shared_ptr<Renderer::MaterialStyleStroke> stroke,
|
std::shared_ptr<Renderer::MaterialStyleStroke> stroke,
|
||||||
|
@ -85,12 +84,13 @@ void StrokeStyleWidget::initStrokeSettings()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: 新增时参数校验
|
||||||
void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke)
|
void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke)
|
||||||
{
|
{
|
||||||
this->strokeTable = new QTableWidget(this);
|
this->strokeTable = new QTableWidget(this);
|
||||||
strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
|
strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
|
||||||
strokeTable->setColumnCount(5);
|
strokeTable->setColumnCount(5);
|
||||||
strokeTable->setRowCount(materialStroke->materialMap.size());
|
strokeTable->setRowCount(materialStroke->materialMap.size() + 1);
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << QStringLiteral("离心距离占比")
|
headers << QStringLiteral("离心距离占比")
|
||||||
<< QStringLiteral("颜色")
|
<< QStringLiteral("颜色")
|
||||||
|
@ -98,13 +98,50 @@ void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient
|
||||||
<< QStringLiteral("粗糙度")
|
<< QStringLiteral("粗糙度")
|
||||||
<< QStringLiteral("其他操作");
|
<< QStringLiteral("其他操作");
|
||||||
strokeTable->setHorizontalHeaderLabels(headers);
|
strokeTable->setHorizontalHeaderLabels(headers);
|
||||||
for (int row = 0; auto & strokePair : materialStroke->materialMap)
|
int row = 0;
|
||||||
|
// 内容
|
||||||
|
for (auto & strokePair : materialStroke->materialMap)
|
||||||
{
|
{
|
||||||
|
setTableRow(row, strokePair.first, strokePair.second);
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
// 新增按钮
|
||||||
|
QtMaterialRaisedButton* addButton = new QtMaterialRaisedButton("+", strokeTable);
|
||||||
|
strokeTable->setSpan(row, 0, 1, 5);
|
||||||
|
strokeTable->setCellWidget(row, 0, addButton);
|
||||||
|
connect(addButton, &QtMaterialRaisedButton::clicked, [this]() {
|
||||||
|
handlingRowInsert = true;
|
||||||
|
auto materialMap = &(radialStroke(this->stroke)->materialMap);
|
||||||
|
float newWidth = 0;
|
||||||
|
if (materialMap->size() == 0)
|
||||||
|
{
|
||||||
|
newWidth = 0.1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto lastPair = materialMap->rbegin();
|
||||||
|
newWidth = lastPair->first + 0.01;
|
||||||
|
}
|
||||||
|
Renderer::Material newMaterial = { QColor::fromRgb(0,0,0), 0.f, .8f };
|
||||||
|
(*materialMap)[newWidth] = newMaterial;
|
||||||
|
int newRow = this->strokeTable->rowCount() - 1;
|
||||||
|
this->strokeTable->insertRow(newRow);
|
||||||
|
setTableRow(newRow, newWidth, newMaterial);
|
||||||
|
this->strokeTable->update();
|
||||||
|
handlingRowInsert = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged);
|
||||||
|
connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& material)
|
||||||
|
{
|
||||||
QTableWidgetItem* widthItem = new QTableWidgetItem;
|
QTableWidgetItem* widthItem = new QTableWidgetItem;
|
||||||
widthItem->setData(Qt::EditRole, strokePair.first);
|
widthItem->setData(Qt::EditRole, width);
|
||||||
strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
|
strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
|
||||||
|
|
||||||
QColor* colorPtr = &(strokePair.second.color);
|
QColor* colorPtr = &(material.color);
|
||||||
QTableWidgetItem* colorItem = new QTableWidgetItem;
|
QTableWidgetItem* colorItem = new QTableWidgetItem;
|
||||||
colorItem->setData(Qt::DisplayRole, *colorPtr);
|
colorItem->setData(Qt::DisplayRole, *colorPtr);
|
||||||
strokeTable->setItem(row, COLUMN_COLOR, colorItem);
|
strokeTable->setItem(row, COLUMN_COLOR, colorItem);
|
||||||
|
@ -116,25 +153,21 @@ void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient
|
||||||
});
|
});
|
||||||
|
|
||||||
QTableWidgetItem* metallicItem = new QTableWidgetItem;
|
QTableWidgetItem* metallicItem = new QTableWidgetItem;
|
||||||
metallicItem->setData(Qt::EditRole, strokePair.second.metallic);
|
metallicItem->setData(Qt::EditRole, material.metallic);
|
||||||
strokeTable->setItem(row, COLUMN_METALLIC, metallicItem);
|
strokeTable->setItem(row, COLUMN_METALLIC, metallicItem);
|
||||||
|
|
||||||
QTableWidgetItem* roughnessItem = new QTableWidgetItem;
|
QTableWidgetItem* roughnessItem = new QTableWidgetItem;
|
||||||
roughnessItem->setData(Qt::EditRole, strokePair.second.roughness);
|
roughnessItem->setData(Qt::EditRole, material.roughness);
|
||||||
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
|
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
|
||||||
|
|
||||||
QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", this);
|
QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", strokeTable);
|
||||||
removeButton->setFixedSize(20, 20);
|
removeButton->setFixedSize(20, 20);
|
||||||
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
|
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
|
||||||
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {
|
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {
|
||||||
|
if (this->strokeTable->rowCount() <= 1) return;
|
||||||
radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat());
|
radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat());
|
||||||
this->strokeTable->removeRow(row);
|
this->strokeTable->removeRow(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged);
|
|
||||||
connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
|
void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
|
||||||
|
@ -149,6 +182,7 @@ void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWi
|
||||||
|
|
||||||
void StrokeStyleWidget::onCellChanged(int row, int column)
|
void StrokeStyleWidget::onCellChanged(int row, int column)
|
||||||
{
|
{
|
||||||
|
if (handlingRowInsert) return;
|
||||||
auto changedItem = strokeTable->item(row, column);
|
auto changedItem = strokeTable->item(row, column);
|
||||||
auto changedItemValue = changedItem->text().toFloat();
|
auto changedItemValue = changedItem->text().toFloat();
|
||||||
if (changedItemValue < 0 || 1 < changedItemValue)
|
if (changedItemValue < 0 || 1 < changedItemValue)
|
||||||
|
|
|
@ -16,9 +16,11 @@ private:
|
||||||
QComboBox* endTypeBox;
|
QComboBox* endTypeBox;
|
||||||
QtMaterialTextField* widthField;
|
QtMaterialTextField* widthField;
|
||||||
QTableWidget* strokeTable;
|
QTableWidget* strokeTable;
|
||||||
|
bool handlingRowInsert = false;
|
||||||
|
|
||||||
void initStrokeSettings();
|
void initStrokeSettings();
|
||||||
void initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke);
|
void initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke);
|
||||||
|
void setTableRow(int row, float width, Renderer::Material& material);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StrokeStyleWidget(std::shared_ptr<Renderer::MaterialStyleStroke> stroke, QWidget* parent = nullptr);
|
StrokeStyleWidget(std::shared_ptr<Renderer::MaterialStyleStroke> stroke, QWidget* parent = nullptr);
|
||||||
|
|
|
@ -50,9 +50,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget()
|
||||||
if (this->strokePair.first == nullptr)
|
if (this->strokePair.first == nullptr)
|
||||||
{
|
{
|
||||||
auto materialMap = std::map<float, Renderer::Material>();
|
auto materialMap = std::map<float, Renderer::Material>();
|
||||||
materialMap[0.3] = Renderer::Material{ QColor(0,255,255), 0.f, .8f };
|
materialMap[1.0] = Renderer::Material{ QColor(0, 0, 0), 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<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
|
this->strokePair.first = std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
|
||||||
15,
|
15,
|
||||||
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
|
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
|
||||||
|
@ -64,8 +62,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget()
|
||||||
if (this->strokePair.second == nullptr)
|
if (this->strokePair.second == nullptr)
|
||||||
{
|
{
|
||||||
auto materialMap = std::map<float, Renderer::Material>();
|
auto materialMap = std::map<float, Renderer::Material>();
|
||||||
materialMap[0.3] = Renderer::Material{ QColor(0,255,255), 0.f, .8f };
|
materialMap[1.0] = Renderer::Material{ QColor(0, 0, 0), 0.f, .8f };
|
||||||
materialMap[1.0] = Renderer::Material{ QColor(80,25,255), 0.f, .8f };
|
|
||||||
this->strokePair.second = std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
|
this->strokePair.second = std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
|
||||||
15,
|
15,
|
||||||
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
|
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
|
||||||
|
|
Loading…
Reference in New Issue