Basic.qml 5.0 KB

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