1 |
torben |
509 |
#include "MainView.h" |
2 |
torben |
512 |
#include <QApplication> |
3 |
torben |
510 |
#include <QPushButton> |
4 |
torben |
512 |
#include <QLabel> |
5 |
torben |
510 |
#include <QVBoxLayout> |
6 |
torben |
509 |
|
7 |
torben |
510 |
#include <QTimer> |
8 |
|
|
|
9 |
torben |
512 |
#include "MyWebView.h" |
10 |
torben |
515 |
#include "clientsiderender.h" |
11 |
torben |
524 |
#include "pictureview.h" |
12 |
torben |
527 |
#include "videoview.h" |
13 |
torben |
511 |
|
14 |
torben |
528 |
#include "httpwrapper.h" |
15 |
|
|
|
16 |
|
|
|
17 |
torben |
509 |
MainView::MainView(QWidget* parent) |
18 |
|
|
: QWidget(parent) |
19 |
|
|
{ |
20 |
torben |
516 |
this->resize(400,400); |
21 |
torben |
512 |
this->setWindowState( Qt::WindowFullScreen ); |
22 |
torben |
516 |
|
23 |
torben |
526 |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
24 |
torben |
510 |
|
25 |
torben |
515 |
render = new ClientSideRender(this); |
26 |
torben |
517 |
render->setVisible( false ); |
27 |
torben |
524 |
|
28 |
torben |
515 |
web = new MyWebView(this); |
29 |
torben |
524 |
web->setVisible( false); |
30 |
torben |
511 |
|
31 |
torben |
524 |
picture = new PictureView(this); |
32 |
torben |
529 |
picture->setVisible( false ); |
33 |
torben |
517 |
|
34 |
torben |
527 |
video = new VideoView(this); |
35 |
|
|
video->setVisible(false); |
36 |
torben |
517 |
|
37 |
torben |
510 |
QVBoxLayout* layout = new QVBoxLayout(); |
38 |
torben |
515 |
layout->addWidget(web,1); |
39 |
|
|
layout->addWidget(render,1); |
40 |
torben |
524 |
layout->addWidget(picture,1); |
41 |
torben |
527 |
layout->addWidget(video,1); |
42 |
torben |
510 |
layout->addStretch(); |
43 |
|
|
layout->setContentsMargins(0,0,0,0); |
44 |
torben |
515 |
setLayout(layout); |
45 |
torben |
510 |
|
46 |
torben |
528 |
|
47 |
|
|
|
48 |
torben |
510 |
QTimer* timer = new QTimer(this); |
49 |
|
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
50 |
torben |
528 |
timer->start(100); |
51 |
torben |
517 |
|
52 |
torben |
509 |
} |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
void MainView::onTimer() |
56 |
|
|
{ |
57 |
torben |
512 |
screenManager.timerTick(); |
58 |
torben |
524 |
|
59 |
torben |
528 |
readXml(); |
60 |
torben |
527 |
|
61 |
torben |
528 |
switchScreens(); |
62 |
|
|
} |
63 |
torben |
527 |
|
64 |
torben |
524 |
|
65 |
torben |
528 |
bool MainView::readXml() |
66 |
|
|
{ |
67 |
|
|
const int TIMEOUT = 30*60*1000; // 30 minutter |
68 |
|
|
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
69 |
torben |
529 |
|
70 |
torben |
528 |
xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" ); |
71 |
torben |
527 |
|
72 |
torben |
528 |
lastXml = QTime::currentTime(); |
73 |
|
|
|
74 |
|
|
screenItems = xmlHandler.getScreenSet(); |
75 |
|
|
|
76 |
|
|
if ( currentItemIdx >= screenItems.size() ) |
77 |
|
|
currentItemIdx = screenItems.size()-1; //avoid overflow |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
return true; |
81 |
|
|
} else { |
82 |
|
|
return false; |
83 |
torben |
524 |
} |
84 |
torben |
509 |
} |
85 |
torben |
528 |
|
86 |
|
|
void MainView::switchScreens() |
87 |
|
|
{ |
88 |
|
|
|
89 |
|
|
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
90 |
|
|
|
91 |
torben |
529 |
QTime now = QTime::currentTime(); |
92 |
torben |
528 |
if (lastScreenSwitch.isNull()) |
93 |
torben |
529 |
currentItemIdx = -1; |
94 |
|
|
|
95 |
|
|
bool found = false; |
96 |
|
|
int tries = 0; |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
while (found == false && tries <= screenItems.size()) { //find next with valid display time |
100 |
|
|
tries++; |
101 |
torben |
528 |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
102 |
torben |
529 |
currentItem = screenItems.at(currentItemIdx); |
103 |
torben |
528 |
|
104 |
torben |
529 |
if (currentItem.start <= now && now <= currentItem.stop ) |
105 |
|
|
found = true; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
if (found) { |
109 |
|
|
|
110 |
|
|
if (currentItem.module == "info_image") { |
111 |
|
|
ensureVisible(picture); |
112 |
|
|
|
113 |
|
|
picture->loadFromUrl( currentItem.url ); |
114 |
|
|
|
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
} else { |
119 |
|
|
qDebug() << "no screen"; |
120 |
|
|
hideAll(); |
121 |
|
|
} |
122 |
torben |
528 |
lastScreenSwitch = QTime::currentTime(); |
123 |
torben |
529 |
|
124 |
torben |
528 |
} |
125 |
|
|
} |
126 |
torben |
529 |
|
127 |
|
|
void MainView::ensureVisible(QWidget* widget) |
128 |
|
|
{ |
129 |
|
|
if (! widget->isVisible()) { |
130 |
|
|
hideAll(); |
131 |
|
|
widget->setVisible(true); |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
void MainView::hideAll() |
136 |
|
|
{ |
137 |
|
|
render->setVisible( false ); |
138 |
|
|
web->setVisible( false); |
139 |
|
|
picture->setVisible( false ); |
140 |
|
|
video->setVisible(false); |
141 |
|
|
} |