main.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. function setView(view) {
  69. d.currentViewFilename = deriveViewPath(overrideViewFilename.length ? overrideViewFilename : view)
  70. }
  71. function deriveViewPath(view) {
  72. return view.toLowerCase() + "/" + view + ".qml"
  73. }
  74. function timeChanged() {
  75. var date = new Date;
  76. timeString = Qt.formatDateTime(date, "hh:mm")
  77. day = Qt.formatDateTime(date, "dd")
  78. month = Qt.formatDateTime(date, "MM")
  79. }
  80. property variant timeTimer: Timer {
  81. interval: 1000; running: true; repeat: true;
  82. onTriggered: d.timeChanged()
  83. }
  84. onCurrentViewFilenameChanged: {
  85. globalUtil.reset()
  86. }
  87. }
  88. Settings {
  89. id: globalSettings
  90. property int columnCount: 6
  91. property int interval: 5
  92. property bool showViewItemCount: false
  93. property bool showScreenResolution: false
  94. property string effect: ""
  95. property string view: "Reel"
  96. property bool smoothArt: true
  97. property bool randomlyMirrorArt: false
  98. property bool fullscreen: true
  99. property bool clockWidget: false
  100. property real clockIntensity: 0.6
  101. property bool commonFeed: true
  102. property bool commonFeedRoundRobin: true
  103. property real artOpacity: 1.0
  104. property bool randomTapestryColour: false
  105. property bool fadeInImages: true
  106. property bool useGoldenRatio: false
  107. //property real lessGoldenRatio: 1.25
  108. property real lessGoldenRatio: 1.35
  109. onColumnCountChanged: globalUtil.reset()
  110. onFullscreenChanged: showAtCorrectSize()
  111. Component.onCompleted: {
  112. d.setView(view)
  113. }
  114. }
  115. Rectangle {
  116. focus: true
  117. color: "black"
  118. anchors.fill: parent
  119. Keys.forwardTo: [loader.item, toplevelhandler]
  120. Loader {
  121. id: loader
  122. anchors.fill: parent
  123. }
  124. Rectangle {
  125. id: clock
  126. width: childrenRect.width
  127. opacity: 0.7
  128. color: "black"
  129. visible: height > 0
  130. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  131. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  132. Text {
  133. //anchors.centerIn: parent
  134. id: clockLabel
  135. color: "white"
  136. font.bold: true
  137. font.pixelSize: parent.height
  138. text: d.timeString
  139. }
  140. Item {
  141. anchors { left: clockLabel.right; leftMargin: 20 }
  142. height: clock.height
  143. width: childrenRect.width
  144. Item {
  145. width: childrenRect.width
  146. height: parent.height/2
  147. Text {
  148. anchors.centerIn: parent
  149. color: "white"
  150. font.bold: true
  151. verticalAlignment: Text.AlignVCenter
  152. horizontalAlignment: Text.AlignHCenter
  153. font.pixelSize: clock.height/3
  154. text: d.day
  155. }
  156. }
  157. Item {
  158. y: parent.height/2
  159. width: childrenRect.width
  160. height: parent.height/2
  161. Text {
  162. anchors.centerIn: parent
  163. color: "white"
  164. font.bold: true
  165. verticalAlignment: Text.AlignVCenter
  166. horizontalAlignment: Text.AlignHCenter
  167. font.pixelSize: clock.height/3
  168. text: d.month
  169. }
  170. }
  171. }
  172. }
  173. }
  174. Item {
  175. id: toplevelhandler
  176. focus: true
  177. Keys.onPressed: {
  178. switch(event.key) {
  179. case Qt.Key_F:
  180. globalSettings.fullscreen = !globalSettings.fullscreen
  181. break;
  182. case Qt.Key_Left:
  183. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  184. break;
  185. case Qt.Key_Right:
  186. globalSettings.columnCount++;
  187. break;
  188. case Qt.Key_Escape:
  189. Qt.quit();
  190. break;
  191. case Qt.Key_F10:
  192. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  193. break;
  194. default:
  195. console.log('Key not handled')
  196. }
  197. }
  198. }
  199. Rectangle {
  200. z: 1
  201. opacity: 0.5
  202. visible: globalSettings.showViewItemCount
  203. color: "black"
  204. anchors { right: parent.right; top: parent.top }
  205. width: itemCountLabel.width
  206. height: itemCountLabel.height
  207. Text {
  208. id: itemCountLabel
  209. font.pixelSize: 100
  210. text: globalUtil.itemCount
  211. color: "white"
  212. }
  213. }
  214. Rectangle {
  215. z: 1
  216. opacity: 0.5
  217. visible: globalSettings.showScreenResolution
  218. color: "black"
  219. anchors { right: parent.right; top: parent.top }
  220. width: resolutionLabel.width
  221. height: resolutionLabel.height
  222. Text {
  223. id: resolutionLabel
  224. font.pixelSize: 100
  225. text: screenSize.width + "x" + screenSize.height
  226. color: "white"
  227. }
  228. }
  229. Component.onCompleted: {
  230. showAtCorrectSize()
  231. }
  232. }