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/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 5bf6bbe..aa7069e 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -1,4 +1,5 @@ #include "MainWindow.h" +#include "ColorHelper.hpp" #include #include #include @@ -51,9 +52,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);