FluentUI/example/qml/page/T_Theme.qml

137 lines
4.4 KiB
QML
Raw Normal View History

2023-08-24 15:50:37 +08:00
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import FluentUI 1.0
2023-08-26 17:20:30 +08:00
import "../component"
2023-03-06 12:09:06 +08:00
2023-03-10 18:08:32 +08:00
FluScrollablePage{
2024-03-07 13:58:23 +08:00
property var colorData: [FluColors.Yellow,FluColors.Orange,FluColors.Red,FluColors.Magenta,FluColors.Purple,FluColors.Blue,FluColors.Teal,FluColors.Green]
id:root
2023-03-10 18:08:32 +08:00
title:"Theme"
2023-04-06 17:32:21 +08:00
FluArea{
Layout.fillWidth: true
2023-03-10 18:08:32 +08:00
Layout.topMargin: 20
2024-03-07 13:58:23 +08:00
Layout.preferredHeight: 340
2023-04-06 17:32:21 +08:00
paddings: 10
2024-03-07 13:58:23 +08:00
2023-04-06 17:32:21 +08:00
ColumnLayout{
spacing:0
anchors{
left: parent.left
}
2024-03-07 13:58:23 +08:00
FluText{
text:"主题颜色"
2023-04-06 17:32:21 +08:00
Layout.topMargin: 10
2024-03-07 13:58:23 +08:00
}
RowLayout{
Layout.topMargin: 5
2023-04-06 17:32:21 +08:00
Repeater{
2024-03-07 13:58:23 +08:00
model: root.colorData
delegate: Rectangle{
2023-04-06 17:32:21 +08:00
width: 42
height: 42
2024-03-07 13:58:23 +08:00
radius: 4
2023-04-06 17:32:21 +08:00
color: mouse_item.containsMouse ? Qt.lighter(modelData.normal,1.1) : modelData.normal
2024-03-07 13:58:23 +08:00
border.color: modelData.darkest
2023-04-06 17:32:21 +08:00
FluIcon {
anchors.centerIn: parent
iconSource: FluentIcons.AcceptMedium
iconSize: 15
2024-03-07 13:58:23 +08:00
visible: modelData === FluTheme.accentColor
2023-04-06 17:32:21 +08:00
color: FluTheme.dark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1)
}
MouseArea{
id:mouse_item
anchors.fill: parent
hoverEnabled: true
onClicked: {
2024-03-07 13:58:23 +08:00
FluTheme.accentColor = modelData
}
}
}
}
}
Row{
Layout.topMargin: 10
spacing: 10
FluText{
text:"自定义主题颜色"
anchors.verticalCenter: parent.verticalCenter
}
FluColorPicker{
id:color_picker
current: FluTheme.accentColor.normal
onAccepted: {
FluTheme.accentColor = FluColors.createAccentColor(current)
}
FluIcon {
anchors.centerIn: parent
iconSource: FluentIcons.AcceptMedium
iconSize: 15
visible: {
for(var i =0 ;i< root.colorData.length; i++){
if(root.colorData[i] === FluTheme.accentColor){
return false
}
2023-04-06 17:32:21 +08:00
}
2024-03-07 13:58:23 +08:00
return true
2023-04-06 17:32:21 +08:00
}
2024-03-07 13:58:23 +08:00
color: FluTheme.dark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1)
2023-03-10 18:08:32 +08:00
}
2023-03-09 11:50:40 +08:00
}
}
2023-04-06 17:32:21 +08:00
FluText{
text:"夜间模式"
Layout.topMargin: 20
}
FluToggleSwitch{
Layout.topMargin: 5
2023-05-26 13:49:32 +08:00
checked: FluTheme.dark
onClicked: {
2023-04-20 09:15:28 +08:00
if(FluTheme.dark){
2023-07-18 18:24:06 +08:00
FluTheme.darkMode = FluThemeType.Light
2023-04-20 09:15:28 +08:00
}else{
2023-07-18 18:24:06 +08:00
FluTheme.darkMode = FluThemeType.Dark
2023-04-20 09:15:28 +08:00
}
2023-04-06 17:32:21 +08:00
}
}
FluText{
text:"native文本渲染"
Layout.topMargin: 20
}
FluToggleSwitch{
Layout.topMargin: 5
2023-05-26 13:49:32 +08:00
checked: FluTheme.nativeText
onClicked: {
2023-04-06 17:32:21 +08:00
FluTheme.nativeText = !FluTheme.nativeText
}
}
2023-07-07 16:04:17 +08:00
FluText{
text:"开启动画效果"
Layout.topMargin: 20
}
FluToggleSwitch{
Layout.topMargin: 5
checked: FluTheme.enableAnimation
onClicked: {
FluTheme.enableAnimation = !FluTheme.enableAnimation
}
}
2023-03-06 12:09:06 +08:00
}
}
2023-04-06 17:32:21 +08:00
CodeExpander{
Layout.fillWidth: true
2023-04-19 17:25:46 +08:00
Layout.topMargin: -1
2024-03-07 13:58:23 +08:00
code:'FluTheme.accentColor = FluColors.Orange
2023-04-06 17:32:21 +08:00
FluTheme.dark = true
2023-04-19 17:25:46 +08:00
FluTheme.nativeText = true'
2023-03-11 21:15:36 +08:00
}
2023-04-06 17:32:21 +08:00
2023-03-06 12:09:06 +08:00
}