| 344 |
Kevin |
1 |
#include "MainWindow.h"
|
|
|
2 |
|
|
|
3 |
MainWindow::MainWindow(QWidget *parent) :
|
|
|
4 |
QMainWindow(parent)
|
|
|
5 |
{
|
|
|
6 |
// Set central widget
|
|
|
7 |
centralWidget = new QWidget();
|
|
|
8 |
setCentralWidget(centralWidget);
|
|
|
9 |
|
|
|
10 |
// Serial data UI
|
|
|
11 |
groupSerialData = new QGroupBox("Data");
|
|
|
12 |
textSerialData = new QTextEdit();
|
|
|
13 |
textSerialData->setCurrentFont(QFont("Consolas", 8));
|
|
|
14 |
textSerialData->append("Waiting for serial connection...");
|
|
|
15 |
textSerialData->setMinimumHeight(100);
|
|
|
16 |
textSerialData->setReadOnly(true);
|
|
|
17 |
textSerialTransmit = new QLineEdit();
|
|
|
18 |
textSerialTransmit->setFont(QFont("Consolas", 8));
|
| 345 |
Kevin |
19 |
btnSerialTransmit = new QPushButton("&Send");
|
| 344 |
Kevin |
20 |
btnSerialClear = new QPushButton("Clear");
|
|
|
21 |
|
|
|
22 |
QHBoxLayout *serialTransmitLayout = new QHBoxLayout();
|
|
|
23 |
serialTransmitLayout->addWidget(textSerialTransmit);
|
|
|
24 |
serialTransmitLayout->addWidget(btnSerialTransmit);
|
|
|
25 |
serialTransmitLayout->addWidget(btnSerialClear);
|
|
|
26 |
QVBoxLayout *serialDataLayout = new QVBoxLayout();
|
|
|
27 |
serialDataLayout->addWidget(textSerialData);
|
|
|
28 |
serialDataLayout->addLayout(serialTransmitLayout);
|
|
|
29 |
groupSerialData->setLayout(serialDataLayout);
|
|
|
30 |
|
| 345 |
Kevin |
31 |
// Macro controller
|
|
|
32 |
groupMacro = new QGroupBox("Other");
|
|
|
33 |
btnMacro = new QPushButton("&Macros");
|
|
|
34 |
QHBoxLayout *macroLayout = new QHBoxLayout();
|
|
|
35 |
macroLayout->addWidget(btnMacro);
|
|
|
36 |
groupMacro->setLayout(macroLayout);
|
|
|
37 |
|
| 351 |
Kevin |
38 |
// Initialize serial controller
|
| 344 |
Kevin |
39 |
serialController = new SerialController();
|
| 351 |
Kevin |
40 |
groupSerialInit = new QGroupBox("Serial Connection");
|
|
|
41 |
QGridLayout *serialInitLayout = new QGridLayout();
|
|
|
42 |
serialInitLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
43 |
serialInitLayout->addWidget(serialController);
|
|
|
44 |
groupSerialInit->setLayout(serialInitLayout);
|
|
|
45 |
connect(serialController, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
|
| 344 |
Kevin |
46 |
|
| 351 |
Kevin |
47 |
// Initialize macro controller
|
| 348 |
Kevin |
48 |
macroDockWidget = new QDockWidget("Macro Controller", this);
|
|
|
49 |
macroController = new MacroController(macroDockWidget);
|
|
|
50 |
macroDockWidget->setWidget(macroController);
|
|
|
51 |
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
52 |
macroDockWidget->hide();
|
|
|
53 |
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
|
| 345 |
Kevin |
54 |
connect(macroController, SIGNAL(Macro_TransmitText(QString)), this, SLOT(Serial_PrepareTransmit(QString)));
|
|
|
55 |
connect(serialController, SIGNAL(Serial_Connected()), macroController, SLOT(Macro_EnableTransmit()));
|
|
|
56 |
connect(serialController, SIGNAL(Serial_Disconnected()), macroController, SLOT(Macro_DisableTransmit()));
|
|
|
57 |
|
|
|
58 |
// Connect local widgets
|
|
|
59 |
connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit()));
|
|
|
60 |
connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked()));
|
|
|
61 |
connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn()));
|
| 348 |
Kevin |
62 |
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 345 |
Kevin |
63 |
|
| 351 |
Kevin |
64 |
// Main layout
|
|
|
65 |
QGridLayout *mainLayout = new QGridLayout();
|
|
|
66 |
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
|
|
|
67 |
mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
|
|
|
68 |
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
|
|
|
69 |
mainLayout->setColumnStretch(0, 0);
|
|
|
70 |
mainLayout->setColumnStretch(1, 1);
|
|
|
71 |
centralWidget->setLayout(mainLayout);
|
| 345 |
Kevin |
72 |
|
|
|
73 |
setWindowTitle("Marlin Controller");
|
| 347 |
Kevin |
74 |
setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
|
| 351 |
Kevin |
75 |
|
|
|
76 |
statusSerial = new QLabel("Serial Status: Disconnected");
|
|
|
77 |
statusSerial->setMinimumWidth(300);
|
|
|
78 |
statusBar()->addPermanentWidget(statusSerial);
|
| 344 |
Kevin |
79 |
}
|
|
|
80 |
|
|
|
81 |
MainWindow::~MainWindow()
|
|
|
82 |
{
|
|
|
83 |
|
|
|
84 |
}
|
|
|
85 |
|
| 345 |
Kevin |
86 |
void MainWindow::Serial_PrepareTransmit(QString string)
|
| 344 |
Kevin |
87 |
{
|
| 345 |
Kevin |
88 |
if (string == "") {
|
|
|
89 |
string = textSerialTransmit->text();
|
|
|
90 |
textSerialTransmit->setText("");
|
|
|
91 |
}
|
|
|
92 |
emit Serial_TransmitString(string);
|
| 344 |
Kevin |
93 |
textSerialData->setTextColor(Qt::darkBlue);
|
| 345 |
Kevin |
94 |
|
|
|
95 |
QStringList cmds = string.split('\n');
|
|
|
96 |
for (int i = 0; i < cmds.size(); i++) {
|
|
|
97 |
textSerialData->append("TX: " + cmds[i]);
|
|
|
98 |
}
|
| 344 |
Kevin |
99 |
}
|
|
|
100 |
|
|
|
101 |
void MainWindow::Serial_ClearBtn()
|
|
|
102 |
{
|
|
|
103 |
textSerialData->clear();
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
void MainWindow::Serial_ReceivedString(QString string)
|
|
|
107 |
{
|
|
|
108 |
textSerialData->setTextColor(Qt::darkRed);
|
|
|
109 |
textSerialData->append("RX: " + string);
|
|
|
110 |
}
|
|
|
111 |
|
| 351 |
Kevin |
112 |
void MainWindow::UpdateStatus(QString string)
|
| 344 |
Kevin |
113 |
{
|
| 351 |
Kevin |
114 |
statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
|
| 344 |
Kevin |
115 |
}
|
|
|
116 |
|
| 351 |
Kevin |
117 |
void MainWindow::UpdateSerialStatus(QString string)
|
| 344 |
Kevin |
118 |
{
|
| 351 |
Kevin |
119 |
statusSerial->setText(string);
|
| 344 |
Kevin |
120 |
}
|