main.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import QtQuick 2.5
  2. import Qt.labs.settings 1.0
  3. import PictureModel 1.0
  4. Item {
  5. id: appWindow
  6. onWidthChanged: {
  7. globalUtil.reset()
  8. }
  9. QtObject {
  10. id: globalVars
  11. property real goldenRatio
  12. property real imageWidthOverride
  13. property bool globalDeathTimer
  14. function reset() {
  15. goldenRatio = 1.61803398875
  16. imageWidthOverride = -1
  17. globalDeathTimer = false
  18. }
  19. Component.onCompleted: reset()
  20. }
  21. QtObject {
  22. id: globalUtil
  23. property int itemCount
  24. property int currentColumn: 0
  25. property bool primed: d.primedColumns === globalSettings.columnCount
  26. property int adjustedInterval: 1000*(globalSettings.interval > 60 ? 60*(globalSettings.interval-60) : Math.max(globalSettings.interval, 1))
  27. function registerColumnPrimed() {
  28. d.primedColumns++
  29. }
  30. function reset() {
  31. if (d.currentViewFilename) {
  32. globalVars.reset()
  33. artViewLoader.source = ""
  34. artViewLoader.source = d.currentViewFilename
  35. itemCount = currentColumn = d.primedColumns = 0
  36. }
  37. }
  38. function columnSelection() {
  39. if (globalSettings.commonFeedRoundRobin) {
  40. var ret = currentColumn
  41. currentColumn = (currentColumn + 1) % globalSettings.columnCount
  42. return ret
  43. } else {
  44. return Math.floor(Math.random()*globalSettings.columnCount)
  45. }
  46. }
  47. function columnWidthRatio(ratio, col) {
  48. return (1 - ratio)/(1 - Math.pow(ratio, col))
  49. }
  50. }
  51. QtObject {
  52. id: d
  53. property int primedColumns: 0
  54. property string currentViewFilename
  55. property string overrideViewFilename
  56. property bool displayUnlicensed: false
  57. function setView(view) {
  58. d.currentViewFilename = deriveViewPath(overrideViewFilename.length ? overrideViewFilename : view)
  59. }
  60. function deriveViewPath(view) {
  61. return "views/" + view.toLowerCase() + "/" + view + ".qml"
  62. }
  63. onCurrentViewFilenameChanged: {
  64. globalUtil.reset()
  65. }
  66. }
  67. Settings {
  68. id: globalSettings
  69. // This colCount + col ratio requires 700M graphical mem at 1080p on the pi
  70. property int columnCount: 8
  71. property int interval: 5
  72. property int itemLimit: -1
  73. property string effect: ""
  74. property string view: "Reel"
  75. property string backdrop: ""
  76. property bool smoothArt: false
  77. property bool randomlyMirrorArt: false
  78. property bool commonFeed: true
  79. property bool commonFeedRoundRobin: true
  80. property bool unlicensed: false
  81. property bool fadeInImages: true
  82. property bool useGoldenRatio: false
  83. property bool infoTray: false
  84. property bool rebootNecessary: true
  85. property real randomlyMirrorArtFreq: 0.5
  86. property real artOpacity: 1.0
  87. property real lessGoldenRatio: 1.4
  88. onColumnCountChanged: globalUtil.reset()
  89. Component.onCompleted: {
  90. d.setView(view)
  91. }
  92. }
  93. Item {
  94. id: root
  95. focus: true
  96. anchors.fill: parent
  97. Keys.forwardTo: [artViewLoader.item, toplevelhandler]
  98. Loader {
  99. id: artViewLoader
  100. z: 1
  101. anchors.fill: parent
  102. }
  103. Component.onCompleted: {
  104. if (globalSettings.backdrop != "") {
  105. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent }', root)
  106. }
  107. if (globalSettings.rebootNecessary) {
  108. Qt.createQmlObject('RebootReq { z: 2; anchors { top: parent.top; right: parent.right } }', root)
  109. }
  110. if (globalSettings.infoTray) {
  111. Qt.createQmlObject('InfoTray { z: 2; anchors { bottom: parent.bottom; left: parent.left } }', root)
  112. }
  113. if (globalSettings.unlicensed) {
  114. Qt.createQmlObject('Unlicensed { z: 3 }', root)
  115. }
  116. }
  117. }
  118. Item {
  119. id: toplevelhandler
  120. focus: true
  121. Keys.onPressed: {
  122. switch(event.key) {
  123. case Qt.Key_Left:
  124. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  125. break;
  126. case Qt.Key_Right:
  127. globalSettings.columnCount++;
  128. break;
  129. case Qt.Key_Escape:
  130. Qt.quit();
  131. break;
  132. case Qt.Key_F10:
  133. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  134. break;
  135. default:
  136. console.log('Key not handled')
  137. }
  138. }
  139. }
  140. Component.onCompleted: appWindow.setFocus()
  141. }