1
0
Fork 0
VideoPlayer/src/qml/UIComponents/VideoProgress.qml

185 lines
6.2 KiB
QML
Raw Normal View History

import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.11
import QtQuick.Window 2.11
import Qt.labs.settings 1.0
import Qt.labs.platform 1.0 as LabsPlatform
import player 1.0
Slider {
id: progressBar
objectName: "progressBar"
to: 1
value: 0.0
Connections {
target: player
enabled: true
onPositionChanged: function (position) {
if (!pressed) {
progressBar.value = position
}
}
onDurationChanged: function (duration) {
progressBar.to = duration
}
onCachedDurationChanged: function (duration) {
cachedLength.duration = duration
}
}
onMoved: {
player.playerCommand(Enums.Commands.SeekAbsolute, value)
}
function getProgressBarHeight(nyan, isMouse) {
2018-11-30 16:42:19 +00:00
var x = fun.nyanCat ? mainWindow.virtualHeight / 64 : Screen.height / 380
if (appearance.themeName == "Niconico" && !fun.nyanCat) {
return x * 2
} else if (isMouse & !fun.nyanCat) {
return x * 2
} else {
return x
}
}
function getHandleVisibility(themeName, isMouse) {
if (appearance.themeName == "Niconico" && isMouse) {
return true
} else if (appearance.themeName == "Niconico") {
return false
} else {
return true
}
}
MouseArea {
id: mouseAreaProgressBar
width: parent.width
height: parent.height
anchors.fill: parent
y: parent.y
x: parent.x
hoverEnabled: true
propagateComposedEvents: false
acceptedButtons: Qt.NoButton
z: 1
onPositionChanged: {
var a = (progressBar.to / progressBar.width) * mouseAreaProgressBar.mouseX
hoverProgressLabel.text = utils.createTimestamp(a)
}
}
background: Rectangle {
id: progressBackground
x: progressBar.leftPadding
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
width: progressBar.availableWidth
height: progressBar.getProgressBarHeight(
fun.nyanCat, mouseAreaProgressBar.containsMouse)
color: getAppearanceValueForTheme(appearance.themeName,
"progressBackgroundColor")
Rectangle {
2018-11-30 16:42:19 +00:00
x: (mouseAreaProgressBar.mouseX - hoverProgressLabel.width / 2)
y: progressBackground.y - 20 - hoverProgressLabel.height
visible: mouseAreaProgressBar.containsMouse
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
2018-11-30 16:42:19 +00:00
height: hoverProgressLabel.height
width: hoverProgressLabel.width
z: 80
Text {
id: hoverProgressLabel
text: "0:00"
color: "white"
padding: 2
font.family: appearance.fontName
2018-11-30 16:42:19 +00:00
font.pixelSize: mainWindow.virtualHeight / 50
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
}
}
ProgressBar {
id: cachedLength
background: Item {
}
contentItem: Item {
Rectangle {
width: cachedLength.visualPosition * parent.width
height: parent.height
color: getAppearanceValueForTheme(appearance.themeName,
"progressCachedColor")
}
}
z: 40
to: progressBar.to
property int duration
value: progressBar.value + duration
anchors.fill: parent
}
Item {
anchors.fill: parent
id: chapterMarkers
Connections {
target: player
enabled: true
onChaptersChanged: function (chapters) {
for (var i = 0, len = chapters.length; i < len; i++) {
var component = Qt.createComponent("ChapterMarker.qml")
var marker = component.createObject(chapterMarkers, {
time: chapters[i]["time"]
})
}
}
}
}
Rectangle {
id: progressLength
z: 50
anchors.left: progressBackground.left
width: progressBar.visualPosition * parent.width
height: parent.height
color: getAppearanceValueForTheme(appearance.themeName,
"progressSliderColor")
Image {
visible: fun.nyanCat
id: rainbow
anchors.fill: parent
height: parent.height
width: parent.width
source: "qrc:/icons/rainbow.png"
fillMode: Image.TileHorizontally
}
}
}
handle: Rectangle {
z: 70
id: handleRect
x: progressBar.leftPadding + progressBar.visualPosition
* (progressBar.availableWidth - width)
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
implicitHeight: radius
implicitWidth: radius
radius: 12 + (progressBackground.height / 2)
color: appearance.themeName
== "RoosterTeeth" ? "white" : fun.nyanCat ? "transparent" : getAppearanceValueForTheme(
appearance.themeName,
"progressSliderColor")
visible: getHandleVisibility(appearance.themeName,
mouseAreaProgressBar.containsMouse)
AnimatedImage {
z: 80
visible: fun.nyanCat
paused: progressBar.pressed
2018-11-30 16:42:19 +00:00
height: mainWindow.virtualHeight / 28
id: nyanimation
anchors.centerIn: parent
source: "qrc:/icons/nyancat.gif"
fillMode: Image.PreserveAspectFit
}
}
}