IconHUD.qml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/sql.js" as HCS
  50. import "../colibri"
  51. Rectangle {
  52. id: structure
  53. property string room : "room1"
  54. property bool lights : false
  55. property int lightVal : 0
  56. property int volume : 0
  57. property bool mute : true
  58. property bool fireAlarm : false
  59. property bool burglarAlarm : false
  60. property int amountNum : countAmount()
  61. property int iconSize : 28
  62. property bool doReload : true;
  63. /**
  64. * Counts the icons currently visible
  65. *
  66. * @return int
  67. */
  68. function countAmount() {
  69. var numValue = 2;
  70. if( fireAlarm ) numValue = numValue + 1;
  71. if( burglarAlarm ) numValue = numValue + 1;
  72. structure.width = ( numValue < 2 ) ? (1*iconSize + 2*gridi.spacing) : (2*iconSize + 3*gridi.spacing);
  73. structure.height = ( numValue < 3 ) ? (1*iconSize + 2*gridi.spacing) : (2*iconSize + 3*gridi.spacing);
  74. return numValue;
  75. }
  76. /**
  77. * Checks the info from database
  78. *
  79. * @return Nothing
  80. */
  81. function checkDetails() {
  82. HCS.getRoom(structure.room);
  83. structure.lights = ( HCS.roomx[0] == 0 ) ? false : true;
  84. structure.lightVal = HCS.roomx[0];
  85. structure.mute = HCS.roomx[2];
  86. structure.volume = (structure.mute)?0:HCS.roomx[1];
  87. structure.fireAlarm = HCS.roomx[3];
  88. structure.burglarAlarm = HCS.roomx[4];
  89. amountNum = countAmount();
  90. return;
  91. }
  92. /**
  93. * Sets values for histogram (speaker volume strength)
  94. *
  95. * @param value The current volume level
  96. * @return Nothing
  97. */
  98. function histogramValues(value){
  99. var array = new Array(3)
  100. if ( 0 <= value && value < 100/3){
  101. array[0]=new Array(2*value/(100/3),"1")
  102. array[1]=new Array(3*value/(100/3),"1")
  103. array[2]=new Array(4*value/(100/3),"1")
  104. }
  105. if (100/3 <= value && value < 100/1.5){
  106. array[0]=new Array(3*value/(100/1.5),"1")
  107. array[1]=new Array(5*value/(100/1.5),"1")
  108. array[2]=new Array(7*value/(100/1.5),"1")
  109. }
  110. if (100/1.5 <= value && value <= 100){
  111. array[0]=new Array(4*value/(100),"1")
  112. array[1]=new Array(7*value/(100),"1")
  113. array[2]=new Array(10*value/(100),"1")
  114. }
  115. histogram.setValues(array);
  116. }
  117. onRoomChanged: if( room == "sauna" ) room = "kph";
  118. onVolumeChanged: histogramValues( volume );
  119. color: "transparent"
  120. Timer {
  121. interval: 1000; running: structure.doReload; repeat: true;
  122. triggeredOnStart: true;
  123. onTriggered: checkDetails();
  124. }
  125. Grid {
  126. id: gridi
  127. anchors.centerIn: parent
  128. columns: 2
  129. spacing: 3
  130. Item {
  131. width: iconSize
  132. height: iconSize
  133. Image {
  134. source: "images/lamp_off_30x30.png"
  135. width: iconSize
  136. height: iconSize
  137. smooth: true
  138. }
  139. Image {
  140. source: "images/lamp_on_30x30.png"
  141. width: iconSize
  142. height: iconSize
  143. smooth: true
  144. opacity: structure.lightVal / 100
  145. }
  146. }
  147. Item {
  148. width: iconSize
  149. height: iconSize
  150. Image {
  151. source: "images/speaker_mute_50x50.png"
  152. visible: ( volume == 0 )?true:false
  153. width: iconSize
  154. height: iconSize
  155. smooth: true
  156. }
  157. Image {
  158. source: "images/speaker_30x30.png"
  159. visible: ( volume > 0 )?true:false
  160. width: iconSize
  161. height: iconSize
  162. smooth: true
  163. }
  164. CLHistogram{
  165. id: histogram
  166. gradientWhenDefault:Gradient {
  167. GradientStop { position: 0.0; color: "#8aff00" }
  168. GradientStop { position: 1.0; color: "#57b229" }
  169. }
  170. colorWhenDefault: "#8aff00"
  171. maxValue: 25
  172. anchors.right : parent.right
  173. anchors.bottom: parent.bottom
  174. width: parent.width
  175. height: parent.height*1.3
  176. spacing: 2
  177. visible: ( volume > 0 )?true:false
  178. }
  179. }
  180. Image {
  181. source: "images/fire_trans_30x30_png.png"
  182. visible: ( fireAlarm )?true:false
  183. width: iconSize
  184. height: iconSize
  185. smooth: true
  186. }
  187. Image {
  188. source: "images/alarm_40x40.png"
  189. visible: ( burglarAlarm )?true:false
  190. width: iconSize
  191. height: iconSize
  192. smooth: true
  193. }
  194. }
  195. }