This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
210 lines (177 loc) · 7.68 KB
/
mainwindow.cpp
File metadata and controls
210 lines (177 loc) · 7.68 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/****************************************************************************
**
** Copyright (C) 2011-2012 Jan M. Binder, Felix Engelmann, Simeon Voelkel
** Contact: jan.binder@sfz-bw.de, felix.engelmann@sfz-bw.de,
** simeon.voelkel@sfz-bw.de
**
** $QT_BEGIN_LICENSE:GPL$
** GNU General Public License Usage
** This file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
MainWindow::MainWindow(QWidget *parent, QHostAddress hostAddress, unsigned int port, unsigned int sig, bool noconfig) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->idButton, SIGNAL(clicked()), this, SLOT(triggerId()));
connect(ui->portButton, SIGNAL(clicked()), this, SLOT(triggerPort()));
connect(ui->startstop, SIGNAL(clicked()), this, SLOT(toggleStartPause()));
connect(ui->delButton, SIGNAL(clicked()), this, SLOT(triggerDel()));
connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveStages()));
ad = new AboutDialog();
connect(ui->actionAbout_IYPTClock, SIGNAL(triggered()), ad, SLOT(exec()));
timer = new QTimer();
connect(timer, SIGNAL(timeout()), ui->graphicsView, SLOT(act()));
timer->start(30);
thc = new ThemeClock();
connect(thc, SIGNAL(timeUpdate(int)), ui->graphicsView, SLOT(setTime(int)));
connect(thc, SIGNAL(timeUpdate(int)), this, SLOT(setLcdWidthForTime(int)));
connect(thc, SIGNAL(allowedTimeChanged(int)), ui->graphicsView, SLOT(setAllowedTime(int)));
connect(thc, SIGNAL(started(int)), ui->graphicsView, SLOT(setTime(int)));
connect(thc, SIGNAL(paused(int)), ui->graphicsView, SLOT(setTime(int)));
connect(thc, SIGNAL(restarted(int)), ui->graphicsView, SLOT(setTime(int)));
connect(thc, SIGNAL(stopped(int)), ui->graphicsView, SLOT(setTime(int)));
connect(ui->startstop, SIGNAL(clicked()), thc, SLOT(startorpause()));
connect(ui->resetButton, SIGNAL(clicked()), thc, SLOT(reset()));
connect(ui->setTimeButton, SIGNAL(clicked()), this, SLOT(setTime()));
ui->setTimeComboBox->addItem(tr("last saved time"), QVariant(TIME_SAVED));
ui->setTimeComboBox->addItem(tr("elapsed time"), QVariant(TIME_ELAPSED));
ui->setTimeComboBox->addItem(tr("remaining time"), QVariant(TIME_LEFT));
connect(thc, SIGNAL(timeUpdate(QString)), ui->lcdNumber, SLOT(display(QString)));
lc = new ListController();
connect(ui->ffwd, SIGNAL(clicked()), lc, SLOT(forward()));
connect(ui->bwd, SIGNAL(clicked()), lc, SLOT(backward()));
connect(ui->addButton, SIGNAL(clicked()), lc, SLOT(add()));
connect(thc, SIGNAL(started(int)), lc, SLOT(checkAutoStart()));
connect(this, SIGNAL(itemShouldBeDeleted(QModelIndex)), lc, SLOT(del(QModelIndex)));
connect(lc, SIGNAL(allowedTimeChanged(int)), thc, SLOT(setAllowedTime(int)));
connect(lc, SIGNAL(roomClockChanged(bool)), ui->graphicsView, SLOT(setRoomclock(bool)));
connect(lc, SIGNAL(resetTime()), thc, SLOT(reset()));
connect(lc, SIGNAL(endOfStage()), thc, SLOT(stop()));
connect(lc, SIGNAL(stageNameChanged(QString)), ui->stageLabel, SLOT(setText(QString)));
connect(lc, SIGNAL(modelChanged(QAbstractTableModel*)), this, SLOT(propagateModel(QAbstractTableModel*)));
ui->portBox->setValue(port);
ui->idBox->setValue(sig);
bs = new BroadcastServer(this, hostAddress, port, sig);
connect(thc, SIGNAL(timeUpdate(int)), bs, SLOT(updateTime(int)));
connect(thc, SIGNAL(restarted(int)), bs, SLOT(updateTime(int)));
connect(thc, SIGNAL(stopped(int)), bs, SLOT(updateTime(int)));
connect(thc, SIGNAL(allowedTimeChanged(int)), bs, SLOT(setAllowedTime(int)));
connect(lc, SIGNAL(roomClockChanged(bool)), bs, SLOT(setRoomclock(bool)));
connect(lc, SIGNAL(stageNameChanged(QString)), bs, SLOT(setStageName(QString)));
connect(this, SIGNAL(newPort(uint)), bs, SLOT(setBroadcastPort(uint)));
connect(this, SIGNAL(newID(uint)), bs, SLOT(setSignature(uint)));
connect(lc, SIGNAL(overTimeChanged(int)), thc, SLOT(setOverTime(int)));
connect(thc, SIGNAL(overtimed(int)), lc, SLOT(handleOvertime(int)));
connect(lc, SIGNAL(elapsedTimeChanged(int)), thc, SLOT(setElapsedTime(int)));
connect(lc, SIGNAL(elapsedTimeChanged(int)), ui->graphicsView, SLOT(setTime(int)));
connect(lc, SIGNAL(elapsedTimeChanged(int)), bs, SLOT(updateTime(int)));
connect(lc, SIGNAL(getElapsedOverTime()), thc, SLOT(getElapsedOverTime()));
connect(thc, SIGNAL(elapsedOverTime(int)), lc, SLOT(setElapsedOverTime(int)));
if (noconfig)
{
ui->tabWidget->setTabEnabled(1,false);
}
if (QFile("stages.txt").exists()){
lc->loadListFromFile("stages.txt");
} else if (QFile("/usr/share/iyptclock/stages.txt").exists()){
lc->loadListFromFile("/usr/share/iyptclock/stages.txt");
} else {
lc->loadListFromFile("");
}
thc->stop();
timer2 = new QTimer();
connect(timer2, SIGNAL(timeout()), this, SLOT(toggleStartPause()));
connect(timer2, SIGNAL(timeout()), this, SLOT(toggleTimeSpinBox()));
timer2->start(100);
savefile = QString("/var/run/iyptclock/autosave_");
savefile += QString::number(sig);
as = new AutoSave(this,savefile,this);
as->load();
timer3 = new QTimer();
connect(timer3, SIGNAL(timeout()),as,SLOT(save()));
timer3->start(1000);
}
MainWindow::~MainWindow()
{
delete timer;
delete bs;
delete lc;
delete thc;
delete ad;
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::triggerId(){
emit newID((unsigned int)(ui->idBox->value()));
}
void MainWindow::triggerPort(){
emit newPort((unsigned int)(ui->portBox->value()));
}
void MainWindow::triggerDel(){
emit itemShouldBeDeleted(ui->tableView->currentIndex());
}
void MainWindow::toggleStartPause(){
if(thc->isRunning()){
ui->startstop->setText("Pause");
}else{
ui->startstop->setText("Start");
}
}
void MainWindow::toggleTimeSpinBox(){
if (ui->setTimeComboBox->itemData(ui->setTimeComboBox->currentIndex()).toInt() == TIME_SAVED){
ui->setTimeSpinBox->setEnabled(false);
ui->setTimeSpinBox->setValue(as->getLastSavedTime()/1000);
}else{
ui->setTimeSpinBox->setEnabled(true);
}
}
void MainWindow::saveStages(){
lc->saveListToFile("stages.txt");
}
void MainWindow::setTime(){
switch (ui->setTimeComboBox->itemData(ui->setTimeComboBox->currentIndex()).toInt()) {
case TIME_SAVED:
thc->setElapsedTime(as->getLastSavedTime());
break;
case TIME_ELAPSED:
thc->setElapsedTime(ui->setTimeSpinBox->value()*1000);
break;
case TIME_LEFT:
thc->setRemainingTime(ui->setTimeSpinBox->value()*1000);
break;
default:
break;
}
}
void MainWindow::propagateModel(QAbstractTableModel* mdl){
ui->stagelist->setModel(mdl);
ui->tableView->setModel(mdl);
}
void MainWindow::setLcdWidthForTime(int time){
if (time < 0) return;
else if (time < 600000) ui->lcdNumber->setDigitCount(4);
else if (time < 3600000) ui->lcdNumber->setDigitCount(5);
else if (time < 36000000) ui->lcdNumber->setDigitCount(7);
else ui->lcdNumber->setDigitCount(8);
}