[editor] 修复了一些会导致warning的问题 | #15

* 添加了ColorHelper
 * LayerStyleDialog重复setLayer导致的warning
 * QColorDialog::getColor时由于Qt的bug未正确设置大小导致的warning
dev-LayerStyle
ArgonarioD 2023-03-20 02:48:52 +08:00
parent b6e79ee6de
commit 855dd2e075
13 changed files with 90 additions and 40 deletions

View File

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

View File

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

View File

@ -0,0 +1,49 @@
#pragma once
#include <lib/qtmaterialstyle.h>
#include <lib/qtmaterialtheme.h>
#include <QColorDialog>
class ColorHelper
{
QtMaterialTheme theme;
QColor primary1;
public:
void setPrimary1(const QColor& color)
{
theme.setColor("primary1", color);
primary1 = color;
}
[[nodiscard]] QColor getPrimary1() const
{
return primary1;
}
ColorHelper()
{
setPrimary1(QColor::fromRgb(0, 90, 158));
QtMaterialStyle::instance().setTheme(&theme);
}
static ColorHelper& instance()
{
static ColorHelper instance;
return instance;
}
static QColor execColorDialog(
const QColor& initial = instance().getPrimary1(),
QWidget* parent = nullptr,
const QString& title = ""
) {
auto dialog = QColorDialog(initial, parent);
if (!title.isEmpty())
{
dialog.setWindowTitle(title);
}
dialog.adjustSize();
dialog.exec();
return dialog.selectedColor();
}
};

View File

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

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "../ColorHelper.hpp"
#include <QPushButton> #include <QPushButton>
class ColorPicker : public QPushButton class ColorPicker : public QPushButton
{ {
@ -6,7 +7,7 @@ class ColorPicker : public QPushButton
private: private:
QColor color; QColor color;
public: 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; QColor getColor() const;
public slots: public slots:
void onClicked(); void onClicked();

View File

@ -4,7 +4,7 @@
#include <QLabel> #include <QLabel>
#include <qtmaterialtextfield.h> #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) : QWidget(parent), fill(fill)
{ {
auto* layout = new QGridLayout(this); auto* layout = new QGridLayout(this);

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
#include "./EditorWidgetComponent/StrokeStyleWidget.h" #include "./EditorWidgetComponent/StrokeStyleWidget.h"
#include "./EditorWidgetComponent/FillStyleWidget.h" #include "./EditorWidgetComponent/FillStyleWidget.h"
#include "./util/EncodeUtil.hpp" #include "./util/EncodeUtil.hpp"
#include "../ColorHelper.hpp"
#include <qtmaterialcheckbox.h> #include <qtmaterialcheckbox.h>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPushButton> #include <QPushButton>
@ -334,7 +335,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater
if (!fillMaterialStyle) if (!fillMaterialStyle)
{ {
this->fillMaterialStyle = std::make_shared<MaterialStyleFill>( 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 "EditorSettingWidget.h"
#include "../ColorHelper.hpp"
#include <QPushButton> #include <QPushButton>
#include <QColorDialog>
#include <QInputDialog> #include <QInputDialog>
EditorSettingWidget::EditorSettingWidget(QWidget* parent) EditorSettingWidget::EditorSettingWidget(QWidget* parent)
@ -8,7 +8,7 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent)
{ {
ui.setupUi(this); ui.setupUi(this);
connect(ui.backgroundColorButton, &QPushButton::clicked, this, [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()) if (color.isValid())
{ {
emit backgroundColorChanged(color); emit backgroundColorChanged(color);

View File

@ -1,11 +1,11 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "ColorHelper.hpp"
#include <QGuiApplication> #include <QGuiApplication>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <FramelessHelper/Core/private/framelessconfig_p.h> #include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <iostream> #include <iostream>
#include <format> #include <format>
#include "consoleapi2.h" #include "consoleapi2.h"
#include <lib/qtmaterialstyle.h>
extern "C" extern "C"
{ {
@ -51,9 +51,7 @@ int main(int argc, char* argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QApplication a(argc, argv); QApplication a(argc, argv);
Q_INIT_RESOURCE(resources); Q_INIT_RESOURCE(resources);
QtMaterialTheme theme; ColorHelper::instance();
theme.setColor("primary1", QColor(0, 90, 158));
QtMaterialStyle::instance().setTheme(&theme);
//FramelessHelper::Core::setApplicationOSThemeAware(); //FramelessHelper::Core::setApplicationOSThemeAware();
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
//FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); //FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);