/[projects]/infoscreen/webview.cpp
ViewVC logotype

Contents of /infoscreen/webview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20