Reel.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. if (!lastColumn) {
  74. columnArray[columnIndex+1].addImage(image)
  75. }
  76. } else if (( lastColumn || !columnArray[columnIndex+1].receptive()) && prospectiveY >= restingY) {
  77. image.y = restingY
  78. if (lastColumn) {
  79. deathTimer.start()
  80. if(!d.initialized) {
  81. d.initialized = true
  82. d.velocity = 4
  83. }
  84. }
  85. } else {
  86. image.y = prospectiveY
  87. }
  88. }
  89. }
  90. Component.onCompleted: columnArray.push(this)
  91. x: d.columnWidth/globalUtil.columnWidthRatio(d.columnRatio, index)
  92. width: {
  93. var colWidth = d.columnWidth*Math.pow(d.columnRatio, index);
  94. (index === (globalSettings.columnCount - 1)) && (globalVars.imageWidthOverride = colWidth)
  95. return colWidth
  96. }
  97. anchors { top: parent.top; bottom: parent.bottom }
  98. }
  99. }
  100. // feed
  101. Timer {
  102. repeat: true
  103. running: true
  104. interval: 100/6
  105. onTriggered: d.animationStep()
  106. }
  107. // accel
  108. Timer {
  109. repeat: true
  110. running: !d.initialized
  111. interval: 100
  112. onTriggered: {
  113. d.velocity += 0.1
  114. }
  115. }
  116. // death
  117. Timer {
  118. id: deathTimer
  119. repeat: false
  120. running: false
  121. interval: reelSettings.deathYawn
  122. onTriggered: {
  123. d.killLastImage()
  124. }
  125. }
  126. Keys.onDownPressed: {
  127. d.killLastImage()
  128. }
  129. }