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