Procession.qml 3.7 KB

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