ClockTimer.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 "../colibri/javascripts/functions.js" as Functions
  50. import "javascript/timer.js" as ClockTimer
  51. import "../colibri"
  52. Rectangle {
  53. id: structure;
  54. property CLStyle style : CLStyle{}
  55. property real roundness : style.roundness
  56. property alias hours : textHours.text
  57. property alias minutes : textMinutes.text
  58. property int fontSize : 25
  59. property string selected: "hours"
  60. property color textColorSelected: "red"
  61. property color textColor: style.textColor
  62. property bool pastClockTimesDisabled: false;
  63. property bool isCurrentDate: true;
  64. property int minuteInterval: 5
  65. function addMinute() {
  66. minutes = ClockTimer.formatTwoDigits(ClockTimer.parseIntClever(minutes) + minuteInterval);
  67. if (minutes > 59) minutes = "00"
  68. if (isCurrentDate && getCurrentHour() >= ClockTimer.parseIntClever(hours)
  69. && getCurrentMinute() > ClockTimer.parseIntClever(minutes) )
  70. minutes = ClockTimer.formatTwoDigits( getCurrentMinute() );
  71. }
  72. /**
  73. *
  74. */
  75. function decreaseMinute() {
  76. minutes = ClockTimer.formatTwoDigits(ClockTimer.parseIntClever(minutes) - minuteInterval);
  77. if (minutes == "0-5" || ClockTimer.parseIntClever(minutes) < 0 ||
  78. isCurrentDate && ( isCurrentDate && getCurrentHour() >= ClockTimer.parseIntClever(hours)
  79. && ClockTimer.parseIntClever(minutes) < getCurrentMinute() )) {
  80. var tempMin = (60 - minuteInterval);
  81. minutes = ClockTimer.formatTwoDigits( tempMin );
  82. }
  83. if (isCurrentDate && getCurrentHour() >= ClockTimer.parseIntClever(hours)
  84. && getCurrentMinute() > ClockTimer.parseIntClever(minutes) )
  85. minutes = ClockTimer.formatTwoDigits( getCurrentMinute() );
  86. }
  87. function addHour() {
  88. if (hours == 23) hours = "00"
  89. else hours = ClockTimer.formatTwoDigits(ClockTimer.parseIntClever(hours) + 1);
  90. if (isCurrentDate && getCurrentHour() > ClockTimer.parseIntClever(hours) ) hours = ClockTimer.formatTwoDigits( getCurrentHour() );
  91. if (isCurrentDate && getCurrentHour() >= ClockTimer.parseIntClever(hours) && getCurrentMinute() > ClockTimer.parseIntClever(minutes) ) minutes = ClockTimer.formatTwoDigits( getCurrentMinute() );
  92. if (minutes == "60" ) {
  93. minutes = "00";
  94. addHour();
  95. }
  96. }
  97. function decreaseHour() {
  98. if (hours == 0 || ( isCurrentDate && ClockTimer.parseIntClever(hours) == getCurrentHour() )) hours = "23"
  99. else hours = ClockTimer.formatTwoDigits(ClockTimer.parseIntClever(hours) - 1);
  100. if (isCurrentDate && getCurrentHour() > ClockTimer.parseIntClever(hours) )
  101. hours = ClockTimer.formatTwoDigits( getCurrentHour() );
  102. if (isCurrentDate && getCurrentHour() >= ClockTimer.parseIntClever(hours)
  103. && getCurrentMinute() > ClockTimer.parseIntClever(minutes) )
  104. minutes = ClockTimer.formatTwoDigits( getCurrentMinute() );
  105. if (minutes == "60" ) {
  106. minutes = "00";
  107. addHour();
  108. }
  109. }
  110. function getCurrentHour() {
  111. var today = new Date();
  112. return today.getHours();
  113. }
  114. function getCurrentMinute() {
  115. var today = new Date();
  116. var theMinutes = today.getMinutes();
  117. theMinutes = ( (theMinutes % structure.minuteInterval) == 0 ) ? theMinutes : ((Math.floor(theMinutes/structure.minuteInterval)*structure.minuteInterval)+structure.minuteInterval);
  118. if (theMinutes<10) return "0"+theMinutes
  119. return theMinutes;
  120. }
  121. function checkTheTime() {
  122. if (getCurrentHour() >= ClockTimer.parseIntClever(hours) && getCurrentMinute() > ClockTimer.parseIntClever(minutes) ) minutes = ClockTimer.formatTwoDigits( getCurrentMinute() );
  123. if (getCurrentHour() > ClockTimer.parseIntClever(hours) ) hours = ClockTimer.formatTwoDigits( getCurrentHour() );
  124. if (minutes == "60" ) {
  125. minutes = "00";
  126. addHour();
  127. }
  128. }
  129. onMinuteIntervalChanged: {
  130. if (minuteInterval < 1 || minuteInterval > 30 ) minuteInterval = 1;
  131. if (((60/minuteInterval)%1) != 0 ) minuteInterval = 1;
  132. }
  133. width: 120
  134. height: 70
  135. radius: Functions.countRadius(roundness,width,height,0,1);
  136. smooth: true
  137. Timer {
  138. id: checkPastTime
  139. running: isCurrentDate
  140. interval: 500
  141. triggeredOnStart: isCurrentDate
  142. onTriggered: checkTheTime()
  143. repeat: true
  144. }
  145. Row {
  146. anchors.verticalCenter: parent.verticalCenter
  147. Text {
  148. id: textHours
  149. text: getCurrentHour()
  150. font.pointSize: 0.001 + fontSize
  151. color: textColorSelected
  152. width: structure.width*0.3
  153. anchors.verticalCenter: parent.verticalCenter
  154. MouseArea {
  155. id: mouseAreaHours
  156. anchors.fill: parent
  157. onClicked: {
  158. textHours.color = textColorSelected
  159. textMinutes.color = textColor
  160. }
  161. hoverEnabled: true;
  162. }
  163. }
  164. Text {
  165. text: ":"
  166. font.pointSize: 0.001 + fontSize
  167. color: textColor
  168. width: structure.width*0.1
  169. anchors.verticalCenter: parent.verticalCenter
  170. }
  171. Text {
  172. id: textMinutes
  173. text: getCurrentMinute()
  174. font.pointSize: 0.001 + fontSize
  175. color: textColor
  176. width: structure.width*0.3
  177. anchors.verticalCenter: parent.verticalCenter
  178. MouseArea {
  179. id: mouseAreaMinutes
  180. anchors.fill: parent
  181. onClicked: {
  182. textMinutes.color = textColorSelected
  183. textHours.color = textColor
  184. }
  185. hoverEnabled: true;
  186. }
  187. }
  188. Column {
  189. CLButton{
  190. id: buttonUp
  191. style: structure.style
  192. text: ""
  193. backgroundImage: Image {source: "../colibri/images/arrow_up_50x50.png"; scale: structure.height*0.006; smooth: structure.smooth}
  194. width: structure.width*0.3
  195. fontSize: 0.00001 + structure.fontSize*0.5
  196. height: structure.height/2
  197. smooth: structure.smooth
  198. onClicked: {
  199. if (textHours.color == textColorSelected) addHour()
  200. else addMinute()
  201. }
  202. }
  203. CLButton{
  204. id: buttonDown
  205. style: structure.style
  206. text: ""
  207. backgroundImage: Image {source: "../colibri/images/arrow_down_50x50.png"; scale: structure.height*0.006; smooth: structure.smooth}
  208. width: structure.width*0.3
  209. fontSize: 0.00001 + structure.fontSize*0.5
  210. height: structure.height/2
  211. smooth: structure.smooth
  212. onClicked: {
  213. if (textHours.color == textColorSelected) decreaseHour()
  214. else decreaseMinute()
  215. }
  216. }
  217. }
  218. }
  219. }