main.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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: 1024
  8. height: 768
  9. onWidthChanged: {
  10. globalUtil.reset()
  11. }
  12. PictureModel {
  13. id: imageModel
  14. }
  15. QtObject {
  16. id: globalVars
  17. property real goldenRatio
  18. property real imageWidthOverride
  19. property bool globalDeathTimer
  20. function reset() {
  21. goldenRatio = 1.61803398875
  22. imageWidthOverride = -1
  23. globalDeathTimer = false
  24. }
  25. Component.onCompleted: reset()
  26. }
  27. QtObject {
  28. id: globalUtil
  29. property int itemCount
  30. property int currentColumn: 0
  31. property bool primed: d.primedColumns === globalSettings.columnCount
  32. property int adjustedInterval: 1000*(globalSettings.interval > 60 ? 60*(globalSettings.interval-60) : Math.max(globalSettings.interval, 1))
  33. function registerColumnPrimed() {
  34. d.primedColumns++
  35. }
  36. function reset() {
  37. if (d.currentViewFilename) {
  38. globalVars.reset()
  39. loader.source = ""
  40. loader.source = d.currentViewFilename
  41. itemCount = currentColumn = d.primedColumns = 0
  42. }
  43. }
  44. function columnSelection() {
  45. if (globalSettings.commonFeedRoundRobin) {
  46. var ret = currentColumn
  47. currentColumn = (currentColumn + 1) % globalSettings.columnCount
  48. return ret
  49. } else {
  50. return Math.floor(Math.random()*globalSettings.columnCount)
  51. }
  52. }
  53. function columnWidthRatio(ratio, col) {
  54. return (1 - ratio)/(1 - Math.pow(ratio, col))
  55. }
  56. }
  57. QtObject {
  58. id: d
  59. property int primedColumns: 0
  60. property string timeString
  61. property string day
  62. property string month
  63. property string currentViewFilename
  64. property string overrideViewFilename: "Procession"
  65. function setView(view) {
  66. d.currentViewFilename = deriveViewPath(overrideViewFilename.length ? overrideViewFilename : view)
  67. }
  68. function deriveViewPath(view) {
  69. return view.toLowerCase() + "/" + view + ".qml"
  70. }
  71. function timeChanged() {
  72. var date = new Date;
  73. timeString = Qt.formatDateTime(date, "hh:mm")
  74. day = Qt.formatDateTime(date, "dd")
  75. month = Qt.formatDateTime(date, "MM")
  76. }
  77. property variant timeTimer: Timer {
  78. interval: 1000; running: true; repeat: true;
  79. onTriggered: d.timeChanged()
  80. }
  81. onCurrentViewFilenameChanged: {
  82. globalUtil.reset()
  83. }
  84. }
  85. Settings {
  86. id: globalSettings
  87. property int columnCount: 5
  88. property int interval: 5
  89. property bool showViewItemCount: false
  90. property bool showScreenResolution: false
  91. property string effect: ""
  92. property string view: "Cascade"
  93. property bool smoothArt: true
  94. property bool randomlyMirrorArt: false
  95. property bool fullscreen: true
  96. property bool clockWidget: false
  97. property real clockIntensity: 0.6
  98. property bool commonFeed: true
  99. property bool commonFeedRoundRobin: true
  100. property real artOpacity: 1.0
  101. property bool randomTapestryColour: false
  102. property bool fadeInImages: true
  103. property bool useGoldenRatio: true
  104. property real lessGoldenRatio: 1.25
  105. onColumnCountChanged: globalUtil.reset()
  106. Component.onCompleted: {
  107. d.setView(view)
  108. }
  109. }
  110. Rectangle {
  111. focus: true
  112. color: "black"
  113. anchors.fill: parent
  114. Keys.forwardTo: [loader.item, toplevelhandler]
  115. Loader {
  116. id: loader
  117. anchors.fill: parent
  118. }
  119. Rectangle {
  120. id: clock
  121. width: childrenRect.width
  122. opacity: 0.7
  123. color: "black"
  124. visible: height > 0
  125. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  126. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  127. Text {
  128. //anchors.centerIn: parent
  129. id: clockLabel
  130. color: "white"
  131. font.bold: true
  132. font.pixelSize: parent.height
  133. text: d.timeString
  134. }
  135. Item {
  136. anchors { left: clockLabel.right; leftMargin: 20 }
  137. height: clock.height
  138. width: childrenRect.width
  139. Item {
  140. width: childrenRect.width
  141. height: parent.height/2
  142. Text {
  143. anchors.centerIn: parent
  144. color: "white"
  145. font.bold: true
  146. verticalAlignment: Text.AlignVCenter
  147. horizontalAlignment: Text.AlignHCenter
  148. font.pixelSize: clock.height/3
  149. text: d.day
  150. }
  151. }
  152. Item {
  153. y: parent.height/2
  154. width: childrenRect.width
  155. height: parent.height/2
  156. Text {
  157. anchors.centerIn: parent
  158. color: "white"
  159. font.bold: true
  160. verticalAlignment: Text.AlignVCenter
  161. horizontalAlignment: Text.AlignHCenter
  162. font.pixelSize: clock.height/3
  163. text: d.month
  164. }
  165. }
  166. }
  167. }
  168. }
  169. Item {
  170. id: toplevelhandler
  171. focus: true
  172. Keys.onPressed: {
  173. switch(event.key) {
  174. case Qt.Key_Left:
  175. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  176. break;
  177. case Qt.Key_Right:
  178. globalSettings.columnCount++;
  179. break;
  180. case Qt.Key_Escape:
  181. Qt.quit();
  182. break;
  183. case Qt.Key_F10:
  184. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  185. break;
  186. default:
  187. console.log('Key not handled')
  188. }
  189. }
  190. }
  191. Rectangle {
  192. z: 1
  193. opacity: 0.5
  194. visible: globalSettings.showViewItemCount
  195. color: "black"
  196. anchors { right: parent.right; top: parent.top }
  197. width: itemCountLabel.width
  198. height: itemCountLabel.height
  199. Text {
  200. id: itemCountLabel
  201. font.pixelSize: 100
  202. text: globalUtil.itemCount
  203. color: "white"
  204. }
  205. }
  206. Rectangle {
  207. z: 1
  208. opacity: 0.5
  209. visible: globalSettings.showScreenResolution
  210. color: "black"
  211. anchors { right: parent.right; top: parent.top }
  212. width: resolutionLabel.width
  213. height: resolutionLabel.height
  214. Text {
  215. id: resolutionLabel
  216. font.pixelSize: 100
  217. text: screenSize.width + "x" + screenSize.height
  218. color: "white"
  219. }
  220. }
  221. Component.onCompleted: {
  222. globalSettings.fullscreen ? showFullScreen() : show()
  223. }
  224. }