Rev 349 | Rev 353 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
// Set central widget
centralWidget = new QWidget();
setCentralWidget(centralWidget);
// Serial data UI
groupSerialData = new QGroupBox("Data");
textSerialData = new QTextEdit();
textSerialData->setCurrentFont(QFont("Consolas", 8));
textSerialData->append("Waiting for serial connection...");
textSerialData->setMinimumHeight(100);
textSerialData->setReadOnly(true);
textSerialTransmit = new QLineEdit();
textSerialTransmit->setFont(QFont("Consolas", 8));
btnSerialTransmit = new QPushButton("&Send");
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);
groupSerialData->setLayout(serialDataLayout);
// Macro controller
groupMacro = new QGroupBox("Other");
btnMacro = new QPushButton("&Macros");
QHBoxLayout *macroLayout = new QHBoxLayout();
macroLayout->addWidget(btnMacro);
groupMacro->setLayout(macroLayout);
// Initialize serial controller
serialController = new SerialController();
groupSerialInit = new QGroupBox("Serial Connection");
QGridLayout *serialInitLayout = new QGridLayout();
serialInitLayout->setContentsMargins(0, 0, 0, 0);
serialInitLayout->addWidget(serialController);
groupSerialInit->setLayout(serialInitLayout);
connect(serialController, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
// Initialize macro controller
macroDockWidget = new QDockWidget("Macro Controller", this);
macroController = new MacroController(macroDockWidget);
macroDockWidget->setWidget(macroController);
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
macroDockWidget->hide();
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
connect(macroController, SIGNAL(Macro_TransmitText(QString)), this, SLOT(Serial_PrepareTransmit(QString)));
connect(serialController, SIGNAL(Serial_Connected()), macroController, SLOT(Macro_EnableTransmit()));
connect(serialController, SIGNAL(Serial_Disconnected()), macroController, SLOT(Macro_DisableTransmit()));
// Connect local widgets
connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit()));
connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked()));
connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn()));
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
// Main layout
QGridLayout *mainLayout = new QGridLayout();
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
mainLayout->setColumnStretch(0, 0);
mainLayout->setColumnStretch(1, 1);
centralWidget->setLayout(mainLayout);
setWindowTitle("Marlin Controller");
setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
statusSerial = new QLabel("Serial Status: Disconnected");
statusSerial->setMinimumWidth(300);
statusBar()->addPermanentWidget(statusSerial);
}
MainWindow::~MainWindow()
{
}
void MainWindow::Serial_PrepareTransmit(QString string)
{
if (string == "") {
string = textSerialTransmit->text();
textSerialTransmit->setText("");
}
emit Serial_TransmitString(string);
textSerialData->setTextColor(Qt::darkBlue);
QStringList cmds = string.split('\n');
for (int i = 0; i < cmds.size(); i++) {
textSerialData->append("TX: " + cmds[i]);
}
}
void MainWindow::Serial_ClearBtn()
{
textSerialData->clear();
}
void MainWindow::Serial_ReceivedString(QString string)
{
textSerialData->setTextColor(Qt::darkRed);
textSerialData->append("RX: " + string);
}
void MainWindow::UpdateStatus(QString string)
{
statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
}
void MainWindow::UpdateSerialStatus(QString string)
{
statusSerial->setText(string);
}