Skip to content

Instantly share code, notes, and snippets.

@amrishodiq
Created November 2, 2012 09:41
Show Gist options
  • Select an option

  • Save amrishodiq/3999790 to your computer and use it in GitHub Desktop.

Select an option

Save amrishodiq/3999790 to your computer and use it in GitHub Desktop.
QML Analog Clock with ability to rotate clock's hand on action press
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {}
ImageView {
imageSource: "asset:///images/bg-wall-blue.jpg"
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
}
ImageView {
imageSource: "asset:///images/bg-clock-700.png"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
ImageView {
id: hours
imageSource: "asset:///images/clock-hour.png"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
rotationZ: _clock.hours
}
ImageView {
id: minutes
imageSource: "asset:///images/clock-minute.png"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
rotationZ: _clock.minutes
}
ImageView {
id: seconds
imageSource: "asset:///images/clock-second.png"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
rotationZ: _clock.seconds
}
ImageView {
imageSource: "asset:///images/clock-nail.png"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
actions: [
ActionItem {
title: "Second"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
seconds.rotationZ += 6
if (seconds.rotationZ % 360 == 0) {
minutes.rotationZ += 6
if (minutes.rotationZ % 360 == 0)
hours.rotationZ += 6
}
}
},
ActionItem {
title: "Quarter"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
minutes.rotationZ += 90
if (minutes.rotationZ % 360 == 0)
hours.rotationZ += 6
}
},
ActionItem {
title: "Reset"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
seconds.rotationZ = 0
minutes.rotationZ = 0
hours.rotationZ = 0
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment