FluToggleButton.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. Button {
  6. property bool disabled: false
  7. property bool selected: false
  8. property color normalColor: {
  9. if(selected){
  10. return FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
  11. }else{
  12. return FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(254/255,254/255,254/255,1)
  13. }
  14. }
  15. property color hoverColor: {
  16. if(selected){
  17. return FluTheme.dark ? Qt.darker(normalColor,1.1) : Qt.lighter(normalColor,1.1)
  18. }else{
  19. return FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
  20. }
  21. }
  22. property color disableColor: {
  23. if(selected){
  24. return FluTheme.dark ? Qt.rgba(82/255,82/255,82/255,1) : Qt.rgba(199/255,199/255,199/255,1)
  25. }else{
  26. return FluTheme.dark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(252/255,252/255,252/255,1)
  27. }
  28. }
  29. property color pressedColor: FluTheme.dark ? Qt.darker(normalColor,1.2) : Qt.lighter(normalColor,1.2)
  30. id: control
  31. enabled: !disabled
  32. topPadding:5
  33. bottomPadding:5
  34. leftPadding:15
  35. rightPadding:15
  36. Keys.onSpacePressed: control.visualFocus&&clicked()
  37. focusPolicy:Qt.TabFocus
  38. background: Rectangle{
  39. radius: 4
  40. border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
  41. border.width: selected ? 0 : 1
  42. FluFocusRectangle{
  43. visible: control.visualFocus
  44. radius:8
  45. }
  46. color:{
  47. if(disabled){
  48. return disableColor
  49. }
  50. if(selected){
  51. if(pressed){
  52. return pressedColor
  53. }
  54. }
  55. return hovered ? hoverColor :normalColor
  56. }
  57. }
  58. contentItem: FluText {
  59. text: control.text
  60. horizontalAlignment: Text.AlignHCenter
  61. verticalAlignment: Text.AlignVCenter
  62. color: {
  63. if(selected){
  64. if(FluTheme.dark){
  65. if(disabled){
  66. return Qt.rgba(173/255,173/255,173/255,1)
  67. }
  68. return Qt.rgba(0,0,0,1)
  69. }else{
  70. return Qt.rgba(1,1,1,1)
  71. }
  72. }else{
  73. if(FluTheme.dark){
  74. if(disabled){
  75. return Qt.rgba(131/255,131/255,131/255,1)
  76. }
  77. if(!selected){
  78. if(pressed){
  79. return Qt.rgba(162/255,162/255,162/255,1)
  80. }
  81. }
  82. return Qt.rgba(1,1,1,1)
  83. }else{
  84. if(disabled){
  85. return Qt.rgba(160/255,160/255,160/255,1)
  86. }
  87. if(!selected){
  88. if(pressed){
  89. return Qt.rgba(96/255,96/255,96/255,1)
  90. }
  91. }
  92. return Qt.rgba(0,0,0,1)
  93. }
  94. }
  95. }
  96. }
  97. }