ModernControlButton.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. visible: parent.parent.icon !== ""
  46. }
  47. Label {
  48. id: buttonLabel
  49. color: "white"
  50. font.pixelSize: parent.parent.fontSize
  51. font.bold: true
  52. }
  53. }
  54. MouseArea {
  55. id: mouseArea
  56. anchors.fill: parent
  57. hoverEnabled: true
  58. enabled: parent.enabled
  59. onClicked: parent.clicked()
  60. // Ripple effect
  61. Rectangle {
  62. id: ripple
  63. width: 0
  64. height: 0
  65. radius: width / 2
  66. color: "#40FFFFFF"
  67. anchors.centerIn: parent
  68. NumberAnimation {
  69. id: rippleAnimation
  70. target: ripple
  71. property: "width"
  72. from: 0
  73. to: parent.width * 1.2
  74. duration: 400
  75. easing.type: Easing.OutQuad
  76. onFinished: {
  77. ripple.width = 0
  78. ripple.height = 0
  79. }
  80. }
  81. Connections {
  82. target: mouseArea
  83. function onPressed() {
  84. ripple.height = ripple.width
  85. rippleAnimation.start()
  86. }
  87. }
  88. }
  89. }
  90. }