Basic.qml 3.8 KB

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