main.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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: 1
  73. property string effect: ""
  74. property string artView: "Trivial"
  75. property string backdrop: "Swirls"
  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(artView)
  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. }