mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 11:17:15 +08:00
update
This commit is contained in:
parent
221afeea58
commit
51aef3f3ec
@ -9,7 +9,7 @@ Window {
|
|||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
FluApp.init(app)
|
FluApp.init(app)
|
||||||
FluTheme.frameless = ("windows" === Qt.platform.os)
|
FluTheme.frameless = ("windows" === Qt.platform.os)
|
||||||
FluTheme.dark = false
|
FluTheme.darkMode = FluDarkMode.System
|
||||||
FluApp.routes = {
|
FluApp.routes = {
|
||||||
"/":"qrc:/page/MainPage.qml",
|
"/":"qrc:/page/MainPage.qml",
|
||||||
"/about":"qrc:/page/AboutPage.qml",
|
"/about":"qrc:/page/AboutPage.qml",
|
||||||
|
@ -14,6 +14,39 @@ FluScrollablePage{
|
|||||||
bottomPadding:20
|
bottomPadding:20
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
|
FluArea{
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.topMargin: 20
|
||||||
|
height: 136
|
||||||
|
paddings: 10
|
||||||
|
|
||||||
|
ColumnLayout{
|
||||||
|
spacing: 10
|
||||||
|
anchors{
|
||||||
|
top: parent.top
|
||||||
|
left: parent.left
|
||||||
|
}
|
||||||
|
FluText{
|
||||||
|
text:lang.dark_mode
|
||||||
|
fontStyle: FluText.BodyStrong
|
||||||
|
Layout.bottomMargin: 4
|
||||||
|
}
|
||||||
|
Repeater{
|
||||||
|
model: [{title:"System",mode:FluDarkMode.System},{title:"Light",mode:FluDarkMode.Light},{title:"Dark",mode:FluDarkMode.Dark}]
|
||||||
|
delegate: FluRadioButton{
|
||||||
|
selected : FluTheme.darkMode === modelData.mode
|
||||||
|
text:modelData.title
|
||||||
|
onClicked:{
|
||||||
|
FluTheme.darkMode = modelData.mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
FluArea{
|
FluArea{
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 20
|
Layout.topMargin: 20
|
||||||
@ -32,9 +65,7 @@ FluScrollablePage{
|
|||||||
fontStyle: FluText.BodyStrong
|
fontStyle: FluText.BodyStrong
|
||||||
Layout.bottomMargin: 4
|
Layout.bottomMargin: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
Repeater{
|
Repeater{
|
||||||
id:repeater
|
|
||||||
model: [{title:"Open",mode:FluNavigationView.Open},{title:"Compact",mode:FluNavigationView.Compact},{title:"Minimal",mode:FluNavigationView.Minimal},{title:"Auto",mode:FluNavigationView.Auto}]
|
model: [{title:"Open",mode:FluNavigationView.Open},{title:"Compact",mode:FluNavigationView.Compact},{title:"Minimal",mode:FluNavigationView.Minimal},{title:"Auto",mode:FluNavigationView.Auto}]
|
||||||
delegate: FluRadioButton{
|
delegate: FluRadioButton{
|
||||||
selected : MainEvent.displayMode===modelData.mode
|
selected : MainEvent.displayMode===modelData.mode
|
||||||
@ -45,7 +76,6 @@ FluScrollablePage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FluArea{
|
FluArea{
|
||||||
@ -82,41 +112,6 @@ FluScrollablePage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FluArea{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 20
|
|
||||||
height: 80
|
|
||||||
paddings: 10
|
|
||||||
|
|
||||||
ColumnLayout{
|
|
||||||
spacing: 10
|
|
||||||
anchors{
|
|
||||||
top: parent.top
|
|
||||||
left: parent.left
|
|
||||||
}
|
|
||||||
|
|
||||||
FluText{
|
|
||||||
text:lang.dark_mode
|
|
||||||
fontStyle: FluText.BodyStrong
|
|
||||||
Layout.bottomMargin: 4
|
|
||||||
}
|
|
||||||
|
|
||||||
Flow{
|
|
||||||
spacing: 5
|
|
||||||
FluToggleSwitch{
|
|
||||||
text:lang.sys_dark_mode
|
|
||||||
selected:FluTheme.dark
|
|
||||||
onClicked:{
|
|
||||||
FluTheme.follow_system = true
|
|
||||||
FluTheme.dark = FluTheme.follow_system
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
src/Def.h
10
src/Def.h
@ -3,6 +3,16 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace Fluent_DarkMode {
|
||||||
|
Q_NAMESPACE
|
||||||
|
enum Fluent_DarkModeType {
|
||||||
|
System = 0x0,
|
||||||
|
Light = 0x1,
|
||||||
|
Dark = 0x2,
|
||||||
|
};
|
||||||
|
Q_ENUMS(Fluent_DarkModeType);
|
||||||
|
}
|
||||||
|
|
||||||
namespace Fluent_Awesome {
|
namespace Fluent_Awesome {
|
||||||
Q_NAMESPACE
|
Q_NAMESPACE
|
||||||
enum class Fluent_AwesomeType {
|
enum class Fluent_AwesomeType {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "FluTheme.h"
|
#include "FluTheme.h"
|
||||||
|
|
||||||
#include "FluColors.h"
|
#include "FluColors.h"
|
||||||
|
#include "Def.h"
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
@ -17,11 +18,14 @@ FluTheme *FluTheme::getInstance()
|
|||||||
FluTheme::FluTheme(QObject *parent)
|
FluTheme::FluTheme(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
|
connect(this,&FluTheme::darkModeChanged,this,[=]{
|
||||||
|
Q_EMIT darkChanged();
|
||||||
|
});
|
||||||
primaryColor(FluColors::getInstance()->Blue());
|
primaryColor(FluColors::getInstance()->Blue());
|
||||||
textSize(13);
|
textSize(13);
|
||||||
nativeText(false);
|
nativeText(false);
|
||||||
frameless(true);
|
frameless(true);
|
||||||
if (follow_system()){dark(isDark());}
|
darkMode(Fluent_DarkMode::Fluent_DarkModeType::Light);
|
||||||
(qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->installEventFilter(this);
|
(qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,16 +34,28 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event)
|
|||||||
Q_UNUSED(obj);
|
Q_UNUSED(obj);
|
||||||
if (event->type() == QEvent::ApplicationPaletteChange)
|
if (event->type() == QEvent::ApplicationPaletteChange)
|
||||||
{
|
{
|
||||||
if (follow_system()){dark(isDark());}
|
Q_EMIT darkChanged();
|
||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FluTheme::isDark()
|
bool FluTheme::systemDark()
|
||||||
{
|
{
|
||||||
QPalette palette = (qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->palette();
|
QPalette palette = (qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->palette();
|
||||||
QColor color = palette.color(QPalette::Window).rgb();
|
QColor color = palette.color(QPalette::Window).rgb();
|
||||||
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
|
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,19 +8,22 @@
|
|||||||
class FluTheme : public QObject
|
class FluTheme : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool dark READ dark NOTIFY darkChanged)
|
||||||
Q_PROPERTY_AUTO(FluColorSet*,primaryColor)
|
Q_PROPERTY_AUTO(FluColorSet*,primaryColor)
|
||||||
Q_PROPERTY_AUTO(bool,frameless);
|
Q_PROPERTY_AUTO(bool,frameless);
|
||||||
Q_PROPERTY_AUTO(bool,dark);
|
Q_PROPERTY_AUTO(int,darkMode);
|
||||||
Q_PROPERTY_AUTO(bool,follow_system);
|
|
||||||
Q_PROPERTY_AUTO(bool,nativeText);
|
Q_PROPERTY_AUTO(bool,nativeText);
|
||||||
Q_PROPERTY_AUTO(int,textSize);
|
Q_PROPERTY_AUTO(int,textSize);
|
||||||
public:
|
public:
|
||||||
explicit FluTheme(QObject *parent = nullptr);
|
explicit FluTheme(QObject *parent = nullptr);
|
||||||
static FluTheme *getInstance();
|
static FluTheme *getInstance();
|
||||||
|
bool dark();
|
||||||
|
Q_SIGNAL void darkChanged();
|
||||||
private:
|
private:
|
||||||
static FluTheme* m_instance;
|
static FluTheme* m_instance;
|
||||||
|
bool _dark;
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
bool isDark();
|
bool systemDark();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUTHEME_H
|
#endif // FLUTHEME_H
|
||||||
|
@ -93,6 +93,8 @@ void Fluent::registerTypes(const char *uri){
|
|||||||
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluToggleSwitch.qml"),uri,major,minor,"FluToggleSwitch");
|
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluToggleSwitch.qml"),uri,major,minor,"FluToggleSwitch");
|
||||||
|
|
||||||
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only");
|
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only");
|
||||||
|
qmlRegisterUncreatableMetaObject(Fluent_DarkMode::staticMetaObject, uri,major,minor,"FluDarkMode", "Access to enums & flags only");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fluent::initializeEngine(QQmlEngine *engine, const char *uri)
|
void Fluent::initializeEngine(QQmlEngine *engine, const char *uri)
|
||||||
|
@ -79,7 +79,11 @@ Rectangle{
|
|||||||
FluToggleSwitch{
|
FluToggleSwitch{
|
||||||
selected: FluTheme.dark
|
selected: FluTheme.dark
|
||||||
clickFunc:function(){
|
clickFunc:function(){
|
||||||
FluTheme.dark = !FluTheme.dark
|
if(FluTheme.dark){
|
||||||
|
FluTheme.darkMode = FluDarkMode.Light
|
||||||
|
}else{
|
||||||
|
FluTheme.darkMode = FluDarkMode.Dark
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user