Reel.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. ReelImage {}
  8. }
  9. Settings {
  10. id: reelSettings
  11. category: "Reel"
  12. property int deathYawn: 5000
  13. }
  14. QtObject {
  15. id: d
  16. property var priorImage
  17. property real velocity: 0
  18. property bool initialized: false
  19. property int imageBuffer: 1
  20. property real columnRatio: globalSettings.useGoldenRatio ? globalVars.goldenRatio : globalSettings.lessGoldenRatio
  21. property real columnWidth: root.width*globalUtil.columnWidthRatio(d.columnRatio, globalSettings.columnCount)
  22. function animationStep() {
  23. columnArray.forEach(function(column) { column.animationStep(); })
  24. }
  25. function killLastImage() {
  26. if(!!priorImage) {
  27. priorImage.destroy()
  28. globalUtil.itemCount--
  29. }
  30. var col = columnArray[globalSettings.columnCount - 1]
  31. priorImage = col.imageArray.shift()
  32. }
  33. }
  34. Component {
  35. id: columnComponent
  36. Item {
  37. id: column
  38. property int columnIndex: index
  39. property var imageArray: []
  40. property var imageQueue: []
  41. property bool lastColumn: columnIndex === (globalSettings.columnCount - 1)
  42. function stackHeight(imageIndex) {
  43. var height = 0
  44. for(var i = 0; i < imageIndex; i++) {
  45. height += imageArray[i].height
  46. }
  47. return height
  48. }
  49. function receptive() {
  50. return !d.initialized || imageQueue.length < d.imageBuffer
  51. }
  52. function addImage(image) {
  53. image.parent = column
  54. image.y = - image.height
  55. imageQueue.push(image)
  56. }
  57. function animationStep() {
  58. if (!imageArray.length || imageArray[imageArray.length - 1].y > -1) {
  59. if (imageQueue.length) {
  60. imageArray.push(imageQueue.pop())
  61. } else if (columnIndex === 0) {
  62. globalUtil.itemCount++
  63. addImage(pictureDelegate.createObject())
  64. imageArray.push(imageQueue.pop())
  65. }
  66. }
  67. for (var i = 0; i < imageArray.length; i++) {
  68. var image = imageArray[i]
  69. var restingY = root.height - image.height - stackHeight(i)
  70. var prospectiveY = image.y + d.velocity
  71. var nextColumn = columnArray[columnIndex+1]
  72. if (image.y > root.height) {
  73. imageArray.shift()
  74. nextColumn.addImage(image)
  75. } else if ((lastColumn || !nextColumn.receptive()) && prospectiveY >= restingY) {
  76. image.y = restingY
  77. if (lastColumn) {
  78. deathTimer.start()
  79. if(!d.initialized) {
  80. d.initialized = true
  81. d.velocity = 4
  82. }
  83. }
  84. } else {
  85. image.y = prospectiveY
  86. }
  87. }
  88. }
  89. Component.onCompleted: columnArray.push(this)
  90. x: d.columnWidth/globalUtil.columnWidthRatio(d.columnRatio, index)
  91. width: {
  92. var colWidth = d.columnWidth*Math.pow(d.columnRatio, index);
  93. lastColumn && (globalVars.imageWidthOverride = colWidth)
  94. return colWidth
  95. }
  96. anchors { top: parent.top; bottom: parent.bottom }
  97. }
  98. }
  99. // feed
  100. Timer {
  101. repeat: true
  102. running: true
  103. interval: 100/6
  104. onTriggered: d.animationStep()
  105. }
  106. // accel
  107. Timer {
  108. repeat: true
  109. running: !d.initialized
  110. interval: 100
  111. onTriggered: {
  112. d.velocity += 0.1
  113. }
  114. }
  115. // death
  116. Timer {
  117. id: deathTimer
  118. repeat: false
  119. running: false
  120. interval: reelSettings.deathYawn
  121. onTriggered: {
  122. d.killLastImage()
  123. }
  124. }
  125. Keys.onDownPressed: {
  126. d.killLastImage()
  127. }
  128. }