diff --git a/src/audiomanager.cpp b/src/audiomanager.cpp index 27041afa..18b44280 100644 --- a/src/audiomanager.cpp +++ b/src/audiomanager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "datamanager.h" @@ -70,6 +71,18 @@ AudioManager::~AudioManager() d->mPowerInterface.setPreventSleep(false); } +QString AudioManager::timeString(qint64 timeInMicroSeconds) +{ + QString outputString; + outputString += qFloor(timeInMicroSeconds / 3600000) < 10 ? QStringLiteral("0") : QStringLiteral(""); + outputString += QString::number(qFloor(timeInMicroSeconds / 3600000)) + QStringLiteral(":"); + outputString += qFloor(timeInMicroSeconds / 60000) % 60 < 10 ? QStringLiteral("0") : QStringLiteral(""); + outputString += QString::number(qFloor(timeInMicroSeconds / 60000) % 60) + QStringLiteral(":"); + outputString += qFloor(timeInMicroSeconds / 1000) % 60 < 10 ? QStringLiteral("0") : QStringLiteral(""); + outputString += QString::number(qFloor(timeInMicroSeconds / 1000) % 60); + return outputString; +} + Entry *AudioManager::entry() const { return d->m_entry; diff --git a/src/audiomanager.h b/src/audiomanager.h index ea0a56f5..405e61e7 100644 --- a/src/audiomanager.h +++ b/src/audiomanager.h @@ -48,6 +48,8 @@ public: ~AudioManager() override; + Q_INVOKABLE static QString timeString(qint64 timeInMicroSeconds); + [[nodiscard]] Entry *entry() const; [[nodiscard]] bool muted() const; diff --git a/src/qml/GenericEntryDelegate.qml b/src/qml/GenericEntryDelegate.qml index bfc6fc31..6a599325 100644 --- a/src/qml/GenericEntryDelegate.qml +++ b/src/qml/GenericEntryDelegate.qml @@ -91,7 +91,7 @@ Kirigami.SwipeListItem { Component { id: subtitle Controls.Label { - text: (Math.floor(entry.enclosure.duration/3600) < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/3600) + ":" + (Math.floor(entry.enclosure.duration/60) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/60) % 60 + ":" + (Math.floor(entry.enclosure.duration) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration) % 60 + text: audio.timeString(entry.enclosure.duration * 1000) Layout.fillWidth: true elide: Text.ElideRight font: Kirigami.Theme.smallFont @@ -113,7 +113,7 @@ Kirigami.SwipeListItem { id: playProgress RowLayout { Controls.Label { - text: (Math.floor(entry.enclosure.playPosition/3600000) < 10 ? "0" : "") + Math.floor(entry.enclosure.playPosition/3600000) + ":" + (Math.floor(entry.enclosure.playPosition/60000) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.playPosition/60000) % 60 + ":" + (Math.floor(entry.enclosure.playPosition/1000) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.playPosition/1000) % 60 + text: audio.timeString(entry.enclosure.playPosition) elide: Text.ElideRight font: Kirigami.Theme.smallFont opacity: 0.7 @@ -121,11 +121,11 @@ Kirigami.SwipeListItem { Controls.ProgressBar { from: 0 to: entry.enclosure.duration - value: entry.enclosure.playPosition/1000 + value: entry.enclosure.playPosition / 1000 Layout.fillWidth: true } Controls.Label { - text: (Math.floor(entry.enclosure.duration/3600) < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/3600) + ":" + (Math.floor(entry.enclosure.duration/60) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/60) % 60 + ":" + (Math.floor(entry.enclosure.duration) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration) % 60 + text: audio.timeString(entry.enclosure.duration * 1000) elide: Text.ElideRight font: Kirigami.Theme.smallFont opacity: 0.7 diff --git a/src/qml/PlayerControls.qml b/src/qml/PlayerControls.qml index de0e58fd..f3254982 100644 --- a/src/qml/PlayerControls.qml +++ b/src/qml/PlayerControls.qml @@ -162,7 +162,7 @@ Kirigami.Page { Layout.fillWidth: true Controls.Label { //anchor.left: parent.left - text: (Math.floor(audio.position/3600000) < 10 ? "0" : "") + Math.floor(audio.position/3600000) + ":" + (Math.floor(audio.position/60000) % 60 < 10 ? "0" : "") + Math.floor(audio.position/60000) % 60 + ":" + (Math.floor(audio.position/1000) % 60 < 10 ? "0" : "") + Math.floor(audio.position/1000) % 60 + text: audio.timeString(audio.position) } Item { Layout.fillWidth: true @@ -175,8 +175,8 @@ Kirigami.Page { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter text: (SettingsManager.toggleRemainingTime) ? - ((Math.floor((audio.duration-audio.position)/3600000) < 10 ? "-0" : "-") + Math.floor((audio.duration-audio.position)/3600000) + ":" + (Math.floor((audio.duration-audio.position)/60000) % 60 < 10 ? "0" : "") + Math.floor((audio.duration-audio.position)/60000) % 60 + ":" + (Math.floor((audio.duration-audio.position)/1000) % 60 < 10 ? "0" : "") + Math.floor((audio.duration-audio.position)/1000) % 60) - : ((Math.floor(audio.duration/3600000) < 10 ? "0" : "") + Math.floor(audio.duration/3600000) + ":" + (Math.floor(audio.duration/60000) % 60 < 10 ? "0" : "") + Math.floor(audio.duration/60000) % 60 + ":" + (Math.floor(audio.duration/1000) % 60 < 10 ? "0" : "") + Math.floor(audio.duration/1000) % 60) + "-" + audio.timeString(audio.duration-audio.position) + : audio.timeString(audio.duration) } MouseArea {