Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
353 Kevin 76
    labelSerialStatus = new QLabel("Serial: Disconnected");
77
    statusBar()->addPermanentWidget(labelSerialStatus);
344 Kevin 78
}
79
 
80
MainWindow::~MainWindow()
81
{
82
 
83
}
84
 
345 Kevin 85
void MainWindow::Serial_PrepareTransmit(QString string)
344 Kevin 86
{
345 Kevin 87
    if (string == "") {
88
        string = textSerialTransmit->text();
89
        textSerialTransmit->setText("");
90
    }
91
    emit Serial_TransmitString(string);
344 Kevin 92
    textSerialData->setTextColor(Qt::darkBlue);
345 Kevin 93
 
94
    QStringList cmds = string.split('\n');
95
    for (int i = 0; i < cmds.size(); i++) {
96
        textSerialData->append("TX:  " + cmds[i]);
97
    }
344 Kevin 98
}
99
 
100
void MainWindow::Serial_ClearBtn()
101
{
102
    textSerialData->clear();
103
}
104
 
105
void MainWindow::Serial_ReceivedString(QString string)
106
{
107
    textSerialData->setTextColor(Qt::darkRed);
108
    textSerialData->append("RX:  " + string);
109
}
110
 
351 Kevin 111
void MainWindow::UpdateStatus(QString string)
344 Kevin 112
{
351 Kevin 113
    statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
344 Kevin 114
}
115
 
351 Kevin 116
void MainWindow::UpdateSerialStatus(QString string)
344 Kevin 117
{
353 Kevin 118
    labelSerialStatus->setText(string);
344 Kevin 119
}