main.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import QtQuick 2.5
  2. import QtQuick.Window 2.2
  3. import Qt.labs.settings 1.0
  4. import PictureModel 1.0
  5. import "."
  6. Window {
  7. id: appWindow
  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. loader.source = ""
  44. loader.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 bool smoothArt: true
  99. property bool randomlyMirrorArt: false
  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 randomTapestryColour: false
  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. Rectangle {
  120. focus: true
  121. color: "black"
  122. anchors.fill: parent
  123. Keys.forwardTo: [loader.item, toplevelhandler]
  124. BackgroundSwirls {
  125. visible: globalSettings.animatedBackground
  126. anchors.fill: parent
  127. }
  128. Loader {
  129. id: loader
  130. anchors.fill: parent
  131. }
  132. Rectangle {
  133. id: clock
  134. width: childrenRect.width
  135. opacity: 0.7
  136. color: "black"
  137. visible: height > 0
  138. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  139. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  140. Text {
  141. //anchors.centerIn: parent
  142. id: clockLabel
  143. color: "white"
  144. font.bold: true
  145. font.pixelSize: parent.height
  146. text: d.timeString
  147. }
  148. Item {
  149. anchors { left: clockLabel.right; leftMargin: 20 }
  150. height: clock.height
  151. width: childrenRect.width
  152. Item {
  153. width: childrenRect.width
  154. height: parent.height/2
  155. Text {
  156. anchors.centerIn: parent
  157. color: "white"
  158. font.bold: true
  159. verticalAlignment: Text.AlignVCenter
  160. horizontalAlignment: Text.AlignHCenter
  161. font.pixelSize: clock.height/3
  162. text: d.day
  163. }
  164. }
  165. Item {
  166. y: parent.height/2
  167. width: childrenRect.width
  168. height: parent.height/2
  169. Text {
  170. anchors.centerIn: parent
  171. color: "white"
  172. font.bold: true
  173. verticalAlignment: Text.AlignVCenter
  174. horizontalAlignment: Text.AlignHCenter
  175. font.pixelSize: clock.height/3
  176. text: d.month
  177. }
  178. }
  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. }