Basic.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. property bool commonFeed: true
  22. }
  23. QtObject {
  24. id: d
  25. property int columnCount: generalSettings.columnCount
  26. property var columnArray: []
  27. property int primedColumns: 0
  28. function reset() {
  29. columnArray = []
  30. primedColumns = 0
  31. }
  32. onColumnCountChanged: {
  33. reset()
  34. }
  35. }
  36. Component {
  37. id: columnComponent
  38. Item {
  39. id: column
  40. x: width * index
  41. height: parent.height
  42. width: parent.width/generalSettings.columnCount
  43. Item {
  44. id: artworkStack
  45. property var headElement
  46. property var pictureArray: []
  47. property int artworkHeight: 0
  48. property int compoundArtworkHeight: 0
  49. property bool full: artworkHeight > root.height
  50. property bool initialized: false
  51. Component.onCompleted: {
  52. d.columnArray.push(this)
  53. }
  54. onFullChanged: {
  55. if (!initialized) {
  56. initialized = true
  57. d.primedColumns++
  58. }
  59. }
  60. height: childrenRect.height
  61. width: parent.width
  62. function addImage() {
  63. var image = pictureDelegate.createObject(artworkStack)
  64. if (generalSettings.effect !== "" && Effects.validate(generalSettings.effect)) {
  65. image.effect = effectDelegate.createObject(artworkStack, { target: image, effect: generalSettings.effect })
  66. }
  67. artworkHeight += image.height
  68. compoundArtworkHeight += image.height
  69. image.y = root.height - compoundArtworkHeight
  70. pictureArray.push(image)
  71. globalVars.itemCount++
  72. }
  73. function removeImage(image) {
  74. if (image.effect) {
  75. image.effect.destroy()
  76. }
  77. image.destroy()
  78. globalVars.itemCount--
  79. }
  80. function shift() {
  81. if (headElement) {
  82. removeImage(headElement)
  83. }
  84. headElement = pictureArray.shift()
  85. artworkHeight -= headElement.height
  86. while (!full) {
  87. addImage()
  88. }
  89. artworkStack.y += headElement.height
  90. }
  91. Timer {
  92. id: populateTimer
  93. running: !artworkStack.initialized
  94. repeat: true
  95. interval: 100
  96. onTriggered: artworkStack.addImage()
  97. }
  98. Timer {
  99. id: deathTimer
  100. running: !basicSettings.commonFeed && artworkStack.initialized
  101. repeat: true
  102. interval: globalVars.adjustedInterval
  103. onTriggered: artworkStack.shift()
  104. }
  105. Behavior on y {
  106. enabled: artworkStack.initialized
  107. NumberAnimation {
  108. duration: Math.min(globalVars.adjustedInterval, basicSettings.animationDuration)
  109. easing.type: basicSettings.easingType
  110. }
  111. }
  112. }
  113. Connections {
  114. target: root
  115. onTogglePause: deathTimer.running = !deathTimer.running
  116. onNext: deathTimer.triggered()
  117. }
  118. }
  119. }
  120. Timer {
  121. id: globalDeathTimer
  122. running: basicSettings.commonFeed && (d.primedColumns === d.columnCount)
  123. repeat: true
  124. interval: globalVars.adjustedInterval
  125. onTriggered: d.columnArray[Math.floor(Math.random()*d.columnCount)].shift()
  126. }
  127. Repeater {
  128. model: d.columnCount
  129. delegate: columnComponent
  130. }
  131. Keys.onUpPressed: root.togglePause()
  132. Keys.onDownPressed: root.next()
  133. }