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