Skip to content

Commit

Permalink
qmlplayer: preview on mouseX change(for mobile)
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 6, 2015
1 parent ab48511 commit b168a5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
35 changes: 27 additions & 8 deletions examples/QMLPlayer/qml/QMLPlayer/ControlPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,7 @@ Rectangle {
// return
if (playState == "stop")
return;
if (PlayerConfig.previewEnabled && preview.video.file) {
preview.video.timestamp = value*duration
}

var v = value * progress.width
preview.anchors.leftMargin = v - preview.width/2
previewText.text = Utils.msec2string(value*duration)
//console.log("hover: "+value + " duration: " + player.duration)
showPreview(value)
}
}
Text {
Expand Down Expand Up @@ -175,6 +168,7 @@ Rectangle {
height: PlayerConfig.previewEnabled ? Utils.scaled(120) : previewText.contentHeight + 2*Utils.kSpacing
color: "black"
state: "out"
property real timestamp
property alias video: video
VideoPreview {
id: video
Expand All @@ -198,6 +192,19 @@ Rectangle {
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
}
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
if (preview.opacity === 0 || root.opacity === 0) {
mouse.accepted = false
return
}
mouse.accepted = true
seek(preview.timestamp)
}
}

states: [
State {
name: "in"
Expand Down Expand Up @@ -452,4 +459,16 @@ Rectangle {
else
aniHide()
}
function showPreview(value) {
preview.visible = true
preview.state = "in"
if (PlayerConfig.previewEnabled && preview.video.file) {
preview.video.timestamp = value*duration
}
var v = value * progress.width
preview.anchors.leftMargin = v - preview.width/2
preview.timestamp = value*duration
previewText.text = Utils.msec2string(preview.timestamp)
//console.log("hover: "+value + " duration: " + player.duration)
}
}
7 changes: 6 additions & 1 deletion examples/QMLPlayer/qml/QMLPlayer/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ Rectangle {

MouseArea {
anchors.fill: parent
onPressed: {
onClicked: {
control.toggleVisible()
if (root.width - mouseX < Utils.scaled(60)) {
configPanel.state = "show"
} else {
configPanel.state = "hide"
}
}
onMouseXChanged: {
if (player.playbackState == MediaPlayer.StoppedState || !player.hasVideo)
return;
control.showPreview(mouseX/parent.width)
}
}
Text {
id: msg
Expand Down

0 comments on commit b168a5b

Please sign in to comment.