Trivial.qml 6.2 KB

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