添加了ColorHelper

dev-LayerStyle
ArgonarioD 2023-03-20 02:41:58 +08:00
parent 64c4646783
commit 412e2eec5e
2 changed files with 51 additions and 3 deletions

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,4 +1,5 @@
#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>
@ -51,9 +52,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);