mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 19:20:59 +08:00
Merge pull request #60 from mentalfl0w/dev
Add sync with system toggle switch and remove the deprecated warning.
This commit is contained in:
commit
d2eb72cc5b
@ -85,4 +85,38 @@ 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ En::En(QObject *parent)
|
|||||||
theming("Theming");
|
theming("Theming");
|
||||||
media("Media");
|
media("Media");
|
||||||
dark_mode("Dark Mode");
|
dark_mode("Dark Mode");
|
||||||
|
sys_dark_mode("Sync with system");
|
||||||
search("Search");
|
search("Search");
|
||||||
about("About");
|
about("About");
|
||||||
settings("Settings");
|
settings("Settings");
|
||||||
|
@ -16,6 +16,7 @@ class Lang : public QObject
|
|||||||
Q_PROPERTY_AUTO(QString,theming);
|
Q_PROPERTY_AUTO(QString,theming);
|
||||||
Q_PROPERTY_AUTO(QString,media);
|
Q_PROPERTY_AUTO(QString,media);
|
||||||
Q_PROPERTY_AUTO(QString,dark_mode);
|
Q_PROPERTY_AUTO(QString,dark_mode);
|
||||||
|
Q_PROPERTY_AUTO(QString,sys_dark_mode);
|
||||||
Q_PROPERTY_AUTO(QString,search);
|
Q_PROPERTY_AUTO(QString,search);
|
||||||
Q_PROPERTY_AUTO(QString,about);
|
Q_PROPERTY_AUTO(QString,about);
|
||||||
Q_PROPERTY_AUTO(QString,settings);
|
Q_PROPERTY_AUTO(QString,settings);
|
||||||
|
@ -13,6 +13,7 @@ Zh::Zh(QObject *parent)
|
|||||||
theming("主题");
|
theming("主题");
|
||||||
media("媒体");
|
media("媒体");
|
||||||
dark_mode("夜间模式");
|
dark_mode("夜间模式");
|
||||||
|
sys_dark_mode("跟随系统");
|
||||||
search("查找");
|
search("查找");
|
||||||
about("关于");
|
about("关于");
|
||||||
settings("设置");
|
settings("设置");
|
||||||
|
@ -21,4 +21,25 @@ FluTheme::FluTheme(QObject *parent)
|
|||||||
textSize(13);
|
textSize(13);
|
||||||
nativeText(false);
|
nativeText(false);
|
||||||
frameless(true);
|
frameless(true);
|
||||||
|
if (follow_system()){dark(isDark());}
|
||||||
|
(qobject_cast<QGuiApplication *>(QCoreApplication::instance()))->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FluTheme::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(obj);
|
||||||
|
if (event->type() == QEvent::ApplicationPaletteChange)
|
||||||
|
{
|
||||||
|
if (follow_system()){dark(isDark());}
|
||||||
|
event->accept();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FluTheme::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);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ class FluTheme : public QObject
|
|||||||
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(bool,dark);
|
||||||
|
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:
|
||||||
@ -18,7 +19,8 @@ public:
|
|||||||
static FluTheme *getInstance();
|
static FluTheme *getInstance();
|
||||||
private:
|
private:
|
||||||
static FluTheme* m_instance;
|
static FluTheme* m_instance;
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
bool isDark();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUTHEME_H
|
#endif // FLUTHEME_H
|
||||||
|
Loading…
Reference in New Issue
Block a user