main.qml 4.8 KB

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