1
0
Fork 0

[UI] Minor improvements.

This commit is contained in:
Kitteh 2018-10-26 15:13:14 +01:00
parent 93706c0c0b
commit bda712a4ce
2 changed files with 80 additions and 69 deletions

View file

@ -123,6 +123,7 @@ MpvObject::MpvObject(QQuickItem * parent)
// Fix? // Fix?
mpv_set_option_string(mpv, "ytdl", "yes"); mpv_set_option_string(mpv, "ytdl", "yes");
mpv_set_option_string(mpv, "vo", "libmpv"); mpv_set_option_string(mpv, "vo", "libmpv");
//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", "Noto Sans");
@ -136,7 +137,7 @@ MpvObject::MpvObject(QQuickItem * parent)
mpv_set_option_string(mpv, "sub-back-color", "#C0080808");*/ mpv_set_option_string(mpv, "sub-back-color", "#C0080808");*/
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-color", "0.0/0.0/0.0/0.0"); 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"); mpv_set_option_string(mpv, "sub-border-color", "0.0/0.0/0.0/0.0");
@ -146,13 +147,15 @@ MpvObject::MpvObject(QQuickItem * parent)
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE); mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE); mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE); mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING); 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, "sub-text", MPV_FORMAT_STRING);
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE);
mpv_set_wakeup_callback(mpv, wakeup, this); mpv_set_wakeup_callback(mpv, wakeup, this);
if (mpv_initialize(mpv) < 0) if (mpv_initialize(mpv) < 0)
@ -237,19 +240,36 @@ void MpvObject::handle_mpv_event(mpv_event *event)
} }
} else if (strcmp(prop->name, "volume") == 0) { } else if (strcmp(prop->name, "volume") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
QMetaObject::invokeMethod(this,"updateVolume"); double volume = *(double *)prop->data;
QMetaObject::invokeMethod(this,"updateVolume",Q_ARG(QVariant,volume));
}
} else if (strcmp(prop->name, "muted") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) {
double muted = *(double *)prop->data;
QMetaObject::invokeMethod(this,"updateMuted",Q_ARG(QVariant,muted));
} }
} else if (strcmp(prop->name, "media-title") == 0) { } else if (strcmp(prop->name, "media-title") == 0) {
if (prop->format == MPV_FORMAT_STRING) { if (prop->format == MPV_FORMAT_STRING) {
QMetaObject::invokeMethod(this,"setTitle"); char *title = *(char **)prop->data;
QMetaObject::invokeMethod(this,"setTitle",Q_ARG(QVariant,title));
} }
} else if (strcmp(prop->name, "sub-text") == 0) { } else if (strcmp(prop->name, "sub-text") == 0) {
QMetaObject::invokeMethod(this,"setSubtitles"); if (prop->format == MPV_FORMAT_STRING) {
char *subs = *(char **)prop->data;
QMetaObject::invokeMethod(this,"setSubtitles",Q_ARG(QVariant,subs));
}
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) { } else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double duration = *(double *)prop->data; double duration = *(double *)prop->data;
QMetaObject::invokeMethod(this,"setCachedDuration",Q_ARG(QVariant,duration)); QMetaObject::invokeMethod(this,"setCachedDuration",Q_ARG(QVariant,duration));
} }
} else if (strcmp(prop->name, "playlist-pos") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) {
double pos = *(double *)prop->data;
QMetaObject::invokeMethod(this,"updatePrev",Q_ARG(QVariant,pos));
}
} else if (strcmp(prop->name, "pause") == 0) {
QMetaObject::invokeMethod(this,"updatePlayPause");
} }
break; break;
} }

View file

@ -31,52 +31,6 @@ ApplicationWindow {
} }
} }
function updatePlayPauseIcon() {
var paused = player.getProperty("pause")
if (paused) {
playPauseButton.icon.source = "qrc:/player/icons/play.svg"
} else {
playPauseButton.icon.source = "qrc:/player/icons/pause.svg"
}
}
function updateVolume() {
var muted = player.getProperty("mute")
var volume = player.getProperty("volume")
if (muted || volume === 0) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
} else {
if (volume < 25) {
volumeButton.icon.source = "qrc:/player/icons/volume-down.svg"
} else {
volumeButton.icon.source = "qrc:/player/icons/volume-up.svg"
}
}
}
function updatePrev() {
var playlist_pos = player.getProperty("playlist-pos")
if (playlist_pos > 0) {
playlistPrevButton.visible = true
playlistPrevButton.width = playPauseButton.width
} else {
playlistPrevButton.visible = false
playlistPrevButton.width = 0
}
}
function updateControls() {
updatePrev()
updatePlayPauseIcon()
updateVolume()
}
function updatePlayPause() {
player.command(["cycle", "pause"])
updatePlayPauseIcon()
}
function tracksMenuUpdate() { function tracksMenuUpdate() {
var tracks = player.getProperty("track-list/count") var tracks = player.getProperty("track-list/count")
var track = 0 var track = 0
@ -214,12 +168,51 @@ ApplicationWindow {
player.command(["seek", skipto, "absolute"]) player.command(["seek", skipto, "absolute"])
} }
function setTitle() { function updatePrev(val) {
titleLabel.text = player.getProperty("media-title") if (val != 0) {
playlistPrevButton.visible = true
playlistPrevButton.width = playPauseButton.width
} else {
playlistPrevButton.visible = false
playlistPrevButton.width = 0
}
} }
function setSubtitles() { function updateVolume(volume) {
nativeSubs.text = player.getProperty("sub-text") console.log(volume)
var muted = player.getProperty("mute")
if (muted || volume === 0) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
} else {
if (volume < 25) {
volumeButton.icon.source = "qrc:/player/icons/volume-down.svg"
} else {
volumeButton.icon.source = "qrc:/player/icons/volume-up.svg"
}
}
}
function updateMuted(muted) {
if (muted) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
}
}
function updatePlayPause() {
var paused = player.getProperty("pause")
if (paused) {
playPauseButton.icon.source = "qrc:/player/icons/play.svg"
} else {
playPauseButton.icon.source = "qrc:/player/icons/pause.svg"
}
}
function setTitle(title) {
titleLabel.text = title
}
function setSubtitles(subs) {
nativeSubs.text = subs
} }
function isAnyMenuOpen() { function isAnyMenuOpen() {
@ -241,7 +234,6 @@ ApplicationWindow {
function showControls() { function showControls() {
if (!controlsBar.visible) { if (!controlsBar.visible) {
updateControls()
//player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height)) //player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height))
controlsBar.visible = true controlsBar.visible = true
controlsBackground.visible = true controlsBackground.visible = true
@ -307,7 +299,6 @@ ApplicationWindow {
cursorShape: controlsBar.visible ? Qt.ArrowCursor : Qt.BlankCursor cursorShape: controlsBar.visible ? Qt.ArrowCursor : Qt.BlankCursor
onClicked: { onClicked: {
player.command(["cycle", "pause"]) player.command(["cycle", "pause"])
updateControls()
} }
Timer { Timer {
id: mouseAreaPlayerTimer id: mouseAreaPlayerTimer
@ -429,7 +420,6 @@ ApplicationWindow {
text: "Play/Pause" text: "Play/Pause"
onTriggered: { onTriggered: {
player.command(["cycle", "pause"]) player.command(["cycle", "pause"])
updateControls()
} }
shortcut: String(keybinds.playPause) shortcut: String(keybinds.playPause)
} }
@ -437,7 +427,6 @@ ApplicationWindow {
text: "Rewind 10s" text: "Rewind 10s"
onTriggered: { onTriggered: {
player.command(["seek", "-10"]) player.command(["seek", "-10"])
updateControls()
} }
shortcut: keybinds.rewind10 shortcut: keybinds.rewind10
} }
@ -445,7 +434,6 @@ ApplicationWindow {
text: "Forward 10s" text: "Forward 10s"
onTriggered: { onTriggered: {
player.command(["seek", "10"]) player.command(["seek", "10"])
updateControls()
} }
shortcut: keybinds.forward10 shortcut: keybinds.forward10
} }
@ -453,7 +441,6 @@ ApplicationWindow {
text: "Rewind 5s" text: "Rewind 5s"
onTriggered: { onTriggered: {
player.command(["seek", "-5"]) player.command(["seek", "-5"])
updateControls()
} }
shortcut: keybinds.rewind5 shortcut: keybinds.rewind5
} }
@ -461,7 +448,6 @@ ApplicationWindow {
text: "Forward 5s" text: "Forward 5s"
onTriggered: { onTriggered: {
player.command(["seek", "5"]) player.command(["seek", "5"])
updateControls()
} }
shortcut: keybinds.forward5 shortcut: keybinds.forward5
} }
@ -469,7 +455,6 @@ ApplicationWindow {
text: "Forward Frame" text: "Forward Frame"
onTriggered: { onTriggered: {
player.command(["frame-step"]) player.command(["frame-step"])
updateControls()
} }
shortcut: keybinds.forwardFrame shortcut: keybinds.forwardFrame
} }
@ -477,7 +462,6 @@ ApplicationWindow {
text: "Back Frame" text: "Back Frame"
onTriggered: { onTriggered: {
player.command(["frame-back-step"]) player.command(["frame-back-step"])
updateControls()
} }
shortcut: keybinds.backwardFrame shortcut: keybinds.backwardFrame
} }
@ -784,6 +768,12 @@ ApplicationWindow {
radius: 5 radius: 5
color: "transparent" color: "transparent"
TextMetrics {
id: t_metrics
font.family: notoFont.name
font.pixelSize: nativeSubs.fontInfo.pixelSize
text: nativeSubs.text
}
Label { Label {
id: nativeSubs id: nativeSubs
@ -799,9 +789,13 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
background: Rectangle { background: Rectangle {
id: subsBackground
color: Qt.rgba(0, 0, 0, 0.6) color: Qt.rgba(0, 0, 0, 0.6)
width: t_metrics.tightBoundingRect.width + 8
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: (nativeSubtitles.width - t_metrics.tightBoundingRect.width) / 2
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: anchors.leftMargin
} }
} }
} }
@ -922,7 +916,6 @@ ApplicationWindow {
width: 0 width: 0
onClicked: { onClicked: {
player.command(["playlist-prev"]) player.command(["playlist-prev"])
updatePrev()
} }
background: Rectangle { background: Rectangle {
color: "transparent" color: "transparent"
@ -939,7 +932,7 @@ ApplicationWindow {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: playlistPrevButton.right anchors.left: playlistPrevButton.right
onClicked: { onClicked: {
updatePlayPause() player.command(["cycle", "pause"])
} }
background: Rectangle { background: Rectangle {
color: "transparent" color: "transparent"
@ -974,7 +967,6 @@ ApplicationWindow {
anchors.left: playlistNextButton.right anchors.left: playlistNextButton.right
onClicked: { onClicked: {
player.command(["cycle", "mute"]) player.command(["cycle", "mute"])
updateVolume()
} }
background: Rectangle { background: Rectangle {
color: "transparent" color: "transparent"
@ -1001,7 +993,6 @@ ApplicationWindow {
onMoved: { onMoved: {
player.command(["set", "volume", Math.round( player.command(["set", "volume", Math.round(
volumeBar.value).toString()]) volumeBar.value).toString()])
updateVolume()
} }
handle: Rectangle { handle: Rectangle {