解决了一些GUI的warning

LayerStyleDialog重复setLayer导致的warning
QColorDialog::getColor时由于Qt的bug未正确设置大小导致的warning
dev-LayerStyle
ArgonarioD 2023-03-20 02:42:03 +08:00
parent 412e2eec5e
commit 93db81503a
12 changed files with 39 additions and 37 deletions

View File

@ -202,6 +202,7 @@
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
<ClInclude Include="src\ColorHelper.hpp" />
<ClInclude Include="src\Editor\LayerWrapper.h" />
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />

View File

@ -519,6 +519,9 @@
<ClInclude Include="src\Editor\LayerWrapper.h">
<Filter>Header Files\Editor\Layer</Filter>
</ClInclude>
<ClInclude Include="src\ColorHelper.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="res\MainWindow.qrc">

View File

@ -1,5 +1,6 @@
#include "ColorPicker.h"
#include <QColorDialog>
#include <QDebug>
QString getStyleSheet(const QColor& color)
{
@ -26,9 +27,8 @@ QColor ColorPicker::getColor() const
void ColorPicker::onClicked()
{
QColorDialog dialog(this->color, this);
dialog.exec();
QColor newColor = dialog.selectedColor();
//const QColor newColor = QColorDialog::getColor(this->color, this);
const QColor newColor = ColorHelper::execColorDialog(this->color, this);
if (newColor.isValid() && this->color != newColor)
{
this->color = newColor;

View File

@ -1,4 +1,5 @@
#pragma once
#include "../ColorHelper.hpp"
#include <QPushButton>
class ColorPicker : public QPushButton
{
@ -6,7 +7,7 @@ class ColorPicker : public QPushButton
private:
QColor color;
public:
ColorPicker(const QColor& color = QColor::fromRgb(0, 0, 0), QWidget* parent = nullptr);
ColorPicker(const QColor& color = ColorHelper::instance().getPrimary1(), QWidget* parent = nullptr);
QColor getColor() const;
public slots:
void onClicked();

View File

@ -4,7 +4,7 @@
#include <QLabel>
#include <qtmaterialtextfield.h>
FillStyleWidget::FillStyleWidget(std::shared_ptr<Renderer::MaterialStyleFill> fill, QWidget* parent)
FillStyleWidget::FillStyleWidget(std::shared_ptr<MaterialStyleFill> fill, QWidget* parent)
: QWidget(parent), fill(fill)
{
auto* layout = new QGridLayout(this);

View File

@ -1,16 +1,15 @@
#include "LayerStyleDialog.h"
#include <QComboBox>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QGridLayout>
LayerStyleDialog::LayerStyleDialog(
LayerStyleContainer& styles,
std::shared_ptr<LayerStyle> existedStyle,
const std::shared_ptr<LayerStyle>& existedStyle,
QWidget* parent
) : QDialog(parent), styles(&styles)
{
auto* dialogLayout = new QVBoxLayout(this);
dialogLayout = new QGridLayout;
dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
this->setLayout(dialogLayout);
@ -18,11 +17,9 @@ LayerStyleDialog::LayerStyleDialog(
{
this->modifyingStyle = existedStyle->clone();
this->styleContainer = nullptr;
this->styleWidget = modifyingStyle->getInputWidget();
this->styleWidget->setParent(this);
dialogLayout->addWidget(styleWidget);
// do something
dialogLayout->addWidget(styleWidget, 1, 0);
}
else
{
@ -34,13 +31,12 @@ LayerStyleDialog::LayerStyleDialog(
typeSelector->addItems(unusedStyleNames);
this->modifyingStyle = std::move(styles.makeUnusedStyle(unusedStyleNames[0]));
dialogLayout->addWidget(typeSelector);
this->styleContainer = new QGridLayout(this);
dialogLayout->addLayout(styleContainer);
dialogLayout->addWidget(typeSelector, 0, 0);
this->styleWidget = this->modifyingStyle->getInputWidget();
this->styleWidget->setParent(this);
this->styleContainer->addWidget(styleWidget);
this->dialogLayout->addWidget(styleWidget, 1, 0);
connect(typeSelector, &QComboBox::currentTextChanged,
this, &LayerStyleDialog::onStyleTypeSelectorChanged);
}
@ -48,7 +44,8 @@ LayerStyleDialog::LayerStyleDialog(
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &LayerStyleDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &LayerStyleDialog::reject);
dialogLayout->addWidget(buttonBox);
dialogLayout->addWidget(buttonBox, 2, 0);
this->adjustSize();
}
void LayerStyleDialog::accept()
@ -61,14 +58,14 @@ void LayerStyleDialog::onStyleTypeSelectorChanged(const QString& current)
{
if (this->styleWidget)
{
this->styleContainer->removeWidget(this->styleWidget);
this->dialogLayout->removeWidget(this->styleWidget);
this->styleWidget->setParent(nullptr);
delete styleWidget;
}
this->modifyingStyle = std::move(styles->makeUnusedStyle(current));
this->styleWidget = this->modifyingStyle->getInputWidget();
this->styleWidget->setParent(this);
this->styleContainer->addWidget(styleWidget, 0, 0, 1, 1);
this->dialogLayout->addWidget(styleWidget, 1, 0);
this->styleWidget->adjustSize();
this->adjustSize();
}

View File

@ -8,13 +8,13 @@ class LayerStyleDialog : public QDialog
Q_OBJECT
private:
QWidget* styleWidget;
QGridLayout* styleContainer;
QGridLayout* dialogLayout;
LayerStyleContainer* styles;
std::unique_ptr<LayerStyle> modifyingStyle;
public:
LayerStyleDialog(
LayerStyleContainer& styles,
std::shared_ptr<LayerStyle> existedStyle = nullptr,
const std::shared_ptr<LayerStyle>& existedStyle = nullptr,
QWidget* parent = nullptr
);
std::shared_ptr<LayerStyle> layerStyle;

View File

@ -1,8 +1,8 @@
#include "StrokeStyleWidget.h"
#include "ColorPicker.h"
#include "../ColorHelper.hpp"
#include <qtmaterialraisedbutton.h>
#include <limits>
#include <lib/qtmaterialstyle.h>
constexpr int COLUMN_WIDTH = 0;
constexpr int COLUMN_COLOR = 1;
@ -105,8 +105,8 @@ void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient
row++;
}
// ÐÂÔö°´Å¥
QtMaterialRaisedButton* addButton = new QtMaterialRaisedButton("+", strokeTable);
addButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1"));
auto* addButton = new QtMaterialRaisedButton("+", strokeTable);
addButton->setBackgroundColor(ColorHelper::instance().getPrimary1());
strokeTable->setSpan(row, 0, 1, 5);
strokeTable->setCellWidget(row, 0, addButton);
strokeTable->setMinimumHeight(strokeTable->rowHeight(row) * 5);
@ -114,18 +114,18 @@ void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient
addButton->setFixedHeight(strokeTable->rowHeight(row));
connect(addButton, &QtMaterialRaisedButton::clicked, [this]() {
handlingRowInsert = true;
auto materialMap = &(radialStroke(this->stroke)->materialMap);
float newWidth = 0;
if (materialMap->size() == 0)
auto materialMap = &radialStroke(this->stroke)->materialMap;
float newWidth;
if (materialMap->empty())
{
newWidth = 0.1;
}
else
{
auto lastPair = materialMap->rbegin();
const auto lastPair = materialMap->rbegin();
newWidth = lastPair->first + 0.01;
}
Renderer::Material newMaterial(QColor::fromRgb(0, 0, 0));
const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1());
(*materialMap)[newWidth] = newMaterial;
int newRow = this->strokeTable->rowCount() - 1;
this->strokeTable->insertRow(newRow);
@ -143,7 +143,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma
widthItem->setData(Qt::EditRole, width);
strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
QColor* colorPtr = &(material.color);
QColor* colorPtr = &material.color;
auto* colorItem = new QTableWidgetItem;
colorItem->setData(Qt::DisplayRole, *colorPtr);
strokeTable->setItem(row, COLUMN_COLOR, colorItem);
@ -163,7 +163,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
auto* removeButton = new QtMaterialRaisedButton("-", strokeTable);
removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1"));
removeButton->setBackgroundColor(ColorHelper::instance().getPrimary1());
removeButton->setFixedSize(20, 20);
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {

View File

@ -23,8 +23,8 @@ private:
void setTableRow(int row, float width, Renderer::Material& material);
public:
StrokeStyleWidget(std::shared_ptr<Renderer::MaterialStyleStroke> stroke, QWidget* parent = nullptr);
std::shared_ptr<Renderer::MaterialStyleStroke> stroke;
StrokeStyleWidget(std::shared_ptr<MaterialStyleStroke> stroke, QWidget* parent = nullptr);
std::shared_ptr<MaterialStyleStroke> stroke;
protected slots:
void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);

View File

@ -2,6 +2,7 @@
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
#include "./EditorWidgetComponent/FillStyleWidget.h"
#include "./util/EncodeUtil.hpp"
#include "../ColorHelper.hpp"
#include <qtmaterialcheckbox.h>
#include <QHBoxLayout>
#include <QPushButton>
@ -334,7 +335,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater
if (!fillMaterialStyle)
{
this->fillMaterialStyle = std::make_shared<MaterialStyleFill>(
std::make_shared<Renderer::FillPlain>(Renderer::Material(QColor::fromRgb(0, 0, 0)))
std::make_shared<Renderer::FillPlain>(ColorHelper::instance().getPrimary1())
);
}
}

View File

@ -1,6 +1,6 @@
#include "EditorSettingWidget.h"
#include "../ColorHelper.hpp"
#include <QPushButton>
#include <QColorDialog>
#include <QInputDialog>
EditorSettingWidget::EditorSettingWidget(QWidget* parent)
@ -8,7 +8,7 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent)
{
ui.setupUi(this);
connect(ui.backgroundColorButton, &QPushButton::clicked, this, [this]() {
QColor color = QColorDialog::getColor(Qt::white, this, QString::fromLocal8Bit("Ñ¡Ôñ±³¾°ÑÕÉ«"));
QColor color = ColorHelper::execColorDialog(Qt::white, this, QString::fromLocal8Bit("Ñ¡Ôñ±³¾°ÑÕÉ«"));
if (color.isValid())
{
emit backgroundColorChanged(color);

View File

@ -6,7 +6,6 @@
#include <iostream>
#include <format>
#include "consoleapi2.h"
#include <lib/qtmaterialstyle.h>
extern "C"
{