-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
63 lines (52 loc) · 1.73 KB
/
mainwindow.cpp
File metadata and controls
63 lines (52 loc) · 1.73 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QCerebellum/message.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
addr("tcp://localhost:1235"),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
poller = new QThread(this);
s = new SocketThread("tcp://localhost:1235", 1, 2); /// TODO: replace it with configuration constant
s->moveToThread(poller);
connect(s, SIGNAL(positionReceived(QCerebellum::PositionMessage)), ui->widget, SLOT(receivePosition(QCerebellum::PositionMessage)));
connect(poller, SIGNAL(finished()), poller, SLOT(deleteLater()));
connect(this, SIGNAL(closed()), s, SLOT(stop()));
connect(this, SIGNAL(closed()), poller, SLOT(quit()));
connect(ui->actionOptions, SIGNAL(triggered()), this, SLOT(setAddress()));
connect(ui->widget, SIGNAL(speedChanged(QCerebellum::TwistMessage)), s, SLOT(sendTwist(QCerebellum::TwistMessage)));
connect(ui->spinBox, SIGNAL(valueChanged(int)), ui->widget, SLOT(SetSpeed(int)));
poller->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::closeEvent(QCloseEvent *e)
{
Q_UNUSED(e);
emit closed();
poller->wait(1000);
if (poller->isRunning())
poller->terminate(); // TODO: remove this bullshit
}
void MainWindow::setAddress()
{
bool ok;
QString text = QInputDialog::getText(this, "Options", "Address:", QLineEdit::Normal, addr, &ok);
if (ok && !text.isEmpty())
{
addr = text;
qDebug() << addr;
}
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
ui->widget->keyPressEvent(event);
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
ui->widget->keyReleaseEvent(event);
}