mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-27 05:38:37 +08:00
Add automatic dark color mode switching function.
This commit is contained in:
parent
6db8c4d4ac
commit
f2db544be0
@ -1,6 +1,8 @@
|
||||
#include "FluTheme.h"
|
||||
|
||||
#include "FluColors.h"
|
||||
#include <QPalette>
|
||||
#include <QGuiApplication>
|
||||
|
||||
FluTheme* FluTheme::m_instance = nullptr;
|
||||
|
||||
@ -19,5 +21,13 @@ FluTheme::FluTheme(QObject *parent)
|
||||
textSize(13);
|
||||
nativeText(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());
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user