mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-02 08:05:29 +08:00
update
This commit is contained in:
@ -2,76 +2,53 @@
|
||||
import QtQuick.Controls 2.0
|
||||
import FluentUI 1.0
|
||||
|
||||
Switch {
|
||||
Button {
|
||||
id: root
|
||||
property var onClickFunc
|
||||
width: 40
|
||||
implicitWidth: 40
|
||||
height: 20
|
||||
implicitHeight: 20
|
||||
checkable: false
|
||||
|
||||
background:FluFocusRectangle{
|
||||
visible: root.visualFocus
|
||||
radius: 20
|
||||
}
|
||||
|
||||
Keys.onEnterPressed:(visualFocus&&handleClick())
|
||||
Keys.onReturnPressed:(visualFocus&&handleClick())
|
||||
|
||||
indicator: Rectangle {
|
||||
checkable: true
|
||||
background : Rectangle {
|
||||
width: root.width
|
||||
height: root.height
|
||||
radius: height / 2
|
||||
FluFocusRectangle{
|
||||
visible: root.visualFocus
|
||||
radius: 20
|
||||
}
|
||||
color: {
|
||||
if(FluTheme.isDark){
|
||||
if(root.checked){
|
||||
if(checked){
|
||||
return FluTheme.primaryColor.dark
|
||||
}
|
||||
if(switch_mouse.containsMouse){
|
||||
if(hovered){
|
||||
return "#3E3E3C"
|
||||
}
|
||||
return "#323232"
|
||||
}else{
|
||||
if(root.checked){
|
||||
if(checked){
|
||||
return FluTheme.primaryColor.dark
|
||||
}
|
||||
if(switch_mouse.containsMouse){
|
||||
if(hovered){
|
||||
return "#F4F4F4"
|
||||
}
|
||||
return "#FFFFFF"
|
||||
}
|
||||
}
|
||||
border.width: 1
|
||||
border.color: root.checked ? Qt.lighter(FluTheme.primaryColor.dark,1.2) : "#666666"
|
||||
|
||||
border.color: checked ? Qt.lighter(FluTheme.primaryColor.dark,1.2) : "#666666"
|
||||
Rectangle {
|
||||
x: root.checked ? root.implicitWidth - width - 4 : 4
|
||||
x: checked ? root.implicitWidth - width - 4 : 4
|
||||
width: root.height - 8
|
||||
height: root.height - 8
|
||||
radius: width / 2
|
||||
scale: switch_mouse.containsMouse ? 1.2 : 1.0
|
||||
scale: hovered ? 1.2 : 1.0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: root.checked ? "#FFFFFF" : "#666666"
|
||||
// border.color: "#D5D5D5"
|
||||
color: checked ? "#FFFFFF" : "#666666"
|
||||
Behavior on x {
|
||||
NumberAnimation { duration: 200 }
|
||||
}
|
||||
}
|
||||
}
|
||||
MouseArea{
|
||||
id:switch_mouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onClicked: handleClick()
|
||||
}
|
||||
|
||||
function handleClick(){
|
||||
if(root.onClickFunc){
|
||||
root.onClickFunc()
|
||||
}else{
|
||||
root.checked = !root.checked
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user