main.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 int artFrameWidth: 0
  73. property string effect: ""
  74. property string artView: "Trivial"
  75. property string backdrop
  76. property bool randomBackdropColor: false
  77. property bool smoothArt: false
  78. property bool randomlyMirrorArt: false
  79. property bool commonFeed: true
  80. property bool commonFeedRoundRobin: true
  81. property bool unlicensed: false
  82. property bool fadeInImages: true
  83. property bool useGoldenRatio: false
  84. property bool infoTray: false
  85. property bool rebootNecessary: true
  86. property real randomlyMirrorArtFreq: 0.5
  87. property real artOpacity: 1.0
  88. property real lessGoldenRatio: 1.4
  89. onColumnCountChanged: globalUtil.reset()
  90. Component.onCompleted: {
  91. d.setView(artView)
  92. }
  93. }
  94. Item {
  95. id: root
  96. focus: true
  97. anchors.fill: parent
  98. Keys.forwardTo: [artViewLoader.item, toplevelhandler]
  99. Loader {
  100. id: artViewLoader
  101. z: 1
  102. anchors.fill: parent
  103. }
  104. Component.onCompleted: {
  105. if (globalSettings.backdrop != "") {
  106. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent }', root)
  107. }
  108. if (globalSettings.rebootNecessary) {
  109. Qt.createQmlObject('RebootReq { z: 2; anchors { top: parent.top; right: parent.right } }', root)
  110. }
  111. if (globalSettings.infoTray) {
  112. Qt.createQmlObject('InfoTray { z: 2; anchors { bottom: parent.bottom; left: parent.left } }', root)
  113. }
  114. if (globalSettings.unlicensed) {
  115. Qt.createQmlObject('Unlicensed { z: 3 }', root)
  116. }
  117. }
  118. }
  119. Item {
  120. id: toplevelhandler
  121. focus: true
  122. Keys.onPressed: {
  123. switch(event.key) {
  124. case Qt.Key_Left:
  125. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  126. break;
  127. case Qt.Key_Right:
  128. globalSettings.columnCount++;
  129. break;
  130. case Qt.Key_Escape:
  131. Qt.quit();
  132. break;
  133. case Qt.Key_F10:
  134. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  135. break;
  136. default:
  137. console.log('Key not handled')
  138. }
  139. }
  140. }
  141. Component.onCompleted: appWindow.setFocus()
  142. }