Trivial.qml 6.2 KB

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