Blame | Last modification | View Log | RSS feed
#include "TextIOWidget.h"
TextIOWidget::TextIOWidget(QWidget *parent) : QWidget(parent)
{
// Serial data UI
textSerialData = new QTextEdit();
textSerialData->setCurrentFont(QFont("Consolas", 8));
textSerialData->append("Waiting for serial connection...");
textSerialData->setMinimumSize(400, 100);
textSerialData->setReadOnly(true);
textSerialTransmit = new QLineEdit();
textSerialTransmit->setEnabled(false);
textSerialTransmit->setFont(QFont("Consolas", 8));
btnSerialTransmit = new QPushButton("&Send");
btnSerialTransmit->setEnabled(false);
btnSerialClear = new QPushButton("Clear");
QHBoxLayout *serialTransmitLayout = new QHBoxLayout();
serialTransmitLayout->addWidget(textSerialTransmit);
serialTransmitLayout->addWidget(btnSerialTransmit);
serialTransmitLayout->addWidget(btnSerialClear);
QVBoxLayout *serialDataLayout = new QVBoxLayout();
serialDataLayout->addWidget(textSerialData);
serialDataLayout->addLayout(serialTransmitLayout);
setLayout(serialDataLayout);
connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit()));
connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked()));
connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn()));
Serial_DisableTransmit();
}
TextIOWidget::~TextIOWidget()
{
}
void TextIOWidget::Serial_PrepareTransmit(QByteArray data)
{
QString str;
if (data.isEmpty()) {
str = textSerialTransmit->text();
textSerialTransmit->setText("");
} else {
str = QString(data);
}
emit Serial_TransmitByteArray(str.toUtf8());
textSerialData->setTextColor(Qt::darkBlue);
QStringList cmds = str.split('\n');
for (int i = 0; i < cmds.size(); i++) {
textSerialData->append("TX: " + cmds[i]);
}
}
void TextIOWidget::Serial_ReceivedByte(char byte)
{
textSerialData->setTextColor(Qt::darkRed);
textSerialData->append("RX: " + QString(byte));
}
void TextIOWidget::Serial_ClearBtn()
{
textSerialData->clear();
}
void TextIOWidget::Serial_EnableTransmit()
{
textSerialTransmit->setEnabled(true);
btnSerialTransmit->setEnabled(true);
}
void TextIOWidget::Serial_DisableTransmit()
{
textSerialTransmit->setEnabled(false);
btnSerialTransmit->setEnabled(false);
}