feat: add subtitle track selection, secondary subtitle and delay
This commit is contained in:
1 parent
1eb67b829c
commit
48cac86d60
5 files changed
+320
-4
No files matched your search
+53
-2
@@ -65,6 +65,27 @@ Kirigami.Page {
|
||||
sequence: "Right"
|
||||
onActivated: mpv.seek(mpv.position + 5)
|
||||
}
|
||||
// Same keys as mpv: z shows subtitles earlier, x later.
|
||||
Shortcut {
|
||||
sequence: "Z"
|
||||
enabled: mpv.fileLoaded
|
||||
onActivated: page.nudgeSubtitleDelay(-0.1)
|
||||
}
|
||||
Shortcut {
|
||||
sequence: "X"
|
||||
enabled: mpv.fileLoaded
|
||||
onActivated: page.nudgeSubtitleDelay(0.1)
|
||||
}
|
||||
|
||||
function nudgeSubtitleDelay(seconds: real) {
|
||||
const delay = mpv.subtitleDelay + seconds
|
||||
mpv.subtitleDelay = delay
|
||||
mpv.showText(KI18n.i18nc("@info:osd", "Subtitle delay: %1 ms", Math.round(delay * 1000)))
|
||||
}
|
||||
|
||||
function isSubtitleFile(url: url): bool {
|
||||
return /\.(srt|ass|ssa|vtt|sub|sup)$/i.test(url.toString())
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
@@ -111,8 +132,14 @@ Kirigami.Page {
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
onDropped: drop => {
|
||||
if (drop.hasUrls) {
|
||||
mpv.loadFile(drop.urls[0])
|
||||
if (!drop.hasUrls) {
|
||||
return
|
||||
}
|
||||
const url = drop.urls[0]
|
||||
if (mpv.fileLoaded && page.isSubtitleFile(url)) {
|
||||
mpv.addSubtitleFile(url)
|
||||
} else {
|
||||
mpv.loadFile(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,6 +192,30 @@ Kirigami.Page {
|
||||
text: page.formatTime(mpv.duration)
|
||||
font.features: { "tnum": 1 }
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
id: subtitleButton
|
||||
enabled: mpv.fileLoaded
|
||||
focusPolicy: Qt.NoFocus
|
||||
checkable: true
|
||||
checked: subtitlePopup.visible
|
||||
icon.name: "media-view-subtitles-symbolic"
|
||||
text: KI18n.i18nc("@action:button", "Subtitles")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
onClicked: subtitlePopup.visible ? subtitlePopup.close() : subtitlePopup.open()
|
||||
|
||||
QQC2.ToolTip.text: text
|
||||
QQC2.ToolTip.visible: hovered && !subtitlePopup.visible
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
|
||||
SubtitlePopup {
|
||||
id: subtitlePopup
|
||||
objectName: "subtitlePopup"
|
||||
mpv: mpv
|
||||
x: subtitleButton.width - width
|
||||
y: -height - Kirigami.Units.smallSpacing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user