-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimerMain.cpp
189 lines (170 loc) · 4.76 KB
/
TimerMain.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
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
/*
* Copyright (c) 2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "TimerMain.h"
# include "TimerControlBox.h"
# include "ui_TimerMain.h"
# include <QKeyEvent>
# include <cassert>
TimerMain::TimerMain(QWidget*parent)
: QMainWindow(parent)
{
ui = new Ui::TimerMain;
ui->setupUi(this);
control_box_ = 0;
fullscreen_flag_ = false;
red_ .setColor(QPalette::Base, QColor(200, 0, 0));
yellow_.setColor(QPalette::Base, QColor(200, 200, 0));
green_ .setColor(QPalette::Base, QColor( 0, 200, 0));
red_ .setColor(QPalette::Text, QColor( 0, 0, 0));
yellow_.setColor(QPalette::Text, QColor( 0, 0, 0));
green_ .setColor(QPalette::Text, QColor( 0, 0, 0));
}
TimerMain::~TimerMain()
{
delete ui;
}
void TimerMain::set_control_box(TimerControlBox*box)
{
assert(! control_box_);
control_box_ = box;
}
void TimerMain::set_end_number(int val, bool practice_flag)
{
QString txt;
txt.setNum(val);
if (practice_flag) txt.prepend("P ");
ui->end_text->setText(txt);
}
void TimerMain::set_line_text(const class QString&txt)
{
ui->line_text->setText(txt);
}
void TimerMain::set_time_value(int val, timer_mode_t mode)
{
QString val_text;
val_text.setNum(val);
switch (mode) {
case TIMER_CALLUP:
ui->timer_text->setPalette(red_);
ui->timer_text->setText(val_text);
break;
case TIMER_END:
ui->timer_text->setPalette(green_);
ui->timer_text->setText(val_text);
break;
case TIMER_END_WARN:
ui->timer_text->setPalette(yellow_);
ui->timer_text->setText(val_text);
break;
case TIMER_STOP:
ui->timer_text->setPalette(red_);
ui->timer_text->setText("STOP");
break;
case TIMER_PREP:
ui->timer_text->setPalette(red_);
ui->timer_text->setText("PREP");
break;
}
}
bool TimerMain::toggle_fullscreen(void)
{
if (fullscreen_flag_) {
showNormal();
fullscreen_flag_ = false;
} else {
showFullScreen();
fullscreen_flag_ = true;
}
return fullscreen_flag_;
}
void TimerMain::set_fullscreen(bool flag)
{
if (flag) {
fullscreen_flag_ = true;
showFullScreen();
} else {
fullscreen_flag_ = false;
showNormal();
}
}
void TimerMain::network_service_port(const QString&port_text)
{
ui->connected_label->setText(port_text);
}
void TimerMain::network_interfaces(const QStringList&if_list)
{
ui->ip_interface_list->clear();
ui->ip_interface_list->addItems(if_list);
}
void TimerMain::keyPressEvent(QKeyEvent*event)
{
// Grab the space bar keypress, and use that to hide/show the
// control box.
if (event->key() == Qt::Key_Space) {
if (control_box_->isVisible())
control_box_->hide();
else
control_box_->show();
return;
}
// Toggle Fullscreen mode with the Escape key
if (event->key() == Qt::Key_Escape) {
toggle_fullscreen();
return;
}
// Fast Forward
if (event->key() == Qt::Key_F) {
control_box_->fast_forward_command();
return;
}
// Makeup end.
if (event->key() == Qt::Key_M) {
control_box_->special_end_command("MAKEUP");
return;
}
// Keyboard commands for running the timer
if (event->key() == Qt::Key_N) {
control_box_->next_end_command();
return;
}
if (event->key() == Qt::Key_P) {
control_box_->pause_timer_command();
return;
}
if (event->key() == Qt::Key_Enter) {
control_box_->start_timer_command();
return;
}
if (event->key() == Qt::Key_Return) {
control_box_->start_timer_command();
return;
}
if (event->key() == Qt::Key_Down) {
control_box_->fast_forward_command();
return;
}
// Emergency Stop
if (event->key() == Qt::Key_E) {
printf("KEYBOARD: Emergency Stop\n");
control_box_->emergency_stop_command();
return;
}
printf("XXXX key() == 0x%04x\n", event->key());
event->ignore();
}