Trivial.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import QtQuick 2.5
  2. import "../.."
  3. import PictureModel 1.0
  4. Item {
  5. id: root
  6. function animationStep() {
  7. var fullyLoaded = true
  8. for (var i = globalSettings.columnCount - 1; i >= 0; i--) {
  9. var col = d.imageArray[i]
  10. var tailItem = col[col.length-1]
  11. var headItem = col[0]
  12. var fullCanvas = !!tailItem && (tailItem.y <= -tailItem.height)
  13. var overloadedCanvas = fullCanvas && (tailItem.y < -headItem.height)
  14. if ((!d.initialized && !fullCanvas) || (i == 0) && !overloadedCanvas && (globalSettings.itemLimit < 0 || (globalUtil.itemCount < globalSettings.itemLimit))) {
  15. globalUtil.itemCount++
  16. tailItem = d.pictureDelegate.createObject(root)
  17. tailItem.loaded.connect(function() { d.loadedImageCount += 1 } )
  18. tailItem.columnIndex = i
  19. col.push(tailItem)
  20. }
  21. if (!d.initialized) {
  22. fullyLoaded = fullyLoaded && fullCanvas
  23. continue
  24. }
  25. if (d.imagesLoaded && (overloadedCanvas || d.animating[i])) {
  26. feedTimer.restart()
  27. d.animating[i] = true
  28. for (var j = 0; j < col.length; j++) {
  29. var item = col[j]
  30. if (item.y > root.height) {
  31. d.animating[i] = false
  32. item = d.imageArray[i].shift()
  33. if (globalSettings.columnCount - i > 1) {
  34. item.columnIndex = i + 1
  35. d.imageArray[i + 1].push(item)
  36. } else {
  37. item.destroy();
  38. globalUtil.itemCount--
  39. }
  40. d.grainsOfSand = 0
  41. d.velocity = 0
  42. d.considerNextMove = false
  43. return
  44. } else {
  45. item.y += d.velocity
  46. }
  47. }
  48. d.grainsOfSand += 0.02
  49. d.velocity = Math.pow(d.grainsOfSand, 2)
  50. return;
  51. }
  52. }
  53. if (!d.initialized && fullyLoaded) {
  54. d.initialized = true
  55. background.color = "black"
  56. return
  57. }
  58. d.animating[0] = true
  59. }
  60. Rectangle {
  61. id: background
  62. color: "white"
  63. anchors.fill: parent
  64. }
  65. Timer {
  66. id: feedTimer
  67. interval: 2000
  68. running: false
  69. repeat: false
  70. onTriggered: {
  71. d.considerNextMove = true
  72. }
  73. }
  74. QtObject {
  75. id: d
  76. property bool considerNextMove: true
  77. property real velocity: 0
  78. property real grainsOfSand: 0
  79. property int loadedImageCount: 0
  80. property bool imagesLoaded: loadedImageCount > 0 && (loadedImageCount >= globalUtil.itemCount)
  81. property bool incoming: false
  82. property bool initialized: globalSettings.itemLimit > -1 ? true : false
  83. property real t: 0
  84. property real columnRatio: globalSettings.useGoldenRatio ? globalVars.goldenRatio : globalSettings.lessGoldenRatio
  85. property var imageArray: []
  86. property var colWidthArray: []
  87. property var xposArray: []
  88. property var animating: []
  89. property var pictureDelegate: Component {
  90. ArtImage {
  91. property int columnIndex: 0
  92. function considerY() {
  93. var col = d.imageArray[columnIndex]
  94. var originatingHeight = d.initialized ? -height : root.height - height
  95. y = !!col[col.length - 1] ? col[col.length - 1].y - height : originatingHeight
  96. }
  97. width: d.colWidthArray[columnIndex]
  98. x: d.xposArray[columnIndex]
  99. onHeightChanged: {
  100. considerY()
  101. }
  102. /*
  103. ShaderEffect {
  104. z: 1
  105. width: src.width; height: src.height
  106. property variant src: artwork
  107. vertexShader: "
  108. uniform highp mat4 qt_Matrix;
  109. attribute highp vec4 qt_Vertex;
  110. attribute highp vec2 qt_MultiTexCoord0;
  111. varying highp vec2 coord;
  112. void main() {
  113. coord = qt_MultiTexCoord0;
  114. gl_Position = qt_Matrix * qt_Vertex;
  115. }"
  116. fragmentShader: "
  117. varying highp vec2 coord;
  118. uniform sampler2D src;
  119. uniform lowp float qt_Opacity;
  120. void main() {
  121. lowp vec4 tex = texture2D(src, coord);
  122. gl_FragColor = vec4(vec3(dot(tex.rgb,
  123. vec3(0.344, 0.5, 0.156))),
  124. tex.a) * qt_Opacity;
  125. }"
  126. }*/
  127. }
  128. }
  129. NumberAnimation on t { running: d.considerNextMove; from: 0; to: 1; duration: 1000; loops: -1 }
  130. onTChanged: { root.animationStep(); }
  131. Component.onCompleted: {
  132. var baseUnit = root.width*globalUtil.columnWidthRatio(d.columnRatio, globalSettings.columnCount)
  133. for(var i = 0; i < globalSettings.columnCount; i++) {
  134. if (i == (globalSettings.columnCount-1)) {
  135. var finalColWidth = root.width - colWidthArray.reduce(function(a,b){ return a+b; }, 0)
  136. colWidthArray.push(finalColWidth)
  137. globalVars.imageWidthOverride = finalColWidth
  138. } else {
  139. colWidthArray.push(Math.round(baseUnit*Math.pow(d.columnRatio, i)))
  140. }
  141. xposArray.push(i === 0 ? 0 : xposArray[i-1] + colWidthArray[i-1])
  142. imageArray[i] = new Array;
  143. d.animating[i] = false
  144. }
  145. }
  146. }
  147. Connections {
  148. target: globalSettings
  149. function onColumnCountChanged() { console.log('Col count:' + globalSettings.columnCount) }
  150. }
  151. }