2023-03-06 14:22:13 +08:00
|
|
|
|
#include "FluTheme.h"
|
|
|
|
|
|
|
|
|
|
#include "FluColors.h"
|
2023-04-19 23:53:00 +08:00
|
|
|
|
#include "Def.h"
|
2023-04-16 01:18:17 +08:00
|
|
|
|
#include <QPalette>
|
|
|
|
|
#include <QGuiApplication>
|
2023-03-06 14:22:13 +08:00
|
|
|
|
|
|
|
|
|
FluTheme* FluTheme::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
FluTheme *FluTheme::getInstance()
|
|
|
|
|
{
|
|
|
|
|
if(FluTheme::m_instance == nullptr){
|
|
|
|
|
FluTheme::m_instance = new FluTheme;
|
|
|
|
|
}
|
|
|
|
|
return FluTheme::m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluTheme::FluTheme(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
2023-04-19 23:53:00 +08:00
|
|
|
|
connect(this,&FluTheme::darkModeChanged,this,[=]{
|
|
|
|
|
Q_EMIT darkChanged();
|
|
|
|
|
});
|
2023-03-06 14:22:13 +08:00
|
|
|
|
primaryColor(FluColors::getInstance()->Blue());
|
2023-03-28 21:37:10 +08:00
|
|
|
|
textSize(13);
|
2023-04-19 18:04:14 +08:00
|
|
|
|
nativeText(false);
|
2023-03-28 21:37:10 +08:00
|
|
|
|
frameless(true);
|
2023-04-19 23:53:00 +08:00
|
|
|
|
darkMode(Fluent_DarkMode::Fluent_DarkModeType::Light);
|
2023-04-19 22:27:27 +08:00
|
|
|
|
(qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FluTheme::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(obj);
|
|
|
|
|
if (event->type() == QEvent::ApplicationPaletteChange)
|
|
|
|
|
{
|
2023-04-19 23:53:00 +08:00
|
|
|
|
Q_EMIT darkChanged();
|
2023-04-19 22:27:27 +08:00
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 23:53:00 +08:00
|
|
|
|
bool FluTheme::systemDark()
|
2023-04-19 22:27:27 +08:00
|
|
|
|
{
|
2023-04-20 00:15:13 +08:00
|
|
|
|
QPalette palette = (qobject_cast<QGuiApplication *>(QGuiApplication::instance()))->palette();
|
2023-04-19 22:27:27 +08:00
|
|
|
|
QColor color = palette.color(QPalette::Window).rgb();
|
|
|
|
|
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
|
2023-03-06 14:22:13 +08:00
|
|
|
|
}
|
2023-04-19 23:53:00 +08:00
|
|
|
|
|
|
|
|
|
bool FluTheme::dark(){
|
|
|
|
|
if(_darkMode == Fluent_DarkMode::Fluent_DarkModeType::Dark){
|
|
|
|
|
return true;
|
|
|
|
|
}else if(_darkMode == Fluent_DarkMode::Fluent_DarkModeType::Light){
|
|
|
|
|
return false;
|
|
|
|
|
}else if(_darkMode == Fluent_DarkMode::Fluent_DarkModeType::System){
|
|
|
|
|
return systemDark();
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|