From ab5d58c3d9ea908667b1d1715660911e878f20d6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 8 Oct 2014 13:20:35 +0200 Subject: DOCS/client_api_examples: qtexample: add a log window For the purpose of demonstration. Also make the windows larger. I'm not exactly sure how Qt determines the default window sizes, but here they are a bit tiny, so force them larger. --- DOCS/client_api_examples/qtexample.cpp | 26 ++++++++++++++++++++++++++ DOCS/client_api_examples/qtexample.h | 3 +++ 2 files changed, 29 insertions(+) (limited to 'DOCS/client_api_examples') diff --git a/DOCS/client_api_examples/qtexample.cpp b/DOCS/client_api_examples/qtexample.cpp index 5ebc788c64..fa657cf7b9 100644 --- a/DOCS/client_api_examples/qtexample.cpp +++ b/DOCS/client_api_examples/qtexample.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "qtexample.h" @@ -27,6 +28,9 @@ static void wakeup(void *ctx) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + setWindowTitle("Qt embedding demo"); + setMinimumSize(640, 480); + QMenu *menu = menuBar()->addMenu(tr("&File")); QAction *on_open = new QAction(tr("&Open"), this); on_open->setShortcuts(QKeySequence::Open); @@ -36,6 +40,14 @@ MainWindow::MainWindow(QWidget *parent) : statusBar(); + QMainWindow *log_window = new QMainWindow(this); + log = new QTextEdit(log_window); + log->setReadOnly(true); + log_window->setCentralWidget(log); + log_window->setWindowTitle("mpv log window"); + log_window->setMinimumSize(500, 50); + log_window->show(); + mpv = mpv_create(); if (!mpv) throw "can't create mpv instance"; @@ -62,6 +74,10 @@ MainWindow::MainWindow(QWidget *parent) : // this property changes. mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); + // Request log messages with level verbose ("v") or higher. + // They are received as MPV_EVENT_LOG_MESSAGE. + mpv_request_log_messages(mpv, "v"); + // From this point on, the wakeup function will be called. The callback // can come from any thread, so we use the Qt QEvent mechanism to relay // the wakeup in a thread-safe way. @@ -108,6 +124,16 @@ void MainWindow::handle_mpv_event(mpv_event *event) } break; } + case MPV_EVENT_LOG_MESSAGE: { + struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data; + std::stringstream ss; + ss << "[" << msg->prefix << "] " << msg->level << ": " << msg->text; + QTextCursor cursor = log->textCursor(); + cursor.movePosition(QTextCursor::End); + cursor.insertText(QString::fromStdString(ss.str())); + log->setTextCursor(cursor); + break; + } case MPV_EVENT_SHUTDOWN: { mpv_terminate_destroy(mpv); mpv = NULL; diff --git a/DOCS/client_api_examples/qtexample.h b/DOCS/client_api_examples/qtexample.h index b5b6fe7fb2..8d5ef41143 100644 --- a/DOCS/client_api_examples/qtexample.h +++ b/DOCS/client_api_examples/qtexample.h @@ -5,6 +5,8 @@ #include +class QTextEdit; + class MainWindow : public QMainWindow { Q_OBJECT @@ -22,6 +24,7 @@ private slots: private: QWidget *mpv_container; mpv_handle *mpv; + QTextEdit *log; void create_player(); void handle_mpv_event(mpv_event *event); -- cgit v1.2.3