KnobDial.qml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import "JavaScript.js" as JavaScript
  6. Image {
  7. id: knob
  8. property real minimumvalue: 5
  9. property real maximumvalue: 100
  10. property real minimumrotation: 35
  11. property real maximumrotation: 290
  12. property real value: 10
  13. width: 300; height: 300
  14. source: "images/btn_accuracy_back.png"
  15. smooth: true
  16. Image {
  17. id: knobImage
  18. width: parent.width
  19. height: parent.height
  20. anchors.centerIn: parent
  21. source: "images/btn_accuracy_shadow.png"
  22. smooth: true
  23. }
  24. Image {
  25. id: knobHat
  26. width: parent.width - 10
  27. height: parent.height - 10
  28. x: 5; y:5
  29. source: "images/btn_accuracy.png"
  30. rotation: knob.minimumrotation + knob.value / knob.maximumvalue *
  31. knob.maximumrotation
  32. smooth: true
  33. }
  34. Text {
  35. anchors.left: parent.right
  36. anchors.horizontalCenter: parent.horizontalCenter
  37. font.pointSize: 6
  38. text: knob.value + "m"
  39. }
  40. MouseArea {
  41. property int previousY: 0
  42. anchors.fill: knob
  43. onPressed: previousY = mouse.y
  44. onPositionChanged: {
  45. var delta = (previousY - mouse.y) * 0.20
  46. if (knob.value + delta > knob.maximumvalue) {
  47. knob.value = knob.maximumvalue
  48. }
  49. else if (knob.value + delta < knob.minimumvalue) {
  50. knob.value = knob.minimumvalue
  51. }
  52. else {
  53. knob.value += delta
  54. previousY = mouse.y
  55. }
  56. var temp = knob.value;
  57. knob.value = temp.toFixed(0);
  58. JavaScript.setGpsAccuracy(knob.value);
  59. }
  60. }
  61. }