[Backend] Move more code to backend.
This commit is contained in:
parent
d4e0115c8f
commit
f32ead3e1d
|
@ -329,6 +329,17 @@ MpvPlayerBackend::on_mpv_events()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::updateDurationStringText()
|
||||
{
|
||||
findChild<QObject*>("timeLabel")
|
||||
->setProperty("text",
|
||||
QString("%1 / %2 (%3x)")
|
||||
.arg(createTimestamp(getProperty("time-pos")).toString(),
|
||||
createTimestamp(getProperty("duration")).toString(),
|
||||
getProperty("speed").toString()));
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||
{
|
||||
|
@ -338,15 +349,13 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
if (strcmp(prop->name, "time-pos") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
double time = *(double*)prop->data;
|
||||
QMetaObject::invokeMethod(
|
||||
this, "setProgressBarValue", Q_ARG(QVariant, time));
|
||||
updateDurationStringText();
|
||||
findChild<QObject*>("progressBar")->setProperty("value", time);
|
||||
}
|
||||
} else if (strcmp(prop->name, "duration") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
double time = *(double*)prop->data;
|
||||
Q_ARG(QVariant, "txt1"),
|
||||
QMetaObject::invokeMethod(
|
||||
this, "setProgressBarEnd", Q_ARG(QVariant, time));
|
||||
findChild<QObject*>("progressBar")->setProperty("to", time);
|
||||
}
|
||||
} else if (strcmp(prop->name, "volume") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
|
@ -363,13 +372,12 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
} else if (strcmp(prop->name, "media-title") == 0) {
|
||||
if (prop->format == MPV_FORMAT_STRING) {
|
||||
char* title = *(char**)prop->data;
|
||||
QMetaObject::invokeMethod(this, "setTitle", Q_ARG(QVariant, title));
|
||||
findChild<QObject*>("titleLabel")->setProperty("text", title);
|
||||
}
|
||||
} else if (strcmp(prop->name, "sub-text") == 0) {
|
||||
if (prop->format == MPV_FORMAT_STRING) {
|
||||
char* subs = *(char**)prop->data;
|
||||
QMetaObject::invokeMethod(
|
||||
this, "setSubtitles", Q_ARG(QVariant, subs));
|
||||
findChild<QObject*>("nativeSubs")->setProperty("text", subs);
|
||||
}
|
||||
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
|
|
|
@ -37,6 +37,7 @@ public slots:
|
|||
void prevPlaylistItem();
|
||||
void nextPlaylistItem();
|
||||
void toggleOnTop();
|
||||
void updateDurationStringText();
|
||||
QVariant getTracks() const;
|
||||
|
||||
QVariant getTrack(const QString& track);
|
||||
|
|
|
@ -168,18 +168,6 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
function setProgressBarEnd(val) {
|
||||
progressBar.to = val
|
||||
}
|
||||
|
||||
function setProgressBarValue(val) {
|
||||
progressBar.value = val
|
||||
timeLabel.text = player.createTimestamp(
|
||||
val) + " / " + player.createTimestamp(
|
||||
progressBar.to) + " (" + parseFloat(
|
||||
player.getProperty("speed").toFixed(2)) + "x)"
|
||||
}
|
||||
|
||||
function skipToNinth(val) {
|
||||
var skipto = 0
|
||||
if (val != 0) {
|
||||
|
@ -226,14 +214,6 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
function setTitle(title) {
|
||||
titleLabel.text = title
|
||||
}
|
||||
|
||||
function setSubtitles(subs) {
|
||||
nativeSubs.text = subs
|
||||
}
|
||||
|
||||
function isAnyMenuOpen() {
|
||||
return settingsMenu.visible || fileMenuBarItem.opened
|
||||
|| playbackMenuBarItem.opened || viewMenuBarItem.opened
|
||||
|
@ -864,6 +844,7 @@ ApplicationWindow {
|
|||
|
||||
Text {
|
||||
id: titleLabel
|
||||
objectName: "titleLabel"
|
||||
text: translate.getTranslation("TITLE", i18n.language)
|
||||
color: "white"
|
||||
width: parent.width
|
||||
|
@ -926,6 +907,7 @@ ApplicationWindow {
|
|||
|
||||
Label {
|
||||
id: nativeSubs
|
||||
objectName: "nativeSubs"
|
||||
onWidthChanged: {
|
||||
|
||||
if (width > parent.width - 10)
|
||||
|
@ -990,6 +972,7 @@ ApplicationWindow {
|
|||
|
||||
Slider {
|
||||
id: progressBar
|
||||
objectName: "progressBar"
|
||||
to: 1
|
||||
value: 0.0
|
||||
anchors.bottom: parent.top
|
||||
|
@ -1206,6 +1189,7 @@ ApplicationWindow {
|
|||
|
||||
Text {
|
||||
id: timeLabel
|
||||
objectName: "timeLabel"
|
||||
text: "0:00 / 0:00"
|
||||
color: "white"
|
||||
anchors.left: volumeBar.right
|
||||
|
|
Loading…
Reference in a new issue