main.qml 4.7 KB

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