Subversion Repositories Code-Repo

Rev

Rev 356 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

#include "MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    // Set central widget
    centralWidget = new QWidget();
    setCentralWidget(centralWidget);

    // Misc button group
    groupMacro = new QGroupBox("Other");
    btnMacro = new QPushButton("&Macros");
    QHBoxLayout *macroLayout = new QHBoxLayout();
    macroLayout->addWidget(btnMacro);
    groupMacro->setLayout(macroLayout);

    // Initialize serial widget
    serialWidget = new SerialWidget();
    groupSerialInit = new QGroupBox("Serial Connection");
    QGridLayout *serialInitLayout = new QGridLayout();
    serialInitLayout->setContentsMargins(0, 0, 0, 0);
    serialInitLayout->addWidget(serialWidget);
    groupSerialInit->setLayout(serialInitLayout);
    connect(serialWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));

    // Initialize data widget
    ioWidget = new IOWidget();
    groupSerialData = new QGroupBox("Data");
    QGridLayout *serialDataLayout = new QGridLayout();
    serialDataLayout->setContentsMargins(0, 0, 0, 0);
    serialDataLayout->addWidget(ioWidget);
    groupSerialData->setLayout(serialDataLayout);
    connect(serialWidget, SIGNAL(ReceivedByte(QByteArray)), ioWidget, SLOT(ProcessReceivedByte(QByteArray)));
    connect(serialWidget, SIGNAL(Connected()), ioWidget, SLOT(EnableTransmit()));
    connect(serialWidget, SIGNAL(Disconnected()), ioWidget, SLOT(DisableTransmit()));
    connect(ioWidget, SIGNAL(TransmitByteArray(QByteArray)), serialWidget, SIGNAL(TransmitByteArray(QByteArray)));

    // Initialize macro widget
    macroDockWidget = new QDockWidget("Macro Controller", this);
    macroWidget = new MacroWidget(macroDockWidget);
    macroDockWidget->setWidget(macroWidget);
    macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    macroDockWidget->hide();
    addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
    connect(macroWidget, SIGNAL(TransmitText(QByteArray)), ioWidget, SLOT(PreprocessTransmit(QByteArray)));
    connect(serialWidget, SIGNAL(Connected()), macroWidget, SLOT(EnableTransmit()));
    connect(serialWidget, SIGNAL(Disconnected()), macroWidget, SLOT(DisableTransmit()));

    // Connect local widgets
    connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));

    // Main layout
    QGridLayout *mainLayout = new QGridLayout();
    mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
    mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
    mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
    mainLayout->setColumnStretch(0, 0);
    mainLayout->setColumnStretch(1, 1);
    centralWidget->setLayout(mainLayout);

    setWindowTitle("Marlin Controller");
    setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));

    labelSerialStatus = new QLabel("Disconnected");
    statusBar()->addPermanentWidget(labelSerialStatus);
}

MainWindow::~MainWindow()
{

}

void MainWindow::UpdateStatus(QString string)
{
    statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
}

void MainWindow::UpdateSerialStatus(QString string)
{
    labelSerialStatus->setText(string);
}