From ff1a4e75056b200b7eb9117ddfd5b6cd27f4e92e Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 30 Oct 2009 11:35:50 +1000 Subject: improve clock example --- examples/declarative/clock/Clock.qml | 69 ++++++++++++++++----------------- examples/declarative/clock/center.png | Bin 0 -> 765 bytes examples/declarative/clock/clock.png | Bin 0 -> 21780 bytes examples/declarative/clock/display.qml | 9 ++++- examples/declarative/clock/hour.png | Bin 391 -> 625 bytes examples/declarative/clock/minute.png | Bin 445 -> 625 bytes examples/declarative/clock/second.png | Bin 345 -> 303 bytes 7 files changed, 41 insertions(+), 37 deletions(-) create mode 100755 examples/declarative/clock/center.png create mode 100755 examples/declarative/clock/clock.png mode change 100644 => 100755 examples/declarative/clock/hour.png mode change 100644 => 100755 examples/declarative/clock/minute.png mode change 100644 => 100755 examples/declarative/clock/second.png diff --git a/examples/declarative/clock/Clock.qml b/examples/declarative/clock/Clock.qml index a061488..636c99f 100644 --- a/examples/declarative/clock/Clock.qml +++ b/examples/declarative/clock/Clock.qml @@ -2,79 +2,76 @@ import Qt 4.6 Item { id: clock - width: 200; height: 200 - property var time + width: 200; height: 230 + + property alias city: cityLabel.text property var hours property var minutes property var seconds - onTimeChanged: { + property int shift : 0 + + function timeChanged() { var date = new Date; - hours = date.getHours(); - minutes = date.getMinutes(); - seconds = date.getSeconds(); + hours = date.getUTCHours() + clock.shift + minutes = date.getUTCMinutes(); + seconds = date.getUTCSeconds(); } + Timer { - interval: 100; running: true; repeat: true; triggeredOnStart: true - onTriggered: clock.time = new Date() + interval: 1000; running: true; repeat: true; triggeredOnStart: true + onTriggered: clock.timeChanged() } - Image { source: "background.png" } + Image { id: background; source: "clock.png" } + Image { - x: 95 - y: 54 + x: 92.5; y: 27 source: "hour.png" smooth: true transform: Rotation { id: hourRotation - origin.x: 4; origin.y: 45 - angle: 0 + origin.x: 7.5; origin.y: 73; angle: 0 angle: SpringFollow { - spring: 2 - damping: .2 - source: clock.hours * 50 * 3 + clock.minutes / 2 + spring: 2; damping: 0.2; modulus: 360 + source: (clock.hours * 30) + (clock.minutes * 0.5) } } } + Image { - x: 95 - y: 30 + x: 93.5; y: 17 source: "minute.png" smooth: true transform: Rotation { id: minuteRotation - origin.x: 4; origin.y: 70 - angle: 0 + origin.x: 6.5; origin.y: 83; angle: 0 angle: SpringFollow { - spring: 2 - damping: .2 + spring: 2; damping: 0.2; modulus: 360 source: clock.minutes * 6 } } } + Image { - x: 96 - y: 40 + x: 97.5; y: 20 source: "second.png" smooth: true transform: Rotation { id: secondRotation - origin.x: 2; origin.y: 60 - angle: 0 + origin.x: 2.5; origin.y: 80; angle: 0 angle: SpringFollow { - spring: 5 - damping: .25 - modulus: 360 + spring: 5; damping: 0.25; modulus: 360 source: clock.seconds * 6 } } } - Rectangle { - x: 93 - y: 94 - width: 11 - height: 11 - radius: 5 - color: "black" + Image { + anchors.centerIn: background; source: "center.png" + } + + Text { + id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" + anchors.horizontalCenter: parent.horizontalCenter } } diff --git a/examples/declarative/clock/center.png b/examples/declarative/clock/center.png new file mode 100755 index 0000000..7fbd802 Binary files /dev/null and b/examples/declarative/clock/center.png differ diff --git a/examples/declarative/clock/clock.png b/examples/declarative/clock/clock.png new file mode 100755 index 0000000..30bc577 Binary files /dev/null and b/examples/declarative/clock/clock.png differ diff --git a/examples/declarative/clock/display.qml b/examples/declarative/clock/display.qml index 20e254d..927adfa 100644 --- a/examples/declarative/clock/display.qml +++ b/examples/declarative/clock/display.qml @@ -3,5 +3,12 @@ import Qt 4.6 Rectangle { width: childrenRect.width height: childrenRect.height - Clock { id: clock } + color: "#646464" + + Grid { + columns: 3 + Clock { city: "New York"; shift: -4 } + Clock { city: "London" } + Clock { city: "Brisbane"; shift: 10 } + } } diff --git a/examples/declarative/clock/hour.png b/examples/declarative/clock/hour.png old mode 100644 new mode 100755 index 603466b..f8061a1 Binary files a/examples/declarative/clock/hour.png and b/examples/declarative/clock/hour.png differ diff --git a/examples/declarative/clock/minute.png b/examples/declarative/clock/minute.png old mode 100644 new mode 100755 index 0207405..1297ec7 Binary files a/examples/declarative/clock/minute.png and b/examples/declarative/clock/minute.png differ diff --git a/examples/declarative/clock/second.png b/examples/declarative/clock/second.png old mode 100644 new mode 100755 index bfcef68..4aa9fb5 Binary files a/examples/declarative/clock/second.png and b/examples/declarative/clock/second.png differ -- cgit v0.12