Animator.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import QtQuick 2.5
  2. import "../.."
  3. import PictureModel 1.0
  4. Item {
  5. id: root
  6. property var imageArray: []
  7. function animationStep() {
  8. var fullyLoaded = true
  9. for (var i = globalSettings.columnCount - 1; i >= 0; i--) {
  10. var col = d.imageArray[i]
  11. var tailItem = col[col.length-1]
  12. var headItem = col[0]
  13. var fullCanvas = !!tailItem && (tailItem.y <= -tailItem.height)
  14. var overloadedCanvas = fullCanvas && (tailItem.y < -headItem.height)
  15. if ((!d.initialized && !fullCanvas) || (i == 0) && !overloadedCanvas && (globalSettings.itemLimit < 0 || (globalUtil.itemCount < globalSettings.itemLimit))) {
  16. globalUtil.itemCount++
  17. tailItem = d.pictureDelegate.createObject(root)
  18. tailItem.columnIndex = i
  19. col.push(tailItem)
  20. }
  21. if (!d.initialized) {
  22. fullyLoaded = fullyLoaded && !fullCanvas
  23. continue
  24. }
  25. if (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. } else {
  41. item.y += 1
  42. }
  43. }
  44. return;
  45. }
  46. }
  47. if (!d.initialized && fullyLoaded) {
  48. settleTimer.start()
  49. }
  50. }
  51. Timer {
  52. id: settleTimer
  53. interval: 5000
  54. onTriggered: {
  55. d.initialized = true
  56. }
  57. }
  58. Timer {
  59. id: feedTimer
  60. interval: globalSettings.interval*100
  61. running: d.initialized
  62. repeat: true
  63. onTriggered: {
  64. d.animating[0] = true
  65. }
  66. }
  67. QtObject {
  68. id: d
  69. property bool incoming: false
  70. property bool initialized: globalSettings.itemLimit > -1 ? true : false
  71. property real t: 0
  72. property real columnRatio: globalSettings.useGoldenRatio ? globalVars.goldenRatio : globalSettings.lessGoldenRatio
  73. property var imageArray: []
  74. property var colWidthArray: []
  75. property var xposArray: []
  76. property var animating: []
  77. property var pictureDelegate: Component {
  78. ArtImage {
  79. property int columnIndex: 0
  80. function considerY() {
  81. var col = d.imageArray[columnIndex]
  82. var originatingHeight = d.initialized ? -height : root.height - height
  83. y = !!col[col.length - 1] ? col[col.length - 1].y - height : originatingHeight
  84. }
  85. width: d.colWidthArray[columnIndex]
  86. x: d.xposArray[columnIndex]
  87. onHeightChanged: {
  88. considerY()
  89. }
  90. }
  91. }
  92. NumberAnimation on t { from: 0; to: 1; duration: 1000; loops: -1 }
  93. onTChanged: { root.animationStep(); }
  94. Component.onCompleted: {
  95. var baseUnit = root.width*globalUtil.columnWidthRatio(d.columnRatio, globalSettings.columnCount)
  96. for(var i = 0; i < globalSettings.columnCount; i++) {
  97. if (i == (globalSettings.columnCount-1)) {
  98. var finalColWidth = root.width - colWidthArray.reduce(function(a,b){ return a+b; }, 0)
  99. colWidthArray.push(finalColWidth)
  100. globalVars.imageWidthOverride = finalColWidth
  101. } else {
  102. colWidthArray.push(Math.round(baseUnit*Math.pow(d.columnRatio, i)))
  103. }
  104. xposArray.push(i === 0 ? 0 : xposArray[i-1] + colWidthArray[i-1])
  105. imageArray[i] = new Array;
  106. d.animating[i] = false
  107. }
  108. }
  109. }
  110. Connections {
  111. target: globalSettings
  112. function onColumnCountChanged() { console.log('Col count:' + globalSettings.columnCount) }
  113. }
  114. }