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