| 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 |
|
| 354 |
Kevin |
10 |
// Misc button group
|
| 345 |
Kevin |
11 |
groupMacro = new QGroupBox("Other");
|
|
|
12 |
btnMacro = new QPushButton("&Macros");
|
|
|
13 |
QHBoxLayout *macroLayout = new QHBoxLayout();
|
|
|
14 |
macroLayout->addWidget(btnMacro);
|
|
|
15 |
groupMacro->setLayout(macroLayout);
|
|
|
16 |
|
| 354 |
Kevin |
17 |
// Initialize serial widget
|
|
|
18 |
serialInitWidget = new SerialWidget();
|
| 351 |
Kevin |
19 |
groupSerialInit = new QGroupBox("Serial Connection");
|
|
|
20 |
QGridLayout *serialInitLayout = new QGridLayout();
|
|
|
21 |
serialInitLayout->setContentsMargins(0, 0, 0, 0);
|
| 354 |
Kevin |
22 |
serialInitLayout->addWidget(serialInitWidget);
|
| 351 |
Kevin |
23 |
groupSerialInit->setLayout(serialInitLayout);
|
| 354 |
Kevin |
24 |
connect(serialInitWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
|
| 344 |
Kevin |
25 |
|
| 354 |
Kevin |
26 |
// Initialize data widget
|
|
|
27 |
textIOWidget = new TextIOWidget();
|
|
|
28 |
groupSerialData = new QGroupBox("Data");
|
|
|
29 |
QGridLayout *serialDataLayout = new QGridLayout();
|
|
|
30 |
serialDataLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
31 |
serialDataLayout->addWidget(textIOWidget);
|
|
|
32 |
groupSerialData->setLayout(serialDataLayout);
|
|
|
33 |
connect(serialInitWidget, SIGNAL(Serial_ReceivedByte(char)), textIOWidget, SLOT(Serial_ReceivedByte(char)));
|
|
|
34 |
connect(serialInitWidget, SIGNAL(Serial_Connected()), textIOWidget, SLOT(Serial_EnableTransmit()));
|
|
|
35 |
connect(serialInitWidget, SIGNAL(Serial_Disconnected()), textIOWidget, SLOT(Serial_DisableTransmit()));
|
|
|
36 |
connect(textIOWidget, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialInitWidget, SIGNAL(Serial_TransmitByteArray(QByteArray)));
|
|
|
37 |
|
|
|
38 |
// Initialize macro widget
|
| 348 |
Kevin |
39 |
macroDockWidget = new QDockWidget("Macro Controller", this);
|
| 354 |
Kevin |
40 |
macroWidget = new MacroWidget(macroDockWidget);
|
|
|
41 |
macroDockWidget->setWidget(macroWidget);
|
| 348 |
Kevin |
42 |
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
43 |
macroDockWidget->hide();
|
|
|
44 |
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
|
| 354 |
Kevin |
45 |
connect(macroWidget, SIGNAL(Macro_TransmitText(QByteArray)), textIOWidget, SLOT(Serial_PrepareTransmit(QByteArray)));
|
|
|
46 |
connect(serialInitWidget, SIGNAL(Serial_Connected()), macroWidget, SLOT(Macro_EnableTransmit()));
|
|
|
47 |
connect(serialInitWidget, SIGNAL(Serial_Disconnected()), macroWidget, SLOT(Macro_DisableTransmit()));
|
| 345 |
Kevin |
48 |
|
|
|
49 |
// Connect local widgets
|
| 348 |
Kevin |
50 |
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 345 |
Kevin |
51 |
|
| 351 |
Kevin |
52 |
// Main layout
|
|
|
53 |
QGridLayout *mainLayout = new QGridLayout();
|
|
|
54 |
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
|
|
|
55 |
mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
|
|
|
56 |
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
|
|
|
57 |
mainLayout->setColumnStretch(0, 0);
|
|
|
58 |
mainLayout->setColumnStretch(1, 1);
|
|
|
59 |
centralWidget->setLayout(mainLayout);
|
| 345 |
Kevin |
60 |
|
|
|
61 |
setWindowTitle("Marlin Controller");
|
| 347 |
Kevin |
62 |
setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
|
| 351 |
Kevin |
63 |
|
| 354 |
Kevin |
64 |
labelSerialStatus = new QLabel("Disconnected");
|
| 353 |
Kevin |
65 |
statusBar()->addPermanentWidget(labelSerialStatus);
|
| 344 |
Kevin |
66 |
}
|
|
|
67 |
|
|
|
68 |
MainWindow::~MainWindow()
|
|
|
69 |
{
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
|
| 351 |
Kevin |
73 |
void MainWindow::UpdateStatus(QString string)
|
| 344 |
Kevin |
74 |
{
|
| 351 |
Kevin |
75 |
statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
|
| 344 |
Kevin |
76 |
}
|
|
|
77 |
|
| 351 |
Kevin |
78 |
void MainWindow::UpdateSerialStatus(QString string)
|
| 344 |
Kevin |
79 |
{
|
| 353 |
Kevin |
80 |
labelSerialStatus->setText(string);
|
| 344 |
Kevin |
81 |
}
|