main.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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
  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: 6
  88. property int interval: 5
  89. property bool showViewItemCount: false
  90. property bool showScreenResolution: false
  91. property string effect: ""
  92. property string view: "Reel"
  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: false
  104. //property real lessGoldenRatio: 1.25
  105. property real lessGoldenRatio: 1.35
  106. onColumnCountChanged: globalUtil.reset()
  107. Component.onCompleted: {
  108. d.setView(view)
  109. }
  110. }
  111. Rectangle {
  112. focus: true
  113. color: "black"
  114. anchors.fill: parent
  115. Keys.forwardTo: [loader.item, toplevelhandler]
  116. Loader {
  117. id: loader
  118. anchors.fill: parent
  119. }
  120. Rectangle {
  121. id: clock
  122. width: childrenRect.width
  123. opacity: 0.7
  124. color: "black"
  125. visible: height > 0
  126. height: globalSettings.clockWidget ? appWindow.height/15 : 0
  127. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  128. Text {
  129. //anchors.centerIn: parent
  130. id: clockLabel
  131. color: "white"
  132. font.bold: true
  133. font.pixelSize: parent.height
  134. text: d.timeString
  135. }
  136. Item {
  137. anchors { left: clockLabel.right; leftMargin: 20 }
  138. height: clock.height
  139. width: childrenRect.width
  140. Item {
  141. width: childrenRect.width
  142. height: parent.height/2
  143. Text {
  144. anchors.centerIn: parent
  145. color: "white"
  146. font.bold: true
  147. verticalAlignment: Text.AlignVCenter
  148. horizontalAlignment: Text.AlignHCenter
  149. font.pixelSize: clock.height/3
  150. text: d.day
  151. }
  152. }
  153. Item {
  154. y: parent.height/2
  155. width: childrenRect.width
  156. height: parent.height/2
  157. Text {
  158. anchors.centerIn: parent
  159. color: "white"
  160. font.bold: true
  161. verticalAlignment: Text.AlignVCenter
  162. horizontalAlignment: Text.AlignHCenter
  163. font.pixelSize: clock.height/3
  164. text: d.month
  165. }
  166. }
  167. }
  168. }
  169. }
  170. Item {
  171. id: toplevelhandler
  172. focus: true
  173. Keys.onPressed: {
  174. switch(event.key) {
  175. case Qt.Key_Left:
  176. globalSettings.columnCount = Math.max(globalSettings.columnCount - 1, 1);
  177. break;
  178. case Qt.Key_Right:
  179. globalSettings.columnCount++;
  180. break;
  181. case Qt.Key_Escape:
  182. Qt.quit();
  183. break;
  184. case Qt.Key_F10:
  185. globalSettings.showViewItemCount = !globalSettings.showViewItemCount;
  186. break;
  187. default:
  188. console.log('Key not handled')
  189. }
  190. }
  191. }
  192. Rectangle {
  193. z: 1
  194. opacity: 0.5
  195. visible: globalSettings.showViewItemCount
  196. color: "black"
  197. anchors { right: parent.right; top: parent.top }
  198. width: itemCountLabel.width
  199. height: itemCountLabel.height
  200. Text {
  201. id: itemCountLabel
  202. font.pixelSize: 100
  203. text: globalUtil.itemCount
  204. color: "white"
  205. }
  206. }
  207. Rectangle {
  208. z: 1
  209. opacity: 0.5
  210. visible: globalSettings.showScreenResolution
  211. color: "black"
  212. anchors { right: parent.right; top: parent.top }
  213. width: resolutionLabel.width
  214. height: resolutionLabel.height
  215. Text {
  216. id: resolutionLabel
  217. font.pixelSize: 100
  218. text: screenSize.width + "x" + screenSize.height
  219. color: "white"
  220. }
  221. }
  222. Component.onCompleted: {
  223. globalSettings.fullscreen ? showFullScreen() : show()
  224. }
  225. }