FluentUI/src/controls/FluIconButton.qml

89 lines
2.0 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 21:49:11 +08:00
Button {
2023-02-26 23:47:07 +08:00
2023-03-12 14:26:03 +08:00
id:control
2023-03-12 21:49:11 +08:00
2023-02-27 18:46:39 +08:00
width: 30
height: 30
2023-03-12 21:49:11 +08:00
implicitWidth: width
implicitHeight: height
padding: 0
2023-02-26 23:47:07 +08:00
2023-02-27 18:46:39 +08:00
property int iconSize: 20
2023-03-12 21:49:11 +08:00
property int iconSource
2023-02-28 18:29:00 +08:00
property bool disabled: false
2023-03-08 18:14:21 +08:00
2023-03-12 21:49:11 +08:00
enabled: !disabled
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
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
2023-03-12 21:49:11 +08:00
width: iconSize
height: iconSize
2023-03-12 14:26:03 +08:00
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.centerIn: parent
color:control.textColor
2023-03-12 21:49:11 +08:00
text: (String.fromCharCode(iconSource).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 21:49:11 +08:00
text:control.text
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
}