From d9d053bb5eb16b265de195fefa3f9687f51afab1 Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Wed, 29 Dec 2021 13:17:57 +0100 Subject: [PATCH] Fix return key, add get_elapsed and get_duration --- src/module/qt_window/mpvwidget.cc | 14 +++++++------- src/module/qt_window/mpvwidget.hh | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/module/qt_window/mpvwidget.cc b/src/module/qt_window/mpvwidget.cc index 35b65b5d..924a0424 100644 --- a/src/module/qt_window/mpvwidget.cc +++ b/src/module/qt_window/mpvwidget.cc @@ -170,13 +170,11 @@ MpvWidget::handle_mpv_event(mpv_event *event) prop = static_cast<mpv_event_property *>(event->data); if (strcmp(prop->name, "time-pos") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { - double time = *static_cast<double *>(prop->data); - Q_EMIT positionChanged(static_cast<int>(time)); + m_position = static_cast<int>(*reinterpret_cast<double*>(prop->data)); } } else if (strcmp(prop->name, "duration") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { - double time = *static_cast<double *>(prop->data); - Q_EMIT durationChanged(static_cast<int>(time)); + m_duration = static_cast<int>(*reinterpret_cast<double*>(prop->data)); } } break; @@ -241,14 +239,14 @@ MpvWidget::on_update(void *ctx) bool MpvWidget::get_elapsed(int UNUSED *elapsed_sec) { - *elapsed_sec = 5; + *elapsed_sec = m_position; return true; } bool MpvWidget::get_duration(int UNUSED *dur_sec) { - *dur_sec = 90; + *dur_sec = m_duration; return true; } @@ -345,10 +343,12 @@ MpvWidget::keyPressEvent(QKeyEvent* event) lmpv_toggle_pause(mpv); //lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_TOGGLE); break; - case Qt::Key_Enter: + case Qt::Key_Return: + LOG_DEBUG("WINDOW", "RETURN PRESSED"); lkt_queue_send(m_queue, LKT_EVENT_PLAY_NEXT, nullptr); break; case Qt::Key_Less: + LOG_DEBUG("WINDOW", "LESS PRESSED"); lkt_queue_send(m_queue, LKT_EVENT_PLAY_PREV, nullptr); break; case Qt::Key_Left: diff --git a/src/module/qt_window/mpvwidget.hh b/src/module/qt_window/mpvwidget.hh index ecf86a36..3f05be02 100644 --- a/src/module/qt_window/mpvwidget.hh +++ b/src/module/qt_window/mpvwidget.hh @@ -15,9 +15,6 @@ public: void setProperty(const QString &name, const QVariant &value); QVariant getProperty(const QString &name) const; QSize sizeHint() const { return QSize(480, 270); } -Q_SIGNALS: - void durationChanged(int value); - void positionChanged(int value); protected: void initializeGL() Q_DECL_OVERRIDE; @@ -38,6 +35,9 @@ private: lkt_db *m_db; struct module_reg *m_reg; + int m_position; + int m_duration; + protected: void keyPressEvent(QKeyEvent* event); -- GitLab