main.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import QtQuick 2.0
  2. import QtSensors 5.0 as Sensors
  3. import "QUItMeterComponent"
  4. Rectangle {
  5. id: root
  6. //Generate dummy values when testing without accelerometer (e.g. PC)
  7. property bool feedWithDummyValues: false
  8. width: 1200
  9. height: 800
  10. color: "#000000"
  11. QUItMeterComponent {
  12. id: meter
  13. width: parent.width
  14. height: parent.height/2
  15. ledWidth: ledWidthSlider.value
  16. ledHeight: ledHeightSlider.value
  17. updateFrequency: meterSpeedSlider.value
  18. SequentialAnimation on value {
  19. running: root.feedWithDummyValues
  20. loops: Animation.Infinite
  21. NumberAnimation { from: 0.5; to: 1; duration: 300; easing.type: Easing.InOutQuad }
  22. NumberAnimation { from: 1.0; to: 0.5; duration: 1000; easing.type: Easing.OutElastic }
  23. NumberAnimation { from: 0.5; to: 0.2; duration: 2000; easing.type: Easing.InOutElastic }
  24. }
  25. }
  26. Sensors.Accelerometer {
  27. id: accel
  28. dataRate: 100
  29. active: !root.feedWithDummyValues
  30. onReadingChanged: {
  31. var v = Math.sqrt(accel.reading.x * accel.reading.x + accel.reading.y * accel.reading.y + accel.reading.z * accel.reading.z);
  32. // Max 3G force
  33. v = v / (3*9.81);
  34. meter.value = v;
  35. }
  36. }
  37. // Add mirror effect
  38. ShaderEffect {
  39. property variant source: ShaderEffectSource { sourceItem: meter; hideSource: false }
  40. anchors.top: meter.bottom
  41. width: meter.width
  42. height: meter.height
  43. fragmentShader: "
  44. varying highp vec2 qt_TexCoord0;
  45. uniform highp float qt_Opacity;
  46. uniform sampler2D source;
  47. void main(void) {
  48. highp vec2 pos = vec2(qt_TexCoord0.x, (1.0 - qt_TexCoord0.y*0.8));
  49. pos.x += (qt_TexCoord0.y*0.2) * (pos.x * -1.0 + 1.0);
  50. highp vec4 pix = texture2D(source, pos);
  51. pix *= (0.4 - qt_TexCoord0.y*0.5) * min(qt_TexCoord0.y*5.0, 1.0);
  52. gl_FragColor = pix * qt_Opacity;
  53. }"
  54. }
  55. Row {
  56. anchors.bottom: parent.bottom
  57. anchors.bottomMargin: 40
  58. width: parent.width
  59. spacing: 0
  60. property int elementWidth: width/3 - spacing
  61. Slider {
  62. id: ledWidthSlider
  63. width: parent.elementWidth
  64. caption: "Led width: " + value + " px"
  65. minimum: 8
  66. maximum: 128
  67. value: 32
  68. }
  69. Slider {
  70. id: ledHeightSlider
  71. width: parent.elementWidth
  72. caption: "Led height: " + value + " px"
  73. minimum: 8
  74. maximum: 64
  75. value: 16
  76. }
  77. Slider {
  78. id: meterSpeedSlider
  79. width: parent.elementWidth
  80. caption: "Meter speed: " + (60/value).toFixed(2) + " fps"
  81. minimum: 1
  82. maximum: 20
  83. value: 5
  84. }
  85. }
  86. }