SaunaBasic.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 bool saunaOn: false;
  58. property CLStyle style: StyleHomeControlSystem {}
  59. property int saunaTemperature: parseInt(getSaunasRoomTemperature());
  60. property int saunaTimeLeft: 0;
  61. property bool ready: false;
  62. property int spacing: 10;
  63. /**
  64. * Returns room temperature in sauna.
  65. * @return Saunas room temperature
  66. */
  67. function getSaunasRoomTemperature() {
  68. HCS.getTheRoom("sauna");
  69. return HCS.theRoom.temperature;
  70. }
  71. /**
  72. * Stops sauna.
  73. */
  74. function stopSauna() {
  75. saunaTemperature = getSaunasRoomTemperature();
  76. HCS.setSaunaTemperature(getSaunasRoomTemperature());
  77. saunaOn = false;
  78. HCS.setSaunaOn(false);
  79. setTime.setValue(0);
  80. }
  81. /**
  82. * Starts sauna to destination temperature found from
  83. * setTemparature-slider.
  84. */
  85. function startSauna() {
  86. saunaTemperature = setTemperature.value;
  87. //saunaTimeLeft = setTime.value*60*1000;
  88. saunaOn = true;
  89. HCS.setSaunaOn(true);
  90. HCS.setSaunaTemperature(setTemperature.value);
  91. }
  92. /**
  93. * Starts sauna to destination temperature and length which
  94. * has been given to function in parameters.
  95. * @param temperature saunas temperature
  96. * @param length Time how long sauna is on.
  97. */
  98. function startSaunaWithParemeters(temperature,length) {
  99. if (length < setTime.value) return
  100. setTemperature.setValue(temperature);
  101. setTime.setValue(length);
  102. saunaOn = true;
  103. HCS.setSaunaOn(true);
  104. HCS.setSaunaTemperature(setTemperature.value);
  105. }
  106. onHeightChanged: {
  107. dial.width = structure.height*0.6
  108. }
  109. Component.onCompleted: {
  110. HCS.setDefaults();
  111. }
  112. width: 640
  113. height: 424
  114. MouseArea {
  115. anchors.fill: parent;
  116. }
  117. Rectangle{
  118. width:structure.width*0.955
  119. height:structure.height*0.924
  120. color:style.selectionColor
  121. anchors.centerIn:parent
  122. radius:6
  123. }
  124. Image {
  125. source: "images/control_bg_trans_420x275_png.png";
  126. anchors.fill: parent;
  127. smooth: true
  128. opacity:0.7
  129. }
  130. Timer {
  131. interval: 60000; running: true; repeat: true
  132. onTriggered: {
  133. /* Information is sauna ready is not needed in the moment
  134. //is sauna ready?
  135. if(!temperatureAnimation.running && saunaOn && !ready) {
  136. ready = true;
  137. } else ready = false;*/
  138. setTime.setValue(setTime.value - 1)
  139. }
  140. }
  141. Timer {
  142. interval: 500; running: true; repeat: true
  143. onTriggered: {
  144. //database listening
  145. if (HCS.isSaunaOn() && !saunaOn) startSauna()
  146. if (!HCS.isSaunaOn() && saunaOn) stopSauna();
  147. }
  148. }
  149. Behavior on saunaTemperature {
  150. SmoothedAnimation { id: temperatureAnimation; velocity: 2; }
  151. }
  152. Row {
  153. x: structure.width*0.02
  154. y: structure.height*0.05;
  155. Column {
  156. width: structure.width*0.42
  157. spacing: 10
  158. CLDial {
  159. id: dial
  160. width: structure.height*0.65
  161. value: saunaTemperature;
  162. needleImage: "../../homecontrol/images/pointer.png_dial2.png";
  163. backgroundImage:"../../homecontrol/images/sauna_meter_600x600.png";
  164. startValue: 0;
  165. endValue: 120;
  166. startAngle: -160//295
  167. endAngle: 80
  168. smooth: true
  169. anchors.horizontalCenter: parent.horizontalCenter
  170. }
  171. Row {
  172. spacing: structure.width*0.05
  173. anchors.horizontalCenter: parent.horizontalCenter
  174. Image {
  175. id: saunaOnCircle
  176. height: structure.height*0.1
  177. width: height
  178. source: "images/red_100x100_png.png"
  179. smooth: true
  180. states: [
  181. State {
  182. name: "saunaOn"; when: saunaOn;
  183. PropertyChanges{target: saunaOnCircle; source: "images/green_100x100_png.png"}
  184. }
  185. ]
  186. }
  187. Text {text: if (saunaOn) "Sauna is on"; else "Sauna is off"; font.pointSize: 0.001 + structure.height*0.05; color: structure.style.textColor}
  188. }
  189. }
  190. Column {
  191. spacing: 20
  192. y: structure.height*0.12
  193. Item {
  194. id: saunaControls
  195. width: structure.width/3;
  196. height: 220;
  197. Column {
  198. spacing: structure.height*0.05
  199. Text {text: "Temperature: " + setTemperature.value + " \u00BAC"; font.pointSize: 0.001+structure.height*0.06; color: structure.style.textColor}
  200. CLSlider{
  201. id: setTemperature;
  202. height: structure.height*0.11;
  203. width: structure.width*0.52;
  204. style: structure.style;
  205. minimum: 30
  206. maximum: 120
  207. borderColor: "white";
  208. borderWidth: 3
  209. onValueChanged: if(saunaOn) saunaTemperature = setTemperature.value;
  210. Component.onCompleted: setValue(70);
  211. }
  212. Text {
  213. text: "Time left: " + (parseInt(setTime.value/60) + " h" + " " +(setTime.value % 60)) + " min"; font.pointSize: 0.001+structure.height*0.06
  214. color: structure.style.textColor
  215. }
  216. CLSlider{
  217. id: setTime;
  218. minimum: 0;
  219. maximum: 180;
  220. height: structure.height*0.11;
  221. width: structure.width*0.52;
  222. style: structure.style; borderColor: "white";
  223. borderWidth: 3;
  224. Component.onCompleted: setValue(0);
  225. onValueChanged: {
  226. if (value <= 0) stopSauna()
  227. else if (!saunaOn) startSauna();
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }