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