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

Annotation of /infoscreen/webview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20