From 9093cdc2c667a2852fb5c814bf50488469faf14f Mon Sep 17 00:00:00 2001 From: Kitteh Date: Tue, 23 Oct 2018 21:03:06 +0100 Subject: [PATCH] [UI] Native subtitles, info keybind, mouse hide. --- src/mpvobject.cpp | 10 +++++--- src/qml/main.qml | 65 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/mpvobject.cpp b/src/mpvobject.cpp index f668268..4b3f652 100644 --- a/src/mpvobject.cpp +++ b/src/mpvobject.cpp @@ -124,7 +124,7 @@ MpvObject::MpvObject(QQuickItem * parent) //mpv_set_option_string(mpv, "ytdl", "yes"); mpv_set_option_string(mpv, "vo", "libmpv"); - 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-ass-override", "force"); mpv_set_option_string(mpv, "sub-ass", "off"); @@ -133,7 +133,9 @@ MpvObject::MpvObject(QQuickItem * parent) 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", "#C0080808"); + mpv_set_option_string(mpv, "sub-back-color", "#C0080808");*/ + mpv_set_option_string(mpv, "sub-color", "0.0/0.0/0.0/0.0"); + mpv_set_option_string(mpv, "sub-scale", "0"); @@ -143,7 +145,7 @@ MpvObject::MpvObject(QQuickItem * parent) mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING); - + mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_set_wakeup_callback(mpv, wakeup, this); @@ -236,6 +238,8 @@ void MpvObject::handle_mpv_event(mpv_event *event) if (prop->format == MPV_FORMAT_STRING) { QMetaObject::invokeMethod(this,"setTitle"); } + } else if (strcmp(prop->name, "sub-text") == 0) { + QMetaObject::invokeMethod(this,"setSubtitles"); } break; } diff --git a/src/qml/main.qml b/src/qml/main.qml index b6fa577..55b7d3d 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -61,6 +61,7 @@ Window { } function updateControls() { + keybinds.focus = true updatePrev() updatePlayPauseIcon() updateVolume() @@ -201,8 +202,12 @@ Window { titleLabel.text = player.getProperty("media-title") } + function setSubtitles() { + nativeSubs.text = player.getProperty("sub-text") + } + function hideControls() { - if ( (!subtitlesMenu.visible) || (!settingsMenu.visible) ) { + if ( ! (subtitlesMenu.visible || settingsMenu.visible) ) { player.setOption("sub-margin-y", "22") controlsBar.visible = false controlsBackground.visible = false @@ -212,13 +217,14 @@ Window { } function showControls() { - updateControls() - player.setOption("sub-margin-y", - String(controlsBar.height + progressBar.height)) - controlsBar.visible = true - controlsBackground.visible = true - titleBar.visible = true - titleBackground.visible = true + if (! controlsBar.visible) { + updateControls() + //player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height)) + controlsBar.visible = true + controlsBackground.visible = true + titleBar.visible = true + titleBackground.visible = true + } } FileDialog { @@ -274,6 +280,7 @@ Window { anchors.top: titleBar.bottom anchors.topMargin: 0 hoverEnabled: true + cursorShape: controlsBar.visible ? Qt.ArrowCursor : Qt.BlankCursor onClicked: { player.command(["cycle", "pause"]) updateControls() @@ -340,8 +347,8 @@ Window { Rectangle { id: controlsBackground - height: controlsBar.height + (progressBar.topPadding * 2) - - (progressBackground.height * 2) + height: controlsBar.visible ? controlsBar.height + (progressBar.topPadding * 2) + - (progressBackground.height * 2) : 0 anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right @@ -351,9 +358,41 @@ Window { opacity: 0.6 } + Rectangle { + id: nativeSubtitles + height: nativeSubs.font.pixelSize + 4 + visible: nativeSubs.text == "" ? false : true + anchors.left: controlsBar.left + anchors.right: controlsBar.right + anchors.bottom: controlsBackground.top + + radius: 5 + color: "transparent" + + Label { + id: nativeSubs + width: parent.width + text: "" + color: "white" + font.family: notoFont.name + font.pixelSize: 24 + renderType: Text.NativeRendering + horizontalAlignment: Text.AlignHCenter + anchors.bottom: parent.top + opacity: 1 + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + + background: Rectangle { + color: Qt.rgba(0, 0, 0, 0.6) + anchors.left: parent.left + anchors.right: parent.right + } + } + } + Rectangle { id: controlsBar - height: Screen.height / 24 + height: controlsBar.visible ? Screen.height / 24 : 0 anchors.right: parent.right anchors.rightMargin: parent.width / 128 anchors.left: parent.left @@ -395,6 +434,7 @@ Window { } } } + Rectangle { id: subtitlesMenuBackground anchors.fill: subtitlesMenu @@ -737,6 +777,7 @@ Window { } Item { + id: keybinds anchors.fill: parent focus: true Keys.onPressed: { @@ -746,6 +787,8 @@ Window { player.command(["seek", "-10"]) } else if (event.key == Qt.Key_L) { player.command(["seek", "10"]) + } else if (event.key == Qt.Key_I) { + player.command(["script-binding", "stats/display-stats-toggle"]) } updateControls() }