Reel.qml 4.5 KB

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