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
 
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)));
363 Kevin 54
 
345 Kevin 55
    // Connect local widgets
348 Kevin 56
    connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
363 Kevin 57
    connect(btnPaste, SIGNAL(clicked()), pasteDockWidget->toggleViewAction(), SLOT(trigger()));
345 Kevin 58
 
351 Kevin 59
    // Main layout
60
    QGridLayout *mainLayout = new QGridLayout();
61
    mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
363 Kevin 62
    mainLayout->addWidget(groupOther, 0, 1, 1, 1, Qt::AlignLeft);
351 Kevin 63
    mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
64
    mainLayout->setColumnStretch(0, 0);
65
    mainLayout->setColumnStretch(1, 1);
66
    centralWidget->setLayout(mainLayout);
364 Kevin 67
    connect(serialWidget, SIGNAL(Connected(bool)), this, SLOT(ToggleGroupLayout(bool)));
345 Kevin 68
 
69
    setWindowTitle("Marlin Controller");
347 Kevin 70
    setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
351 Kevin 71
 
354 Kevin 72
    labelSerialStatus = new QLabel("Disconnected");
353 Kevin 73
    statusBar()->addPermanentWidget(labelSerialStatus);
344 Kevin 74
}
75
 
76
MainWindow::~MainWindow()
77
{
78
 
79
}
80
 
351 Kevin 81
void MainWindow::UpdateStatus(QString string)
344 Kevin 82
{
351 Kevin 83
    statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
344 Kevin 84
}
85
 
351 Kevin 86
void MainWindow::UpdateSerialStatus(QString string)
344 Kevin 87
{
353 Kevin 88
    labelSerialStatus->setText(string);
344 Kevin 89
}
364 Kevin 90
 
91
void MainWindow::ToggleGroupLayout(bool toggle)
92
{
93
    QGridLayout *layout = qobject_cast<QGridLayout*>(groupOther->layout());
94
    if (layout == NULL) layout = new QGridLayout();
95
    layout->removeWidget(btnMacro);
96
    layout->removeWidget(btnPaste);
97
    if (toggle) {
98
        layout->addWidget(btnMacro, 0, 0);
99
        layout->addWidget(btnPaste, 0, 1);
100
    } else {
101
        layout->addWidget(btnMacro, 0, 0);
102
        layout->addWidget(btnPaste, 1, 0);
103
    }
104
    groupOther->setLayout(layout);
105
    groupOther->repaint();
106
}