FluentUI/src/controls/FluCheckBox.qml

96 lines
3.1 KiB
QML
Raw Normal View History

2023-02-28 18:29:00 +08:00
import QtQuick 2.15
2023-03-02 18:21:43 +08:00
import QtQuick.Layouts 1.15
2023-02-28 18:29:00 +08:00
import FluentUI 1.0
2023-02-26 23:47:07 +08:00
Item {
2023-03-02 18:21:43 +08:00
id:root
property bool checked: false
property string text: "Check Box"
2023-03-07 23:27:32 +08:00
property var checkClicked
2023-03-08 11:46:40 +08:00
property bool hovered: mouse_area.containsMouse
2023-03-09 11:50:40 +08:00
property bool disabled: false
2023-03-02 18:21:43 +08:00
width: childrenRect.width
height: childrenRect.height
2023-03-09 11:50:40 +08:00
property color borderNormalColor: FluTheme.isDark ? Qt.rgba(160/255,160/255,160/255,1) : Qt.rgba(136/255,136/255,136/255,1)
property color borderCheckedColor: FluTheme.isDark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
property color borderHoverColor: FluTheme.isDark ? Qt.rgba(167/255,167/255,167/255,1) : Qt.rgba(135/255,135/255,135/255,1)
2023-03-09 13:23:39 +08:00
property color borderDisableColor: FluTheme.isDark ? Qt.rgba(82/255,82/255,82/255,1) : Qt.rgba(199/255,199/255,199/255,1)
2023-03-09 11:50:40 +08:00
property color normalColor: FluTheme.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(247/255,247/255,247/255,1)
property color checkedColor: FluTheme.isDark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
property color hoverColor: FluTheme.isDark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(244/255,244/255,244/255,1)
property color checkedHoverColor: FluTheme.isDark ? Qt.darker(checkedColor,1.1) : Qt.lighter(checkedColor,1.1)
2023-03-09 13:23:39 +08:00
property color checkedDisableColor: FluTheme.isDark ? Qt.rgba(82/255,82/255,82/255,1) : Qt.rgba(199/255,199/255,199/255,1)
property color disableColor: FluTheme.isDark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(253/255,253/255,253/255,1)
2023-03-02 18:21:43 +08:00
RowLayout{
spacing: 4
Rectangle{
width: 22
height: 22
radius: 4
border.color: {
2023-03-09 13:23:39 +08:00
if(disabled){
return borderDisableColor
}
2023-03-09 11:50:40 +08:00
if(checked){
return borderCheckedColor
}
if(hovered){
return borderHoverColor
2023-03-02 18:21:43 +08:00
}
2023-03-09 11:50:40 +08:00
return borderNormalColor
2023-03-02 18:21:43 +08:00
}
border.width: 1
color: {
2023-03-09 11:50:40 +08:00
if(checked){
2023-03-09 13:23:39 +08:00
if(disabled){
return checkedDisableColor
}
2023-03-09 11:50:40 +08:00
if(hovered){
return checkedHoverColor
2023-03-02 18:21:43 +08:00
}
2023-03-09 11:50:40 +08:00
return checkedColor
}
if(hovered){
return hoverColor
2023-03-02 18:21:43 +08:00
}
2023-03-09 11:50:40 +08:00
return normalColor
2023-03-02 18:21:43 +08:00
}
FluIcon {
anchors.centerIn: parent
icon: FluentIcons.FA_check
iconSize: 15
visible: checked
2023-03-06 14:22:13 +08:00
color: FluTheme.isDark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1)
2023-03-02 18:21:43 +08:00
}
}
FluText{
text:root.text
}
}
MouseArea{
id:mouse_area
anchors.fill: parent
hoverEnabled: true
2023-03-09 11:50:40 +08:00
enabled: !disabled
2023-03-02 18:21:43 +08:00
onClicked: {
2023-03-07 23:27:32 +08:00
if(checkClicked){
checkClicked()
return
}
2023-03-02 18:21:43 +08:00
checked = !checked
}
}
2023-02-26 23:47:07 +08:00
}