-
Notifications
You must be signed in to change notification settings - Fork 4
/
frontend_qt.cpp
93 lines (80 loc) · 2.3 KB
/
frontend_qt.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
#include "interface.h"
#include <iostream>
#include <stdlib.h>
#include <QApplication>
#include <QCommandLineParser>
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>
#include <QWidget>
class MainWindow : public QWidget {
Q_OBJECT
public:
MainWindow(void *s) : QWidget(NULL) {
state = s;
screen_dark = true;
setWindowFlag(Qt::Window);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_PaintUnclipped);
// TODO: add mode with WA_PaintOnScreen ?
timer.setSingleShot(false);
timer.setInterval(2);
timer.start();
connect(&timer, &QTimer::timeout, this, &MainWindow::checkCamera);
}
virtual void paintEvent(QPaintEvent *event) override {
QPainter p(this);
p.fillRect(this->rect(), screen_dark ? Qt::black : Qt::white);
}
virtual QSize sizeHint() const override {
return QSize(SMALL_WINDOW_SIZE, SMALL_WINDOW_SIZE);
}
public slots:
void checkCamera() {
enum WhatToDo wtd = update_backend(state);
bool next_dark = wtd == DisplayDark;
if (next_dark != screen_dark) {
screen_dark = next_dark;
update();
}
}
private:
QTimer timer;
void *state;
bool screen_dark;
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("Qt frontend for latency tester");
parser.addHelpOption();
parser.addPositionalArgument(
"camera_number",
"Which camera device to read from. Should be /dev/videoN");
bool succeeded = parser.parse(app.arguments());
if (!succeeded) {
return EXIT_FAILURE;
}
if (parser.positionalArguments().size() != 1) {
parser.showHelp();
return EXIT_FAILURE;
}
QString cn = parser.positionalArguments().first();
bool ok;
int camera_number = cn.toInt(&ok);
if (!ok) {
parser.showHelp();
return EXIT_FAILURE;
}
void *state = setup_backend(camera_number);
if (!state) {
qDebug("Failed to open camera #%d", camera_number);
return EXIT_FAILURE;
}
MainWindow window(state);
window.setVisible(true);
int ret = app.exec();
cleanup_backend(state);
return ret;
}
#include "obj/frontend_qt.moc"