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

Contents of /infoscreen/webview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 884 - (show annotations) (download)
Thu Jun 24 09:44:57 2010 UTC (13 years, 10 months ago) by torben
File size: 1263 byte(s)
rename MyWebView to WebView
1 #include <QApplication>
2 #include <QDesktopWidget>
3 #include <stdexcept>
4
5 #include "webview.h"
6
7
8 WebView::WebView(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 WebView::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 WebView::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 WebView::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 }

  ViewVC Help
Powered by ViewVC 1.1.20