Reel.qml 4.8 KB

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