Trivial.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. Rectangle {
  52. color: "white"
  53. anchors.fill: parent
  54. }
  55. Timer {
  56. id: settleTimer
  57. interval: 5000
  58. onTriggered: {
  59. d.initialized = true
  60. }
  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 bool incoming: false
  74. property bool initialized: globalSettings.itemLimit > -1 ? true : false
  75. property real t: 0
  76. property real columnRatio: globalSettings.useGoldenRatio ? globalVars.goldenRatio : globalSettings.lessGoldenRatio
  77. property var imageArray: []
  78. property var colWidthArray: []
  79. property var xposArray: []
  80. property var animating: []
  81. property var pictureDelegate: Component {
  82. ArtImage {
  83. property int columnIndex: 0
  84. function considerY() {
  85. var col = d.imageArray[columnIndex]
  86. var originatingHeight = d.initialized ? -height : root.height - height
  87. y = !!col[col.length - 1] ? col[col.length - 1].y - height : originatingHeight
  88. }
  89. width: d.colWidthArray[columnIndex]
  90. x: d.xposArray[columnIndex]
  91. onHeightChanged: {
  92. considerY()
  93. }
  94. }
  95. }
  96. NumberAnimation on t { from: 0; to: 1; duration: 1000; loops: -1 }
  97. onTChanged: { root.animationStep(); }
  98. Component.onCompleted: {
  99. var baseUnit = root.width*globalUtil.columnWidthRatio(d.columnRatio, globalSettings.columnCount)
  100. for(var i = 0; i < globalSettings.columnCount; i++) {
  101. if (i == (globalSettings.columnCount-1)) {
  102. var finalColWidth = root.width - colWidthArray.reduce(function(a,b){ return a+b; }, 0)
  103. colWidthArray.push(finalColWidth)
  104. globalVars.imageWidthOverride = finalColWidth
  105. } else {
  106. colWidthArray.push(Math.round(baseUnit*Math.pow(d.columnRatio, i)))
  107. }
  108. xposArray.push(i === 0 ? 0 : xposArray[i-1] + colWidthArray[i-1])
  109. imageArray[i] = new Array;
  110. d.animating[i] = false
  111. }
  112. }
  113. }
  114. Connections {
  115. target: globalSettings
  116. onColumnCountChanged: console.log('Col count:' + globalSettings.columnCount)
  117. }
  118. }