FluentUI/src/FluTheme.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

2023-05-18 22:58:35 +08:00
//#include "FluTheme.h"
//#include "Def.h"
//#include "FluColors.h"
//#include <QPalette>
//#include <QtGui/qpa/qplatformtheme.h>
//#include <QtGui/private/qguiapplication_p.h>
//#include <QGuiApplication>
//#include <FramelessHelper/Core/utils.h>
//#include <FramelessHelper/Core/framelessmanager.h>
//FRAMELESSHELPER_USE_NAMESPACE;
//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}
//{
// primaryColor(FluColors::getInstance()->Blue());
// nativeText(false);
// dark(FramelessManager::instance()->systemTheme() == Global::SystemTheme::Dark);
// connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, [this](){
// dark(Utils::getSystemTheme()==Global::SystemTheme::Dark);
// });
//}
#include "FluTheme.h"
2023-03-06 14:22:13 +08:00
2023-04-19 23:53:00 +08:00
#include "Def.h"
2023-05-17 11:42:03 +08:00
#include "FluColors.h"
#include <QPalette>
2023-05-17 22:02:09 +08:00
#include <QtGui/qpa/qplatformtheme.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QGuiApplication>
2023-05-18 22:58:35 +08:00
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Core/framelessmanager.h>
FRAMELESSHELPER_USE_NAMESPACE;
2023-03-06 14:22:13 +08:00
2023-05-11 18:24:58 +08:00
FluTheme* FluTheme::m_instance = nullptr;
FluTheme *FluTheme::getInstance()
{
if(FluTheme::m_instance == nullptr){
FluTheme::m_instance = new FluTheme;
}
return FluTheme::m_instance;
}
2023-03-06 14:22:13 +08:00
FluTheme::FluTheme(QObject *parent)
: QObject{parent}
{
2023-04-19 23:53:00 +08:00
connect(this,&FluTheme::darkModeChanged,this,[=]{
Q_EMIT darkChanged();
});
2023-05-11 18:24:58 +08:00
primaryColor(FluColors::getInstance()->Blue());
2023-04-19 18:04:14 +08:00
nativeText(false);
2023-04-19 23:53:00 +08:00
darkMode(Fluent_DarkMode::Fluent_DarkModeType::Light);
_systemDark = systemDark();
2023-04-20 09:15:28 +08:00
qApp->installEventFilter(this);
}
bool FluTheme::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
2023-05-17 22:02:09 +08:00
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange)
{
2023-05-17 22:02:09 +08:00
_systemDark = systemDark();
2023-04-19 23:53:00 +08:00
Q_EMIT darkChanged();
event->accept();
return true;
}
return false;
}
2023-05-18 22:58:35 +08:00
2023-04-19 23:53:00 +08:00
bool FluTheme::systemDark()
{
2023-05-18 22:58:35 +08:00
return Utils::getSystemTheme()==Global::SystemTheme::Dark;
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){
2023-05-17 22:02:09 +08:00
return _systemDark;
2023-04-19 23:53:00 +08:00
}else{
return false;
}
}