Trivial.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import QtQuick 2.5
  2. import "../.."
  3. import PictureModel 1.0
  4. Item {
  5. id: root
  6. property var imageArray: []
  7. property real velocity: 0
  8. property real grainsOfSand: 0
  9. function animationStep() {
  10. var fullyLoaded = true
  11. for (var i = globalSettings.columnCount - 1; i >= 0; i--) {
  12. var col = d.imageArray[i]
  13. var tailItem = col[col.length-1]
  14. var headItem = col[0]
  15. var fullCanvas = !!tailItem && (tailItem.y <= -tailItem.height)
  16. var overloadedCanvas = fullCanvas && (tailItem.y < -headItem.height)
  17. if ((!d.initialized && !fullCanvas) || (i == 0) && !overloadedCanvas && (globalSettings.itemLimit < 0 || (globalUtil.itemCount < globalSettings.itemLimit))) {
  18. globalUtil.itemCount++
  19. tailItem = d.pictureDelegate.createObject(root)
  20. tailItem.columnIndex = i
  21. col.push(tailItem)
  22. }
  23. if (!d.initialized) {
  24. fullyLoaded = fullyLoaded && !fullCanvas
  25. continue
  26. }
  27. if (overloadedCanvas || d.animating[i]) {
  28. feedTimer.restart()
  29. d.animating[i] = true
  30. for (var j = 0; j < col.length; j++) {
  31. var item = col[j]
  32. if (item.y > root.height) {
  33. d.animating[i] = false
  34. item = d.imageArray[i].shift()
  35. if (globalSettings.columnCount - i > 1) {
  36. item.columnIndex = i + 1
  37. d.imageArray[i + 1].push(item)
  38. root.grainsOfSand = 0
  39. root.velocity = 0
  40. } else {
  41. item.destroy();
  42. globalUtil.itemCount--
  43. }
  44. } else {
  45. item.y += root.velocity
  46. }
  47. }
  48. root.grainsOfSand += 0.05
  49. root.velocity = Math.pow(root.grainsOfSand, 2)
  50. return;
  51. }
  52. }
  53. if (!d.initialized && fullyLoaded) {
  54. settleTimer.start()
  55. }
  56. }
  57. Rectangle {
  58. id: background
  59. color: "white"
  60. anchors.fill: parent
  61. }
  62. Timer {
  63. id: settleTimer
  64. interval: 5000
  65. onTriggered: {
  66. d.initialized = true
  67. background.color = "black"
  68. }
  69. }
  70. Timer {
  71. id: feedTimer
  72. interval: globalSettings.interval*100
  73. running: d.initialized
  74. repeat: true
  75. onTriggered: {
  76. d.animating[0] = true
  77. }
  78. }
  79. QtObject {
  80. id: d
  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 { 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. onColumnCountChanged: console.log('Col count:' + globalSettings.columnCount)
  150. }
  151. }