RoomAdjustWidget.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. import "styles"
  52. Item {
  53. id: screen
  54. property int colSpacing : 15
  55. property string room : "room1"
  56. property bool isVisible : false
  57. property CLStyle style : StyleHomeControlSystem{}
  58. property int textSize : 28
  59. property color textColor: style.textColor
  60. property bool mute: false
  61. property int light : 0
  62. property int temp : 0
  63. property int volume : 0
  64. property string name : ""
  65. property bool onStartUp : true
  66. signal closeWindow()
  67. /**
  68. * Updates room information.
  69. */
  70. function updateInfo() {
  71. HCS.getTheRoom(screen.room);
  72. screen.name = HCS.theRoom.name;
  73. meter.opacity = (HCS.theRoom.temperature-adjustTemperature.minimum)/(adjustTemperature.maximum-adjustTemperature.minimum)
  74. meter.text = HCS.theRoom.temperature+"<html>&deg;</html>C";
  75. meter1.text = HCS.theRoom.temperature+"<html>&deg;</html>C";
  76. if (HCS.theRoom.temperature == adjustTemperature.minimum)meter.value = false
  77. else meter.value = true
  78. adjustTemperature.setValue(HCS.theRoom.temperature);
  79. lamp.opacity = (HCS.theRoom.light-adjustLight.minimum)/(adjustLight.maximum-adjustLight.minimum)
  80. if (HCS.theRoom.light == adjustLight.minimum)lamp.light = false
  81. else lamp.light = true
  82. adjustLight.setValue(HCS.theRoom.light);
  83. screen.mute = HCS.theRoom.mute
  84. if (!screen.mute && HCS.theRoom.volume != adjustVolume.minimum){
  85. screen.mute = false
  86. mute.opacity = 0
  87. speaker.opacity = 1
  88. } else {
  89. screen.mute = true
  90. mute.opacity = 1
  91. speaker.opacity = 0
  92. }
  93. onStartUp = true;
  94. adjustVolume.setValue(HCS.theRoom.volume);
  95. histogramValues(volume);
  96. }
  97. /**
  98. * Sets values to small histogram which is over loudspeaker.
  99. * @param value Current volume in speaker
  100. */
  101. function histogramValues(value){
  102. var array = new Array(3)
  103. if ( adjustVolume.minimum <= value && value < adjustVolume.maximum/3){
  104. array[0]=new Array(2*value/(adjustVolume.maximum/3),"1")
  105. array[1]=new Array(3*value/(adjustVolume.maximum/3),"1")
  106. array[2]=new Array(4*value/(adjustVolume.maximum/3),"1")
  107. }
  108. if (adjustVolume.maximum/3 <= value && value < adjustVolume.maximum/1.5){
  109. array[0]=new Array(3*value/(adjustVolume.maximum/1.5),"1")
  110. array[1]=new Array(5*value/(adjustVolume.maximum/1.5),"1")
  111. array[2]=new Array(7*value/(adjustVolume.maximum/1.5),"1")
  112. }
  113. if (adjustVolume.maximum/1.5 <= value && value <= adjustVolume.maximum){
  114. array[0]=new Array(4*value/(adjustVolume.maximum),"1")
  115. array[1]=new Array(7*value/(adjustVolume.maximum),"1")
  116. array[2]=new Array(10*value/(adjustVolume.maximum),"1")
  117. }
  118. histogram.setValues(array);
  119. }
  120. Component.onCompleted: {
  121. updateInfo();
  122. textSize = screen.height * 0.075
  123. }
  124. onHeightChanged: {
  125. textSize = screen.height * 0.075
  126. }
  127. onRoomChanged: {
  128. updateInfo();
  129. }
  130. width: 600//parent.width
  131. height: 480//parent.height
  132. Item {
  133. id: roomAdjustWidget
  134. anchors.horizontalCenter:parent.horizontalCenter
  135. anchors.verticalCenter: parent.verticalCenter
  136. width: parent.width
  137. height: parent.height
  138. Rectangle{
  139. width:roomAdjustWidget.width * (400/420)
  140. height:roomAdjustWidget.height * (255/275)
  141. color: style.selectionColor
  142. anchors.centerIn:parent
  143. radius:7
  144. }
  145. Image {
  146. id:bgPic
  147. source: "images/control_bg_trans_420x275_png.png";
  148. width:roomAdjustWidget.width
  149. height:roomAdjustWidget.height
  150. opacity:0.7
  151. }
  152. MouseArea {
  153. anchors.fill: parent
  154. }
  155. RoomExitButton {
  156. windowWidth: screen.width
  157. windowHeight: screen.height
  158. style: screen.style
  159. onClicked: screen.closeWindow();
  160. }
  161. Column{
  162. spacing: colSpacing
  163. anchors.verticalCenter: parent.verticalCenter
  164. anchors.horizontalCenter: parent.horizontalCenter
  165. Text {
  166. id: roomName
  167. text: screen.name
  168. anchors.horizontalCenter:parent.horizontalCenter
  169. font.bold: true
  170. color: screen.textColor
  171. font.pixelSize: textSize
  172. }
  173. Row {
  174. spacing: colSpacing
  175. Item{
  176. height:roomAdjustWidget.height*0.20
  177. width: height
  178. Text{
  179. id:meter1
  180. font.pixelSize: textSize
  181. color: screen.style.textColor
  182. smooth:true
  183. y:roomAdjustWidget.height*0.03
  184. }
  185. Text{
  186. id:meter
  187. property bool value : false
  188. font.pixelSize: textSize
  189. color: screen.style.textColor
  190. smooth:true
  191. y:roomAdjustWidget.height*0.03
  192. }
  193. MouseArea {
  194. id: mouseArea2
  195. anchors.fill: parent
  196. onClicked: {
  197. meter.value = !meter.value
  198. if(meter.value){
  199. temp=adjustTemperature.maximum
  200. meter.opacity = 1
  201. adjustTemperature.setValue(adjustTemperature.maximum)
  202. } else {
  203. temp=adjustTemperature.minimum
  204. meter.opacity = 0
  205. adjustTemperature.setValue(adjustTemperature.minimum)
  206. }
  207. meter.text = temp+"<html>&deg;</html>C";
  208. meter1.text = temp+"<html>&deg;</html>C";
  209. }
  210. }
  211. }
  212. CLSlider{
  213. id:adjustTemperature
  214. style: screen.style
  215. height:roomAdjustWidget.height*0.15
  216. width:roomAdjustWidget.width*0.6
  217. minimum:18
  218. maximum:30
  219. borderWidth: 3
  220. onValueChanged: {
  221. temp = adjustTemperature.value
  222. if(temp == adjustTemperature.minimum)meter.value = false
  223. else meter.value = true
  224. meter.opacity = (temp-adjustTemperature.minimum)/(adjustTemperature.maximum-adjustTemperature.minimum)
  225. meter.text = temp+"<html>&deg;</html>C";
  226. meter1.text = temp+"<html>&deg;</html>C";
  227. }
  228. }
  229. }
  230. Row {
  231. spacing: colSpacing
  232. Item{
  233. height:roomAdjustWidget.height*0.20
  234. width: height
  235. Image {
  236. anchors.fill:parent
  237. smooth:true
  238. source:"images/lamp_off_100x100.png"
  239. }
  240. Rectangle{
  241. id:lamp
  242. property bool light : false
  243. color:"transparent"
  244. anchors.fill:parent
  245. Image{
  246. anchors.fill:parent
  247. smooth:true
  248. source:"images/glow_200x200.png"
  249. }
  250. Image{
  251. anchors.fill:parent
  252. smooth:true
  253. source:"images/lamp_on_100x100.png"
  254. }
  255. }
  256. MouseArea {
  257. id: mouseArea
  258. anchors.fill: parent
  259. onClicked: {
  260. if(lamp.light){
  261. light=adjustLight.minimum
  262. adjustLight.setValue(adjustLight.minimum)
  263. lamp.opacity = 0
  264. lamp.light = false
  265. } else {
  266. light=adjustLight.maximum
  267. lamp.opacity = 1
  268. adjustLight.setValue(adjustLight.maximum)
  269. lamp.light = true
  270. }
  271. }
  272. }
  273. }
  274. CLSlider{
  275. id:adjustLight
  276. style:screen.style
  277. minimum:0
  278. maximum:100
  279. borderWidth: 3
  280. height:roomAdjustWidget.height*0.15
  281. width:roomAdjustWidget.width*0.6
  282. onValueChanged: {
  283. light=adjustLight.value
  284. if(light == adjustLight.minimum)lamp.light = false
  285. else lamp.light = true
  286. lamp.opacity = (light-adjustLight.minimum)/(adjustLight.maximum-adjustLight.minimum)
  287. }
  288. }
  289. }
  290. Row {
  291. spacing: colSpacing
  292. Item{
  293. height:roomAdjustWidget.height*0.20
  294. width: height
  295. Image {
  296. anchors.fill:parent
  297. source:"images/speaker_100x100.png"
  298. smooth:true
  299. }
  300. Item{
  301. anchors.fill:parent
  302. id:speaker
  303. CLHistogram{
  304. id: histogram;
  305. style: screen.style;
  306. gradientWhenDefault:Gradient {
  307. GradientStop { position: 0.0; color: "#8aff00" }
  308. GradientStop { position: 1.0; color: "#57b229" }
  309. }
  310. colorWhenDefault:"#8aff00"
  311. maxValue: 25;
  312. anchors.right : parent.right;
  313. anchors.bottom: parent.bottom;
  314. width: parent.width
  315. height: parent.height*1.3
  316. opacity: 1;
  317. y:-20
  318. }
  319. }
  320. Image{
  321. id:mute
  322. anchors.fill:parent
  323. source:"images/speaker_mute_100x100.png"
  324. smooth:true
  325. }
  326. MouseArea {
  327. id: mouseArea3
  328. anchors.fill: parent
  329. onClicked: {
  330. if (adjustVolume.value != adjustVolume.minimum) {
  331. screen.mute = !screen.mute
  332. mute.opacity = (screen.mute)?1:0;
  333. speaker.opacity = (screen.mute)?0:1;
  334. }
  335. }
  336. }
  337. }
  338. CLSlider{
  339. id:adjustVolume
  340. style:screen.style
  341. minimum:0
  342. maximum:100
  343. borderWidth: 3
  344. height:roomAdjustWidget.height*0.15
  345. width:roomAdjustWidget.width*0.6
  346. onValueChanged: {
  347. volume=adjustVolume.value
  348. if( !onStartUp ) {
  349. if(volume == adjustVolume.minimum) {
  350. screen.mute = true
  351. mute.opacity = 1
  352. speaker.opacity = 0
  353. } else {
  354. screen.mute = false
  355. mute.opacity = 0
  356. histogramValues(value)
  357. speaker.opacity = 1
  358. }
  359. }
  360. onStartUp = false;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. }