More work on Timelineview GUI application

This commit is contained in:
Alexander Bock
2015-04-22 18:22:40 +02:00
parent 19417d87c8
commit 07eaf6d7be
7 changed files with 169 additions and 57 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets)
find_package(Qt5Network)
add_executable(TimelineView WIN32 main.cpp mainwindow.cpp configurationwidget.cpp informationwidget.cpp timecontrolwidget.cpp timelinewidget.cpp)
add_executable(TimelineView main.cpp mainwindow.cpp configurationwidget.cpp informationwidget.cpp timecontrolwidget.cpp timelinewidget.cpp)
target_link_libraries(TimelineView Qt5::Widgets Qt5::Network)
+13 -4
View File
@@ -28,16 +28,25 @@
ConfigurationWidget::ConfigurationWidget(QWidget* parent)
: QWidget(parent)
, _ipAddress(new QLineEdit)
, _ipAddress(new QLineEdit("localhost"))
, _port(new QLineEdit("20500"))
, _connect(new QPushButton("Connect"))
, _playbook(new QLineEdit)
, _load(new QPushButton("Load"))
{
QGridLayout* layout = new QGridLayout;
layout->addWidget(_ipAddress, 0, 0);
layout->addWidget(_connect, 0, 1);
layout->addWidget(_playbook, 1, 0);
layout->addWidget(_load, 1, 1);
layout->addWidget(_port, 0, 1);
layout->addWidget(_connect, 0, 2);
layout->addWidget(_playbook, 1, 0, 1, 2);
layout->addWidget(_load, 1, 2);
setLayout(layout);
QObject::connect(_connect, SIGNAL(clicked()), this, SLOT(onConnectButton()));
}
void ConfigurationWidget::onConnectButton() {
emit connect(_ipAddress->text(), _port->text());
}
+7
View File
@@ -34,8 +34,15 @@ Q_OBJECT
public:
ConfigurationWidget(QWidget* parent);
signals:
void connect(QString host, QString port);
private slots:
void onConnectButton();
private:
QLineEdit* _ipAddress;
QLineEdit* _port;
QPushButton* _connect;
QLineEdit* _playbook;
+57 -50
View File
@@ -33,6 +33,9 @@
#include <QPushButton>
#include <QTextEdit>
#include <array>
#include <cstdint>
MainWindow::MainWindow()
: QWidget(nullptr)
, _configurationWidget(nullptr)
@@ -55,70 +58,74 @@ MainWindow::MainWindow()
layout->addWidget(_timelineWidget, 0, 1, 3, 1);
QObject::connect(
_configurationWidget, SIGNAL(connect(QString, QString)),
this, SLOT(onConnect(QString, QString))
);
QObject::connect(
_timeControlWidget, SIGNAL(scriptActivity(QString)),
this, SLOT(sendScript(QString))
);
//_ipAddress->setMinimumWidth(200);
//_ipAddress->setText("127.0.0.1");
//layout->addWidget(_ipAddress, 0, 0);
//QPushButton* connectButton = new QPushButton("Connect");
//connect(connectButton, SIGNAL(clicked()), this, SLOT(onConnectButton()));
//connectButton->show();
//layout->addWidget(connectButton, 0, 1);
//_command->setMinimumWidth(200);
//layout->addWidget(_command, 1, 0);
//QPushButton* sendButton = new QPushButton("Send");
//sendButton->setDefault(true);
//connect(sendButton, SIGNAL(clicked()), this, SLOT(sendCommandButton()));
//layout->addWidget(sendButton, 1, 1);
//layout->addWidget(_logWindow, 2, 0, 1, 2);
setLayout(layout);
}
MainWindow::~MainWindow() {
//delete _command;
//delete _socket;
delete _socket;
}
void MainWindow::onConnect(QString host, QString port) {
delete _socket;
_socket = new QTcpSocket(this);
connect(_socket, SIGNAL(readyRead()), SLOT(readTcpData()));
_socket->connectToHost(host, port.toUInt());
}
void MainWindow::readTcpData() {
// QByteArray data = _socket->readAll();
static const uint8_t MessageTypeStatus = 0;
//if (_logWindow->toPlainText().isEmpty())
// _logWindow->setText(data.data());
//else
// _logWindow->setText(_logWindow->toPlainText() + "\n" + data.data());
QByteArray data = _socket->readAll();
if (QString(data) == "Connected to SGCT!\r\n")
return;
if (QString(data) == "OK\r\n")
return;
uint8_t messageType = data[0];
if (messageType == MessageTypeStatus)
handleStatusMessage(data.mid(1));
handleStatusMessage(data.right(data.length() - 1));
}
void MainWindow::onConnectButton() {
//delete _socket;
//
//_socket = new QTcpSocket(this);
// connect( _socket, SIGNAL(readyRead()), SLOT(readTcpData()) );
// _socket->connectToHost(_ipAddress->text(), 20500);
void MainWindow::handleStatusMessage(QByteArray data) {
const char* buffer = data.data();
union {
double value;
std::array<char, 8> buffer;
} et;
std::memmove(et.buffer.data(), buffer, sizeof(double));
std::vector<char> timeString(24);
std::memmove(timeString.data(), buffer + sizeof(double), 24);
union {
double value;
std::array<char, 8> buffer;
} delta;
std::memmove(delta.buffer.data(), buffer + sizeof(double) + 24, sizeof(double));
_timeControlWidget->update(
QString::fromStdString(std::string(timeString.begin(), timeString.end())),
QString::number(delta.value)
);
}
void MainWindow::sendCommandButton() {
//if (!_socket) {
// if (_logWindow->toPlainText().isEmpty())
// _logWindow->setText("No connection found");
// else
// _logWindow->setText(_logWindow->toPlainText() + "\n" + "No connection found");
// return;
//}
//QString command = _command->text();
//if (_logWindow->toPlainText().isEmpty())
// _logWindow->setText(command);
//else
// _logWindow->setText(_logWindow->toPlainText() + "\n" + command);
//
//_socket->write(("0" + command + "\r\n").toLatin1());
void MainWindow::sendScript(QString script) {
_socket->write(("0" + script + "\r\n").toLatin1());
}
+8 -2
View File
@@ -39,10 +39,16 @@ public:
MainWindow();
~MainWindow();
public slots:
void sendScript(QString script);
private slots:
void onConnectButton();
void sendCommandButton();
void onConnect(QString host, QString port);
//void onConnectButton();
//void sendCommandButton();
void readTcpData();
void handleStatusMessage(QByteArray data);
private:
ConfigurationWidget* _configurationWidget;
+69
View File
@@ -42,6 +42,44 @@ TimeControlWidget::TimeControlWidget(QWidget* parent)
, _play(new QPushButton("|>"))
, _forward(new QPushButton(">>"))
{
_setDelta->setMinimum(-100);
_setDelta->setMaximum(100);
_setDelta->setValue(0);
QObject::connect(
_setDelta,
SIGNAL(valueChanged(int)),
this,
SLOT(onValueChange())
);
QObject::connect(
_rewind,
SIGNAL(clicked()),
this,
SLOT(onRewindButton())
);
QObject::connect(
_pause,
SIGNAL(clicked()),
this,
SLOT(onPauseButton())
);
QObject::connect(
_play,
SIGNAL(clicked()),
this,
SLOT(onPlayButton())
);
QObject::connect(
_forward,
SIGNAL(clicked()),
this,
SLOT(onForwardButton())
);
QGridLayout* layout = new QGridLayout;
layout->addWidget(_currentTime, 0, 0);
@@ -60,3 +98,34 @@ TimeControlWidget::TimeControlWidget(QWidget* parent)
setLayout(layout);
}
void TimeControlWidget::update(QString currentTime, QString currentDelta) {
_currentTime->setText(currentTime);
_currentDelta->setText(currentDelta);
}
void TimeControlWidget::onValueChange() {
QString script = "openspace.time.setDeltaTime(" + QString::number(_setDelta->value()) + ");";
emit scriptActivity(script);
}
void TimeControlWidget::onRewindButton() {
QString script = "openspace.time.setDeltaTime(-openspace.time.deltaTime());";
emit scriptActivity(script);
}
void TimeControlWidget::onPauseButton() {
QString script = "openspace.time.setPause(true);";
emit scriptActivity(script);
}
void TimeControlWidget::onPlayButton() {
QString script = "openspace.time.setPause(false);";
emit scriptActivity(script);
}
void TimeControlWidget::onForwardButton() {
QString script = "openspace.time.setDeltaTime(-openspace.time.deltaTime());";
emit scriptActivity(script);
}
+14
View File
@@ -37,6 +37,18 @@ Q_OBJECT
public:
TimeControlWidget(QWidget* parent);
void update(QString currentTime, QString currentDelta);
signals:
void scriptActivity(QString script);
private slots:
void onValueChange();
void onRewindButton();
void onPauseButton();
void onPlayButton();
void onForwardButton();
private:
QLabel* _currentTime;
QComboBox* _setTime;
@@ -46,6 +58,8 @@ private:
QPushButton* _pause;
QPushButton* _play;
QPushButton* _forward;
bool _stateNoNotification = false;
};
#endif // __TIMECONTROLWIDGET_H__