-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresenter.cpp
More file actions
131 lines (101 loc) · 3.3 KB
/
presenter.cpp
File metadata and controls
131 lines (101 loc) · 3.3 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// PDF presenter
// Author: Max Schwarz <max.schwarz@online.de>
#include "rendering_pool.h"
#include "image_view.h"
#include "view_controller.h"
#include <poppler-qt5.h>
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QImage>
#include <QScreen>
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlContext>
#include <iostream>
#include <memory>
static const std::map<QString, int> EXTERNAL_SCREEN_SCORE{
{"eDP", -100}, // Most notebook displays
{"HDMI", 50},
{"VGA", 100},
{"DVI", 0},
{"DP", -50},
};
int main(int argc, char** argv)
{
// Smooth video playback
if(!getenv("QSG_RENDER_LOOP"))
setenv("QSG_RENDER_LOOP", "threaded", 1);
QApplication app(argc, argv);
app.setApplicationName("presenter");
app.setApplicationVersion("0.9.0");
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", QCoreApplication::translate("presenter", "PDF file to open"));
QCommandLineOption optSwap({"s", "swap"}, QCoreApplication::translate("presenter", "Swap screens"));
parser.addOption(optSwap);
parser.process(app);
QString file = parser.positionalArguments().at(0);
qDebug() << "Opening" << file;
std::shared_ptr<Poppler::Document> document(
Poppler::Document::load(file)
);
if(!document || document->isLocked())
{
std::cerr << "Could not open PDF.\n";
return 1;
}
document->setRenderHint(Poppler::Document::Antialiasing, true);
document->setRenderHint(Poppler::Document::TextAntialiasing, true);
using ScoredScreen = std::pair<QScreen*, int>;
std::vector<ScoredScreen> scoredScreens;
for(auto& screen : app.screens())
{
int score = 0;
for(auto& rule : EXTERNAL_SCREEN_SCORE)
{
if(screen->name().contains(rule.first))
{
score += rule.second;
}
}
scoredScreens.emplace_back(screen, score);
}
if(scoredScreens.empty())
{
std::cerr << "Could not find presentation screen\n";
return 1;
}
std::sort(scoredScreens.begin(), scoredScreens.end(), [](const ScoredScreen& a, const ScoredScreen& b){
return a.second < b.second;
});
for(auto& sc : scoredScreens)
{
qDebug() << "Screen" << sc.first->name() << "has score" << sc.second;
}
QScreen* presentationScreen = scoredScreens.front().first;
QScreen* consoleScreen = scoredScreens.back().first;
if(parser.isSet(optSwap))
std::swap(presentationScreen, consoleScreen);
RenderingPool pool(QUrl::fromLocalFile(file), document);
QObject::connect(&pool, &RenderingPool::renderingFinished, [&](){
reinterpret_cast<RenderingPage*>(pool.at(0))->image().save("/tmp/test.png");
});
pool.triggerRender(presentationScreen->size());
ViewController controller(&pool);
qmlRegisterType<ImageView>("presenter", 1, 0, "ImageView");
QQuickView presenterView;
presenterView.setScreen(presentationScreen);
presenterView.setGeometry(presentationScreen->geometry());
presenterView.showFullScreen();
presenterView.engine()->rootContext()->setContextProperty("controller", &controller);
presenterView.setSource(QUrl("../PresenterScreen.qml"));
QQuickView consoleView;
consoleView.setScreen(consoleScreen);
consoleView.setGeometry(consoleScreen->geometry());
consoleView.showFullScreen();
consoleView.engine()->rootContext()->setContextProperty("controller", &controller);
consoleView.setSource(QUrl("../ConsoleScreen.qml"));
return app.exec();
}