FluentUI/src/controls/FluIconButton.qml

94 lines
2.2 KiB
QML
Raw Normal View History

2023-02-26 23:47:07 +08:00
import QtQuick 2.15
2023-03-12 14:26:03 +08:00
import QtQuick.Controls 2.15
2023-02-28 18:29:00 +08:00
import FluentUI 1.0
2023-02-26 23:47:07 +08:00
2023-03-12 14:26:03 +08:00
Control {
2023-02-26 23:47:07 +08:00
2023-03-12 14:26:03 +08:00
id:control
2023-02-27 18:46:39 +08:00
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-08 18:14:21 +08:00
2023-03-10 18:08:32 +08:00
property color hoverColor: FluTheme.isDark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(0,0,0,0.03)
property color normalColor: FluTheme.isDark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
property color disableColor: FluTheme.isDark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(0,0,0,0)
2023-03-08 18:14:21 +08:00
2023-03-12 14:26:03 +08:00
property color color: {
if(disabled){
return disableColor
}
return hovered ? hoverColor : normalColor
}
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
2023-03-12 14:26:03 +08:00
focusPolicy:Qt.TabFocus
Keys.onEnterPressed:(visualFocus&&handleClick())
Keys.onReturnPressed:(visualFocus&&handleClick())
MouseArea {
anchors.fill: parent
onClicked: handleClick()
}
function handleClick(){
2023-03-08 18:14:21 +08:00
if(disabled){
2023-03-12 14:26:03 +08:00
return
2023-02-27 18:46:39 +08:00
}
2023-03-12 14:26:03 +08:00
control.clicked()
2023-02-27 18:46:39 +08:00
}
2023-02-26 23:47:07 +08:00
2023-03-12 14:26:03 +08:00
background: Rectangle{
radius: 4
color:control.color
FluFocusRectangle{
visible: control.visualFocus
}
2023-02-26 23:47:07 +08:00
}
2023-03-12 14:26:03 +08:00
contentItem: Item{
Text {
id:text_icon
font.family: "Segoe Fluent Icons"
font.pixelSize: iconSize
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.centerIn: parent
color:control.textColor
text: (String.fromCharCode(icon).toString(16));
2023-02-27 18:46:39 +08:00
}
2023-03-12 14:26:03 +08:00
FluTooltip{
id:tool_tip
visible: {
if(control.text === ""){
return false
}
return hovered
2023-02-28 18:29:00 +08:00
}
2023-03-12 14:26:03 +08:00
delay: 1000
2023-02-28 18:29:00 +08:00
}
}
2023-03-12 14:26:03 +08:00
2023-02-26 23:47:07 +08:00
}