ModernControlButton.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. Rectangle {
  5. id: root
  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 for better visibility on linuxfb
  16. border.width: 2
  17. border.color: enabled ? Qt.darker(root.buttonColor, 1.2) : "#BDBDBD"
  18. // Gradient effect (compatible with software rendering)
  19. gradient: Gradient {
  20. GradientStop { position: 0; color: Qt.lighter(root.buttonColor, 1.1) }
  21. GradientStop { position: 1; color: root.buttonColor }
  22. }
  23. // Press animation
  24. scale: mouseArea.pressed ? 0.95 : 1.0
  25. Behavior on scale {
  26. NumberAnimation { duration: 150; easing.type: Easing.OutQuad }
  27. }
  28. Behavior on color {
  29. ColorAnimation { duration: 200 }
  30. }
  31. // Simple shadow using Rectangle (linuxfb compatible)
  32. Rectangle {
  33. anchors.fill: parent
  34. anchors.topMargin: 2
  35. anchors.leftMargin: 2
  36. radius: parent.radius
  37. color: "#20000000"
  38. z: -1
  39. }
  40. RowLayout {
  41. anchors.centerIn: parent
  42. spacing: 8
  43. Text {
  44. text: root.icon
  45. font.pixelSize: root.fontSize + 2
  46. color: "white"
  47. visible: root.icon !== ""
  48. }
  49. Label {
  50. id: buttonLabel
  51. color: "white"
  52. font.pixelSize: root.fontSize
  53. font.bold: true
  54. }
  55. }
  56. MouseArea {
  57. id: mouseArea
  58. anchors.fill: parent
  59. hoverEnabled: true
  60. enabled: parent.enabled
  61. onClicked: parent.clicked()
  62. // Ripple effect
  63. Rectangle {
  64. id: ripple
  65. width: 0
  66. height: 0
  67. radius: width / 2
  68. color: "#40FFFFFF"
  69. anchors.centerIn: parent
  70. NumberAnimation {
  71. id: rippleAnimation
  72. target: ripple
  73. property: "width"
  74. from: 0
  75. to: parent.width * 1.2
  76. duration: 400
  77. easing.type: Easing.OutQuad
  78. onFinished: {
  79. ripple.width = 0
  80. ripple.height = 0
  81. }
  82. }
  83. Connections {
  84. target: mouseArea
  85. function onPressed() {
  86. ripple.height = ripple.width
  87. rippleAnimation.start()
  88. }
  89. }
  90. }
  91. }
  92. }