[UI] Added improved subtitles.
This commit is contained in:
parent
84e68b7545
commit
7e2aea044f
|
@ -4,8 +4,10 @@ TEMPLATE = app
|
||||||
QT += qml quickcontrols2 widgets core-private gui-private
|
QT += qml quickcontrols2 widgets core-private gui-private
|
||||||
SOURCES += src/main.cpp src/mpvobject.cpp src/filesavedialog.cpp src/fileopendialog.cpp
|
SOURCES += src/main.cpp src/mpvobject.cpp src/filesavedialog.cpp src/fileopendialog.cpp
|
||||||
|
|
||||||
CONFIG += release
|
CONFIG += debug
|
||||||
CONFIG+=qtquickcompiler
|
CONFIG+=qml_debug
|
||||||
|
|
||||||
|
#CONFIG+=qtquickcompiler
|
||||||
QT_CONFIG -= no-pkg-config
|
QT_CONFIG -= no-pkg-config
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += mpv
|
PKGCONFIG += mpv
|
||||||
|
|
|
@ -129,21 +129,10 @@ MpvObject::MpvObject(QQuickItem * parent)
|
||||||
//mpp_set_option_string(mpv, "no-sub-ass", "yes)
|
//mpp_set_option_string(mpv, "no-sub-ass", "yes)
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "slang", "en");
|
mpv_set_option_string(mpv, "slang", "en");
|
||||||
mpv_set_option_string(mpv, "sub-font", "Noto Sans");
|
|
||||||
mpv_set_option_string(mpv, "sub-font-size", "24");
|
|
||||||
mpv_set_option_string(mpv, "sub-ass-override", "force");
|
|
||||||
mpv_set_option_string(mpv, "sub-ass", "off");
|
|
||||||
mpv_set_option_string(mpv, "sub-border-size", "0");
|
|
||||||
mpv_set_option_string(mpv, "sub-bold", "off");
|
|
||||||
mpv_set_option_string(mpv, "sub-scale-by-window", "on");
|
|
||||||
mpv_set_option_string(mpv, "sub-scale-with-window", "on");
|
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "sub-back-color", "0.0/0.0/0.0/0.0");
|
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "config", "yes");
|
mpv_set_option_string(mpv, "config", "yes");
|
||||||
//mpv_set_option_string(mpv, "sub-visibility", "no");
|
//mpv_set_option_string(mpv, "sub-visibility", "no");
|
||||||
mpv_set_option_string(mpv, "sub-color", "0.0/0.0/0.0/0.0");
|
|
||||||
mpv_set_option_string(mpv, "sub-border-color", "0.0/0.0/0.0/0.0");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
138
src/qml/main.qml
138
src/qml/main.qml
|
@ -85,6 +85,20 @@ ApplicationWindow {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
|
Settings {
|
||||||
|
id: appearance
|
||||||
|
category: "Appearance"
|
||||||
|
property bool titleOnlyOnFullscreen: true
|
||||||
|
property bool clickToPause: true
|
||||||
|
property bool useMpvSubs: false
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings {
|
||||||
|
id: fun
|
||||||
|
category: "Fun"
|
||||||
|
property bool nyanCat: false
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: initTimer
|
id: initTimer
|
||||||
interval: 1000
|
interval: 1000
|
||||||
|
@ -102,6 +116,21 @@ ApplicationWindow {
|
||||||
var args = Qt.application.arguments
|
var args = Qt.application.arguments
|
||||||
var len = Qt.application.arguments.length
|
var len = Qt.application.arguments.length
|
||||||
var argNo = 0
|
var argNo = 0
|
||||||
|
|
||||||
|
if (!appearance.useMpvSubs) {
|
||||||
|
player.setOption("sub-font", "Noto Sans")
|
||||||
|
player.setOption("sub-font-size", "24")
|
||||||
|
player.setOption("sub-ass-override", "force")
|
||||||
|
player.setOption("sub-ass", "off")
|
||||||
|
player.setOption("sub-border-size", "0")
|
||||||
|
player.setOption("sub-bold", "off")
|
||||||
|
player.setOption("sub-scale-by-window", "on")
|
||||||
|
player.setOption("sub-scale-with-window", "on")
|
||||||
|
player.setOption("sub-color", "0.0/0.0/0.0/0.0")
|
||||||
|
player.setOption("sub-border-color", "0.0/0.0/0.0/0.0")
|
||||||
|
player.setOption("sub-back-color", "0.0/0.0/0.0/0.0")
|
||||||
|
}
|
||||||
|
|
||||||
player.setOption("ytdl-format", "bestvideo[width<=" + Screen.width
|
player.setOption("ytdl-format", "bestvideo[width<=" + Screen.width
|
||||||
+ "][height<=" + Screen.height + "]+bestaudio")
|
+ "][height<=" + Screen.height + "]+bestaudio")
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
|
@ -211,13 +240,12 @@ ApplicationWindow {
|
||||||
return subtitlesMenu.visible || settingsMenu.visible
|
return subtitlesMenu.visible || settingsMenu.visible
|
||||||
|| fileMenuBarItem.opened || playbackMenuBarItem.opened
|
|| fileMenuBarItem.opened || playbackMenuBarItem.opened
|
||||||
|| viewMenuBarItem.opened || audioMenuBarItem.opened
|
|| viewMenuBarItem.opened || audioMenuBarItem.opened
|
||||||
|| screenshotSaveDialog.visible || videoMenuBarItem.opened
|
|| videoMenuBarItem.opened || subsMenuBarItem.opened
|
||||||
|| subsMenuBarItem.opened || aboutMenuBarItem.opened
|
|| aboutMenuBarItem.opened
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideControls(force) {
|
function hideControls(force) {
|
||||||
if (!isAnyMenuOpen() || force) {
|
if (!isAnyMenuOpen() || force) {
|
||||||
//player.setOption("sub-margin-y", "22")
|
|
||||||
controlsBar.visible = false
|
controlsBar.visible = false
|
||||||
controlsBackground.visible = false
|
controlsBackground.visible = false
|
||||||
titleBar.visible = false
|
titleBar.visible = false
|
||||||
|
@ -228,7 +256,6 @@ ApplicationWindow {
|
||||||
|
|
||||||
function showControls() {
|
function showControls() {
|
||||||
if (!controlsBar.visible) {
|
if (!controlsBar.visible) {
|
||||||
//player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height))
|
|
||||||
controlsBar.visible = true
|
controlsBar.visible = true
|
||||||
controlsBackground.visible = true
|
controlsBackground.visible = true
|
||||||
if (appearance.titleOnlyOnFullscreen) {
|
if (appearance.titleOnlyOnFullscreen) {
|
||||||
|
@ -243,19 +270,6 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings {
|
|
||||||
id: appearance
|
|
||||||
category: "Appearance"
|
|
||||||
property bool titleOnlyOnFullscreen: true
|
|
||||||
property bool clickToPause: true
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings {
|
|
||||||
id: fun
|
|
||||||
category: "Fun"
|
|
||||||
property bool nyanCat: false
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSaveDialog {
|
FileSaveDialog {
|
||||||
id: screenshotSaveDialog
|
id: screenshotSaveDialog
|
||||||
title: "Save Screenshot To"
|
title: "Save Screenshot To"
|
||||||
|
@ -267,7 +281,7 @@ ApplicationWindow {
|
||||||
"file://", '')
|
"file://", '')
|
||||||
console.log("Saving screenshot to: " + filepath)
|
console.log("Saving screenshot to: " + filepath)
|
||||||
result.saveToFile(filepath)
|
result.saveToFile(filepath)
|
||||||
nativeSubs.visible = true
|
subtitlesBar.visible = appearance.useMpvSubs ? false : true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,6 +329,8 @@ ApplicationWindow {
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseAreaPlayer
|
id: mouseAreaPlayer
|
||||||
|
z: 1000
|
||||||
|
focus: true
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.bottom: mouseAreaBar.top
|
anchors.bottom: mouseAreaBar.top
|
||||||
anchors.bottomMargin: 10
|
anchors.bottomMargin: 10
|
||||||
|
@ -334,8 +350,8 @@ ApplicationWindow {
|
||||||
Timer {
|
Timer {
|
||||||
id: mouseAreaPlayerTimer
|
id: mouseAreaPlayerTimer
|
||||||
interval: 1000
|
interval: 1000
|
||||||
running: false
|
running: true
|
||||||
repeat: false
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
player.hideControls()
|
player.hideControls()
|
||||||
}
|
}
|
||||||
|
@ -456,7 +472,7 @@ ApplicationWindow {
|
||||||
text: "Screenshot w/o subtitles"
|
text: "Screenshot w/o subtitles"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
player.hideControls(true)
|
player.hideControls(true)
|
||||||
nativeSubs.visible = false
|
subtitlesBar.visible = false
|
||||||
screenshotSaveDialog.open()
|
screenshotSaveDialog.open()
|
||||||
}
|
}
|
||||||
shortcut: keybinds.screenshotWithoutSubtitles
|
shortcut: keybinds.screenshotWithoutSubtitles
|
||||||
|
@ -659,6 +675,13 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
shortcut: keybinds.cycleSubBackwards
|
shortcut: keybinds.cycleSubBackwards
|
||||||
}
|
}
|
||||||
|
Action {
|
||||||
|
text: "Toggle MPV Subs"
|
||||||
|
onTriggered: {
|
||||||
|
appearance.useMpvSubs = !appearance.useMpvSubs
|
||||||
|
}
|
||||||
|
shortcut: keybinds.cycleSubBackwards
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu {
|
Menu {
|
||||||
|
@ -925,44 +948,57 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: nativeSubtitles
|
id: subtitlesBar
|
||||||
height: nativeSubs.font.pixelSize + 4
|
visible: !appearance.useMpvSubs
|
||||||
visible: nativeSubs.text == "" ? false : true
|
|
||||||
anchors.left: controlsBar.left
|
|
||||||
anchors.right: controlsBar.right
|
|
||||||
anchors.bottom: controlsBackground.top
|
|
||||||
anchors.bottomMargin: 0
|
|
||||||
|
|
||||||
radius: 5
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
TextMetrics {
|
height: player.height / 8
|
||||||
id: subTextMetrics
|
anchors.bottom: controlsBackground.top
|
||||||
font.family: notoFont.name
|
anchors.bottomMargin: 5
|
||||||
font.pixelSize: nativeSubs.fontInfo.pixelSize
|
anchors.right: parent.right
|
||||||
text: nativeSubs.text
|
anchors.left: parent.left
|
||||||
}
|
|
||||||
|
RowLayout {
|
||||||
|
id: nativeSubtitles
|
||||||
|
visible: true
|
||||||
|
anchors.left: subtitlesBar.left
|
||||||
|
anchors.right: subtitlesBar.right
|
||||||
|
height: childrenRect.height
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.bottomMargin: 10
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: subsContainer
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.rightMargin: 0
|
||||||
|
Layout.leftMargin: 0
|
||||||
|
Layout.maximumWidth: nativeSubtitles.width
|
||||||
|
color: "transparent"
|
||||||
|
height: childrenRect.height
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: nativeSubs
|
id: nativeSubs
|
||||||
width: parent.width
|
onWidthChanged: {
|
||||||
text: ""
|
|
||||||
color: "white"
|
|
||||||
font.family: notoFont.name
|
|
||||||
font.pixelSize: Screen.height / 24
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
anchors.bottom: parent.top
|
|
||||||
opacity: 1
|
|
||||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
||||||
|
|
||||||
|
if (width > parent.width - 10)
|
||||||
|
width = parent.width - 10
|
||||||
|
}
|
||||||
|
onTextChanged: if (width <= parent.width - 10)
|
||||||
|
width = undefined
|
||||||
|
color: "white"
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||||
|
font.pixelSize: Screen.height / 24
|
||||||
|
font.family: notoFont.name
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
opacity: 1
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
id: subsBackground
|
id: subsBackground
|
||||||
color: Qt.rgba(0, 0, 0, 0.6)
|
color: Qt.rgba(0, 0, 0, 0.6)
|
||||||
width: subTextMetrics.tightBoundingRect.width + 8
|
width: subsContainer.childrenRect.width
|
||||||
anchors.left: parent.left
|
height: subsContainer.childrenRect.height
|
||||||
anchors.leftMargin: (nativeSubtitles.width
|
}
|
||||||
- subTextMetrics.tightBoundingRect.width) / 2
|
}
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: anchors.leftMargin
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue