-
Notifications
You must be signed in to change notification settings - Fork 6
/
mainwindow.cpp
114 lines (88 loc) · 2.66 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
#include "mainwindow.h"
#include "ui_mainwindow.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 <QMouseEvent>
#include <QSettings>
#include <QSettings>
#include <QString>
#include <QDebug>
#include<iostream>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// setWindowFlags(Qt::FramelessWindowHint);
QSettings *configIniRead = new QSettings("config.ini", QSettings::IniFormat);
//将读取到的ini文件保存在QString中,先取值,然后通过toString()函数转换成QString类型
rtspUrl = configIniRead->value("/rtsp/url").toString();
videoPath = configIniRead->value("/video/path").toString();
//读入入完成后删除指针
delete configIniRead;
mPlayer = new VideoPlayer(rtspUrl);
connect(mPlayer,SIGNAL(sig_GetOneFrame(QImage)),this,SLOT(slotGetOneFrame(QImage)));
connect(ui->Open_red,&QAction::triggered,this,&MainWindow::slotOpenRed);
connect(ui->Close_Red,&QAction::triggered,this,&MainWindow::slotCloseRed);
mPlayer->startPlay();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::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 MainWindow::slotGetOneFrame(QImage img)
{
mImage = img;
update(); //调用update将执行 paintEvent函数
}
//小窗口显示
void MainWindow::slotGetRFrame(QImage img)
{
R_mImage = img;
update(); //调用update将执行 paintEvent函数
}
//显示图像红色通道,2017.8.12---lizhen
bool MainWindow::slotOpenRed()
{
open_red=true;
return open_red;
}
//关闭图像红色通道,2017.8.12
bool MainWindow::slotCloseRed()
{
open_red=false;
return open_red;
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
int key = event->key();
qDebug() << "QKeyEvent:" <<key;
if(key == Qt::Key_A){
vWindow = new videowindow;
vWindow->setAttribute(Qt::WA_DeleteOnClose,true);
vWindow->showFullScreen();
}
}