Merge pull request #53 from mentalfl0w/dev

Add automatic dark color mode switching function.
main
zhuzichu 2023-04-16 02:30:08 +08:00 committed by GitHub
commit cb94db8a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,8 @@
#include "FluTheme.h" #include "FluTheme.h"
#include "FluColors.h" #include "FluColors.h"
#include <QPalette>
#include <QGuiApplication>
FluTheme* FluTheme::m_instance = nullptr; FluTheme* FluTheme::m_instance = nullptr;
@ -19,5 +21,13 @@ FluTheme::FluTheme(QObject *parent)
textSize(13); textSize(13);
nativeText(true); nativeText(true);
frameless(true); frameless(true);
dark(false); std::function<bool()> isDark = [](){
QPalette palette = (qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->palette();
QColor color = palette.color(QPalette::Window).rgb();
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
};
dark(isDark());
connect(qobject_cast<QGuiApplication *>(QCoreApplication::instance()), &QGuiApplication::paletteChanged, this, [=] (const QPalette &) {
dark(isDark());
});
} }