-
Notifications
You must be signed in to change notification settings - Fork 2
/
walldisplay.cpp
108 lines (88 loc) · 3.4 KB
/
walldisplay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "walldisplay.h"
#include "ui_walldisplay.h"
#include "walldisplaysettings.h"
#include "ui_walldisplaysettings.h"
QList<QString> urls;
int changeUrlInterval;
QTimer *timer = new QTimer();
WallDisplay::WallDisplay(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::WallDisplay)
{
ui->setupUi(this);
qApp->installEventFilter(this);
/* start with hidden menubar */
ui->menuBar->hide();
/* Enable interval stop button, connect interval start/stop buttons */
ui->actionStart_interval->setDisabled(true);
ui->actionS_top_interval->setEnabled(true);
connect(ui->actionStart_interval, SIGNAL(triggered()), this, SLOT(startInterval()));
connect(ui->actionS_top_interval, SIGNAL(triggered()), this, SLOT(stopInterval()));
/* wire up the settings and about dialog */
connect(ui->action_Info, SIGNAL(triggered()), this, SLOT(showAbout()));
connect(ui->action_settings, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
/* read urls and cycle interval from the settings file */
settings_ = new QSettings();
urls = settings_->value("wall-display/urls","http://endocode.com").toStringList();
changeUrlInterval = settings_->value("wall-display/interval", 10).toInt();
/* Load the first url */
ui->webView->setUrl(QUrl(urls[0]));
/* start the timer with interval */
connect(timer, SIGNAL(timeout()), this, SLOT(changeUrl()));
timer->start(changeUrlInterval * 1000);
}
WallDisplay::~WallDisplay()
{
delete ui;
delete settings_;
}
/* triggered by the timer change the shown url */
void WallDisplay::changeUrl() {
if ( urls.length() > 1) {
QString url = urls.takeFirst();
urls.append(url);
ui->webView->setUrl(QUrl(urls[0]));
}
}
void WallDisplay::startInterval() {
timer->start();
ui->actionStart_interval->setDisabled(true);
ui->actionS_top_interval->setEnabled(true);
}
void WallDisplay::stopInterval() {
timer->stop();
ui->actionStart_interval->setEnabled(true);
ui->actionS_top_interval->setDisabled(true);
}
/* on a key press unhide the menubar */
bool WallDisplay::eventFilter(QObject *obj, QEvent *event) {
if ( event->type() == QEvent::KeyPress ){
QKeyEvent *key = static_cast<QKeyEvent *>(event);
qDebug() << "Key " << key->key() << " pressed in " << obj->objectName();
if ( ui->menuBar->isHidden() ) {
ui->menuBar->setVisible(true);
}
} else if (event->type() == QEvent::MouseButtonDblClick ) {
if ( ui->menuBar->isHidden() ) {
ui->menuBar->setVisible(true);
}
}
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
void WallDisplay::showAbout(){
QMessageBox::about(this, tr("About wall-display"),
tr("Wall-Display was written by\n"
"Matthias Schmitz <matthias@sigxcpu.org>\n"
"Nikolas Sepos <nikolas@endocode.com>\n"
"Gerald Schmidt"));
}
void WallDisplay::showSettingsDialog() {
qDebug() << "showSettingsDialog aufgerufen";
WallDisplaySettings *settingsdialog = new WallDisplaySettings(settings_);
int retval = settingsdialog->exec();
if ( retval == QDialog::Accepted) {
urls = settings_->value("wall-display/urls","http://endocode.com").toStringList();
changeUrlInterval = settings_->value("wall-display/interval", 10).toInt();
}
}