main.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. property int columnCount: 6
  70. property int interval: 5
  71. property int itemLimit: -1
  72. property string effect: ""
  73. property string view: "Reel"
  74. property string backdrop: ""
  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: 4/3
  87. onColumnCountChanged: globalUtil.reset()
  88. Component.onCompleted: {
  89. d.setView(view)
  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. }