Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 88fb82c8 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Connect mpvwidget to mainwindow to update window title

parent e878b899
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!186Add the Qt window module as an alternative to the SDL2 module
...@@ -4,6 +4,7 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent) ...@@ -4,6 +4,7 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this); qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this);
connect(qt_window->mpv_widget, &MpvWidget::titleChanged, this, &MainWindow::updateWindowTitle);
setCentralWidget(qt_window->mpv_widget); setCentralWidget(qt_window->mpv_widget);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
} }
...@@ -10,4 +10,9 @@ class MainWindow : public QMainWindow { ...@@ -10,4 +10,9 @@ class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(struct module_qt_window_s *qt_window, QWidget *parent = nullptr); explicit MainWindow(struct module_qt_window_s *qt_window, QWidget *parent = nullptr);
public slots:
inline void updateWindowTitle(QString str) noexcept {
setWindowTitle(str);
}
}; };
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
#include <QtCore/QMetaObject> #include <QtCore/QMetaObject>
#include <QApplication> #include <QApplication>
#include <QKeyEvent> #include <QKeyEvent>
#include <QString>
#include "qthelper.hh" #include "qthelper.hh"
#include "../mpv.h" #include "../mpv.h"
#include <lektor/mkv.h>
PRIVATE_FUNCTION void PRIVATE_FUNCTION void
wakeup(void *ctx) wakeup(void *ctx)
{ {
...@@ -235,7 +238,7 @@ MpvWidget::load_file(const char *filepath) ...@@ -235,7 +238,7 @@ MpvWidget::load_file(const char *filepath)
if (ret) { if (ret) {
LOG_DEBUG("WINDOW", "Loaded file: %s", filepath); LOG_DEBUG("WINDOW", "Loaded file: %s", filepath);
//set_window_title(win); update_window_title();
} else { } else {
LOG_ERROR("WINDOW", "Failed to load kara with path: %s", filepath); LOG_ERROR("WINDOW", "Failed to load kara with path: %s", filepath);
} }
...@@ -244,6 +247,27 @@ MpvWidget::load_file(const char *filepath) ...@@ -244,6 +247,27 @@ MpvWidget::load_file(const char *filepath)
return ret; return ret;
} }
void
MpvWidget::update_window_title()
{
struct kara_metadata kara_mdt;
int changed_kara = 0;
char *kara_title = nullptr;
char window_title[LKT_LINE_MAX];
if (database_queue_current_kara(m_db, &kara_mdt, &changed_kara)) {
mdtcat(&kara_mdt, &kara_title);
safe_snprintf(window_title, LKT_LINE_MAX, "[Lektord] %d: %s", changed_kara, kara_title);
LOG_DEBUG("WINDOW", "Set window title to: %s", window_title);
titleChanged(QString::fromLocal8Bit(window_title));
free(kara_title);
}
else {
LOG_ERROR("WINDOW", "Failed to get current kara, can't change window title");
}
}
bool bool
MpvWidget::toggle_pause() MpvWidget::toggle_pause()
{ {
......
...@@ -48,4 +48,10 @@ public: ...@@ -48,4 +48,10 @@ public:
bool set_position(int); bool set_position(int);
bool load_file(const char *); bool load_file(const char *);
bool toggle_pause(); bool toggle_pause();
private:
void update_window_title();
signals:
void titleChanged(QString str);
}; };
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter