Basic.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import QtQuick 2.5
  2. import Box2D 2.0
  3. import Qt.labs.settings 1.0
  4. import ".."
  5. Item {
  6. id: root
  7. signal togglePause
  8. signal next
  9. property var pictureDelegate: Component {
  10. ArtImage {}
  11. }
  12. property var effectDelegate: Component {
  13. VisualEffect {}
  14. }
  15. anchors.fill: parent
  16. Settings {
  17. id: basicSettings
  18. category: "Basic"
  19. property int animationDuration: 2000
  20. property int easingType: Easing.Linear
  21. }
  22. Component {
  23. id: columnComponent
  24. Item {
  25. id: column
  26. x: width * index
  27. height: parent.height
  28. width: parent.width/generalSettings.columnCount
  29. Item {
  30. id: artworkStack
  31. property var headElement
  32. property var pictureArray: []
  33. property int artworkHeight: 0
  34. property int compoundArtworkHeight: 0
  35. property bool full: artworkHeight > root.height
  36. property bool initialized: false
  37. onFullChanged: initialized = true
  38. height: childrenRect.height
  39. width: parent.width
  40. function addImage() {
  41. var image = pictureDelegate.createObject(artworkStack)
  42. if (generalSettings.effect !== "" && Effects.validate(generalSettings.effect)) {
  43. image.effect = effectDelegate.createObject(artworkStack, { target: image, effect: generalSettings.effect })
  44. }
  45. artworkHeight += image.height
  46. compoundArtworkHeight += image.height
  47. image.y = root.height - compoundArtworkHeight
  48. pictureArray.push(image)
  49. globalVars.itemCount++
  50. }
  51. function removeImage(image) {
  52. if (image.effect) {
  53. image.effect.destroy()
  54. }
  55. image.destroy()
  56. globalVars.itemCount--
  57. }
  58. function shift() {
  59. if (headElement) {
  60. removeImage(headElement)
  61. }
  62. headElement = pictureArray.shift()
  63. artworkHeight -= headElement.height
  64. while (!full) {
  65. addImage()
  66. }
  67. artworkStack.y += headElement.height
  68. }
  69. Timer {
  70. id: populateTimer
  71. running: !artworkStack.initialized
  72. repeat: true
  73. interval: 100
  74. onTriggered: artworkStack.addImage()
  75. }
  76. Timer {
  77. id: deathTimer
  78. running: artworkStack.initialized
  79. repeat: true
  80. interval: globalVars.adjustedInterval
  81. onTriggered: artworkStack.shift()
  82. }
  83. Behavior on y {
  84. NumberAnimation {
  85. duration: Math.min(globalVars.adjustedInterval, basicSettings.animationDuration)
  86. easing.type: basicSettings.easingType
  87. }
  88. }
  89. }
  90. Connections {
  91. target: root
  92. onTogglePause: deathTimer.running = !deathTimer.running
  93. onNext: deathTimer.triggered()
  94. }
  95. }
  96. }
  97. Repeater {
  98. model: generalSettings.columnCount
  99. delegate: columnComponent
  100. }
  101. Keys.onUpPressed: root.togglePause()
  102. Keys.onDownPressed: root.next()
  103. }