main.qml 5.3 KB

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