ModernControlButton.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. // import QtQuick.Effects // Disabled - causes issues on linuxfb
  5. Rectangle {
  6. property alias text: buttonLabel.text
  7. property string icon: ""
  8. property color buttonColor: "#2196F3"
  9. property bool enabled: true
  10. property int fontSize: 16
  11. signal clicked()
  12. radius: 12
  13. color: enabled ? buttonColor : "#E0E0E0"
  14. opacity: enabled ? 1.0 : 0.6
  15. border.width: 1
  16. border.color: Qt.darker(buttonColor, 1.2)
  17. // Gradient effect
  18. gradient: Gradient {
  19. GradientStop { position: 0; color: Qt.lighter(buttonColor, 1.1) }
  20. GradientStop { position: 1; color: buttonColor }
  21. }
  22. // Press animation
  23. scale: mouseArea.pressed ? 0.95 : (mouseArea.containsMouse ? 1.02 : 1.0)
  24. Behavior on scale {
  25. NumberAnimation { duration: 150; easing.type: Easing.OutQuad }
  26. }
  27. Behavior on color {
  28. ColorAnimation { duration: 200 }
  29. }
  30. // Shadow effect - disabled on linuxfb (causes rendering issues)
  31. // Using border instead for visual separation
  32. // layer.enabled: true
  33. // layer.effect: MultiEffect {
  34. // shadowEnabled: true
  35. // shadowColor: "#25000000"
  36. // shadowBlur: 0.8
  37. // shadowVerticalOffset: 2
  38. // }
  39. RowLayout {
  40. anchors.centerIn: parent
  41. spacing: 8
  42. Text {
  43. text: parent.parent.icon
  44. font.pixelSize: parent.parent.fontSize + 2
  45. color: "white"
  46. visible: parent.parent.icon !== ""
  47. }
  48. Label {
  49. id: buttonLabel
  50. color: "white"
  51. font.pixelSize: parent.parent.fontSize
  52. font.bold: true
  53. }
  54. }
  55. MouseArea {
  56. id: mouseArea
  57. anchors.fill: parent
  58. hoverEnabled: true
  59. enabled: parent.enabled
  60. onClicked: parent.clicked()
  61. // Ripple effect
  62. Rectangle {
  63. id: ripple
  64. width: 0
  65. height: 0
  66. radius: width / 2
  67. color: "#40FFFFFF"
  68. anchors.centerIn: parent
  69. NumberAnimation {
  70. id: rippleAnimation
  71. target: ripple
  72. property: "width"
  73. from: 0
  74. to: parent.width * 1.2
  75. duration: 400
  76. easing.type: Easing.OutQuad
  77. onFinished: {
  78. ripple.width = 0
  79. ripple.height = 0
  80. }
  81. }
  82. Connections {
  83. target: mouseArea
  84. function onPressed() {
  85. ripple.height = ripple.width
  86. rippleAnimation.start()
  87. }
  88. }
  89. }
  90. }
  91. }