MyButton.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. Rectangle {
  4. id: button
  5. property alias text: txtButton.text
  6. property alias iconSource: imgButton.source
  7. property bool indicator: true
  8. property int fontSize: 26
  9. property string color: "lightgray"
  10. property bool isGlow: true
  11. signal clicked
  12. radius: 20
  13. border.color: "gray"
  14. border.width: 2
  15. smooth: true
  16. Behavior on scale { NumberAnimation {duration: 200} }
  17. Text {
  18. id: txtButton
  19. //anchors.centerIn: parent
  20. anchors.left: imgButton.right
  21. anchors.leftMargin: 0.1*button.width
  22. anchors.verticalCenter: parent.verticalCenter
  23. font.pixelSize: button.fontSize
  24. font.bold: true
  25. color: button.enabled ? "black" : "gray"
  26. }
  27. Image {
  28. id: imgButton
  29. smooth: true
  30. anchors.left: parent.left
  31. anchors.leftMargin: 0.07*button.width
  32. anchors.verticalCenter: parent.verticalCenter
  33. visible: imgButton.source !=""
  34. z: 1
  35. /*BusyIndicator {
  36. id: busyIndicator
  37. opacity: 0
  38. anchors.centerIn: parent
  39. platformStyle: BusyIndicatorStyle { size: "large" }
  40. running: true
  41. scale: 0.94
  42. smooth: true
  43. visible: button.indicator
  44. }*/
  45. Image {
  46. id: imgGlow
  47. opacity: 0
  48. anchors.centerIn: parent
  49. smooth: true
  50. source: "images/glow80.png"
  51. visible: isGlow
  52. z:0
  53. }
  54. }
  55. Gradient {
  56. id: gr1
  57. GradientStop { color: button.color; position: 0 }
  58. GradientStop { color: "transparent"; position: 0.5 }
  59. GradientStop { color: button.color; position: 1 }
  60. }
  61. Gradient {
  62. id: gr2
  63. GradientStop { color: button.color; position: 0 }
  64. GradientStop { color: "transparent"; position: 1 }
  65. }
  66. gradient: gr2
  67. MouseArea {
  68. id: maButton
  69. anchors.fill: parent
  70. onClicked: {
  71. button.clicked()
  72. }
  73. onPressedChanged: {
  74. if( pressed ) {
  75. button.gradient = gr1
  76. button.scale = 0.96
  77. txtButton.style = Text.Outline;
  78. txtButton.styleColor = "yellow"
  79. //busyIndicator.opacity = 1
  80. imgGlow.opacity = 0.7
  81. } else {
  82. button.gradient = gr2
  83. button.scale = 1
  84. txtButton.style = Text.Normal;
  85. //busyIndicator.opacity = 0
  86. imgGlow.opacity = 0
  87. }
  88. }
  89. }
  90. }