main.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 widgetTray: false
  94. property real randomlyMirrorArtFreq: 0.5
  95. property real artOpacity: 1.0
  96. property real lessGoldenRatio: 4/3
  97. onColumnCountChanged: globalUtil.reset()
  98. onFullscreenChanged: showAtCorrectSize()
  99. Component.onCompleted: {
  100. d.setView(view)
  101. }
  102. }
  103. Item {
  104. id: root
  105. focus: true
  106. anchors.fill: parent
  107. Keys.forwardTo: [artViewLoader.item, toplevelhandler]
  108. Loader {
  109. id: artViewLoader
  110. z: 1
  111. anchors.fill: parent
  112. }
  113. Component.onCompleted: {
  114. if (globalSettings.backdrop != "") {
  115. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent }', root)
  116. }
  117. if (globalSettings.widgetTray) {
  118. Qt.createQmlObject('WidgetTray { z: 2; anchors { top: parent.top; right: parent.right } }', root)
  119. }
  120. if (globalSettings.unlicensed) {
  121. Qt.createQmlObject('Unlicensed { z: 3 }', root)
  122. }
  123. }
  124. }
  125. Item {
  126. id: toplevelhandler
  127. focus: true
  128. Keys.onPressed: {
  129. switch(event.key) {
  130. case Qt.Key_F:
  131. globalSettings.fullscreen = !globalSettings.fullscreen
  132. break;
  133. case Qt.Key_Left:
  134. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  135. break;
  136. case Qt.Key_Right:
  137. globalSettings.columnCount++;
  138. break;
  139. case Qt.Key_Escape:
  140. Qt.quit();
  141. break;
  142. case Qt.Key_F10:
  143. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  144. break;
  145. default:
  146. console.log('Key not handled')
  147. }
  148. }
  149. }
  150. Component.onCompleted: {
  151. showTimer.start()
  152. }
  153. Timer {
  154. id: showTimer
  155. running: false
  156. repeat: false
  157. interval: 1
  158. onTriggered: {
  159. showAtCorrectSize()
  160. }
  161. }
  162. }