diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 7e5f767..66f7fb1 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -8,7 +8,7 @@ #include #include #include - +#include namespace { void @@ -282,6 +282,22 @@ MpvPlayerBackend::getTracks() const return mpv::qt::get_property_variant(mpv, "track-list"); } +QVariant +MpvPlayerBackend::createTimestamp(const QVariant& seconds) const +{ + int d = seconds.toInt(); + double h = floor(d / 3600); + double m = floor(d % 3600 / 60); + double s = floor(d % 3600 % 60); + + QString hour = h > 0 ? QString::number(h) + ":" : ""; + QString minute = h < 1 ? QString::number(m) + ":" + : (m < 10 ? "0" + QString::number(m) + ":" + : QString::number(m) + ":"); + QString second = s < 10 ? "0" + QString::number(s) : QString::number(s); + return hour + minute + second; +} + void MpvPlayerBackend::on_mpv_events() { diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index a52d089..d430d10 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -45,6 +45,7 @@ public slots: void setProperty(const QString& name, const QVariant& value); void setOption(const QString& name, const QVariant& value); QVariant getProperty(const QString& name) const; + QVariant createTimestamp(const QVariant& seconds) const; signals: void onUpdate(); diff --git a/src/qml/main.qml b/src/qml/main.qml index f26f2e6..505ef47 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -145,24 +145,12 @@ ApplicationWindow { } } - function createTimestamp(d) { - d = Number(d) - var h = Math.floor(d / 3600) - var m = Math.floor(d % 3600 / 60) - var s = Math.floor(d % 3600 % 60) - - var hour = h > 0 ? h + ":" : "" - var minute = h < 1 ? m + ":" : (m < 10 ? "0" + m + ":" : m + ":") - var second = s < 10 ? "0" + s : s - return hour + minute + second - } - function setProgressBarEnd(val) { progressBar.to = val } function setProgressBarValue(val) { - timeLabel.text = createTimestamp(val) + " / " + createTimestamp( + timeLabel.text = player.createTimestamp(val) + " / " + player.createTimestamp( progressBar.to) + " (" + parseFloat( player.getProperty("speed").toFixed(2)) + "x)" progressBar.value = val