From 412e2eec5ec738f0d640cce6521760adb3a44080 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 02:41:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86ColorHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ColorHelper.hpp | 49 +++++++++++++++++++ ArchitectureColoredPainting/src/main.cpp | 5 +- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 ArchitectureColoredPainting/src/ColorHelper.hpp 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);