main.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. width: 1280
  8. height: 720
  9. onWidthChanged: {
  10. globalUtil.reset()
  11. }
  12. function showAtCorrectSize() {
  13. globalSettings.fullscreen ? showFullScreen() : show()
  14. }
  15. PictureModel {
  16. id: imageModel
  17. }
  18. QtObject {
  19. id: globalVars
  20. property real goldenRatio
  21. property real imageWidthOverride
  22. property bool globalDeathTimer
  23. function reset() {
  24. goldenRatio = 1.61803398875
  25. imageWidthOverride = -1
  26. globalDeathTimer = false
  27. }
  28. Component.onCompleted: reset()
  29. }
  30. QtObject {
  31. id: globalUtil
  32. property int itemCount
  33. property int currentColumn: 0
  34. property bool primed: d.primedColumns === globalSettings.columnCount
  35. property int adjustedInterval: 1000*(globalSettings.interval > 60 ? 60*(globalSettings.interval-60) : Math.max(globalSettings.interval, 1))
  36. function registerColumnPrimed() {
  37. d.primedColumns++
  38. }
  39. function reset() {
  40. if (d.currentViewFilename) {
  41. globalVars.reset()
  42. artViewLoader.source = ""
  43. artViewLoader.source = d.currentViewFilename
  44. itemCount = currentColumn = d.primedColumns = 0
  45. }
  46. }
  47. function columnSelection() {
  48. if (globalSettings.commonFeedRoundRobin) {
  49. var ret = currentColumn
  50. currentColumn = (currentColumn + 1) % globalSettings.columnCount
  51. return ret
  52. } else {
  53. return Math.floor(Math.random()*globalSettings.columnCount)
  54. }
  55. }
  56. function columnWidthRatio(ratio, col) {
  57. return (1 - ratio)/(1 - Math.pow(ratio, col))
  58. }
  59. }
  60. QtObject {
  61. id: d
  62. property int primedColumns: 0
  63. property string timeString
  64. property string day
  65. property string month
  66. property string currentViewFilename
  67. property string overrideViewFilename
  68. property bool displayUnlicensed: false
  69. function setView(view) {
  70. d.currentViewFilename = deriveViewPath(overrideViewFilename.length ? overrideViewFilename : view)
  71. }
  72. function deriveViewPath(view) {
  73. return view.toLowerCase() + "/" + view + ".qml"
  74. }
  75. function timeChanged() {
  76. var date = new Date;
  77. timeString = Qt.formatDateTime(date, "hh:mm")
  78. day = Qt.formatDateTime(date, "dd")
  79. month = Qt.formatDateTime(date, "MM")
  80. }
  81. property variant timeTimer: Timer {
  82. interval: 1000; running: true; repeat: true;
  83. onTriggered: d.timeChanged()
  84. }
  85. onCurrentViewFilenameChanged: {
  86. globalUtil.reset()
  87. }
  88. }
  89. Settings {
  90. id: globalSettings
  91. property int columnCount: 6
  92. property int interval: 5
  93. property bool showViewItemCount: false
  94. property bool showScreenResolution: false
  95. property string effect: ""
  96. property string view: "Reel"
  97. property string backdrop: ""
  98. property bool smoothArt: false
  99. property bool randomlyMirrorArt: true
  100. property bool fullscreen: true
  101. property bool clockWidget: false
  102. property real clockIntensity: 0.6
  103. property bool commonFeed: true
  104. property bool commonFeedRoundRobin: true
  105. property bool unlicensed: false
  106. property real artOpacity: 1.0
  107. property bool fadeInImages: true
  108. property bool animatedBackground: false
  109. property bool useGoldenRatio: false
  110. //property real lessGoldenRatio: 1.25
  111. property real lessGoldenRatio: 1.35
  112. onColumnCountChanged: globalUtil.reset()
  113. onFullscreenChanged: showAtCorrectSize()
  114. Component.onCompleted: {
  115. d.setView(view)
  116. }
  117. }
  118. Item {
  119. id: root
  120. focus: true
  121. anchors.fill: parent
  122. Keys.forwardTo: [artViewLoader.item, toplevelhandler]
  123. Loader {
  124. id: artViewLoader
  125. anchors.fill: parent
  126. }
  127. Rectangle {
  128. id: clock
  129. width: childrenRect.width
  130. opacity: 0.7
  131. color: "black"
  132. visible: height > 0
  133. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  134. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  135. Text {
  136. //anchors.centerIn: parent
  137. id: clockLabel
  138. color: "white"
  139. font.bold: true
  140. font.pixelSize: parent.height
  141. text: d.timeString
  142. }
  143. Item {
  144. anchors { left: clockLabel.right; leftMargin: 20 }
  145. height: clock.height
  146. width: childrenRect.width
  147. Item {
  148. width: childrenRect.width
  149. height: parent.height/2
  150. Text {
  151. anchors.centerIn: parent
  152. color: "white"
  153. font.bold: true
  154. verticalAlignment: Text.AlignVCenter
  155. horizontalAlignment: Text.AlignHCenter
  156. font.pixelSize: clock.height/3
  157. text: d.day
  158. }
  159. }
  160. Item {
  161. y: parent.height/2
  162. width: childrenRect.width
  163. height: parent.height/2
  164. Text {
  165. anchors.centerIn: parent
  166. color: "white"
  167. font.bold: true
  168. verticalAlignment: Text.AlignVCenter
  169. horizontalAlignment: Text.AlignHCenter
  170. font.pixelSize: clock.height/3
  171. text: d.month
  172. }
  173. }
  174. }
  175. }
  176. Component.onCompleted: {
  177. if (globalSettings.backdrop != "") {
  178. Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent}', root)
  179. }
  180. }
  181. }
  182. Item {
  183. id: toplevelhandler
  184. focus: true
  185. Keys.onPressed: {
  186. switch(event.key) {
  187. case Qt.Key_F:
  188. globalSettings.fullscreen = !globalSettings.fullscreen
  189. break;
  190. case Qt.Key_Left:
  191. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  192. break;
  193. case Qt.Key_Right:
  194. globalSettings.columnCount++;
  195. break;
  196. case Qt.Key_Escape:
  197. Qt.quit();
  198. break;
  199. case Qt.Key_F10:
  200. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  201. break;
  202. default:
  203. console.log('Key not handled')
  204. }
  205. }
  206. }
  207. Rectangle {
  208. z: 1
  209. opacity: 0.5
  210. visible: globalSettings.showViewItemCount
  211. color: "black"
  212. anchors { right: parent.right; top: parent.top }
  213. width: itemCountLabel.width
  214. height: itemCountLabel.height
  215. Text {
  216. id: itemCountLabel
  217. font.pixelSize: 100
  218. text: globalUtil.itemCount
  219. color: "white"
  220. }
  221. }
  222. Rectangle {
  223. z: 1
  224. opacity: 0.5
  225. visible: globalSettings.showScreenResolution
  226. color: "black"
  227. anchors { right: parent.right; top: parent.top }
  228. width: resolutionLabel.width
  229. height: resolutionLabel.height
  230. Text {
  231. id: resolutionLabel
  232. font.pixelSize: 100
  233. text: screenSize.width + "x" + screenSize.height
  234. color: "white"
  235. }
  236. }
  237. Component.onCompleted: {
  238. showTimer.start()
  239. }
  240. Item {
  241. z: 1
  242. visible: d.displayUnlicensed
  243. anchors { right: parent.right; bottom: parent.bottom }
  244. width: appWindow.width/2
  245. height: appWindow.height/2
  246. Text {
  247. z: 1
  248. color: "white"
  249. font.pointSize: 60
  250. anchors { horizontalCenter: parent.horizontalCenter; top: parent.top }
  251. text: "UNLICENCED"
  252. }
  253. Image {
  254. id: mug
  255. property int revolutions: 1000000
  256. fillMode: Image.PreserveAspectFit
  257. height: appWindow.height/2
  258. anchors { centerIn: parent }
  259. source: "qrc:///unlicensed.png"
  260. RotationAnimator {
  261. target: mug;
  262. from: 0;
  263. to: 360*mug.revolutions
  264. duration: 2000*mug.revolutions
  265. running: mug.visible
  266. }
  267. }
  268. Text {
  269. z: 1
  270. color: "white"
  271. font.pointSize: 60
  272. anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom }
  273. text: "COPY"
  274. }
  275. }
  276. Timer {
  277. id: showTimer
  278. running: false
  279. repeat: false
  280. interval: 1
  281. onTriggered: {
  282. showAtCorrectSize()
  283. }
  284. }
  285. Timer {
  286. running: true
  287. interval: 60*1000
  288. onTriggered: {
  289. if (globalSettings.unlicensed) {
  290. d.displayUnlicensed = true
  291. }
  292. }
  293. }
  294. FPSMonitor {
  295. anchors { top: parent.top; right: parent.right }
  296. }
  297. }