forked from shi-yan/H264Naked
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
65 lines (51 loc) · 1.97 KB
/
Copy pathMainWindow.cpp
File metadata and controls
65 lines (51 loc) · 1.97 KB
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
#include "MainWindow.hpp"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QProgressBar>
#include <QFileInfo>
#include <QDebug>
#include <QKeySequence>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
_fileChooser(this, tr("Open H264 file"), QString(), tr("H264 Files (*.h264 *.264)")),
_openShortcut(QKeySequence::Open, &_fileChooser, SLOT(open())),
_ui(new Ui::MainWindow)
{
_ui->setupUi(this);
connect(&_streamModel, &H264NALListModel::parsingProgress, [this](qreal progress) {
auto val = static_cast<int>(progress * 100);
_ui->progressBar->setVisible(!(val == 100));
_ui->progressBar->setValue(val);
});
connect(&_fileChooser, SIGNAL(fileSelected(const QString&)), this, SLOT(openFile(const QString &)));
connect(_ui->openPushButton, SIGNAL(clicked()), &_fileChooser, SLOT(open()));
if (QApplication::arguments().size() > 1)
openFile(QApplication::arguments().at(1));
}
MainWindow::~MainWindow()
{
delete _ui;
}
void MainWindow::openFile(const QString& filename)
{
if (filename.isEmpty()) return;
QFileInfo fileInfo(filename);
if (!fileInfo.isReadable())
{
QMessageBox::critical(this, tr("Error"), tr("Can't open file %1.").arg(filename));
return;
}
_ui->progressBar->setTextVisible(true);
_ui->filePathLineEdit->setText(fileInfo.absoluteFilePath());
_streamModel.setFile(filename);
_ui->nalTableView->setModel(&_streamModel);
connect(_ui->nalTableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(onNalTableItemSelected(const QItemSelection &, const QItemSelection &)));
}
void MainWindow::onNalTableItemSelected(const QItemSelection &selected, const QItemSelection &deselected)
{
auto index = selected.indexes().first();
Q_UNUSED(deselected)
_ui->nalPlainTextEdit->setPlainText(_streamModel.data(index, Qt::UserRole).toString());
}