1
0

ModernControlButton.qml 2.6 KB

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