main.qml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 timeString
  65. property string day
  66. property string month
  67. property string currentViewFilename
  68. property string overrideViewFilename
  69. property bool displayUnlicensed: false
  70. function setView(view) {
  71. d.currentViewFilename = deriveViewPath(overrideViewFilename.length ? overrideViewFilename : view)
  72. }
  73. function deriveViewPath(view) {
  74. return view.toLowerCase() + "/" + view + ".qml"
  75. }
  76. function timeChanged() {
  77. var date = new Date;
  78. timeString = Qt.formatDateTime(date, "hh:mm")
  79. day = Qt.formatDateTime(date, "dd")
  80. month = Qt.formatDateTime(date, "MM")
  81. }
  82. property variant timeTimer: Timer {
  83. interval: 1000; running: true; repeat: true;
  84. onTriggered: d.timeChanged()
  85. }
  86. onCurrentViewFilenameChanged: {
  87. globalUtil.reset()
  88. }
  89. }
  90. Settings {
  91. id: globalSettings
  92. property int columnCount: 6
  93. property int interval: 5
  94. property bool showViewItemCount: false
  95. property bool showScreenResolution: false
  96. property string effect: ""
  97. property string view: "Reel"
  98. property string backdrop: ""
  99. property bool smoothArt: false
  100. property bool randomlyMirrorArt: true
  101. property bool fullscreen: true
  102. property bool clockWidget: false
  103. property real clockIntensity: 0.6
  104. property bool commonFeed: true
  105. property bool commonFeedRoundRobin: true
  106. property bool unlicensed: false
  107. property real artOpacity: 1.0
  108. property bool fadeInImages: true
  109. property bool animatedBackground: false
  110. property bool useGoldenRatio: false
  111. //property real lessGoldenRatio: 1.25
  112. property real lessGoldenRatio: 1.35
  113. onColumnCountChanged: globalUtil.reset()
  114. onFullscreenChanged: showAtCorrectSize()
  115. Component.onCompleted: {
  116. d.setView(view)
  117. }
  118. }
  119. Item {
  120. id: root
  121. focus: true
  122. anchors.fill: parent
  123. Keys.forwardTo: [artViewLoader.item, toplevelhandler]
  124. Loader {
  125. id: artViewLoader
  126. z: 1
  127. anchors.fill: parent
  128. }
  129. Rectangle {
  130. id: clock
  131. width: childrenRect.width
  132. opacity: 0.7
  133. color: "black"
  134. visible: height > 0
  135. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  136. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  137. Text {
  138. //anchors.centerIn: parent
  139. id: clockLabel
  140. color: "white"
  141. font.bold: true
  142. font.pixelSize: parent.height
  143. text: d.timeString
  144. }
  145. Item {
  146. anchors { left: clockLabel.right; leftMargin: 20 }
  147. height: clock.height
  148. width: childrenRect.width
  149. Item {
  150. width: childrenRect.width
  151. height: parent.height/2
  152. Text {
  153. anchors.centerIn: parent
  154. color: "white"
  155. font.bold: true
  156. verticalAlignment: Text.AlignVCenter
  157. horizontalAlignment: Text.AlignHCenter
  158. font.pixelSize: clock.height/3
  159. text: d.day
  160. }
  161. }
  162. Item {
  163. y: parent.height/2
  164. width: childrenRect.width
  165. height: parent.height/2
  166. Text {
  167. anchors.centerIn: parent
  168. color: "white"
  169. font.bold: true
  170. verticalAlignment: Text.AlignVCenter
  171. horizontalAlignment: Text.AlignHCenter
  172. font.pixelSize: clock.height/3
  173. text: d.month
  174. }
  175. }
  176. }
  177. }
  178. Component.onCompleted: {
  179. if (globalSettings.backdrop != "") {
  180. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent}', root)
  181. }
  182. if (globalSettings.unlicensed) {
  183. Qt.createQmlObject('Unlicensed { z: 2 }', root)
  184. }
  185. }
  186. }
  187. Item {
  188. id: toplevelhandler
  189. focus: true
  190. Keys.onPressed: {
  191. switch(event.key) {
  192. case Qt.Key_F:
  193. globalSettings.fullscreen = !globalSettings.fullscreen
  194. break;
  195. case Qt.Key_Left:
  196. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  197. break;
  198. case Qt.Key_Right:
  199. globalSettings.columnCount++;
  200. break;
  201. case Qt.Key_Escape:
  202. Qt.quit();
  203. break;
  204. case Qt.Key_F10:
  205. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  206. break;
  207. default:
  208. console.log('Key not handled')
  209. }
  210. }
  211. }
  212. Rectangle {
  213. z: 1
  214. opacity: 0.5
  215. visible: globalSettings.showViewItemCount
  216. color: "black"
  217. anchors { right: parent.right; top: parent.top }
  218. width: itemCountLabel.width
  219. height: itemCountLabel.height
  220. Text {
  221. id: itemCountLabel
  222. font.pixelSize: 100
  223. text: globalUtil.itemCount
  224. color: "white"
  225. }
  226. }
  227. Rectangle {
  228. z: 1
  229. opacity: 0.5
  230. visible: globalSettings.showScreenResolution
  231. color: "black"
  232. anchors { right: parent.right; top: parent.top }
  233. width: resolutionLabel.width
  234. height: resolutionLabel.height
  235. Text {
  236. id: resolutionLabel
  237. font.pixelSize: 100
  238. text: screenSize.width + "x" + screenSize.height
  239. color: "white"
  240. }
  241. }
  242. Component.onCompleted: {
  243. showTimer.start()
  244. }
  245. Timer {
  246. id: showTimer
  247. running: false
  248. repeat: false
  249. interval: 1
  250. onTriggered: {
  251. showAtCorrectSize()
  252. }
  253. }
  254. FPSMonitor {
  255. anchors { top: parent.top; right: parent.right }
  256. }
  257. }