FluentUI/src/controls/FluIconButton.qml

76 lines
1.9 KiB
QML
Raw Normal View History

2023-02-26 23:47:07 +08:00
import QtQuick 2.15
2023-02-28 18:29:00 +08:00
import FluentUI 1.0
2023-02-26 23:47:07 +08:00
Rectangle {
2023-02-27 18:46:39 +08:00
id:button
width: 30
height: 30
2023-02-26 23:47:07 +08:00
2023-02-27 18:46:39 +08:00
property int iconSize: 20
2023-02-26 23:47:07 +08:00
property int icon
2023-02-28 18:29:00 +08:00
property alias text: tool_tip.text
2023-02-27 18:46:39 +08:00
signal clicked
2023-02-28 18:29:00 +08:00
property bool disabled: false
2023-03-06 14:22:13 +08:00
property bool hovered: button_mouse.containsMouse
2023-03-08 18:14:21 +08:00
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 normalColor: FluTheme.isDark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(1,1,1,1)
property color disableColor: FluTheme.isDark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(1,1,1,1)
2023-03-06 14:22:13 +08:00
property color textColor: {
if(FluTheme.isDark){
if(disabled){
return Qt.rgba(130/255,130/255,130/255,1)
}
return Qt.rgba(1,1,1,1)
}else{
if(disabled){
return Qt.rgba(161/255,161/255,161/255,1)
}
return Qt.rgba(0,0,0,1)
}
}
2023-02-27 18:46:39 +08:00
radius: 4
color: {
2023-03-08 18:14:21 +08:00
if(disabled){
return disableColor
2023-02-27 18:46:39 +08:00
}
2023-03-08 18:14:21 +08:00
return (hovered || button_mouse.containsMouse) ? hoverColor : normalColor
2023-02-27 18:46:39 +08:00
}
2023-02-26 23:47:07 +08:00
Text {
2023-02-27 18:46:39 +08:00
id:text_icon
2023-02-26 23:47:07 +08:00
font.family: "fontawesome"
2023-02-27 18:46:39 +08:00
font.pixelSize: iconSize
2023-02-26 23:47:07 +08:00
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
2023-02-27 18:46:39 +08:00
anchors.centerIn: parent
2023-03-06 14:22:13 +08:00
color:button.textColor
2023-02-26 23:47:07 +08:00
text: (String.fromCharCode(icon).toString(16));
}
2023-02-27 18:46:39 +08:00
MouseArea{
id:button_mouse
anchors.fill: parent
hoverEnabled: true
2023-02-28 18:29:00 +08:00
enabled: !disabled
2023-02-27 18:46:39 +08:00
onClicked: {
button.clicked()
}
}
2023-02-28 18:29:00 +08:00
FluTooltip{
id:tool_tip
visible: {
if(button.text === ""){
return false
}
2023-03-08 18:14:21 +08:00
return (hovered || button_mouse.containsMouse)
2023-02-28 18:29:00 +08:00
}
delay: 1000
}
2023-02-26 23:47:07 +08:00
}