1 |
#include <QApplication> |
#include <QApplication> |
|
#include <QtWebKit> |
|
2 |
#include <QDesktopWidget> |
#include <QDesktopWidget> |
|
#include <iostream> |
|
3 |
#include <stdexcept> |
#include <stdexcept> |
4 |
|
|
5 |
#include "MyWebView.h" |
#include "MyWebView.h" |
6 |
|
|
7 |
|
|
8 |
MyWebView::MyWebView(QWidget* parent) : QWebView(parent) { |
MyWebView::MyWebView(QWidget* parent) : QWebView(parent) { |
9 |
// this->setWindowState( Qt::WindowFullScreen ); |
connect(this, SIGNAL( loadFinished(bool) ), this, SLOT( onChange(bool) ) ); |
10 |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
|
11 |
|
QWebSettings* settings = QWebSettings::globalSettings(); |
12 |
connect(this, SIGNAL( loadStarted() ), this, SLOT( test() ) ); |
settings->setAttribute( QWebSettings::JavascriptEnabled, true); |
13 |
|
settings->setAttribute( QWebSettings::PluginsEnabled, true); |
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
QTimer* timer = new QTimer(this); |
18 |
|
connect(timer, SIGNAL(timeout()), this, SLOT(onTimer())); |
19 |
|
timer->start(1000); |
20 |
|
|
21 |
} |
} |
22 |
|
|
23 |
void MyWebView::show() { |
void MyWebView::start(QString url, QString screenid) { |
24 |
QWebView::show(); |
try { |
25 |
try { |
this->load( QUrl( generateUrl(url, screenid) ) ); |
26 |
this->load( QUrl( generateUrl() ) ); |
} catch (std::exception& e) { |
27 |
} catch (std::exception& e) { |
showError(e.what() ); |
28 |
showError(e.what() ); |
} |
|
} |
|
29 |
|
|
30 |
} |
} |
31 |
|
|
32 |
void MyWebView::showError(const char* msg) { |
void MyWebView::showError(const char* msg) { |
33 |
QString str("<html><body><center><h1>"); |
QString str("<html><body><center><h1>"); |
34 |
str.append(msg).append("</h1></center></body></html>"); |
str.append(msg).append("</h1></center></body></html>"); |
35 |
this->setHtml( str ); |
this->setHtml( str ); |
36 |
} |
} |
37 |
|
|
38 |
QString MyWebView::generateUrl() { |
QString MyWebView::generateUrl(QString url, QString screenid) { |
39 |
QDesktopWidget* desktop = QApplication::desktop(); |
QDesktopWidget* desktop = QApplication::desktop(); |
40 |
QRect rect = desktop->screenGeometry(); |
QRect rect = desktop->screenGeometry(); |
|
|
|
|
QString width; |
|
|
width.setNum( rect.width() ); |
|
41 |
|
|
|
QString height; |
|
|
height.setNum( rect.height() ); |
|
42 |
|
|
43 |
|
QString width, height; |
44 |
QSettings settings("Caddi", "infoscreen"); |
width.setNum( rect.width() ); |
45 |
std::cout << settings.fileName().toAscii().data() << std::endl; |
height.setNum( rect.height() ); |
|
QString url = settings.value("url").toString(); |
|
|
QString screenid = settings.value("screenid").toString(); |
|
46 |
|
|
|
if (url.length() == 0) { |
|
|
throw std::runtime_error("No url in config file"); |
|
|
} |
|
47 |
|
|
48 |
url.append("?screen_id=").append(screenid); |
if (url.length() == 0) { |
49 |
url.append("&width=").append(width); |
throw std::runtime_error("No url in config file"); |
50 |
url.append("&height=").append(height); |
} |
51 |
|
|
52 |
|
url.append("?screen_id=").append(screenid); |
53 |
|
url.append("&width=").append(width); |
54 |
|
url.append("&height=").append(height); |
55 |
|
|
|
std::cout << url.toAscii().data() << std::endl; |
|
56 |
|
|
57 |
return url; |
qDebug() << "URL:" << url; |
58 |
|
|
59 |
|
|
60 |
|
return url; |
61 |
} |
} |
62 |
|
|
63 |
//public slots: |
//public slots: |
64 |
void MyWebView::test() { |
void MyWebView::onChange(bool success) { |
65 |
std::cout << "test" << std::endl; |
//qDebug() << "html" << this->page()->mainFrame()->toHtml(); |
66 |
} |
} |
67 |
|
|
68 |
|
|
69 |
|
void MyWebView::onTimer() { |
70 |
|
} |