ModernControlButton.qml 2.6 KB

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