-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
102 lines (77 loc) · 2.83 KB
/
mainwindow.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
/*
LatencyTest with Qt4
(c) 2020 by Christian.Lorenz@gromeck.de
This file is part of LatencyMeasure.
LatencyMeasure is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LatencyMeasure 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 LatencyMeasure. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <unistd.h>
#include "mainwindow.h"
#define __TITLE__ "Qt4 TestClient for LatencyMeasure"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
toggle = false;
mainWidget = new QWidget();
this->setWindowTitle(__TITLE__);
this->setCentralWidget(mainWidget);
this->setFixedSize(300,340);
latencyLabel = new QLabel("Latency to add [ms]:");
latencyLabel->setFixedHeight(30);
latencyInput = new QLineEdit("0");
latencyInput->setMaxLength(5);
latencyInput->setInputMask("00000");
toggleButton = new QPushButton("Toggle sensor areas background");
connect(toggleButton,SIGNAL(clicked()),this,SLOT(clickedToggleButton()));
triggerButton = new QPushButton("Place mouse cursor here!");
connect(triggerButton,SIGNAL(clicked()),this,SLOT(clickedTriggerButton()));
sensorArea = new QLabel("Place sensor here!");
//sensorArea->setFixedSize(180,180);
sensorArea->setStyleSheet(toggle ? STYLE_RED_ON_WHITE : STYLE_RED_ON_BLACK);
sensorArea->setAlignment(Qt::AlignTop);
layout = new QVBoxLayout();
layout->addWidget(latencyLabel);
layout->addWidget(latencyInput);
layout->addWidget(toggleButton);
layout->addWidget(triggerButton);
layout->addWidget(sensorArea);
mainWidget->setLayout(layout);
timerBlack = new QTimer();
timerBlack->setSingleShot(true);
connect(timerBlack,SIGNAL(timeout()),this,SLOT(timeoutTimerRise()));
timerWhite = new QTimer();
timerWhite->setSingleShot(true);
connect(timerWhite,SIGNAL(timeout()),this,SLOT(timeoutTimerFall()));
}
void MainWindow::clickedToggleButton()
{
toggle = !toggle;
sensorArea->setStyleSheet(toggle ? STYLE_RED_ON_WHITE : STYLE_RED_ON_BLACK);
}
void MainWindow::clickedTriggerButton()
{
int timeout = latencyInput->text().toInt();
latencyInput->setText(QString::number(timeout));
timerBlack->start(timeout);
}
void MainWindow::timeoutTimerRise()
{
sensorArea->setStyleSheet(!toggle ? STYLE_RED_ON_WHITE : STYLE_RED_ON_BLACK);
timerWhite->start(500);
}
void MainWindow::timeoutTimerFall()
{
sensorArea->setStyleSheet(toggle ? STYLE_RED_ON_WHITE : STYLE_RED_ON_BLACK);
}
MainWindow::~MainWindow()
{
}
/**/