FluIconButton.qml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. Button {
  6. property int iconSize: 20
  7. property int iconSource
  8. property bool disabled: false
  9. property int radius:4
  10. property color hoverColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(0,0,0,0.03)
  11. property color pressedColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(0,0,0,0.06)
  12. property color normalColor: FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
  13. property color disableColor: FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
  14. property color color: {
  15. if(disabled){
  16. return disableColor
  17. }
  18. if(pressed){
  19. return pressedColor
  20. }
  21. return hovered ? hoverColor : normalColor
  22. }
  23. property color iconColor: {
  24. if(FluTheme.dark){
  25. if(disabled){
  26. return Qt.rgba(130/255,130/255,130/255,1)
  27. }
  28. return Qt.rgba(1,1,1,1)
  29. }else{
  30. if(disabled){
  31. return Qt.rgba(161/255,161/255,161/255,1)
  32. }
  33. return Qt.rgba(0,0,0,1)
  34. }
  35. }
  36. id:control
  37. width: 30
  38. height: 30
  39. implicitWidth: width
  40. implicitHeight: height
  41. padding: 0
  42. enabled: !disabled
  43. focusPolicy:Qt.TabFocus
  44. Keys.onSpacePressed: control.visualFocus&&clicked()
  45. background: Rectangle{
  46. radius: control.radius
  47. color:control.color
  48. FluFocusRectangle{
  49. visible: control.visualFocus
  50. }
  51. }
  52. contentItem: Item{
  53. Text {
  54. id:text_icon
  55. font.family: "Segoe Fluent Icons"
  56. font.pixelSize: iconSize
  57. width: iconSize
  58. height: iconSize
  59. horizontalAlignment: Text.AlignHCenter
  60. verticalAlignment: Text.AlignVCenter
  61. anchors.centerIn: parent
  62. color:control.iconColor
  63. text: (String.fromCharCode(iconSource).toString(16));
  64. }
  65. FluTooltip{
  66. id:tool_tip
  67. visible: {
  68. if(control.text === ""){
  69. return false
  70. }
  71. return hovered
  72. }
  73. text:control.text
  74. delay: 1000
  75. }
  76. }
  77. }