FluentUI/src/controls/FluRadioButton.qml

105 lines
2.9 KiB
QML
Raw Normal View History

2023-03-25 13:35:21 +08:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
2023-02-28 18:29:00 +08:00
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
2023-03-12 21:49:11 +08:00
property bool selected: false
2023-02-28 18:29:00 +08:00
property bool disabled: false
2023-03-12 21:49:11 +08:00
id:control
enabled: !disabled
2023-03-12 22:36:31 +08:00
focusPolicy:Qt.TabFocus
2023-03-12 21:49:11 +08:00
padding:0
2023-03-12 14:26:03 +08:00
background: Item{
FluFocusRectangle{
2023-03-12 22:36:31 +08:00
visible: control.visualFocus
2023-03-12 14:26:03 +08:00
}
}
2023-03-12 22:36:31 +08:00
Keys.onSpacePressed: control.visualFocus&&clicked()
2023-03-12 14:26:03 +08:00
contentItem: RowLayout{
2023-02-28 18:29:00 +08:00
Rectangle{
id:rect_check
width: 20
height: 20
radius: 10
layer.samples: 4
layer.enabled: true
layer.smooth: true
border.width: {
2023-03-12 21:49:11 +08:00
if(selected&&disabled){
2023-02-28 18:29:00 +08:00
return 3
}
2023-03-16 14:34:20 +08:00
if(pressed){
2023-03-12 21:49:11 +08:00
if(selected){
2023-02-28 18:29:00 +08:00
return 5
}
return 1
}
2023-03-12 14:26:03 +08:00
if(hovered){
2023-03-12 21:49:11 +08:00
if(selected){
2023-02-28 18:29:00 +08:00
return 3
}
return 1
}
2023-03-12 21:49:11 +08:00
return selected ? 5 : 1
2023-02-28 18:29:00 +08:00
}
Behavior on border.width {
NumberAnimation{
2023-03-16 14:34:20 +08:00
duration: 150
2023-02-28 18:29:00 +08:00
}
}
border.color: {
if(disabled){
2023-03-06 14:22:13 +08:00
if(FluTheme.isDark){
2023-02-28 18:29:00 +08:00
return Qt.rgba(82/255,82/255,82/255,1)
}else{
return Qt.rgba(198/255,198/255,198/255,1)
}
}
2023-03-12 21:49:11 +08:00
if(selected){
2023-03-06 14:22:13 +08:00
if(FluTheme.isDark){
2023-03-06 12:09:06 +08:00
return FluTheme.primaryColor.lighter
2023-02-28 18:29:00 +08:00
}else{
2023-03-06 12:09:06 +08:00
return FluTheme.primaryColor.dark
2023-02-28 18:29:00 +08:00
}
}else{
2023-03-06 14:22:13 +08:00
if(FluTheme.isDark){
2023-02-28 18:29:00 +08:00
return Qt.rgba(161/255,161/255,161/255,1)
}else{
return Qt.rgba(141/255,141/255,141/255,1)
}
}
}
color:{
2023-03-12 21:49:11 +08:00
if(disabled&&selected){
2023-02-28 18:29:00 +08:00
return Qt.rgba(159/255,159/255,159/255,1)
}
2023-03-06 14:22:13 +08:00
if(FluTheme.isDark){
2023-03-12 14:26:03 +08:00
if(hovered){
2023-02-28 18:29:00 +08:00
return Qt.rgba(43/255,43/255,43/255,1)
}
return Qt.rgba(50/255,50/255,50/255,1)
}else{
2023-03-12 14:26:03 +08:00
if(hovered){
2023-03-12 21:49:11 +08:00
if(selected){
2023-02-28 18:29:00 +08:00
return Qt.rgba(1,1,1,1)
}
return Qt.rgba(222/255,222/255,222/255,1)
}
return Qt.rgba(1,1,1,1)
}
}
}
FluText{
2023-03-12 14:26:03 +08:00
text: control.text
2023-02-28 18:29:00 +08:00
Layout.alignment: Qt.AlignVCenter
}
}
2023-02-26 23:47:07 +08:00
}
2023-02-28 18:29:00 +08:00