main.qml Example File
led/assets/main.qml
import bb.cascades 1.0
import bb.device 1.0
Page {
Container {
leftPadding: 20
topPadding: 20
rightPadding: 20
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
imageSource: "asset:///images/background.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
Label {
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base: SystemDefaults.TextStyles.TitleText
fontWeight: FontWeight.Bold
color: Color.White
}
preferredHeight: 150
text: qsTr ("LED Tester")
}
DropDown {
id: colorChooser
topMargin: 100
horizontalAlignment: HorizontalAlignment.Center
title: qsTr ("LED Color")
Option {
text: qsTr ("Red")
value: LedColor.Red
imageSource: "asset:///images/red.png"
selected: true
}
Option {
text: qsTr ("Green")
value: LedColor.Green
imageSource: "asset:///images/green.png"
}
Option {
text: qsTr ("Blue")
value: LedColor.Blue
imageSource: "asset:///images/blue.png"
}
Option {
text: qsTr ("Yellow")
value: LedColor.Yellow
imageSource: "asset:///images/yellow.png"
}
Option {
text: qsTr ("Cyan")
value: LedColor.Cyan
imageSource: "asset:///images/cyan.png"
}
Option {
text: qsTr ("Magenta")
value: LedColor.Magenta
imageSource: "asset:///images/magenta.png"
}
Option {
text: qsTr ("White")
value: LedColor.White
imageSource: "asset:///images/white.png"
}
}
Label {
topMargin: 100
horizontalAlignment: HorizontalAlignment.Center
text: qsTr ("Flash Count: %1").arg(slider.normalizedValue == -1 ? "?" : slider.normalizedValue)
textStyle {
fontSize: FontSize.Medium
color: Color.White
}
}
Slider {
id: slider
property int normalizedValue: (Math.floor (value) == toValue ? -1 : Math.floor (value))
horizontalAlignment: HorizontalAlignment.Fill
fromValue: 1
toValue: 10
value: 1
enabled: !ledID.active
}
Button {
topMargin: 100
horizontalAlignment: HorizontalAlignment.Center
text: ledID.active ? qsTr ("Cancel") : qsTr ("Flash")
onClicked: {
if (ledID.active) {
ledID.cancel ();
} else {
if (slider.normalizedValue == -1) {
ledID.flash ()
} else {
ledID.flash (slider.normalizedValue)
}
}
}
}
Label {
topMargin: 100
horizontalAlignment: HorizontalAlignment.Center
visible: ledID.active
text: qsTr ("Remaining flash count: %1").arg(slider.normalizedValue == -1 ? "?" : ledID.remainingFlashCount)
textStyle {
fontSize: FontSize.Medium
color: Color.White
}
}
}
}
attachedObjects: [
Led {
id: ledID
color: colorChooser.selectedValue
}
]
}