-
Notifications
You must be signed in to change notification settings - Fork 6
/
videowindow.cpp
96 lines (74 loc) · 2.36 KB
/
videowindow.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
#include "videowindow.h"
#include "ui_videowindow.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtCore/QCommandLineParser>
#include <QtCore/QCommandLineOption>
#include <QtCore/QDir>
#include <QThread>
#include <QPainter>
#include <QInputDialog>
#include <QtMath>
#include <QSettings>
#include <QString>
#include <QDebug>
#include <QMouseEvent>
videowindow::videowindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::videowindow)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
setFocusPolicy(Qt::StrongFocus);
QSettings *configIniRead = new QSettings("config.ini", QSettings::IniFormat);
//将读取到的ini文件保存在QString中,先取值,然后通过toString()函数转换成QString类型
QString videoPath = configIniRead->value("/video/path").toString();
//读入入完成后删除指针
delete configIniRead;
mLocalPlayer = new LocalVideoPlayer(videoPath);
connect(mLocalPlayer,SIGNAL(sig_GetVideoFrame(QImage)),this,SLOT(slotGetVideoFrame(QImage)));
connect(mLocalPlayer,SIGNAL(sig_VideoFinished()),this,SLOT(slotVideoFinished()));
mLocalPlayer->startPlay();
}
videowindow::~videowindow()
{
delete ui;
}
void videowindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setBrush(QColor(0,0,0,0));
//painter.setBrush(Qt::black);
//painter.drawRect(0, 0, this->width(), this->height()); //先画成白色
if (mImage.size().width() <= 0) return;
//将图像按比例缩放成和窗口一样大小
QImage img = mImage.scaled(this->size(),Qt::KeepAspectRatioByExpanding);
int x = this->width() - img.width();
int y = this->height() - img.height();
x /= 2;
y /= 2;
painter.drawImage(QPoint(x,y),img); //画出图像
}
void videowindow::slotGetVideoFrame(QImage img)
{
mImage = img;
update(); //调用update将执行 paintEvent函数
}
void videowindow::slotVideoFinished()
{
qDebug() << "slotVideoFinished!!";
isClose = true;
this->setWindowFlags(Qt::SubWindow);
this->showNormal();
this->close();
}
void videowindow::keyPressEvent(QKeyEvent *event)
{
int key = event->key();
qDebug() << "videowindow QKeyEvent" <<key;
isClose = true;
this->setWindowFlags(Qt::SubWindow);
this->showNormal();
this->close();
}