mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-30 15:06:52 +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 "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());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user