| 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");
|
| 364 |
Kevin |
14 |
ToggleGroupLayout(false);
|
| 345 |
Kevin |
15 |
|
| 354 |
Kevin |
16 |
// Initialize serial widget
|
| 362 |
Kevin |
17 |
serialWidget = new SerialWidget();
|
| 351 |
Kevin |
18 |
groupSerialInit = new QGroupBox("Serial Connection");
|
|
|
19 |
QGridLayout *serialInitLayout = new QGridLayout();
|
|
|
20 |
serialInitLayout->setContentsMargins(0, 0, 0, 0);
|
| 362 |
Kevin |
21 |
serialInitLayout->addWidget(serialWidget);
|
| 351 |
Kevin |
22 |
groupSerialInit->setLayout(serialInitLayout);
|
| 362 |
Kevin |
23 |
connect(serialWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
|
| 344 |
Kevin |
24 |
|
| 354 |
Kevin |
25 |
// Initialize data widget
|
| 362 |
Kevin |
26 |
ioWidget = new IOWidget();
|
| 354 |
Kevin |
27 |
groupSerialData = new QGroupBox("Data");
|
|
|
28 |
QGridLayout *serialDataLayout = new QGridLayout();
|
|
|
29 |
serialDataLayout->setContentsMargins(0, 0, 0, 0);
|
| 362 |
Kevin |
30 |
serialDataLayout->addWidget(ioWidget);
|
| 354 |
Kevin |
31 |
groupSerialData->setLayout(serialDataLayout);
|
| 362 |
Kevin |
32 |
connect(serialWidget, SIGNAL(ReceivedByte(QByteArray)), ioWidget, SLOT(ProcessReceivedByte(QByteArray)));
|
| 364 |
Kevin |
33 |
connect(serialWidget, SIGNAL(Connected(bool)), ioWidget, SLOT(EnableTransmit(bool)));
|
| 362 |
Kevin |
34 |
connect(ioWidget, SIGNAL(TransmitByteArray(QByteArray)), serialWidget, SIGNAL(TransmitByteArray(QByteArray)));
|
| 354 |
Kevin |
35 |
|
|
|
36 |
// Initialize macro widget
|
| 348 |
Kevin |
37 |
macroDockWidget = new QDockWidget("Macro Controller", this);
|
| 354 |
Kevin |
38 |
macroWidget = new MacroWidget(macroDockWidget);
|
|
|
39 |
macroDockWidget->setWidget(macroWidget);
|
| 348 |
Kevin |
40 |
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
41 |
macroDockWidget->hide();
|
|
|
42 |
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
|
| 362 |
Kevin |
43 |
connect(macroWidget, SIGNAL(TransmitText(QByteArray)), ioWidget, SLOT(PreprocessTransmit(QByteArray)));
|
| 364 |
Kevin |
44 |
connect(serialWidget, SIGNAL(Connected(bool)), macroWidget, SLOT(EnableTransmit(bool)));
|
| 345 |
Kevin |
45 |
|
| 363 |
Kevin |
46 |
// Initialize paste controller widget
|
|
|
47 |
pasteDockWidget = new QDockWidget("Paste Controller", this);
|
|
|
48 |
pasteWidget = new PasteController(pasteDockWidget);
|
|
|
49 |
pasteDockWidget->setWidget(pasteWidget);
|
|
|
50 |
pasteDockWidget->setFloating(true);
|
| 364 |
Kevin |
51 |
pasteDockWidget->hide();
|
|
|
52 |
connect(serialWidget, SIGNAL(Connected(bool)), pasteWidget, SLOT(EnableTransmit(bool)));
|
|
|
53 |
connect(pasteWidget, SIGNAL(TransmitData(QByteArray)), ioWidget, SLOT(PreprocessTransmit(QByteArray)));
|
| 372 |
Kevin |
54 |
connect(serialWidget, SIGNAL(ReceivedByte(QByteArray)), pasteWidget, SLOT(ProcessData(QByteArray)));
|
| 363 |
Kevin |
55 |
|
| 345 |
Kevin |
56 |
// Connect local widgets
|
| 348 |
Kevin |
57 |
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 363 |
Kevin |
58 |
connect(btnPaste, SIGNAL(clicked()), pasteDockWidget->toggleViewAction(), SLOT(trigger()));
|
| 345 |
Kevin |
59 |
|
| 351 |
Kevin |
60 |
// Main layout
|
|
|
61 |
QGridLayout *mainLayout = new QGridLayout();
|
|
|
62 |
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
|
| 363 |
Kevin |
63 |
mainLayout->addWidget(groupOther, 0, 1, 1, 1, Qt::AlignLeft);
|
| 351 |
Kevin |
64 |
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
|
|
|
65 |
mainLayout->setColumnStretch(0, 0);
|
|
|
66 |
mainLayout->setColumnStretch(1, 1);
|
|
|
67 |
centralWidget->setLayout(mainLayout);
|
| 364 |
Kevin |
68 |
connect(serialWidget, SIGNAL(Connected(bool)), this, SLOT(ToggleGroupLayout(bool)));
|
| 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 |
}
|
| 364 |
Kevin |
91 |
|
|
|
92 |
void MainWindow::ToggleGroupLayout(bool toggle)
|
|
|
93 |
{
|
|
|
94 |
QGridLayout *layout = qobject_cast<QGridLayout*>(groupOther->layout());
|
|
|
95 |
if (layout == NULL) layout = new QGridLayout();
|
|
|
96 |
layout->removeWidget(btnMacro);
|
|
|
97 |
layout->removeWidget(btnPaste);
|
|
|
98 |
if (toggle) {
|
|
|
99 |
layout->addWidget(btnMacro, 0, 0);
|
|
|
100 |
layout->addWidget(btnPaste, 0, 1);
|
|
|
101 |
} else {
|
|
|
102 |
layout->addWidget(btnMacro, 0, 0);
|
|
|
103 |
layout->addWidget(btnPaste, 1, 0);
|
|
|
104 |
}
|
|
|
105 |
groupOther->setLayout(layout);
|
|
|
106 |
groupOther->repaint();
|
|
|
107 |
}
|