SaunaTimer.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /**
  2. * Copyright © 2010 Digia Plc
  3. * Copyright © 2010 Nokia Corporation
  4. *
  5. * All rights reserved.
  6. *
  7. * Nokia and Nokia Connecting People are registered trademarks of
  8. * Nokia Corporation.
  9. * Java and all Java-based marks are trademarks or registered
  10. * trademarks of
  11. * Sun Microsystems, Inc. Other product and company names
  12. * mentioned herein may be
  13. * trademarks or trade names of their respective owners.
  14. *
  15. *
  16. * Subject to the conditions below, you may, without charge:
  17. *
  18. * · Use, copy, modify and/or merge copies of this software and
  19. * associated documentation files (the "Software")
  20. *
  21. * · Publish, distribute, sub-licence and/or sell new software
  22. * derived from or incorporating the Software.
  23. *
  24. *
  25. * This file, unmodified, shall be included with all copies or
  26. * substantial portions
  27. * of the Software that are distributed in source code form.
  28. *
  29. * The Software cannot constitute the primary value of any new
  30. * software derived
  31. * from or incorporating the Software.
  32. *
  33. * Any person dealing with the Software shall not misrepresent
  34. * the source of the Software.
  35. *
  36. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  37. * KIND, EXPRESS OR IMPLIED,
  38. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39. * MERCHANTABILITY, FITNESS FOR A
  40. * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  41. * AUTHORS OR COPYRIGHT
  42. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  43. * WHETHER IN AN ACTION
  44. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  45. * CONNECTION WITH THE
  46. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  47. */
  48. import Qt 4.7
  49. import "javascript/sauna.js" as SaunaEngine
  50. import "javascript/sql.js" as HCS
  51. import "../colibri/javascripts/functions.js" as Functions
  52. import "../colibri"
  53. import "styles"
  54. Item {
  55. id: structure
  56. property bool timerVisible: false
  57. property CLStyle style: StyleHomeControlSystem {}
  58. property int spacing: 10;
  59. signal saunaTimed(int temperature, int length);
  60. /**
  61. * Get set sauna timimgs.
  62. */
  63. function getSaunaTimings(){
  64. saunaTimings.clear();
  65. for(var i=0;i < SaunaEngine.saunaTimes.length; i++) {
  66. saunaTimings.append({"date": SaunaEngine.saunaTimes[i].on.toString("dd.MM.yyyy HH:mm"), "length": SaunaEngine.saunaTimes[i].time})
  67. }
  68. }
  69. /**
  70. * Removes timing from SaunaTimes-array and updates
  71. * screen in UI which shows set sauna timimgs.
  72. * @param index Timing to remove.
  73. */
  74. function removeTiming(index) {
  75. SaunaEngine.saunaTimes.splice(index,1);
  76. getSaunaTimings();
  77. }
  78. Component.onCompleted: {
  79. getSaunaTimings()
  80. HCS.setDefaults();
  81. }
  82. width: 640
  83. height: 424
  84. MouseArea {
  85. anchors.fill: parent;
  86. }
  87. Rectangle{
  88. width:structure.width*0.955
  89. height:structure.height*0.924
  90. color:style.selectionColor
  91. anchors.centerIn:parent
  92. radius:6
  93. }
  94. Image {
  95. source: "images/control_bg_trans_420x275_png.png";
  96. anchors.fill: parent;
  97. smooth: true
  98. opacity:0.7
  99. }
  100. Timer {
  101. interval: 1000; running: true; repeat: true
  102. onTriggered: {
  103. var saunaTiming = SaunaEngine.isSaunaOn();
  104. if(saunaTiming != null) {
  105. structure.saunaTimed(saunaTiming.setTemperature,
  106. SaunaEngine.saunaTimeLeft(saunaTiming.off)/60/1000);
  107. }
  108. if(SaunaEngine.deleteOldTimings()) getSaunaTimings();
  109. }
  110. }
  111. Row {
  112. x: structure.width*0.02;
  113. y: structure.height*0.05;
  114. Column {
  115. width: structure.width*0.42
  116. Text {
  117. x: structure.width*0.02
  118. text: "Scheduled sauna times:"
  119. font.pointSize: 0.001+structure.height*0.035
  120. color: structure.style.textColor
  121. }
  122. Component {
  123. id: timingsDelegate
  124. Row {
  125. x: structure.width*0.02
  126. spacing: 5
  127. width: structure.width*0.32
  128. Text { text: date; font.pointSize: 0.001+structure.height*0.025; anchors.verticalCenter: parent.verticalCenter; color: structure.style.textColor}
  129. Text { text: length + " min"; font.pointSize: 0.001+structure.height*0.025; anchors.verticalCenter: parent.verticalCenter; color: structure.style.textColor}
  130. CLButton{
  131. gradientWhenDefault: structure.style.gradientWhenDefault;
  132. gradientWhenHovered: structure.style.gradientWhenHovered;
  133. gradientWhenPressed: structure.style.gradientWhenPressed;
  134. colorWhenDefault: structure.style.colorWhenDefault;
  135. colorWhenHovered: structure.style.colorWhenHovered;
  136. colorWhenPressed: structure.style.colorWhenPressed;
  137. borderWidth: -1
  138. text: "del"; fontSize: 0.001+structure.height*0.025;
  139. onClicked: removeTiming(index);
  140. textColor: structure.style.textColor;
  141. anchors.right: parent.right
  142. smooth: true
  143. }
  144. }
  145. }
  146. Rectangle {
  147. width: structure.width*0.35;
  148. height: structure.height*0.85;
  149. color: "transparent"
  150. radius: 10//Functions.countRadius(styleHCS.roundness,width,height,0,1);
  151. ListView {
  152. width: parent.width
  153. height: parent.height
  154. model: saunaTimings
  155. delegate: timingsDelegate
  156. clip: true
  157. }
  158. }
  159. ListModel {
  160. id: saunaTimings;
  161. }
  162. }
  163. Column {
  164. y: structure.height*0.12
  165. spacing: structure.height*0.05
  166. Text {text: "Temperature: " + setTemperature.value + " \u00BAC"; font.pointSize: 0.001+structure.height*0.06; color: structure.style.textColor}
  167. CLSlider{
  168. id: setTemperature;
  169. height: structure.height*0.11;
  170. width: structure.width*0.52;
  171. style: structure.style;
  172. minimum: 30
  173. maximum: 120
  174. Component.onCompleted: setValue(70);
  175. borderColor: "white";
  176. borderWidth: 3
  177. }
  178. Text {
  179. text: "Duration: " + (parseInt(setTime.value/60) + " h" + " " +(setTime.value % 60)) + " min"; font.pointSize: 0.001+structure.height*0.06
  180. color: structure.style.textColor
  181. }
  182. CLSlider{
  183. id: setTime;
  184. minimum: 0;
  185. maximum: 180;
  186. height: structure.height*0.11;
  187. width: structure.width*0.52;
  188. style: structure.style; borderColor: "white";
  189. borderWidth: 3;
  190. Component.onCompleted: setValue(30);
  191. }
  192. Row {
  193. spacing: 4
  194. CLButton {
  195. id: timerIcon;
  196. style: structure.style
  197. text: ""
  198. width: structure.width*0.11
  199. height: structure.height*0.16
  200. backgroundImage: Image{source: "images/calendar_100x100.png"; width: structure.width*0.1; height: structure.height*0.15; smooth:true}
  201. onClicked: {
  202. timer.state = "visible"
  203. timer.visible = true
  204. }
  205. }
  206. Column {
  207. Text {
  208. text: datePicker.selected
  209. font.pointSize: 0.001+structure.height*0.047
  210. color: structure.style.textColor
  211. }
  212. Text {
  213. text: clock.hours + ":" + clock.minutes
  214. font.pointSize: 0.001+structure.height*0.047
  215. color: structure.style.textColor
  216. }
  217. width: structure.width*0.2
  218. }
  219. CLButton{
  220. style: structure.style;
  221. text: "Set Timer";
  222. anchors.verticalCenter: parent.verticalCenter;
  223. fontSize: 0.001+structure.height*0.045;
  224. onClicked: {
  225. if(setTime.value > 0) SaunaEngine.newSaunaOn(datePicker.selected,clock.hours,clock.minutes,setTime.value,setTemperature.value);
  226. getSaunaTimings();
  227. }
  228. }
  229. }
  230. }
  231. }
  232. Rectangle {
  233. id: timer
  234. x: structure.width+200
  235. state: "unvisible"
  236. anchors.verticalCenter: structure.verticalCenter;
  237. width: structure.width*0.94;
  238. height: structure.height*0.9;
  239. visible: false
  240. radius: 10
  241. z: 1
  242. color: structure.style.bgColor;
  243. border.color: structure.style.borderColor;
  244. MouseArea {
  245. anchors.fill: parent
  246. }
  247. CLDatePicker {
  248. id: datePicker;
  249. style: structure.style;
  250. showSelectedDate: false;
  251. width: structure.width*0.47;
  252. height: structure.height*0.85;
  253. pastDaysDisabled: true
  254. anchors.top: parent.top
  255. anchors.topMargin: structure.height*0.02
  256. anchors.left: parent.left
  257. anchors.leftMargin: structure.width*0.02
  258. onClicked: {
  259. if (SaunaEngine.isToday(datePicker.selected)) clock.pastClockTimesDisabled = true
  260. else clock.pastClockTimesDisabled = false
  261. }
  262. smooth: true
  263. hoveredStateOn: false
  264. }
  265. ClockTimer {
  266. id: clock
  267. style: structure.style
  268. textColor: textColor
  269. width: structure.width*0.4
  270. height: structure.height*0.2
  271. anchors.right: parent.right
  272. anchors.rightMargin: structure.width*0.015
  273. anchors.top: parent.top
  274. color: "transparent"
  275. anchors.topMargin: structure.height*0.02
  276. fontSize: structure.height*0.11
  277. }
  278. CLButton {
  279. text: "OK";
  280. style: structure.style;
  281. anchors.bottom: parent.bottom;
  282. anchors.bottomMargin: structure.width*0.01;
  283. anchors.right: parent.right
  284. anchors.rightMargin: structure.width*0.01
  285. fontSize: structure.height*0.08;
  286. onClicked: {
  287. timer.state = "unvisible"
  288. }
  289. }
  290. states: [
  291. State {
  292. name: "visible"; //when: timerVisible
  293. }, State {
  294. name: "unvisible"
  295. }
  296. ]
  297. transitions: [
  298. Transition {
  299. from: "unvisible"
  300. to: "visible"
  301. PropertyAnimation{target: timer; property: "x"; to: structure.width*0.03; duration: 500}
  302. },
  303. Transition {
  304. from: "visible"
  305. to: "unvisible"
  306. PropertyAnimation{target: timer; property: "x"; to: structure.width + 200; duration: 500}
  307. PropertyAnimation{target: timer; property: "visible"; to: "false"; duration: 500}
  308. }
  309. ]
  310. }
  311. }