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