main.qml 5.1 KB

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