1 |
#include <QApplication> |
2 |
#include <QDesktopWidget> |
3 |
#include <stdexcept> |
4 |
|
5 |
#include "MyWebView.h" |
6 |
|
7 |
|
8 |
MyWebView::MyWebView(QWidget* parent) : QWebView(parent) { |
9 |
|
10 |
QWebSettings* settings = QWebSettings::globalSettings(); |
11 |
settings->setAttribute( QWebSettings::JavascriptEnabled, true); |
12 |
settings->setAttribute( QWebSettings::PluginsEnabled, true); |
13 |
} |
14 |
|
15 |
void MyWebView::start(QString url, QString screenid) { |
16 |
try { |
17 |
this->load( QUrl( generateUrl(url, screenid) ) ); |
18 |
} catch (std::exception& e) { |
19 |
showError(e.what() ); |
20 |
} |
21 |
|
22 |
} |
23 |
|
24 |
void MyWebView::showError(const char* msg) { |
25 |
QString str("<html><body><center><h1>"); |
26 |
str.append(msg).append("</h1></center></body></html>"); |
27 |
this->setHtml( str ); |
28 |
} |
29 |
|
30 |
QString MyWebView::generateUrl(QString url, QString screenid) { |
31 |
QDesktopWidget* desktop = QApplication::desktop(); |
32 |
QRect rect = desktop->screenGeometry(); |
33 |
|
34 |
|
35 |
QString width, height; |
36 |
width.setNum( rect.width() ); |
37 |
height.setNum( rect.height() ); |
38 |
|
39 |
|
40 |
if (url.length() == 0) { |
41 |
throw std::runtime_error("No url in config file"); |
42 |
} |
43 |
|
44 |
url.append("?screen_id=").append(screenid); |
45 |
url.append("&width=").append(width); |
46 |
url.append("&height=").append(height); |
47 |
|
48 |
|
49 |
qDebug() << "URL:" << url; |
50 |
|
51 |
|
52 |
return url; |
53 |
} |