main.qml 9.1 KB

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