Procession.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import QtQuick 2.5
  2. import Qt.labs.settings 1.0
  3. import ".."
  4. View {
  5. id: root
  6. property var pictureDelegate: Component {
  7. ProcessionImage {}
  8. }
  9. QtObject {
  10. id: d
  11. property bool initialAcceleration: true
  12. property int count: 0
  13. property real velocity: 0
  14. property int imageBuffer: Math.sqrt(globalSettings.columnCount) + 1
  15. property real columnRatio: globalSettings.useGoldenRatio ? globalVars.goldenRatio : globalSettings.lessGoldenRatio
  16. property real columnWidth: root.width*globalUtil.columnWidthRatio(d.columnRatio, globalSettings.columnCount)
  17. function animationStep() {
  18. columnArray.forEach(function(column) { column.animationStep(); })
  19. }
  20. }
  21. Component {
  22. id: columnComponent
  23. Item {
  24. id: column
  25. property int columnIndex: index
  26. property var imageArray: []
  27. property var imageQueue: []
  28. function receptive() {
  29. return imageQueue.length < d.imageBuffer
  30. }
  31. function addImage(image) {
  32. image.parent = column
  33. image.y = - image.height
  34. imageQueue.push(image)
  35. }
  36. function animationStep() {
  37. if (d.initialAcceleration && (++d.count % 10 === 0)) {
  38. d.count = 0
  39. d.velocity += 0.1
  40. }
  41. if (!imageArray.length || imageArray[imageArray.length - 1].y > -1) {
  42. if (imageQueue.length) {
  43. imageArray.push(imageQueue.pop())
  44. } else if (columnIndex === 0) {
  45. globalUtil.itemCount++
  46. addImage(pictureDelegate.createObject())
  47. imageArray.push(imageQueue.pop())
  48. }
  49. }
  50. imageArray.forEach(function(image) {
  51. image.y = image.y + d.velocity
  52. if (image.y > root.height) {
  53. imageArray.shift()
  54. if (columnIndex === (globalSettings.columnCount - 1)) {
  55. if (image.primed) {
  56. image.destroy()
  57. globalUtil.itemCount--
  58. } else {
  59. d.initialAcceleration = false
  60. d.velocity = 1
  61. image.primed = true
  62. column.addImage(image)
  63. }
  64. } else {
  65. var nextColumn = columnArray[columnIndex+1]
  66. if (nextColumn.receptive())
  67. nextColumn.addImage(image)
  68. else
  69. column.addImage(image)
  70. }
  71. }
  72. })
  73. }
  74. Component.onCompleted: columnArray.push(this)
  75. x: d.columnWidth/globalUtil.columnWidthRatio(d.columnRatio, index)
  76. width: {
  77. var colWidth = d.columnWidth*Math.pow(d.columnRatio, index);
  78. (index === (globalSettings.columnCount - 1)) && (globalVars.imageWidthOverride = colWidth)
  79. return colWidth
  80. }
  81. anchors { top: parent.top; bottom: parent.bottom }
  82. }
  83. }
  84. Timer {
  85. repeat: true
  86. running: true
  87. interval: 100/6
  88. onTriggered: d.animationStep()
  89. }
  90. Keys.onUpPressed: globalSettings.interval++
  91. Keys.onDownPressed: globalSettings.interval = Math.max(1, globalSettings.interval - 1)
  92. }