Subversion Repositories Code-Repo

Rev

Rev 353 | 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
    serialInitWidget = new SerialWidget();
    groupSerialInit = new QGroupBox("Serial Connection");
    QGridLayout *serialInitLayout = new QGridLayout();
    serialInitLayout->setContentsMargins(0, 0, 0, 0);
    serialInitLayout->addWidget(serialInitWidget);
    groupSerialInit->setLayout(serialInitLayout);
    connect(serialInitWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));

    // Initialize data widget
    textIOWidget = new TextIOWidget();
    groupSerialData = new QGroupBox("Data");
    QGridLayout *serialDataLayout = new QGridLayout();
    serialDataLayout->setContentsMargins(0, 0, 0, 0);
    serialDataLayout->addWidget(textIOWidget);
    groupSerialData->setLayout(serialDataLayout);
    connect(serialInitWidget, SIGNAL(Serial_ReceivedByte(char)), textIOWidget, SLOT(Serial_ReceivedByte(char)));
    connect(serialInitWidget, SIGNAL(Serial_Connected()), textIOWidget, SLOT(Serial_EnableTransmit()));
    connect(serialInitWidget, SIGNAL(Serial_Disconnected()), textIOWidget, SLOT(Serial_DisableTransmit()));
    connect(textIOWidget, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialInitWidget, SIGNAL(Serial_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(Macro_TransmitText(QByteArray)), textIOWidget, SLOT(Serial_PrepareTransmit(QByteArray)));
    connect(serialInitWidget, SIGNAL(Serial_Connected()), macroWidget, SLOT(Macro_EnableTransmit()));
    connect(serialInitWidget, SIGNAL(Serial_Disconnected()), macroWidget, SLOT(Macro_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);
}