summaryrefslogtreecommitdiffstats
path: root/DOCS/client_api_examples/qt_opengl/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'DOCS/client_api_examples/qt_opengl/mainwindow.cpp')
-rw-r--r--DOCS/client_api_examples/qt_opengl/mainwindow.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/DOCS/client_api_examples/qt_opengl/mainwindow.cpp b/DOCS/client_api_examples/qt_opengl/mainwindow.cpp
new file mode 100644
index 0000000000..2e3cf210ee
--- /dev/null
+++ b/DOCS/client_api_examples/qt_opengl/mainwindow.cpp
@@ -0,0 +1,53 @@
+#include "mainwindow.h"
+#include "mpvwidget.h"
+#include <QPushButton>
+#include <QSlider>
+#include <QLayout>
+#include <QFileDialog>
+
+MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
+{
+ m_mpv = new MpvWidget(this);
+ m_slider = new QSlider();
+ m_slider->setOrientation(Qt::Horizontal);
+ m_openBtn = new QPushButton("Open");
+ m_playBtn = new QPushButton("Pause");
+ QHBoxLayout *hb = new QHBoxLayout();
+ hb->addWidget(m_openBtn);
+ hb->addWidget(m_playBtn);
+ QVBoxLayout *vl = new QVBoxLayout();
+ vl->addWidget(m_mpv);
+ vl->addWidget(m_slider);
+ vl->addLayout(hb);
+ setLayout(vl);
+ connect(m_slider, SIGNAL(sliderMoved(int)), SLOT(seek(int)));
+ connect(m_openBtn, SIGNAL(clicked()), SLOT(openMedia()));
+ connect(m_playBtn, SIGNAL(clicked()), SLOT(pauseResume()));
+ connect(m_mpv, SIGNAL(positionChanged(int)), m_slider, SLOT(setValue(int)));
+ connect(m_mpv, SIGNAL(durationChanged(int)), this, SLOT(setSliderRange(int)));
+}
+
+void MainWindow::openMedia()
+{
+ QString file = QFileDialog::getOpenFileName(0, "Open a video");
+ if (file.isEmpty())
+ return;
+ m_mpv->command(QStringList() << "loadfile" << file);
+}
+
+void MainWindow::seek(int pos)
+{
+ m_mpv->command(QVariantList() << "seek" << pos << "absolute");
+}
+
+void MainWindow::pauseResume()
+{
+ const bool paused = m_mpv->getProperty("pause").toBool();
+ m_mpv->setProperty("pause", !paused);
+}
+
+void MainWindow::setSliderRange(int duration)
+{
+ const int time0 = m_mpv->getProperty("time-start").toInt();
+ m_slider->setRange(time0, time0+duration);
+}