diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index c403fad..7414c08 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -202,6 +202,7 @@
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index e198184..835a354 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -519,6 +519,9 @@
Header Files\Editor\Layer
+
+ Header Files
+
diff --git a/ArchitectureColoredPainting/src/ColorHelper.hpp b/ArchitectureColoredPainting/src/ColorHelper.hpp
new file mode 100644
index 0000000..f337382
--- /dev/null
+++ b/ArchitectureColoredPainting/src/ColorHelper.hpp
@@ -0,0 +1,49 @@
+#pragma once
+#include
+#include
+#include
+
+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();
+ }
+};
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp
index 7010ae4..4ccb504 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp
@@ -1,5 +1,6 @@
#include "ColorPicker.h"
#include
+#include
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;
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h
index a8edd67..50c1c34 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h
@@ -1,4 +1,5 @@
#pragma once
+#include "../ColorHelper.hpp"
#include
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();
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp
index bf78dbc..662ff47 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp
@@ -4,7 +4,7 @@
#include
#include
-FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent)
+FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent)
: QWidget(parent), fill(fill)
{
auto* layout = new QGridLayout(this);
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp
index 33a3568..40c2555 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp
@@ -1,28 +1,25 @@
#include "LayerStyleDialog.h"
#include
#include
-#include
#include
LayerStyleDialog::LayerStyleDialog(
LayerStyleContainer& styles,
- std::shared_ptr existedStyle,
+ const std::shared_ptr& existedStyle,
QWidget* parent
) : QDialog(parent), styles(&styles)
{
- auto* dialogLayout = new QVBoxLayout(this);
+ dialogLayout = new QGridLayout;
dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
this->setLayout(dialogLayout);
if (existedStyle)
{
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();
}
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h
index b703e80..485b58c 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h
@@ -8,13 +8,13 @@ class LayerStyleDialog : public QDialog
Q_OBJECT
private:
QWidget* styleWidget;
- QGridLayout* styleContainer;
+ QGridLayout* dialogLayout;
LayerStyleContainer* styles;
std::unique_ptr modifyingStyle;
public:
LayerStyleDialog(
LayerStyleContainer& styles,
- std::shared_ptr existedStyle = nullptr,
+ const std::shared_ptr& existedStyle = nullptr,
QWidget* parent = nullptr
);
std::shared_ptr layerStyle;
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp
index e2c9ce7..e9999bb 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp
@@ -1,8 +1,8 @@
#include "StrokeStyleWidget.h"
#include "ColorPicker.h"
+#include "../ColorHelper.hpp"
#include
#include
-#include
constexpr int COLUMN_WIDTH = 0;
constexpr int COLUMN_COLOR = 1;
@@ -105,8 +105,8 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetBackgroundColor(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_ptrsetFixedHeight(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]() {
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h
index 6d5dbdd..67af3ee 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h
@@ -23,8 +23,8 @@ private:
void setTableRow(int row, float width, Renderer::Material& material);
public:
- StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr);
- std::shared_ptr stroke;
+ StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr);
+ std::shared_ptr stroke;
protected slots:
void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp
index 16ff56c..292d0ca 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp
+++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp
@@ -2,6 +2,7 @@
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
#include "./EditorWidgetComponent/FillStyleWidget.h"
#include "./util/EncodeUtil.hpp"
+#include "../ColorHelper.hpp"
#include
#include
#include
@@ -334,7 +335,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater
if (!fillMaterialStyle)
{
this->fillMaterialStyle = std::make_shared(
- std::make_shared(Renderer::Material(QColor::fromRgb(0, 0, 0)))
+ std::make_shared(ColorHelper::instance().getPrimary1())
);
}
}
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp
index 2f54a22..979af0b 100644
--- a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp
@@ -1,6 +1,6 @@
#include "EditorSettingWidget.h"
+#include "../ColorHelper.hpp"
#include
-#include
#include
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);
diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp
index 5bf6bbe..0e3d73b 100644
--- a/ArchitectureColoredPainting/src/main.cpp
+++ b/ArchitectureColoredPainting/src/main.cpp
@@ -1,11 +1,11 @@
#include "MainWindow.h"
+#include "ColorHelper.hpp"
#include
#include
#include
#include
#include
#include "consoleapi2.h"
-#include
extern "C"
{
@@ -51,9 +51,7 @@ int main(int argc, char* argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QApplication a(argc, argv);
Q_INIT_RESOURCE(resources);
- QtMaterialTheme theme;
- theme.setColor("primary1", QColor(0, 90, 158));
- QtMaterialStyle::instance().setTheme(&theme);
+ ColorHelper::instance();
//FramelessHelper::Core::setApplicationOSThemeAware();
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
//FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);