[vlc-commits] qml: add msToString helper function
Prince Gupta
git at videolan.org
Tue Apr 6 13:11:56 UTC 2021
vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Mon Mar 15 18:39:03 2021 +0530| [65428b9575f96f444dba940ae38988f882be132e] | committer: Pierre Lamot
qml: add msToString helper function
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=65428b9575f96f444dba940ae38988f882be132e
---
modules/gui/qt/Makefile.am | 1 +
modules/gui/qt/util/qml/Helpers.js | 38 ++++++++++++++++++++++++++++++++++++++
modules/gui/qt/vlc.qrc | 1 +
3 files changed, 40 insertions(+)
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 7672343d3c..969a6c0035 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -731,6 +731,7 @@ libqt_plugin_la_QML = \
gui/qt/style/VLCIcons.qml \
gui/qt/style/VLCStyle.qml \
gui/qt/style/qmldir \
+ gui/qt/util/qml/Helpers.js \
gui/qt/util/qml/KeyHelper.js \
gui/qt/util/qml/SelectableDelegateModel.qml \
gui/qt/widgets/qml/BannerTabButton.qml \
diff --git a/modules/gui/qt/util/qml/Helpers.js b/modules/gui/qt/util/qml/Helpers.js
new file mode 100644
index 0000000000..761d13a4c6
--- /dev/null
+++ b/modules/gui/qt/util/qml/Helpers.js
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (C) 2021 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+.pragma library
+
+function msToString(time, short) {
+ if (time < 0) return "--:--"
+
+ var t_sec = Math.floor(time / 1000)
+ var sec = t_sec % 60
+ var min = Math.floor(t_sec / 60) % 60
+ var hour = Math.floor(t_sec / 3600)
+
+ function prefixZero(number) {
+ return number < 10 ? "0" + number : number;
+ }
+
+ if (hour === 0)
+ return "%1:%2".arg(prefixZero(min)).arg(prefixZero(sec))
+ if (!!short)
+ return "%1h%2".arg(hour.toFixed()).arg(prefixZero(min))
+ return "%1:%2:%3".arg(prefixZero(hour)).arg(prefixZero(min)).arg(prefixZero(sec))
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 05bcc008c3..5cc9022d39 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -26,6 +26,7 @@
<file alias="wait4.svg">pixmaps/util/wait4.svg</file>
<file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
<file alias="KeyHelper.js">util/qml/KeyHelper.js</file>
+ <file alias="Helpers.js">util/qml/Helpers.js</file>
</qresource>
<qresource prefix="/toolbar">
<file alias="faster.svg">pixmaps/faster.svg</file>
More information about the vlc-commits
mailing list