Basic.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. height: childrenRect.height
  37. width: parent.width
  38. function addImage() {
  39. var image = pictureDelegate.createObject(artworkStack)
  40. if (generalSettings.effect !== "" && Effects.validate(generalSettings.effect)) {
  41. image.effect = effectDelegate.createObject(artworkStack, { target: image, effect: generalSettings.effect })
  42. }
  43. artworkHeight += image.height
  44. compoundArtworkHeight += image.height
  45. image.y = root.height - compoundArtworkHeight
  46. pictureArray.push(image)
  47. globalVars.itemCount++
  48. }
  49. function removeImage(image) {
  50. if (image.effect) {
  51. image.effect.destroy()
  52. }
  53. image.destroy()
  54. globalVars.itemCount--
  55. }
  56. function shift() {
  57. if (headElement) {
  58. headElement.destroy()
  59. }
  60. headElement = pictureArray.shift()
  61. artworkHeight -= headElement.height
  62. artworkStack.y += headElement.height
  63. }
  64. Timer {
  65. id: populateTimer
  66. running: !artworkStack.full
  67. repeat: true
  68. interval: 100*Math.random() + 100
  69. onTriggered: artworkStack.addImage()
  70. }
  71. Timer {
  72. id: deathTimer
  73. running: artworkStack.full
  74. repeat: true
  75. interval: globalVars.adjustedInterval
  76. onTriggered: artworkStack.shift()
  77. }
  78. Behavior on y {
  79. NumberAnimation {
  80. duration: Math.min(globalVars.adjustedInterval, basicSettings.animationDuration)
  81. easing.type: basicSettings.easingType
  82. }
  83. }
  84. }
  85. Connections {
  86. target: root
  87. onTogglePause: deathTimer.running = !deathTimer.running
  88. onNext: deathTimer.triggered()
  89. }
  90. }
  91. }
  92. Repeater {
  93. model: generalSettings.columnCount
  94. delegate: columnComponent
  95. }
  96. Keys.onUpPressed: root.togglePause()
  97. Keys.onDownPressed: root.next()
  98. }