将StrokeStyleWidget的表格改为了其中的一个类
parent
460428c135
commit
27c1d4d18a
|
@ -153,7 +153,7 @@
|
|||
<ClCompile Include="src\Renderer\Painting\StraightLine.cpp" />
|
||||
<ClCompile Include="src\Renderer\VirtualTextureManager.cpp" />
|
||||
<ClCompile Include="src\SvgParser.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleWidget.cpp" />
|
||||
<QtUic Include="EditorWidget.ui" />
|
||||
<QtUic Include="EditorWidgetItem.ui" />
|
||||
<QtUic Include="MainWindow.ui" />
|
||||
|
@ -189,7 +189,7 @@
|
|||
<None Include="res\Shaders\ssgi.comp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleWidget.h" />
|
||||
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" />
|
||||
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
|
||||
<QtMoc Include="src\MainWindow.h" />
|
||||
|
|
|
@ -216,7 +216,7 @@
|
|||
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.cpp">
|
||||
<Filter>Source Files\Editor\Style</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.cpp">
|
||||
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleWidget.cpp">
|
||||
<Filter>Source Files\Editor\Style</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
|
||||
|
@ -254,7 +254,7 @@
|
|||
<QtMoc Include="src\FluentMenu.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.h">
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleWidget.h">
|
||||
<Filter>Header Files\Editor\Style</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "StrokeStyleListView.h"
|
||||
#include "StrokeStyleWidget.h"
|
||||
#include "ColorPicker.h"
|
||||
#include <qtmaterialraisedbutton.h>
|
||||
|
||||
|
@ -8,63 +8,73 @@ constexpr int COLUMN_METALLIC = 2;
|
|||
constexpr int COLUMN_ROUGHNESS = 3;
|
||||
constexpr int COLUMN_OPERATIONS = 4;
|
||||
|
||||
// TODO: 将这个类改为继承QWidget,把table转为其中的一个元素,加上新增行按钮和宽度设置
|
||||
StrokeStyleListView::StrokeStyleListView(
|
||||
// TODO: 加上新增行按钮和宽度设置
|
||||
StrokeStyleWidget::StrokeStyleWidget(
|
||||
std::shared_ptr<Renderer::StrokeRadialGradient> stroke,
|
||||
QWidget* parent
|
||||
) : QTableWidget(parent), stroke(stroke)
|
||||
) : QWidget(parent), stroke(stroke)
|
||||
{
|
||||
this->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
|
||||
this->setColumnCount(5);
|
||||
this->setRowCount(stroke->materialMap.size());
|
||||
this->viewLayout = new QVBoxLayout(this);
|
||||
this->setLayout(viewLayout);
|
||||
|
||||
initTable(stroke);
|
||||
viewLayout->addWidget(strokeTable);
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient>& stroke)
|
||||
{
|
||||
this->strokeTable = new QTableWidget(this);
|
||||
strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
|
||||
strokeTable->setColumnCount(5);
|
||||
strokeTable->setRowCount(stroke->materialMap.size());
|
||||
QStringList headers;
|
||||
headers.append(QStringLiteral("离心距离占比"));
|
||||
headers.append(QStringLiteral("颜色"));
|
||||
headers.append(QStringLiteral("金属度"));
|
||||
headers.append(QStringLiteral("粗糙度"));
|
||||
headers.append(QStringLiteral("其他操作"));
|
||||
this->setHorizontalHeaderLabels(headers);
|
||||
for (int row = 0; auto& strokePair : stroke->materialMap)
|
||||
headers << QStringLiteral("离心距离占比")
|
||||
<< QStringLiteral("颜色")
|
||||
<< QStringLiteral("金属度")
|
||||
<< QStringLiteral("粗糙度")
|
||||
<< QStringLiteral("其他操作");
|
||||
strokeTable->setHorizontalHeaderLabels(headers);
|
||||
for (int row = 0; auto & strokePair : stroke->materialMap)
|
||||
{
|
||||
QTableWidgetItem* widthItem = new QTableWidgetItem;
|
||||
widthItem->setData(Qt::EditRole, strokePair.first);
|
||||
this->setItem(row, COLUMN_WIDTH, widthItem);
|
||||
strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
|
||||
|
||||
QColor* colorPtr = &(strokePair.second.color);
|
||||
QTableWidgetItem* colorItem = new QTableWidgetItem;
|
||||
colorItem->setData(Qt::DisplayRole, *colorPtr);
|
||||
this->setItem(row, COLUMN_COLOR, colorItem);
|
||||
ColorPicker* colorPicker = new ColorPicker(*colorPtr, this);
|
||||
this->setCellWidget(row, COLUMN_COLOR, colorPicker);
|
||||
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->update();
|
||||
this->strokeTable->update();
|
||||
});
|
||||
|
||||
QTableWidgetItem* metallicItem = new QTableWidgetItem;
|
||||
metallicItem->setData(Qt::EditRole, strokePair.second.metallic);
|
||||
this->setItem(row, COLUMN_METALLIC, metallicItem);
|
||||
strokeTable->setItem(row, COLUMN_METALLIC, metallicItem);
|
||||
|
||||
QTableWidgetItem* roughnessItem = new QTableWidgetItem;
|
||||
roughnessItem->setData(Qt::EditRole, strokePair.second.roughness);
|
||||
this->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
|
||||
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
|
||||
|
||||
QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", this);
|
||||
removeButton->setFixedSize(20, 20);
|
||||
this->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
|
||||
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
|
||||
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {
|
||||
this->stroke->materialMap.erase(this->item(row, COLUMN_WIDTH)->text().toFloat());
|
||||
this->removeRow(row);
|
||||
this->stroke->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat());
|
||||
this->strokeTable->removeRow(row);
|
||||
});
|
||||
|
||||
row++;
|
||||
}
|
||||
connect(this, &StrokeStyleListView::currentItemChanged, this, &StrokeStyleListView::onCurrentItemChanged);
|
||||
connect(this, &StrokeStyleListView::cellChanged, this, &StrokeStyleListView::onCellChanged);
|
||||
this->adjustSize();
|
||||
connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged);
|
||||
connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged);
|
||||
}
|
||||
|
||||
void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
|
||||
void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
|
||||
{
|
||||
if (!current) return;
|
||||
int column = current->column();
|
||||
|
@ -74,16 +84,16 @@ void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTable
|
|||
}
|
||||
}
|
||||
|
||||
void StrokeStyleListView::onCellChanged(int row, int column)
|
||||
void StrokeStyleWidget::onCellChanged(int row, int column)
|
||||
{
|
||||
auto changedItem = this->item(row, column);
|
||||
auto changedItem = strokeTable->item(row, column);
|
||||
auto changedItemValue = changedItem->text().toFloat();
|
||||
if (changedItemValue < 0 || 1 < changedItemValue)
|
||||
{
|
||||
changedItem->setData(Qt::EditRole, this->currentItemValue.toFloat());
|
||||
return;
|
||||
}
|
||||
auto changedWidth = this->item(row, COLUMN_WIDTH)->text().toFloat();
|
||||
auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->text().toFloat();
|
||||
switch (row)
|
||||
{
|
||||
case COLUMN_WIDTH:
|
|
@ -1,17 +1,21 @@
|
|||
#pragma once
|
||||
#include "LayerStyle.h"
|
||||
#include "../Renderer/Painting/MaterialStyleStroke.h"
|
||||
#include <QListView>
|
||||
#include <QListWidget>
|
||||
#include <QTableWidget>
|
||||
class StrokeStyleListView : public QTableWidget
|
||||
#include <QVBoxLayout>
|
||||
class StrokeStyleWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString currentItemValue;
|
||||
|
||||
QVBoxLayout* viewLayout;
|
||||
QTableWidget* strokeTable;
|
||||
|
||||
void initTable(std::shared_ptr<Renderer::StrokeRadialGradient>& stroke);
|
||||
|
||||
public:
|
||||
StrokeStyleListView(std::shared_ptr<Renderer::StrokeRadialGradient> stroke, QWidget* parent = nullptr);
|
||||
StrokeStyleWidget(std::shared_ptr<Renderer::StrokeRadialGradient> stroke, QWidget* parent = nullptr);
|
||||
std::shared_ptr<Renderer::StrokeRadialGradient> stroke;
|
||||
|
||||
protected slots:
|
|
@ -1,5 +1,5 @@
|
|||
#include "LayerStyle.h"
|
||||
#include "./EditorWidgetComponent/StrokeStyleListView.h"
|
||||
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
|
||||
#include <qtmaterialcheckbox.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
|
@ -79,7 +79,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget()
|
|||
QVBoxLayout* layout = new QVBoxLayout(w);
|
||||
layout->setMargin(0);
|
||||
|
||||
StrokeStyleListView* leftStrokeView = new StrokeStyleListView(
|
||||
StrokeStyleWidget* leftStrokeView = new StrokeStyleWidget(
|
||||
std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(this->strokePair.first->materialStroke), w
|
||||
);
|
||||
layout->addWidget(leftStrokeView);
|
||||
|
@ -89,7 +89,7 @@ QWidget* StrokeElementLayerStyle::getInputWidget()
|
|||
checkEachSideIndependent->setChecked(enableEachSideIndependent);
|
||||
layout->addWidget(checkEachSideIndependent);
|
||||
|
||||
StrokeStyleListView* rightStrokeView = new StrokeStyleListView(
|
||||
StrokeStyleWidget* rightStrokeView = new StrokeStyleWidget(
|
||||
std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(this->strokePair.second->materialStroke), w
|
||||
);
|
||||
layout->addWidget(rightStrokeView);
|
||||
|
|
Loading…
Reference in New Issue