Reel.qml 4.4 KB

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