Add automatic dark color mode switching function.
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