1
0
Fork 0

[Backend] Reimplement createTimestamp in C++.

This commit is contained in:
Kitteh 2018-11-06 08:24:24 +00:00
parent 8fc36d20b7
commit 8d68ab2a46
3 changed files with 19 additions and 14 deletions

View file

@ -8,7 +8,7 @@
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
#include <QQuickWindow>
#include <math.h>
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()
{

View file

@ -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();

View file

@ -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