Trivial.qml 4.5 KB

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