-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
100 lines (82 loc) · 2.18 KB
/
mainwindow.cpp
File metadata and controls
100 lines (82 loc) · 2.18 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
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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QFileDialog>
#include <XDemuxThread.h>
#include <QMessageBox>
static XDemuxThread dt;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
dt.Start();
startTimer(40);
}
MainWindow::~MainWindow()
{
delete ui;
dt.Close();
}
void MainWindow::timerEvent(QTimerEvent *e)
{
if(isSliderPress) return;
long long total = dt.totalMs;
if(total > 0)
{
double pos = static_cast<double>(dt.pts) / static_cast<double>(total);
int v = ui->playPos->maximum() * pos;
ui->playPos->setValue(v);
}
}
void MainWindow::resizeEvent(QResizeEvent *e)
{
ui->playPos->move(50, this->height() - 100);
ui->playPos->resize(this->width() - 100, ui->playPos->height());
ui->openFile->move(100, this->height() - 150);
ui->isPlay->move(ui->openFile->x() + ui->openFile->width() + 10, ui->openFile->y());
// ui->video->resize(this->size());
}
void MainWindow::mouseDoubleClickEvent(QMouseEvent *e)
{
if(isFullScreen())
this->showNormal();
else
this->showFullScreen();
}
void MainWindow::SetPause(bool isPause)
{
if(isPause)
ui->isPlay->setText("播放");
else
ui->isPlay->setText("暂停");
}
void MainWindow::on_openFile_clicked()
{
QString name = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择视频文件"));
if(name.isEmpty())
return ;
this->setWindowTitle(name);
if(!dt.Open(name.toLocal8Bit(), this->ui->video))
{
QMessageBox::information(0, "error", "open file filed!");
return ;
}
SetPause(false);
}
void MainWindow::on_isPlay_clicked()
{
bool isPause = !dt.isPause;
SetPause(isPause);
dt.SetPause(isPause);
}
void MainWindow::on_playPos_sliderPressed()
{
isSliderPress = true;
}
void MainWindow::on_playPos_sliderReleased()
{
isSliderPress = false;
double pos = 0.0;
pos = static_cast<double>(ui->playPos->value()) / static_cast<double>(ui->playPos->maximum());
dt.Seek(pos);
}