[style/stroke] 完成所有设置控件

dev-LayerStyle
ArgonarioD 2023-03-15 15:09:55 +08:00
parent 1e3bef78f4
commit 7079b335cb
3 changed files with 66 additions and 16 deletions

View File

@ -1,7 +1,6 @@
#include "StrokeStyleWidget.h"
#include "ColorPicker.h"
#include <qtmaterialraisedbutton.h>
#include <qtmaterialtextfield.h>
#include <limits>
#define radialStroke(stroke) std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(stroke->materialStroke)
@ -18,21 +17,19 @@ StrokeStyleWidget::StrokeStyleWidget(
QWidget* parent
) : QWidget(parent), stroke(stroke)
{
this->viewLayout = new QVBoxLayout(this);
QVBoxLayout* viewLayout = new QVBoxLayout(this);
this->setLayout(viewLayout);
QtMaterialTextField* widthField = new QtMaterialTextField(this);
widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È"));
widthField->setText(QString::number(stroke->halfWidth));
QDoubleValidator* widthValidator = new QDoubleValidator(0.1, std::numeric_limits<float>::max(), 3, widthField);
widthValidator->setNotation(QDoubleValidator::StandardNotation);
widthField->setValidator(widthValidator);
connect(widthField, &QtMaterialTextField::textChanged, [this, widthField](const QString& changed) {
if (widthField->hasAcceptableInput())
{
this->stroke->halfWidth = changed.toFloat();
}
});
initStrokeSettings();
QWidget* strokeProperties = new QWidget(this);
QHBoxLayout* strokePropertiesLayout = new QHBoxLayout(strokeProperties);
strokePropertiesLayout->setMargin(0);
strokeProperties->setLayout(strokePropertiesLayout);
strokePropertiesLayout->addWidget(enableGradual);
strokePropertiesLayout->addWidget(endTypeBox);
viewLayout->addWidget(strokeProperties);
viewLayout->addWidget(widthField);
initTable(std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(stroke->materialStroke));
@ -40,6 +37,54 @@ StrokeStyleWidget::StrokeStyleWidget(
this->adjustSize();
}
void StrokeStyleWidget::initStrokeSettings()
{
this->enableGradual = new QtMaterialCheckBox(this);
enableGradual->setText(QStringLiteral("启用渐变"));
enableGradual->setChecked(radialStroke(stroke)->gradual);
connect(enableGradual, &QtMaterialCheckBox::toggled, [this](bool checked) {
radialStroke(this->stroke)->gradual = checked;
});
#define endTypeBoxLabel(start, end) QStringLiteral(start##" -> "##end)
this->endTypeBox = new QComboBox(this);
endTypeBox->addItem(endTypeBoxLabel("圆头", "圆头")); // kRound
endTypeBox->addItem(endTypeBoxLabel("平头", "圆头")); // kFlatRound
endTypeBox->addItem(endTypeBoxLabel("圆头", "平头")); // kRoundFlat
endTypeBox->addItem(endTypeBoxLabel("平头", "平头")); // kFlat
endTypeBox->setCurrentIndex(static_cast<int>(this->stroke->endType));
connect(endTypeBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
switch (index)
{
case 0:
this->stroke->endType = Renderer::StrokeEndType::kRound;
break;
case 1:
this->stroke->endType = Renderer::StrokeEndType::kFlatRound;
break;
case 2:
this->stroke->endType = Renderer::StrokeEndType::kRoundFlat;
break;
case 3:
this->stroke->endType = Renderer::StrokeEndType::kFlat;
break;
}
});
this->widthField = new QtMaterialTextField(this);
widthField->setLabel(QStringLiteral("本侧描边宽度"));
widthField->setText(QString::number(stroke->halfWidth));
QDoubleValidator* widthValidator = new QDoubleValidator(0.1, std::numeric_limits<float>::max(), 3, widthField);
widthValidator->setNotation(QDoubleValidator::StandardNotation);
widthField->setValidator(widthValidator);
connect(widthField, &QtMaterialTextField::textChanged, [this](const QString& changed) {
if (this->widthField->hasAcceptableInput())
{
this->stroke->halfWidth = changed.toFloat();
}
});
}
void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke)
{
this->strokeTable = new QTableWidget(this);

View File

@ -3,15 +3,21 @@
#include "../Renderer/Painting/MaterialStyleStroke.h"
#include <QTableWidget>
#include <QVBoxLayout>
#include <QComboBox>
#include <qtmaterialtextfield.h>
#include <qtmaterialcheckbox.h>
class StrokeStyleWidget : public QWidget
{
Q_OBJECT
private:
QString currentItemValue;
QVBoxLayout* viewLayout;
QtMaterialCheckBox* enableGradual;
QComboBox* endTypeBox;
QtMaterialTextField* widthField;
QTableWidget* strokeTable;
void initStrokeSettings();
void initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke);
public:

View File

@ -1,7 +1,6 @@
#include "LayerStyle.h"
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
#include <qtmaterialcheckbox.h>
#include <qtmaterialtextfield.h>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>