summaryrefslogtreecommitdiffstats
path: root/DOCS/client_api_examples
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-08 13:20:35 +0200
committerwm4 <wm4@nowhere>2014-10-08 13:34:06 +0200
commitab5d58c3d9ea908667b1d1715660911e878f20d6 (patch)
tree968d9985fdf4862ed2ab20e9f645ec403442c50a /DOCS/client_api_examples
parentf73778ad82685bd15c40e20b9983ce460d9c3226 (diff)
downloadmpv-ab5d58c3d9ea908667b1d1715660911e878f20d6.tar.bz2
mpv-ab5d58c3d9ea908667b1d1715660911e878f20d6.tar.xz
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.
Diffstat (limited to 'DOCS/client_api_examples')
-rw-r--r--DOCS/client_api_examples/qtexample.cpp26
-rw-r--r--DOCS/client_api_examples/qtexample.h3
2 files changed, 29 insertions, 0 deletions
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 <QMenu>
#include <QGridLayout>
#include <QApplication>
+#include <QTextEdit>
#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 <mpv/client.h>
+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);