Reel.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. function stackHeight(imageIndex) {
  42. var height = 0
  43. for(var i = 0; i < imageIndex; i++) {
  44. height += imageArray[i].height
  45. }
  46. return height
  47. }
  48. function receptive() {
  49. return imageQueue.length < d.imageBuffer
  50. }
  51. function addImage(image) {
  52. image.parent = column
  53. image.y = - image.height
  54. imageQueue.push(image)
  55. }
  56. function animationStep() {
  57. if (!imageArray.length || imageArray[imageArray.length - 1].y > -1) {
  58. if (imageQueue.length) {
  59. imageArray.push(imageQueue.pop())
  60. } else if (columnIndex === 0) {
  61. globalUtil.itemCount++
  62. addImage(pictureDelegate.createObject())
  63. imageArray.push(imageQueue.pop())
  64. }
  65. }
  66. for (var i = 0; i < imageArray.length; i++) {
  67. var image = imageArray[i]
  68. var restingY = root.height - image.height - stackHeight(i)
  69. var prospectiveY = image.y + d.velocity
  70. var lastColumn = columnIndex === (globalSettings.columnCount - 1)
  71. if (image.y > root.height) {
  72. imageArray.shift()
  73. columnArray[columnIndex+1].addImage(image)
  74. } else if (( lastColumn || !columnArray[columnIndex+1].receptive()) && prospectiveY >= restingY) {
  75. image.y = restingY
  76. if (lastColumn) {
  77. deathTimer.start()
  78. if(!d.initialized) {
  79. d.initialized = true
  80. d.velocity = 4
  81. }
  82. }
  83. } else {
  84. image.y = prospectiveY
  85. }
  86. }
  87. }
  88. Component.onCompleted: columnArray.push(this)
  89. x: d.columnWidth/globalUtil.columnWidthRatio(d.columnRatio, index)
  90. width: {
  91. var colWidth = d.columnWidth*Math.pow(d.columnRatio, index);
  92. (index === (globalSettings.columnCount - 1)) && (globalVars.imageWidthOverride = colWidth)
  93. return colWidth
  94. }
  95. anchors { top: parent.top; bottom: parent.bottom }
  96. }
  97. }
  98. // feed
  99. Timer {
  100. repeat: true
  101. running: true
  102. interval: 100/6
  103. onTriggered: d.animationStep()
  104. }
  105. // accel
  106. Timer {
  107. repeat: true
  108. running: !d.initialized
  109. interval: 100
  110. onTriggered: {
  111. d.velocity += 0.1
  112. }
  113. }
  114. // death
  115. Timer {
  116. id: deathTimer
  117. repeat: false
  118. running: false
  119. interval: reelSettings.deathYawn
  120. onTriggered: {
  121. d.killLastImage()
  122. }
  123. }
  124. Keys.onDownPressed: {
  125. d.killLastImage()
  126. }
  127. }