-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindow.cpp
62 lines (54 loc) · 1.13 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
#include "ImageWidget.h"
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QDebug>
#include <QMutex>
#include <QThread>
#include <QKeyEvent>
#include <QFileDialog>
#include "CameraCaptureThread.h"
#include <QMessageBox>
struct MainWindow::Private {
CameraCaptureThread capture_thread;
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m(new Private)
{
ui->setupUi(this);
m->capture_thread.start();
startTimer(1000 / 30);
}
MainWindow::~MainWindow()
{
m->capture_thread.requestInterruption();
m->capture_thread.wait();
delete m;
delete ui;
}
void MainWindow::timerEvent(QTimerEvent *event)
{
QImage image = m->capture_thread.image();
if (!image.isNull()) {
ui->widget->setImage(image);
}
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
int k = e->key();
if (k == Qt::Key_S) {
if (e->modifiers() & Qt::ControlModifier) {
saveas();
}
}
QMainWindow::keyPressEvent(e);
}
void MainWindow::saveas()
{
QImage image = ui->widget->image();
if (image.isNull()) return;
QString path = QFileDialog::getSaveFileName(this, "Save as");
if (path.isEmpty()) return;
image.save(path);
}