FluentUI/src/controls/FluToggleSwitch.qml

55 lines
1.4 KiB
QML
Raw Normal View History

2023-02-26 23:47:07 +08:00
import QtQuick 2.0
import QtQuick.Controls 2.0
2023-02-28 18:29:00 +08:00
import FluentUI 1.0
2023-02-26 23:47:07 +08:00
2023-03-12 21:49:11 +08:00
Button {
2023-02-26 23:47:07 +08:00
id: root
2023-02-27 18:46:39 +08:00
width: 40
implicitWidth: 40
height: 20
implicitHeight: 20
2023-03-12 21:49:11 +08:00
checkable: true
background : Rectangle {
2023-02-27 18:46:39 +08:00
width: root.width
height: root.height
2023-02-26 23:47:07 +08:00
radius: height / 2
2023-03-12 21:49:11 +08:00
FluFocusRectangle{
2023-03-12 22:02:12 +08:00
visible: root.focus
2023-03-12 21:49:11 +08:00
radius: 20
}
2023-02-27 23:04:52 +08:00
color: {
2023-03-06 14:22:13 +08:00
if(FluTheme.isDark){
2023-03-12 21:49:11 +08:00
if(checked){
2023-03-06 12:09:06 +08:00
return FluTheme.primaryColor.dark
2023-02-27 23:04:52 +08:00
}
2023-03-12 21:49:11 +08:00
if(hovered){
2023-02-27 23:04:52 +08:00
return "#3E3E3C"
}
return "#323232"
}else{
2023-03-12 21:49:11 +08:00
if(checked){
2023-03-06 12:09:06 +08:00
return FluTheme.primaryColor.dark
2023-02-28 18:29:00 +08:00
}
2023-03-12 21:49:11 +08:00
if(hovered){
2023-02-27 23:04:52 +08:00
return "#F4F4F4"
}
2023-02-28 18:29:00 +08:00
return "#FFFFFF"
2023-02-27 23:04:52 +08:00
}
}
2023-02-26 23:47:07 +08:00
border.width: 1
2023-03-12 21:49:11 +08:00
border.color: checked ? Qt.lighter(FluTheme.primaryColor.dark,1.2) : "#666666"
2023-02-26 23:47:07 +08:00
Rectangle {
2023-03-12 21:49:11 +08:00
x: checked ? root.implicitWidth - width - 4 : 4
2023-02-27 23:04:52 +08:00
width: root.height - 8
height: root.height - 8
2023-02-26 23:47:07 +08:00
radius: width / 2
2023-03-12 21:49:11 +08:00
scale: hovered ? 1.2 : 1.0
2023-02-26 23:47:07 +08:00
anchors.verticalCenter: parent.verticalCenter
2023-03-12 21:49:11 +08:00
color: checked ? "#FFFFFF" : "#666666"
2023-02-26 23:47:07 +08:00
Behavior on x {
NumberAnimation { duration: 200 }
}
}
}
}