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