Slider.qml 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. Item {
  6. id: slider
  7. width: 50; height: 200
  8. // value is read/write.
  9. property real value: minimum
  10. property real maximum: 2
  11. property real minimum: 1
  12. property int yMax: slider.height - handle.height
  13. Rectangle {
  14. anchors.horizontalCenter: parent.horizontalCenter
  15. y: 10
  16. width: parent.width / 3; height: parent.height - 20
  17. border.color: "#AA444444"; border.width: 1; radius: 4
  18. gradient: Gradient {
  19. GradientStop { position: 0.0; color: "#66343434" }
  20. GradientStop { position: 1.0; color: "#66000000" }
  21. }
  22. }
  23. Rectangle {
  24. id: handle
  25. anchors.horizontalCenter: parent.horizontalCenter
  26. y: (value - minimum) * slider.yMax / (maximum - minimum)
  27. width: slider.width - 3; height: 30
  28. radius: 3; smooth: true
  29. border.color: "#AA444444"; border.width: 1
  30. gradient: Gradient {
  31. GradientStop { position: 0.0; color: "lightgray" }
  32. GradientStop { position: 1.0; color: "gray" }
  33. }
  34. MouseArea {
  35. anchors.fill: parent
  36. drag.target: parent
  37. drag.axis: "YAxis"; drag.minimumY: 0; drag.maximumY: slider.yMax
  38. onPositionChanged: { value = (maximum - minimum) * (handle.y) / slider.yMax + minimum; }
  39. }
  40. }
  41. }