1 |
#include "MainView.h" |
#include "mainview.h" |
2 |
#include <QApplication> |
#include <QApplication> |
3 |
#include <QPushButton> |
#include <QPushButton> |
4 |
#include <QLabel> |
#include <QLabel> |
5 |
#include <QVBoxLayout> |
#include <QStackedLayout> |
6 |
#include <QSvgWidget> |
#include <QSvgWidget> |
7 |
|
|
8 |
#include <QTimer> |
#include <QTimer> |
10 |
#include <QSettings> |
#include <QSettings> |
11 |
#include <QMessageBox> |
#include <QMessageBox> |
12 |
|
|
13 |
#include "MyWebView.h" |
#include "webview.h" |
14 |
#include "clientsiderender.h" |
#include "clientsiderender.h" |
15 |
#include "pictureview.h" |
#include "pictureview.h" |
16 |
#include "videoview.h" |
#include "videoview.h" |
17 |
|
#include "clockoverlay.h" |
18 |
#include "httpwrapper.h" |
#include "httpwrapper.h" |
19 |
|
#include "screenmanager.h" |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
29 |
xmlUrl = url + "?screen_id=" + screenid; |
xmlUrl = url + "?screen_id=" + screenid; |
30 |
qDebug() << "Starting XML mode"; |
qDebug() << "Starting XML mode"; |
31 |
qDebug() << "xmlUrl" << xmlUrl; |
qDebug() << "xmlUrl" << xmlUrl; |
32 |
|
qDebug() << "xmlInterval" << xmlInterval/(60*1000); |
33 |
} |
} |
34 |
|
|
35 |
if (currentMode == ModeSimpleWeb){ |
if (currentMode == ModeSimpleWeb){ |
36 |
qDebug() << "Starting plain browser mode"; |
qDebug() << "Starting plain browser mode"; |
|
web->setVisible(true); |
|
|
web->start(url,screenid); |
|
37 |
} |
} |
38 |
|
|
39 |
if (currentMode == ModeLocal ) { |
if (currentMode == ModeLocal ) { |
43 |
readLocalFiles(); |
readLocalFiles(); |
44 |
} |
} |
45 |
|
|
46 |
this->resize(400,400); |
this->resize(640,480); |
47 |
this->setWindowState( Qt::WindowFullScreen ); |
this->setWindowState( Qt::WindowFullScreen ); |
48 |
this->grabKeyboard(); |
this->grabKeyboard(); |
49 |
|
|
50 |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
51 |
|
|
52 |
render = new ClientSideRender(this); |
render = new ClientSideRender(this); |
|
render->setVisible( false ); |
|
53 |
|
|
54 |
web = new MyWebView(this); |
web = new WebView(this); |
|
web->setVisible( false); |
|
55 |
|
|
56 |
picture = new PictureView(this); |
picture = new PictureView(this); |
|
picture->setVisible( false ); |
|
57 |
|
|
58 |
video = new VideoView(this); |
video = new VideoView(this); |
|
video->setVisible(false); |
|
59 |
|
|
60 |
svg = new QSvgWidget(this); |
svg = new QSvgWidget(this); |
|
svg->setVisible(false); |
|
61 |
|
|
62 |
QVBoxLayout* layout = new QVBoxLayout(); |
layout = new QStackedLayout(); |
63 |
layout->addWidget(web,1); |
layout->addWidget(web); |
64 |
layout->addWidget(render,1); |
layout->addWidget(render); |
65 |
layout->addWidget(picture,1); |
layout->addWidget(picture); |
66 |
layout->addWidget(video,1); |
layout->addWidget(video); |
67 |
layout->addWidget(svg,1); |
layout->addWidget(svg); |
|
layout->addStretch(); |
|
68 |
layout->setContentsMargins(0,0,0,0); |
layout->setContentsMargins(0,0,0,0); |
69 |
setLayout(layout); |
setLayout(layout); |
70 |
|
|
71 |
|
if (showClock == true) { |
72 |
|
clockOverlay = new ClockOverlay(this); |
73 |
|
clockOverlay->move(10,10); |
74 |
|
clockOverlay->resize(150,75); |
75 |
|
} |
76 |
|
|
77 |
if (currentMode == ModeXml || currentMode == ModeLocal) { |
|
78 |
qDebug() << "Starting timer..."; |
|
79 |
timer = new QTimer(this); |
if (currentMode == ModeSimpleWeb) { |
80 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
web->setVisible(true); |
81 |
timer->start(100); |
web->start(url,screenid); |
82 |
|
} |
83 |
|
|
84 |
|
if (enableScreenManager) { |
85 |
|
screenManager = new ScreenManager(screenManagerOn, screenManagerOff); |
86 |
|
} else { |
87 |
|
qDebug() << "ScreenManager is disabled"; |
88 |
} |
} |
89 |
|
|
90 |
|
|
91 |
|
qDebug() << "Starting timer..."; |
92 |
|
timer = new QTimer(this); |
93 |
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
94 |
|
timer->start(100); |
95 |
} |
} |
96 |
|
|
97 |
void MainView::loadSettings() |
void MainView::loadSettings() |
113 |
exit(1); |
exit(1); |
114 |
} |
} |
115 |
|
|
116 |
|
enableScreenManager = settings->value("enablescreenmanager").toBool(); |
117 |
|
if (enableScreenManager) { |
118 |
|
screenManagerOn = settings->value("screenmanager_on").toTime(); |
119 |
|
screenManagerOff = settings->value("screenmanager_off").toTime(); |
120 |
|
} |
121 |
|
|
122 |
|
showClock = settings->value("showclock").toBool(); |
123 |
|
|
124 |
|
xmlInterval = settings->value("xmlinterval", 30).toInt(); |
125 |
|
xmlInterval = (xmlInterval * 60 * 1000); //convert to milliseconds |
126 |
|
|
127 |
|
|
128 |
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
129 |
url = settings->value("url").toString(); |
url = settings->value("url").toString(); |
157 |
if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { |
if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { |
158 |
close(); |
close(); |
159 |
} |
} |
160 |
|
|
161 |
|
if (key == 'f' || key == 'F') { |
162 |
|
Qt::WindowStates current = this->windowState(); |
163 |
|
if (current == Qt::WindowFullScreen) { |
164 |
|
this->setWindowState(Qt::WindowActive); |
165 |
|
} else { |
166 |
|
this->setWindowState(Qt::WindowFullScreen); |
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
} |
} |
171 |
|
|
172 |
void MainView::onTimer() |
void MainView::onTimer() |
173 |
{ |
{ |
174 |
screenManager.timerTick(); |
if (enableScreenManager == true) { |
175 |
|
screenManager->timerTick(); |
176 |
|
} |
177 |
|
|
178 |
if (currentMode == ModeXml) { |
if (currentMode == ModeXml) { |
179 |
readXml(); |
readXml(); |
180 |
} |
} |
181 |
|
|
182 |
switchScreens(); |
if (currentMode == ModeXml || currentMode == ModeLocal) { |
183 |
|
switchScreens(); |
184 |
|
} |
185 |
|
if (showClock == true) { |
186 |
|
clockOverlay->timerTick(); |
187 |
|
} |
188 |
} |
} |
189 |
|
|
190 |
|
|
238 |
|
|
239 |
bool MainView::readXml() |
bool MainView::readXml() |
240 |
{ |
{ |
241 |
const int TIMEOUT = 30*60*1000; // 30 minutter |
if ( lastXml.isNull() || lastXml.elapsed() > xmlInterval) { |
242 |
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
qDebug() << "Reading XML"; |
243 |
|
|
244 |
|
|
245 |
bool res = xmlHandler.readXml( xmlUrl ); |
bool res = xmlHandler.readXml( xmlUrl ); |
265 |
} |
} |
266 |
|
|
267 |
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
|
|
|
268 |
QTime now = QTime::currentTime(); |
QTime now = QTime::currentTime(); |
269 |
if (lastScreenSwitch.isNull()) |
if (lastScreenSwitch.isNull()) |
270 |
currentItemIdx = -1; |
currentItemIdx = -1; |
311 |
} |
} |
312 |
|
|
313 |
} else { |
} else { |
|
qDebug() << "no screen"; |
|
314 |
errorInfoScreen("Der er ingen information at vise"); |
errorInfoScreen("Der er ingen information at vise"); |
315 |
|
currentItem = ScreenItem(); |
316 |
|
currentItem.runtime = 60; //switch screens again in 1 minute |
317 |
} |
} |
318 |
lastScreenSwitch = QTime::currentTime(); |
lastScreenSwitch = QTime::currentTime(); |
319 |
|
|
322 |
|
|
323 |
void MainView::errorInfoScreen(QString msg) |
void MainView::errorInfoScreen(QString msg) |
324 |
{ |
{ |
325 |
ensureVisible(web); |
ensureVisible(web); |
326 |
web->setHtml("<html>\ |
QString html("<html><body text='#505050' bgcolor='#000000'>"); |
327 |
<body text='#505050' bgcolor='#000000'>\ |
html.append("<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>") |
328 |
<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\ |
.append(msg) |
329 |
</body></html>"); |
.append("</h1></td></tr></table></body></html>"); |
330 |
|
web->setHtml(html); |
331 |
} |
} |
332 |
|
|
333 |
void MainView::ensureVisible(QWidget* widget) |
void MainView::ensureVisible(QWidget* widget) |
334 |
{ |
{ |
335 |
if (! widget->isVisible()) { |
layout->setCurrentWidget(widget); |
|
hideAll(); |
|
|
widget->setVisible(true); |
|
|
} |
|
336 |
} |
} |
337 |
|
|
|
void MainView::hideAll() |
|
|
{ |
|
|
render->setVisible( false ); |
|
|
web->setVisible( false); |
|
|
picture->setVisible( false ); |
|
|
video->setVisible(false); |
|
|
svg->setVisible(false); |
|
|
} |
|