main.qml Example File
dictaphone/assets/main.qml
import bb.cascades 1.0
import bb.multimedia 1.0
NavigationPane {
id: navigationPane
onPopTransitionEnded: page.destroy()
Page {
id: mainPage
DictaphoneScrollView {
Container {
layout: DockLayout {
}
ImageView {
id: imageBackground
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
imageSource: "asset:///images/background.png"
}
Led {
id: led
horizontalAlignment: HorizontalAlignment.Left
verticalAlignment: VerticalAlignment.Top
translationX: 40
translationY: 500
state: (recorder.mediaState == MediaState.Started ? "rec" : recorder.mediaState == MediaState.Paused ? "pause" : "off")
}
Tape {
id: tape
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Top
translationY: 570
running: (recorder.mediaState == MediaState.Started)
}
ImageView {
id: label
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Top
translationY: -205
imageSource: "asset:///images/dictaphone_label.png"
}
ImageView {
id: buttonBackground
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Bottom
imageSource: "asset:///images/buttons_background.png"
}
Container {
id: buttonContainer
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Bottom
preferredWidth: 670
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
ImageToggleButton {
rightMargin: 2
imageSourceDefault: "asset:///images/rec_button.png"
imageSourcePressedUnchecked: "asset:///images/rec_button.png"
imageSourceChecked: "asset:///images/rec_button_pressed.png"
imageSourcePressedChecked: "asset:///images/rec_button_pressed.png"
imageSourceDisabledChecked: "asset:///images/rec_button_pressed.png"
enabled: (recorder.mediaState != MediaState.Paused)
onCheckedChanged: {
if (recorder.mediaState == MediaState.Started) {
recorder.reset()
_trackManager.update()
recordStopSound.play()
} else {
_trackManager.update()
recorder.outputUrl = "file://" + _trackManager.nextTrackUrl()
recordStartSound.play()
recorder.record()
}
}
}
ImageToggleButton {
leftMargin: 2
rightMargin: 2
imageSourceDefault: "asset:///images/pause_button.png"
imageSourceDisabledUnchecked: "asset:///images/pause_button.png"
imageSourcePressedUnchecked: "asset:///images/pause_button.png"
imageSourceChecked: "asset:///images/pause_button_pressed.png"
imageSourcePressedChecked: "asset:///images/pause_button_pressed.png"
enabled: (recorder.mediaState == MediaState.Started || recorder.mediaState == MediaState.Paused)
onCheckedChanged: {
if (recorder.mediaState == MediaState.Started) recorder.pause(); else recorder.record()
}
}
ImageButton {
leftMargin: 2
defaultImageSource: "asset:///images/play_button.png"
pressedImageSource: "asset:///images/play_button_pressed.png"
disabledImageSource: "asset:///images/play_button.png"
enabled: (_trackManager.hasRecordedTracks && recorder.mediaState != MediaState.Started && recorder.mediaState != MediaState.Paused)
onClicked: navigationPane.push(playerPage.createObject())
}
}
}
}
attachedObjects: [
AudioRecorder {
id: recorder
},
ComponentDefinition {
id: playerPage
source: "PlayerPage.qml"
},
SystemSound {
id: recordStartSound
sound: SystemSound.RecordingStartEvent
},
SystemSound {
id: recordStopSound
sound: SystemSound.RecordingStopEvent
},
OrientationHandler {
onOrientationAboutToChange: {
mainPage.reLayout(orientation);
}
}
]
function reLayout(orientation) {
if (orientation == UIOrientation.Landscape) {
imageBackground.imageSource = "asset:///images/background_landscape.png"
led.translationY = 40
tape.translationY = 120
tape.translationX = -30
tape.horizontalAlignment = HorizontalAlignment.Right
label.verticalAlignment = VerticalAlignment.Top
label.translationY = 50
label.translationX = 260
buttonBackground.horizontalAlignment = HorizontalAlignment.Right
buttonBackground.translationX = -40
buttonContainer.horizontalAlignment = HorizontalAlignment.Right
buttonContainer.translationX = -40
} else {
imageBackground.imageSource = "asset:///images/background.png"
led.translationY = 500
tape.translationY = 570
tape.translationX = 0
tape.horizontalAlignment = HorizontalAlignment.Center
label.verticalAlignment = VerticalAlignment.Bottom
label.translationY = -205
label.translationX = 0
buttonBackground.horizontalAlignment = HorizontalAlignment.Center
buttonBackground.translationX = 0
buttonContainer.horizontalAlignment = HorizontalAlignment.Center
buttonContainer.translationX = 0
}
}
onCreationCompleted: {
OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
reLayout(OrientationSupport.orientation);
}
}
}