[vlc-devel] [RFC 14/82] qt: provide a wrapper around vlc_tick_t usable from QML
Pierre Lamot
pierre at videolabs.io
Fri Feb 1 14:01:18 CET 2019
---
modules/gui/qt/Makefile.am | 3 ++
modules/gui/qt/util/vlctick.cpp | 51 +++++++++++++++++++++++++++++++++
modules/gui/qt/util/vlctick.hpp | 47 ++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+)
create mode 100644 modules/gui/qt/util/vlctick.cpp
create mode 100644 modules/gui/qt/util/vlctick.hpp
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index a37baeb1a9..0b20509bc0 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -144,6 +144,8 @@ libqt_plugin_la_SOURCES = \
gui/qt/util/qvlcframe.hpp \
gui/qt/util/qvlcapp.hpp \
gui/qt/util/singleton.hpp \
+ gui/qt/util/vlctick.cpp \
+ gui/qt/util/vlctick.hpp \
gui/qt/util/imagehelper.cpp gui/qt/util/imagehelper.hpp \
gui/qt/styles/seekstyle.cpp gui/qt/styles/seekstyle.hpp
if HAVE_WIN32
@@ -230,6 +232,7 @@ nodist_libqt_plugin_la_SOURCES = \
gui/qt/util/qmenuview.moc.cpp \
gui/qt/util/qvlcapp.moc.cpp \
gui/qt/util/pictureflow.moc.cpp \
+ gui/qt/util/vlctick.moc.cpp \
gui/qt/util/validators.moc.cpp \
gui/qt/util/buttons/RoundButton.moc.cpp \
gui/qt/util/buttons/DeckButtonsLayout.moc.cpp \
diff --git a/modules/gui/qt/util/vlctick.cpp b/modules/gui/qt/util/vlctick.cpp
new file mode 100644
index 0000000000..bd0074da54
--- /dev/null
+++ b/modules/gui/qt/util/vlctick.cpp
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (C) 2019 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.
+ *****************************************************************************/
+#include "vlctick.hpp"
+
+VLCTick::VLCTick()
+ : m_ticks(VLC_TICK_INVALID)
+{
+
+}
+
+VLCTick::VLCTick(vlc_tick_t ticks)
+ : m_ticks(ticks)
+{
+}
+
+VLCTick::operator vlc_tick_t() const
+{
+ return m_ticks;
+}
+
+QString VLCTick::toString() const
+{
+ int64_t t_sec = SEC_FROM_VLC_TICK(m_ticks);
+ int sec = t_sec % 60;
+ int min = (t_sec / 60) % 60;
+ int hour = t_sec / 3600;
+ if (hour == 0)
+ return QString("%1:%2")
+ .arg(min, 2, 10, QChar('0'))
+ .arg(sec, 2, 10, QChar('0'));
+ else
+ return QString("%1:%2:%3")
+ .arg(hour, 2, 10, QChar('0'))
+ .arg(min, 2, 10, QChar('0'))
+ .arg(sec, 2, 10, QChar('0'));
+}
diff --git a/modules/gui/qt/util/vlctick.hpp b/modules/gui/qt/util/vlctick.hpp
new file mode 100644
index 0000000000..19ea5d1db5
--- /dev/null
+++ b/modules/gui/qt/util/vlctick.hpp
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (C) 2019 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.
+ *****************************************************************************/
+#ifndef VLCTICK_HPP
+#define VLCTICK_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <QObject>
+#include <vlc_common.h>
+#include <vlc_tick.h>
+
+class VLCTick
+{
+ Q_GADGET
+public:
+ VLCTick();
+ VLCTick(vlc_tick_t ticks);
+
+ operator vlc_tick_t() const;
+ /**
+ * @brief toString
+ * @return time as HH:MM:SS
+ */
+ Q_INVOKABLE QString toString() const;
+
+private:
+ vlc_tick_t m_ticks;
+};
+
+#endif // VLCTICK_HPP
--
2.19.1
More information about the vlc-devel
mailing list