main.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. anchors.fill: parent
  127. }
  128. Rectangle {
  129. id: clock
  130. width: childrenRect.width
  131. opacity: 0.7
  132. color: "black"
  133. visible: height > 0
  134. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  135. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  136. Text {
  137. //anchors.centerIn: parent
  138. id: clockLabel
  139. color: "white"
  140. font.bold: true
  141. font.pixelSize: parent.height
  142. text: d.timeString
  143. }
  144. Item {
  145. anchors { left: clockLabel.right; leftMargin: 20 }
  146. height: clock.height
  147. width: childrenRect.width
  148. Item {
  149. width: childrenRect.width
  150. height: parent.height/2
  151. Text {
  152. anchors.centerIn: parent
  153. color: "white"
  154. font.bold: true
  155. verticalAlignment: Text.AlignVCenter
  156. horizontalAlignment: Text.AlignHCenter
  157. font.pixelSize: clock.height/3
  158. text: d.day
  159. }
  160. }
  161. Item {
  162. y: parent.height/2
  163. width: childrenRect.width
  164. height: parent.height/2
  165. Text {
  166. anchors.centerIn: parent
  167. color: "white"
  168. font.bold: true
  169. verticalAlignment: Text.AlignVCenter
  170. horizontalAlignment: Text.AlignHCenter
  171. font.pixelSize: clock.height/3
  172. text: d.month
  173. }
  174. }
  175. }
  176. }
  177. Component.onCompleted: {
  178. if (globalSettings.backdrop != "") {
  179. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent}', root)
  180. }
  181. }
  182. }
  183. Item {
  184. id: toplevelhandler
  185. focus: true
  186. Keys.onPressed: {
  187. switch(event.key) {
  188. case Qt.Key_F:
  189. globalSettings.fullscreen = !globalSettings.fullscreen
  190. break;
  191. case Qt.Key_Left:
  192. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  193. break;
  194. case Qt.Key_Right:
  195. globalSettings.columnCount++;
  196. break;
  197. case Qt.Key_Escape:
  198. Qt.quit();
  199. break;
  200. case Qt.Key_F10:
  201. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  202. break;
  203. default:
  204. console.log('Key not handled')
  205. }
  206. }
  207. }
  208. Rectangle {
  209. z: 1
  210. opacity: 0.5
  211. visible: globalSettings.showViewItemCount
  212. color: "black"
  213. anchors { right: parent.right; top: parent.top }
  214. width: itemCountLabel.width
  215. height: itemCountLabel.height
  216. Text {
  217. id: itemCountLabel
  218. font.pixelSize: 100
  219. text: globalUtil.itemCount
  220. color: "white"
  221. }
  222. }
  223. Rectangle {
  224. z: 1
  225. opacity: 0.5
  226. visible: globalSettings.showScreenResolution
  227. color: "black"
  228. anchors { right: parent.right; top: parent.top }
  229. width: resolutionLabel.width
  230. height: resolutionLabel.height
  231. Text {
  232. id: resolutionLabel
  233. font.pixelSize: 100
  234. text: screenSize.width + "x" + screenSize.height
  235. color: "white"
  236. }
  237. }
  238. Component.onCompleted: {
  239. showTimer.start()
  240. }
  241. Item {
  242. z: 1
  243. visible: d.displayUnlicensed
  244. anchors { right: parent.right; bottom: parent.bottom }
  245. width: appWindow.width/2
  246. height: appWindow.height/2
  247. Text {
  248. z: 1
  249. color: "white"
  250. font.pointSize: 60
  251. anchors { horizontalCenter: parent.horizontalCenter; top: parent.top }
  252. text: "UNLICENCED"
  253. }
  254. Image {
  255. id: mug
  256. property int revolutions: 1000000
  257. fillMode: Image.PreserveAspectFit
  258. height: appWindow.height/2
  259. anchors { centerIn: parent }
  260. source: "qrc:///unlicensed.png"
  261. RotationAnimator {
  262. target: mug;
  263. from: 0;
  264. to: 360*mug.revolutions
  265. duration: 2000*mug.revolutions
  266. running: mug.visible
  267. }
  268. }
  269. Text {
  270. z: 1
  271. color: "white"
  272. font.pointSize: 60
  273. anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom }
  274. text: "COPY"
  275. }
  276. }
  277. Timer {
  278. id: showTimer
  279. running: false
  280. repeat: false
  281. interval: 1
  282. onTriggered: {
  283. showAtCorrectSize()
  284. }
  285. }
  286. Timer {
  287. running: true
  288. interval: 60*1000
  289. onTriggered: {
  290. if (globalSettings.unlicensed) {
  291. d.displayUnlicensed = true
  292. }
  293. }
  294. }
  295. FPSMonitor {
  296. anchors { top: parent.top; right: parent.right }
  297. }
  298. }