FluentUI/src/controls/FluIconButton.qml

81 lines
2.2 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Controls
import FluentUI
2023-02-26 23:47:07 +08:00
2023-04-05 16:37:27 +08:00
FluControl {
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-28 11:53:25 +08:00
property int radius:4
2023-03-28 21:37:10 +08:00
property color hoverColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(0,0,0,0.03)
2023-04-07 20:19:18 +08:00
property color pressedColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(0,0,0,0.06)
2023-03-28 21:37:10 +08:00
property color normalColor: FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
2023-03-29 18:10:34 +08:00
property color disableColor: FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
2023-03-12 14:26:03 +08:00
property color color: {
if(disabled){
return disableColor
}
2023-04-07 20:19:18 +08:00
if(pressed){
return pressedColor
}
2023-03-12 14:26:03 +08:00
return hovered ? hoverColor : normalColor
}
2023-04-04 16:39:41 +08:00
property color iconColor: {
2023-03-28 21:37:10 +08:00
if(FluTheme.dark){
2023-03-06 14:22:13 +08:00
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 22:36:31 +08:00
id:control
width: 30
height: 30
2023-04-11 23:43:20 +08:00
clip: true
2023-03-12 22:36:31 +08:00
implicitWidth: width
implicitHeight: height
padding: 0
enabled: !disabled
focusPolicy:Qt.TabFocus
Keys.onSpacePressed: control.visualFocus&&clicked()
2023-03-12 14:26:03 +08:00
background: Rectangle{
2023-03-28 11:53:25 +08:00
radius: control.radius
2023-03-12 14:26:03 +08:00
color:control.color
FluFocusRectangle{
2023-03-12 22:36:31 +08:00
visible: control.visualFocus
2023-03-12 14:26:03 +08:00
}
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
2023-04-04 16:39:41 +08:00
color:control.iconColor
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-02-26 23:47:07 +08:00
}