| 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
|
| 363 |
Kevin |
11 |
groupOther = new QGroupBox("Other");
|
| 345 |
Kevin |
12 |
btnMacro = new QPushButton("&Macros");
|
| 363 |
Kevin |
13 |
btnPaste = new QPushButton("&Paste");
|
|
|
14 |
QGridLayout *otherLayout = new QGridLayout();
|
|
|
15 |
otherLayout->addWidget(btnMacro, 0, 0);
|
|
|
16 |
otherLayout->addWidget(btnPaste, 1, 0);
|
|
|
17 |
groupOther->setLayout(otherLayout);
|
| 345 |
Kevin |
18 |
|
| 354 |
Kevin |
19 |
// Initialize serial widget
|
| 362 |
Kevin |
20 |
serialWidget = new SerialWidget();
|
| 351 |
Kevin |
21 |
groupSerialInit = new QGroupBox("Serial Connection");
|
|
|
22 |
QGridLayout *serialInitLayout = new QGridLayout();
|
|
|
23 |
serialInitLayout->setContentsMargins(0, 0, 0, 0);
|
| 362 |
Kevin |
24 |
serialInitLayout->addWidget(serialWidget);
|
| 351 |
Kevin |
25 |
groupSerialInit->setLayout(serialInitLayout);
|
| 362 |
Kevin |
26 |
connect(serialWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
|
| 344 |
Kevin |
27 |
|
| 354 |
Kevin |
28 |
// Initialize data widget
|
| 362 |
Kevin |
29 |
ioWidget = new IOWidget();
|
| 354 |
Kevin |
30 |
groupSerialData = new QGroupBox("Data");
|
|
|
31 |
QGridLayout *serialDataLayout = new QGridLayout();
|
|
|
32 |
serialDataLayout->setContentsMargins(0, 0, 0, 0);
|
| 362 |
Kevin |
33 |
serialDataLayout->addWidget(ioWidget);
|
| 354 |
Kevin |
34 |
groupSerialData->setLayout(serialDataLayout);
|
| 362 |
Kevin |
35 |
connect(serialWidget, SIGNAL(ReceivedByte(QByteArray)), ioWidget, SLOT(ProcessReceivedByte(QByteArray)));
|
|
|
36 |
connect(serialWidget, SIGNAL(Connected()), ioWidget, SLOT(EnableTransmit()));
|
|
|
37 |
connect(serialWidget, SIGNAL(Disconnected()), ioWidget, SLOT(DisableTransmit()));
|
|
|
38 |
connect(ioWidget, SIGNAL(TransmitByteArray(QByteArray)), serialWidget, SIGNAL(TransmitByteArray(QByteArray)));
|
| 354 |
Kevin |
39 |
|
|
|
40 |
// Initialize macro widget
|
| 348 |
Kevin |
41 |
macroDockWidget = new QDockWidget("Macro Controller", this);
|
| 354 |
Kevin |
42 |
macroWidget = new MacroWidget(macroDockWidget);
|
|
|
43 |
macroDockWidget->setWidget(macroWidget);
|
| 348 |
Kevin |
44 |
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
45 |
macroDockWidget->hide();
|
|
|
46 |
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
|
| 362 |
Kevin |
47 |
connect(macroWidget, SIGNAL(TransmitText(QByteArray)), ioWidget, SLOT(PreprocessTransmit(QByteArray)));
|
|
|
48 |
connect(serialWidget, SIGNAL(Connected()), macroWidget, SLOT(EnableTransmit()));
|
|
|
49 |
connect(serialWidget, SIGNAL(Disconnected()), macroWidget, SLOT(DisableTransmit()));
|
| 345 |
Kevin |
50 |
|
| 363 |
Kevin |
51 |
// Initialize paste controller widget
|
|
|
52 |
pasteDockWidget = new QDockWidget("Paste Controller", this);
|
|
|
53 |
pasteWidget = new PasteController(pasteDockWidget);
|
|
|
54 |
pasteDockWidget->setWidget(pasteWidget);
|
|
|
55 |
pasteDockWidget->setFloating(true);
|
|
|
56 |
|
| 345 |
Kevin |
57 |
// Connect local widgets
|
| 348 |
Kevin |
58 |
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 363 |
Kevin |
59 |
connect(btnPaste, SIGNAL(clicked()), pasteDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 345 |
Kevin |
60 |
|
| 351 |
Kevin |
61 |
// Main layout
|
|
|
62 |
QGridLayout *mainLayout = new QGridLayout();
|
|
|
63 |
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
|
| 363 |
Kevin |
64 |
mainLayout->addWidget(groupOther, 0, 1, 1, 1, Qt::AlignLeft);
|
| 351 |
Kevin |
65 |
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
|
|
|
66 |
mainLayout->setColumnStretch(0, 0);
|
|
|
67 |
mainLayout->setColumnStretch(1, 1);
|
|
|
68 |
centralWidget->setLayout(mainLayout);
|
| 345 |
Kevin |
69 |
|
|
|
70 |
setWindowTitle("Marlin Controller");
|
| 347 |
Kevin |
71 |
setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
|
| 351 |
Kevin |
72 |
|
| 354 |
Kevin |
73 |
labelSerialStatus = new QLabel("Disconnected");
|
| 353 |
Kevin |
74 |
statusBar()->addPermanentWidget(labelSerialStatus);
|
| 344 |
Kevin |
75 |
}
|
|
|
76 |
|
|
|
77 |
MainWindow::~MainWindow()
|
|
|
78 |
{
|
|
|
79 |
|
|
|
80 |
}
|
|
|
81 |
|
| 351 |
Kevin |
82 |
void MainWindow::UpdateStatus(QString string)
|
| 344 |
Kevin |
83 |
{
|
| 351 |
Kevin |
84 |
statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
|
| 344 |
Kevin |
85 |
}
|
|
|
86 |
|
| 351 |
Kevin |
87 |
void MainWindow::UpdateSerialStatus(QString string)
|
| 344 |
Kevin |
88 |
{
|
| 353 |
Kevin |
89 |
labelSerialStatus->setText(string);
|
| 344 |
Kevin |
90 |
}
|