-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmonitorsim.cpp
76 lines (64 loc) · 1.99 KB
/
monitorsim.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
#include <QApplication>
#include <QPushButton>
#include <QListWidget>
#include <QListWidgetItem>
#include <QGridLayout>
#include <fstream>
#include <iostream>
#include <libevdipp/evdi.hpp>
#include "screenpreview.h"
namespace {
bool read_edid_from_file(const std::string& filename,
std::vector<unsigned char>& edid)
{
try {
std::ifstream input(filename.c_str(), std::ios::binary | std::ios::ate);
input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
if (input) {
std::streamsize size = input.tellg();
input.seekg(0, std::ios::beg);
edid.resize(size);
input.read((char*)edid.data(), size);
return input.good();
}
} catch (const std::ios::failure&) {
return false;
}
return false;
}
} // anonymous namespace
int main(int argc, char* argv[])
{
std::vector<unsigned char> edid;
if (argc > 1) {
if (!read_edid_from_file(argv[1], edid)) {
std::cerr << "Reading the EDID file " << argv[1] << " failed."
<< std::endl;
return 1;
}
} else {
std::cerr << "Warning: no argument passed, using built-in sample EDID" << std::endl;
}
QApplication app(argc, argv);
auto log = new QListWidget;
Evdi::log_handler = [&log](const std::string& message) {
new QListWidgetItem(QString::fromStdString(message), log);
};
Evdi evdi;
if (!evdi) {
std::cerr << "No usable EVDI found" << std::endl;
return 3;
}
auto window = new QWidget;
QEvdiScreen screen(evdi, edid);
auto preview = new ScreenPreview(screen);
auto grid = new QGridLayout(window);
auto button = new QPushButton("Save screenshot");
grid->addWidget(button, 0, 0);
grid->addWidget(log, 0, 1);
grid->addWidget(preview, 1, 0, 1, 2);
window->setLayout(grid);
window->connect(button, SIGNAL(clicked()), preview, SLOT(save_screenshot()));
window->show();
return app.exec();
}