Kylin/Fluent/qml/Button.qml

65 lines
2.1 KiB
QML
Raw Normal View History

2024-08-31 04:13:21 +08:00
import QtQuick as Quick
import QtQuick.Controls as Control
import Fluent
Control.Button {
property bool disabled: false
property string contentDescription: ""
property Quick.color normalColor: Theme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(254/255,254/255,254/255,1)
property Quick.color hoverColor: Theme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(246/255,246/255,246/255,1)
property Quick.color disableColor: Theme.dark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(251/255,251/255,251/255,1)
property Quick.color dividerColor: Theme.dark ? Qt.rgba(80/255,80/255,80/255,1) : Qt.rgba(233/255,233/255,233/255,1)
property Quick.color textColor: {
if(Theme.dark){
if(!enabled){
return Qt.rgba(131/255,131/255,131/255,1)
}
if(pressed){
return Qt.rgba(162/255,162/255,162/255,1)
}
return Qt.rgba(1,1,1,1)
}else{
if(!enabled){
return Qt.rgba(160/255,160/255,160/255,1)
}
if(pressed){
return Qt.rgba(96/255,96/255,96/255,1)
}
return Qt.rgba(0,0,0,1)
}
}
Quick.Accessible.role: Quick.Accessible.Button
Quick.Accessible.name: control.text
Quick.Accessible.description: contentDescription
Quick.Accessible.onPressAction: control.clicked()
id: control
enabled: !disabled
verticalPadding: 0
horizontalPadding:12
font:TextStyle.Body
focusPolicy:Qt.TabFocus
background: ControlBackground{
implicitWidth: 30
implicitHeight: 30
radius: 4
color: {
if(!enabled){
return disableColor
}
return hovered ? hoverColor :normalColor
}
shadow: !pressed && enabled
FocusRectangle{
visible: control.activeFocus
radius:4
}
}
contentItem: Text {
text: control.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font: control.font
color: control.textColor
}
}