-
Notifications
You must be signed in to change notification settings - Fork 4
/
mainwindow.cpp
132 lines (116 loc) · 4.14 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (c) 2011 Dan Dennedy <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QVBoxLayout>
MainWindow::MainWindow (QWidget *parent)
: QMainWindow (parent)
, ui (new Ui::MainWindow)
{
// Create the UI.
ui->setupUi (this);
// This is required for SDL embeddding.
ui->centralWidget->setAttribute (Qt::WA_NativeWindow);
// These use the icon theme on Linux, with fallbacks to the icons specified in QtDesigner for other platforms.
ui->actionOpen->setIcon (QIcon::fromTheme ("document-open", ui->actionOpen->icon ()));
ui->actionPlay->setIcon (QIcon::fromTheme ("media-playback-start", ui->actionPlay->icon ()));
ui->actionPause->setIcon (QIcon::fromTheme ("media-playback-pause", ui->actionPause->icon ()));
// Connect UI signals.
connect (ui->actionOpen, SIGNAL(triggered()), this, SLOT(openVideo()));
connect (ui->actionPlay, SIGNAL(triggered()), this, SLOT(play()));
connect (ui->actionPause, SIGNAL(triggered()), this, SLOT(pause()));
// Create MLT controller and connect its signals.
mlt = new MltController (ui->centralWidget);
connect (mlt, SIGNAL(frameReceived (void*, unsigned)), this, SLOT(onShowFrame (void*, unsigned)));
#ifdef Q_WS_MAC
gl = new GLWidget (this);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (gl);
layout->setMargin (0);
ui->centralWidget->setLayout (layout);
connect (this, SIGNAL (showImageSignal (QImage)), gl, SLOT (showImage(QImage)));
#endif
}
MainWindow::~MainWindow ()
{
delete mlt;
#ifdef Q_WS_MAC
delete gl;
#endif
delete ui;
}
void MainWindow::initializeMlt ()
{
ui->statusBar->showMessage (tr("Loading plugins..."));
mlt->init ();
// Load a color producer to clear the video region with black.
mlt->open ("color:");
pause ();
ui->statusBar->showMessage (tr("Ready"));
}
void MainWindow::openVideo ()
{
QString filename = QFileDialog::getOpenFileName (this);
if (!filename.isNull())
{
if (!mlt->open (filename.toUtf8().constData())) {
#ifdef Q_WS_MAC
gl->setImageAspectRatio (mlt->profile()->dar());
#endif
play();
}
}
// If file invalid, then on some platforms the dialog messes up SDL.
mlt->onWindowResize ();
}
void MainWindow::play ()
{
mlt->play ();
forceResize ();
ui->statusBar->showMessage (tr("Playing"));
}
void MainWindow::pause ()
{
mlt->pause ();
forceResize ();
ui->statusBar->showMessage (tr("Paused"));
}
void MainWindow::resizeEvent (QResizeEvent*)
{
mlt->onWindowResize();
}
void MainWindow::forceResize()
{
// XXX: this is a hack to force video container to resize
int width = ui->centralWidget->width();
int height = ui->centralWidget->height();
ui->centralWidget->resize (width - 1, height - 1);
ui->centralWidget->resize (width, height);
}
void MainWindow::onShowFrame (void* frame, unsigned position)
{
#ifdef Q_WS_MAC
emit showImageSignal (mlt->getImage (frame));
#endif
ui->statusBar->showMessage (QString().sprintf ("%.3f", position / mlt->profile()->fps()));
}