diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -26,8 +26,8 @@ #include #include -#include "ui_mainwindow.h" #include "atcore.h" +#include "widgets/plotwidget.h" class SerialLayer; @@ -173,13 +173,9 @@ /** * @brief show/hide dock titlebars + * @param checked: True if shown */ - void toggleDockTitles(); - - /** - * @brief Show the about dialog - */ - void about(); + void toggleDockTitles(bool checked); /** * @brief List Files on the sd card. @@ -192,7 +188,6 @@ void sdDelPBClicked(); private: - Ui::MainWindow *ui; AtCore *core; QTemporaryFile *logFile; QTime *printTime; @@ -282,4 +277,77 @@ * @brief Gui Changes for when sd card mount status has changed. */ void sdChanged(bool mounted); + + //UI Functions + + /** + * @brief Create The Menubar + */ + void initMenu(); + + /** + * @brief Create StatusBar + */ + void initStatusBar(); + + /** + * @brief Create Main Widgets. + */ + void initWidgets(); + +//Private GUI Items + //menuView is global to allow for docks to be added / removed. + QMenu *menuView = nullptr; + //Status Bar Items + QLabel *lblState = nullptr; + QLabel *lblSd = nullptr; + QWidget *printProgressWidget = nullptr; + QProgressBar *printingProgress = nullptr; + QLabel *lblTime = nullptr; + QLabel *lblTimeLeft = nullptr; + //Docks + void makeLogDock(); + QDockWidget *logDock = nullptr; + QPlainTextEdit *textLog = nullptr; + + void makeTempTimelineDock(); + QDockWidget *tempTimelineDock = nullptr; + PlotWidget *plotWidget = nullptr; + + void makeCommandDock(); + QDockWidget *printDock = nullptr; + QDockWidget *commandDock = nullptr; + QLineEdit *lineCommand = nullptr; + QLineEdit *lineMessage = nullptr; + + void makePrintDock(); + QPushButton *buttonPrint = nullptr; + QLineEdit *linePostPause = nullptr; + QSpinBox *sbFlowRate = nullptr; + QSpinBox *sbPrintSpeed = nullptr; + + void makeConnectDock(); + QDockWidget *connectDock = nullptr; + QComboBox *comboPort = nullptr; + QComboBox *comboBAUD = nullptr; + QComboBox *comboPlugin = nullptr; + QPushButton *buttonConnect = nullptr; + + void makeMoveDock(); + QDockWidget *moveDock = nullptr; + QComboBox *comboMoveAxis = nullptr; + QDoubleSpinBox *sbMoveAxis = nullptr; + + void makeTempControlsDock(); + QDockWidget *tempControlsDock = nullptr; + QCheckBox *checkAndWait = nullptr; + QSpinBox *sbBedTemp = nullptr; + QComboBox *comboExtruderSelect; + QSpinBox *sbExtruderTemp; + QComboBox *comboFanSelect; + QSpinBox *sbFanSpeed; + + void makeSdDock(); + QDockWidget *sdDock = nullptr; + QListWidget *listSdFiles = nullptr; }; diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -39,125 +39,469 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow), core(new AtCore(this)), logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) { - ui->setupUi(this); + setWindowTitle(QStringLiteral("AtCore - Test Client")); setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); QCoreApplication::setApplicationVersion(core->version()); - ui->serialPortCB->setEditable(true); - QValidator *validator = new QIntValidator(); - ui->baudRateLE->setValidator(validator); - ui->baudRateLE->addItems(core->portSpeeds()); - ui->baudRateLE->setCurrentIndex(9); - - ui->pluginCB->addItem(tr("Autodetect")); - ui->pluginCB->addItems(core->availableFirmwarePlugins()); - - AxisControl *axisControl = new AxisControl; - ui->moveDockContents->layout()->addWidget(axisControl); + initMenu(); + initStatusBar(); + initWidgets(); addLog(tr("Attempting to locate Serial Ports")); core->setSerialTimerInterval(1000); populateCBs(); - //Icon for actionQuit -#ifndef Q_OS_MAC - ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); -#endif - //hide the printing progress bar. - ui->printLayout->setVisible(false); + printProgressWidget->setVisible(false); - ui->statusBar->addWidget(ui->statusBarWidget); printTime = new QTime(); printTimer = new QTimer(); printTimer->setInterval(1000); printTimer->setSingleShot(false); connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); - connect(ui->connectPB, &QPushButton::clicked, this, &MainWindow::connectPBClicked); - connect(ui->saveLogPB, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); - connect(ui->sendPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); - connect(ui->commandLE, &QLineEdit::returnPressed, this, &MainWindow::sendPBClicked); - connect(ui->homeAllPB, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); - connect(ui->homeXPB, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); - connect(ui->homeYPB, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); - connect(ui->homeZPB, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); - connect(ui->bedTempPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); - connect(ui->extTempPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); - connect(ui->mvAxisPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); - connect(ui->fanSpeedPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); - connect(ui->printPB, &QPushButton::clicked, this, &MainWindow::printPBClicked); - connect(ui->sdPrintPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); - connect(ui->sdDelPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); - connect(ui->printerSpeedPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); - connect(ui->flowRatePB, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); - connect(ui->showMessagePB, &QPushButton::clicked, this, &MainWindow::showMessage); - connect(ui->pluginCB, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); - connect(ui->disableMotorsPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); - connect(ui->sdListPB, &QPushButton::clicked, this, &MainWindow::getSdList); connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); - connect(ui->stopPB, &QPushButton::clicked, core, &AtCore::stop); - connect(ui->emergencyStopPB, &QPushButton::clicked, core, &AtCore::emergencyStop); - connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { - ui->sdFileListView->clear(); - ui->sdFileListView->addItems(fileList); + listSdFiles->clear(); + listSdFiles->addItems(fileList); }); connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { checkTemperature(0x00, 0, temp); - ui->plotWidget->appendPoint(tr("Actual Bed"), temp); - ui->plotWidget->update(); + plotWidget->appendPoint(tr("Actual Bed"), temp); + plotWidget->update(); }); connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x01, 0, temp); - ui->plotWidget->appendPoint(tr("Target Bed"), temp); - ui->plotWidget->update(); + plotWidget->appendPoint(tr("Target Bed"), temp); + plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { checkTemperature(0x02, 0, temp); - ui->plotWidget->appendPoint(tr("Actual Ext.1"), temp); - ui->plotWidget->update(); + plotWidget->appendPoint(tr("Actual Ext.1"), temp); + plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x03, 0, temp); - ui->plotWidget->appendPoint(tr("Target Ext.1"), temp); - ui->plotWidget->update(); + plotWidget->appendPoint(tr("Target Ext.1"), temp); + plotWidget->update(); }); - connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close); - connect(ui->actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); - connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::about); - - ui->menuView->insertAction(nullptr, ui->connectDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->tempControlsDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->commandDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->printDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->moveDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->tempTimelineDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->logDock->toggleViewAction()); - ui->menuView->insertAction(nullptr, ui->sdDock->toggleViewAction()); - //more dock stuff. setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); - tabifyDockWidget(ui->moveDock, ui->tempControlsDock); - tabifyDockWidget(ui->moveDock, ui->sdDock); - ui->moveDock->raise(); + tabifyDockWidget(moveDock, tempControlsDock); + tabifyDockWidget(moveDock, sdDock); + moveDock->raise(); - tabifyDockWidget(ui->connectDock, ui->printDock); - tabifyDockWidget(ui->connectDock, ui->commandDock); - ui->connectDock->raise(); + tabifyDockWidget(connectDock, printDock); + tabifyDockWidget(connectDock, commandDock); + connectDock->raise(); setCentralWidget(nullptr); } +void MainWindow::initMenu() +{ + QMenu *menuFile = new QMenu(QStringLiteral("&File")); + QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), QStringLiteral("Quit")); + connect(actionQuit, &QAction::triggered, this, &MainWindow::close); + menuFile->addAction(actionQuit); + + menuView = new QMenu(QStringLiteral("&View")); + QAction *actionShowDockTitles = new QAction(QStringLiteral("Show Dock Titles")); + actionShowDockTitles->setCheckable(true); + actionShowDockTitles->setChecked(true); + connect(actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); + menuView->addAction(actionShowDockTitles); + + QMenu *menuHelp = new QMenu(QStringLiteral("&Help")); + QAction *actionAbout = new QAction(QStringLiteral("About")); + actionAbout->setShortcut(QKeySequence(Qt::Key_F1)); + connect(actionAbout, &QAction::triggered, [] { + auto *dialog = new About; + dialog->exec(); + }); + menuHelp->addAction(actionAbout); + + menuBar()->addMenu(menuFile); + menuBar()->addMenu(menuView); + menuBar()->addMenu(menuHelp); +} + +void MainWindow::initStatusBar() +{ + auto *labelStatus = new QLabel(QStringLiteral("AtCore State:")); + lblState = new QLabel(QStringLiteral("Not Connected")); + lblSd = new QLabel(); + printingProgress = new QProgressBar; + auto *stopPB = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); + connect(stopPB, &QPushButton::clicked, core, &AtCore::stop); + lblTime = new QLabel(QStringLiteral("00:00:00")); + lblTime->setAlignment(Qt::AlignHCenter); + auto *labelSlash = new QLabel(QStringLiteral(" / ")); + lblTimeLeft = new QLabel(QStringLiteral("00:00:00")); + lblTimeLeft->setAlignment(Qt::AlignHCenter); + + auto *printLayout = new QHBoxLayout; + printLayout->addWidget(printingProgress); + printLayout->addWidget(stopPB); + printLayout->addWidget(lblTime); + printLayout->addWidget(labelSlash); + printLayout->addWidget(lblTimeLeft); + printProgressWidget = new QWidget(); + printProgressWidget->setLayout(printLayout); + + auto *statusLayout = new QHBoxLayout; + statusLayout->addWidget(labelStatus); + statusLayout->addWidget(lblState); + statusLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); + statusLayout->addWidget(lblSd); + statusLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); + statusLayout->addWidget(printProgressWidget); + QWidget *sBar = new QWidget(); + sBar->setLayout(statusLayout); + statusBar()->addPermanentWidget(sBar, width()); +} + +void MainWindow::initWidgets() +{ + makeCommandDock(); + commandDock->setEnabled(false); + makePrintDock(); + printDock->setEnabled(false); + makeTempTimelineDock(); + tempTimelineDock->setEnabled(false); + makeLogDock(); + makeConnectDock(); + makeMoveDock(); + moveDock->setEnabled(false); + makeTempControlsDock(); + tempControlsDock->setEnabled(false); + makeSdDock(); + sdDock->setEnabled(false); +} + +void MainWindow::makeCommandDock() +{ + lineCommand = new QLineEdit; + lineCommand->setPlaceholderText(QStringLiteral("Send Command")); + auto *newPB = new QPushButton(QStringLiteral("Send")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); + + auto *hBoxLayout1 = new QHBoxLayout; + hBoxLayout1->addWidget(lineCommand); + hBoxLayout1->addWidget(newPB); + + lineMessage = new QLineEdit; + lineMessage->setPlaceholderText(QStringLiteral("Show Message")); + newPB = new QPushButton(QStringLiteral("Send")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::showMessage); + auto *hBoxLayout2 = new QHBoxLayout; + hBoxLayout2->addWidget(lineMessage); + hBoxLayout2->addWidget(newPB); + + auto *vBoxLayout1 = new QVBoxLayout; + vBoxLayout1->addItem(hBoxLayout1); + vBoxLayout1->addItem(hBoxLayout2); + + auto *dockContents = new QWidget; + dockContents->setLayout(vBoxLayout1); + + commandDock = new QDockWidget(QStringLiteral("Commands"), this); + menuView->insertAction(nullptr, commandDock->toggleViewAction()); + commandDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, commandDock); +} + +void MainWindow::makePrintDock() +{ + buttonPrint = new QPushButton(QStringLiteral("Print File")); + connect(buttonPrint, &QPushButton::clicked, this, &MainWindow::printPBClicked); + + auto *newPB = new QPushButton(QStringLiteral("Emergency Stop")); + connect(newPB, &QPushButton::clicked, core, &AtCore::emergencyStop); + auto *hBoxLayout1 = new QHBoxLayout; + hBoxLayout1->addWidget(buttonPrint); + hBoxLayout1->addWidget(newPB); + + auto *newLabel = new QLabel(QStringLiteral("On Pause:")); + linePostPause = new QLineEdit; + linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); + auto *hBoxLayout2 = new QHBoxLayout; + hBoxLayout2->addWidget(newLabel); + hBoxLayout2->addWidget(linePostPause); + + newLabel = new QLabel(QStringLiteral("Printer Speed")); + sbPrintSpeed = new QSpinBox; + sbPrintSpeed->setRange(1, 300); + sbPrintSpeed->setValue(100); + sbPrintSpeed->setSuffix(QStringLiteral("%")); + + newPB = new QPushButton(QStringLiteral("Set")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); + + auto *hBoxLayout3 = new QHBoxLayout; + hBoxLayout3->addWidget(newLabel, 35); + hBoxLayout3->addWidget(sbPrintSpeed, 10); + hBoxLayout3->addWidget(newPB, 20); + + newLabel = new QLabel(QStringLiteral("Flow Rate")); + sbFlowRate = new QSpinBox; + sbFlowRate->setRange(1, 300); + sbFlowRate->setValue(100); + sbFlowRate->setSuffix(QStringLiteral("%")); + + newPB = new QPushButton(QStringLiteral("Set")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); + + auto *hBoxLayout4 = new QHBoxLayout; + hBoxLayout4->addWidget(newLabel, 35); + hBoxLayout4->addWidget(sbFlowRate, 10); + hBoxLayout4->addWidget(newPB, 20); + + auto *vBoxLayout1 = new QVBoxLayout; + vBoxLayout1->addItem(hBoxLayout1); + vBoxLayout1->addItem(hBoxLayout2); + vBoxLayout1->addItem(hBoxLayout3); + vBoxLayout1->addItem(hBoxLayout4); + + auto *dockContents = new QWidget; + dockContents->setLayout(vBoxLayout1); + + printDock = new QDockWidget(QStringLiteral("Print"), this); + menuView->insertAction(nullptr, printDock->toggleViewAction()); + printDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, printDock); +} + +void MainWindow::makeTempTimelineDock() +{ + plotWidget = new PlotWidget; + tempTimelineDock = new QDockWidget(QStringLiteral("Temperature Timeline"), this); + menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); + tempTimelineDock->setWidget(plotWidget); + addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); +} + +void MainWindow::makeLogDock() +{ + textLog = new QPlainTextEdit; + textLog->setReadOnly(true); + textLog->setMaximumBlockCount(1000); + + auto *buttonSave = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), QStringLiteral("Save Session Log")); + connect(buttonSave, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); + + auto *vBoxLayout1 = new QVBoxLayout; + vBoxLayout1->addWidget(textLog); + vBoxLayout1->addWidget(buttonSave); + + auto *dockContents = new QWidget(); + dockContents->setLayout(vBoxLayout1); + + logDock = new QDockWidget(QStringLiteral("Session Log"), this); + menuView->insertAction(nullptr, logDock->toggleViewAction()); + logDock->setWidget(dockContents); + addDockWidget(Qt::RightDockWidgetArea, logDock); +} + +void MainWindow::makeConnectDock() +{ + auto *newLabel = new QLabel(QStringLiteral("Port:")); + comboPort = new QComboBox; + comboPort->setEditable(true); + auto *hBoxLayout1 = new QHBoxLayout; + hBoxLayout1->addWidget(newLabel); + hBoxLayout1->addWidget(comboPort, 75); + + newLabel = new QLabel(QStringLiteral("Baud Rate:")); + comboBAUD = new QComboBox; + comboBAUD->addItems(core->portSpeeds()); + comboBAUD->setCurrentIndex(9); + + auto *hBoxLayout2 = new QHBoxLayout; + hBoxLayout2->addWidget(newLabel); + hBoxLayout2->addWidget(comboBAUD, 75); + + newLabel = new QLabel(QStringLiteral("Use Plugin:")); + comboPlugin = new QComboBox; + comboPlugin->addItem(tr("Autodetect")); + comboPlugin->addItems(core->availableFirmwarePlugins()); + connect(comboPlugin, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); + + auto *hBoxLayout3 = new QHBoxLayout; + hBoxLayout3->addWidget(newLabel); + hBoxLayout3->addWidget(comboPlugin, 75); + + buttonConnect = new QPushButton(QStringLiteral("Connect")); + auto *vBoxLayout = new QVBoxLayout; + vBoxLayout->addItem(hBoxLayout1); + vBoxLayout->addItem(hBoxLayout2); + vBoxLayout->addItem(hBoxLayout3); + vBoxLayout->addWidget(buttonConnect); + + auto *dockContents = new QWidget; + dockContents->setLayout(vBoxLayout); + + connectDock = new QDockWidget(QStringLiteral("Connect"), this); + menuView->insertAction(nullptr, connectDock->toggleViewAction()); + connectDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, connectDock); +} + +void MainWindow::makeMoveDock() +{ + auto *buttonHomeA = new QPushButton(QStringLiteral("Home All")); + connect(buttonHomeA, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); + + auto *buttonHomeX = new QPushButton(QStringLiteral("Home X")); + connect(buttonHomeX, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); + + auto *buttonHomeY = new QPushButton(QStringLiteral("Home Y")); + connect(buttonHomeY, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); + + auto *buttonHomeZ = new QPushButton(QStringLiteral("Home Z")); + connect(buttonHomeZ, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); + + auto *hBoxLayout1 = new QHBoxLayout; + hBoxLayout1->addWidget(buttonHomeA); + hBoxLayout1->addWidget(buttonHomeX); + hBoxLayout1->addWidget(buttonHomeY); + hBoxLayout1->addWidget(buttonHomeZ); + + comboMoveAxis = new QComboBox; + comboMoveAxis->addItem(QStringLiteral("Move X Axis to")); + comboMoveAxis->addItem(QStringLiteral("Move Y Axis to")); + comboMoveAxis->addItem(QStringLiteral("Move Z Axis to")); + + sbMoveAxis = new QDoubleSpinBox; + sbMoveAxis->setRange(0, 200); + + auto *newPB = new QPushButton(QStringLiteral("Go")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); + + auto *hBoxLayout2 = new QHBoxLayout; + hBoxLayout2->addWidget(comboMoveAxis); + hBoxLayout2->addWidget(sbMoveAxis); + hBoxLayout2->addWidget(newPB); + + newPB = new QPushButton(QStringLiteral("Disable Motors")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); + + auto *axisControl = new AxisControl; + connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); + + auto *vBoxLayout = new QVBoxLayout; + vBoxLayout->addItem(hBoxLayout1); + vBoxLayout->addItem(hBoxLayout2); + vBoxLayout->addWidget(newPB); + vBoxLayout->addWidget(axisControl); + + auto *dockContents = new QWidget; + dockContents->setLayout(vBoxLayout); + + moveDock = new QDockWidget(QStringLiteral("Movement"), this); + menuView->insertAction(nullptr, moveDock->toggleViewAction()); + moveDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, moveDock); +} + +void MainWindow::makeTempControlsDock() +{ + auto *mainLayout = new QVBoxLayout; + checkAndWait = new QCheckBox(QStringLiteral("Wait Untill Temperature Stablizes")); + mainLayout->addWidget(checkAndWait); + + auto label = new QLabel(QStringLiteral("Bed Temp")); + + sbBedTemp = new QSpinBox; + sbBedTemp->setRange(0, 120); + sbBedTemp->setSuffix(QStringLiteral("°C")); + + auto *newPB = new QPushButton(QStringLiteral("Set")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); + + auto *hboxLayout = new QHBoxLayout; + hboxLayout->addWidget(label, 80); + hboxLayout->addWidget(sbBedTemp); + hboxLayout->addWidget(newPB); + mainLayout->addItem(hboxLayout); + + comboExtruderSelect = new QComboBox; + sbExtruderTemp = new QSpinBox; + sbExtruderTemp->setRange(0, 275); + sbExtruderTemp->setSuffix(QStringLiteral("°C")); + + newPB = new QPushButton(QStringLiteral("Set")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); + hboxLayout = new QHBoxLayout; + hboxLayout->addWidget(comboExtruderSelect, 80); + hboxLayout->addWidget(sbExtruderTemp); + hboxLayout->addWidget(newPB); + mainLayout->addItem(hboxLayout); + + comboFanSelect = new QComboBox; + sbFanSpeed = new QSpinBox; + sbFanSpeed->setRange(0, 100); + sbFanSpeed->setSuffix(QStringLiteral("%")); + + newPB = new QPushButton(QStringLiteral("Set")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); + hboxLayout = new QHBoxLayout; + hboxLayout->addWidget(comboFanSelect, 80); + hboxLayout->addWidget(sbFanSpeed); + hboxLayout->addWidget(newPB); + mainLayout->addItem(hboxLayout); + + auto *dockContents = new QWidget; + dockContents->setLayout(mainLayout); + + tempControlsDock = new QDockWidget(QStringLiteral("Temperatures"), this); + menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); + tempControlsDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); +} + +void MainWindow::makeSdDock() +{ + auto *hBoxLayout = new QHBoxLayout; + auto *newPB = new QPushButton(QStringLiteral("Get List")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::getSdList); + hBoxLayout->addWidget(newPB); + + newPB = new QPushButton(QStringLiteral("Print Selected")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); + hBoxLayout->addWidget(newPB); + + newPB = new QPushButton(QStringLiteral("Delete Selected")); + connect(newPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); + hBoxLayout->addWidget(newPB); + + auto *groupFiles = new QGroupBox(QStringLiteral("Files On Sd Card")); + listSdFiles = new QListWidget; + auto *groupLayout = new QVBoxLayout; + groupLayout->addWidget(listSdFiles); + groupFiles->setLayout(groupLayout); + + auto *finalLayout = new QVBoxLayout; + finalLayout->addItem(hBoxLayout); + finalLayout->addWidget(groupFiles); + + auto *dockContents = new QWidget; + dockContents->setLayout(finalLayout); + + sdDock = new QDockWidget(QStringLiteral("Sd Card"), this); + menuView->insertAction(nullptr, sdDock->toggleViewAction()); + sdDock->setWidget(dockContents); + addDockWidget(Qt::LeftDockWidgetArea, sdDock); +} + void MainWindow::closeEvent(QCloseEvent *event) { core->close(); @@ -167,7 +511,6 @@ MainWindow::~MainWindow() { delete logFile; - delete ui; } QString MainWindow::getTime() @@ -208,21 +551,21 @@ void MainWindow::addLog(QString msg) { QString message(logHeader() + msg); - ui->logTE->appendPlainText(message); + textLog->appendPlainText(message); writeTempFile(message); } void MainWindow::addRLog(QString msg) { QString message(rLogHeader() + msg); - ui->logTE->appendPlainText(message); + textLog->appendPlainText(message); writeTempFile(message); } void MainWindow::addSLog(QString msg) { QString message(sLogHeader() + msg); - ui->logTE->appendPlainText(message); + textLog->appendPlainText(message); writeTempFile(message); } @@ -283,32 +626,32 @@ */ void MainWindow::locateSerialPort(const QStringList &ports) { - ui->serialPortCB->clear(); + comboPort->clear(); if (!ports.isEmpty()) { - ui->serialPortCB->addItems(ports); + comboPort->addItems(ports); addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); } else { QString portError(tr("No available ports! Please connect a serial device to continue!")); - if (! ui->logTE->toPlainText().endsWith(portError)) { + if (! textLog->toPlainText().endsWith(portError)) { addLog(portError); } } } void MainWindow::connectPBClicked() { if (core->state() == AtCore::DISCONNECTED) { - if (core->initSerial(ui->serialPortCB->currentText(), ui->baudRateLE->currentText().toInt())) { + if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); - ui->connectPB->setText(tr("Disconnect")); + buttonConnect->setText(tr("Disconnect")); addLog(tr("Serial connected")); - if (ui->pluginCB->currentText().contains(tr("Autodetect"))) { + if (comboPlugin->currentText().contains(tr("Autodetect"))) { addLog(tr("No plugin loaded !")); addLog(tr("Requesting Firmware...")); core->detectFirmware(); } else { - core->loadFirmwarePlugin(ui->pluginCB->currentText()); + core->loadFirmwarePlugin(comboPlugin->currentText()); } } else { addLog(tr("Failed to open serial in r/w mode")); @@ -319,15 +662,15 @@ core->closeConnection(); core->setState(AtCore::DISCONNECTED); addLog(tr("Disconnected")); - ui->connectPB->setText(tr("Connect")); + buttonConnect->setText(tr("Connect")); } } void MainWindow::sendPBClicked() { - QString comm = ui->commandLE->text().toUpper(); + QString comm = lineCommand->text().toUpper(); core->pushCommand(comm); - ui->commandLE->clear(); + lineCommand->clear(); } void MainWindow::homeAllPBClicked() @@ -356,40 +699,40 @@ void MainWindow::bedTempPBClicked() { - if (ui->cb_andWait->isChecked()) { + if (checkAndWait->isChecked()) { addSLog(GCode::description(GCode::M190)); } else { addSLog(GCode::description(GCode::M140)); } - core->setBedTemp(ui->bedTempSB->value(), ui->cb_andWait->isChecked()); + core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); } void MainWindow::extTempPBClicked() { - if (ui->cb_andWait->isChecked()) { + if (checkAndWait->isChecked()) { addSLog(GCode::description(GCode::M109)); } else { addSLog(GCode::description(GCode::M104)); } - core->setExtruderTemp(ui->extTempSB->value(), ui->extTempSelCB->currentIndex(), ui->cb_andWait->isChecked()); + core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); } void MainWindow::mvAxisPBClicked() { addSLog(GCode::description(GCode::G1)); - if (ui->mvAxisCB->currentIndex() == 0) { - core->move(AtCore::X, ui->mvAxisSB->value()); - } else if (ui->mvAxisCB->currentIndex() == 1) { - core->move(AtCore::Y, ui->mvAxisSB->value()); - } else if (ui->mvAxisCB->currentIndex() == 2) { - core->move(AtCore::Z, ui->mvAxisSB->value()); + if (comboMoveAxis->currentIndex() == 0) { + core->move(AtCore::X, sbMoveAxis->value()); + } else if (comboMoveAxis->currentIndex() == 1) { + core->move(AtCore::Y, sbMoveAxis->value()); + } else if (comboMoveAxis->currentIndex() == 2) { + core->move(AtCore::Z, sbMoveAxis->value()); } } void MainWindow::fanSpeedPBClicked() { addSLog(GCode::description(GCode::M106)); - core->setFanSpeed(ui->fanSpeedSB->value(), ui->fanSpeedSelCB->currentIndex()); + core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); } void MainWindow::printPBClicked() @@ -403,7 +746,7 @@ case AtCore::CONNECTING: QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); - ui->pluginCB->setCurrentText(QStringLiteral("repetier")); + comboPlugin->setCurrentText(QStringLiteral("repetier")); break; case AtCore::IDLE: @@ -417,7 +760,7 @@ break; case AtCore::BUSY: - core->pause(ui->postPauseLE->text()); + core->pause(linePostPause->text()); break; case AtCore::PAUSE: @@ -450,64 +793,64 @@ void MainWindow::flowRatePBClicked() { - core->setFlowRate(ui->flowRateSB->value()); + core->setFlowRate(sbFlowRate->value()); } void MainWindow::printerSpeedPBClicked() { - core->setPrinterSpeed(ui->printerSpeedSB->value()); + core->setPrinterSpeed(sbPrintSpeed->value()); } void MainWindow::printerStateChanged(AtCore::STATES state) { QString stateString; switch (state) { case AtCore::IDLE: - ui->printPB->setText(tr("Print File")); + buttonPrint->setText(tr("Print File")); stateString = QStringLiteral("Connected to ") + core->connectedPort(); break; case AtCore::STARTPRINT: stateString = QStringLiteral("START PRINT"); - ui->printPB->setText(tr("Pause Print")); - ui->printLayout->setVisible(true); + buttonPrint->setText(tr("Pause Print")); + printProgressWidget->setVisible(true); printTime->start(); printTimer->start(); break; case AtCore::FINISHEDPRINT: stateString = QStringLiteral("Finished Print"); - ui->printPB->setText(tr("Print File")); - ui->printLayout->setVisible(false); + buttonPrint->setText(tr("Print File")); + printProgressWidget->setVisible(false); printTimer->stop(); break; case AtCore::PAUSE: stateString = QStringLiteral("Paused"); - ui->printPB->setText(tr("Resume Print")); + buttonPrint->setText(tr("Resume Print")); break; case AtCore::BUSY: stateString = QStringLiteral("Printing"); - ui->printPB->setText(tr("Pause Print")); + buttonPrint->setText(tr("Pause Print")); break; case AtCore::DISCONNECTED: stateString = QStringLiteral("Not Connected"); - ui->commandDock->setDisabled(true); - ui->moveDock->setDisabled(true); - ui->tempControlsDock->setDisabled(true); - ui->printDock->setDisabled(true); - ui->sdDock->setDisabled(true); + commandDock->setDisabled(true); + moveDock->setDisabled(true); + tempControlsDock->setDisabled(true); + printDock->setDisabled(true); + sdDock->setDisabled(true); break; case AtCore::CONNECTING: stateString = QStringLiteral("Connecting"); - ui->commandDock->setDisabled(false); - ui->moveDock->setDisabled(false); - ui->tempControlsDock->setDisabled(false); - ui->printDock->setDisabled(false); - ui->sdDock->setDisabled(false); + commandDock->setDisabled(false); + moveDock->setDisabled(false); + tempControlsDock->setDisabled(false); + printDock->setDisabled(false); + sdDock->setDisabled(false); break; case AtCore::STOP: @@ -518,72 +861,66 @@ stateString = QStringLiteral("Command ERROR"); break; } - ui->lblState->setText(stateString); + lblState->setText(stateString); } void MainWindow::populateCBs() { // Extruders for (int count = 0; count < core->extruderCount(); count++) { - ui->extTempSelCB->insertItem(count, tr("Extruder %1").arg(count)); + comboExtruderSelect->insertItem(count, tr("Extruder %1").arg(count)); } // Fan for (int count = 0; count < fanCount; count++) { - ui->fanSpeedSelCB->insertItem(count, tr("Fan %1 speed").arg(count)); + comboFanSelect->insertItem(count, tr("Fan %1 speed").arg(count)); } } void MainWindow::showMessage() { - core->showMessage(ui->messageLE->text()); + core->showMessage(lineMessage->text()); } void MainWindow::updatePrintTime() { QTime temp(0, 0, 0); - ui->time->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); + lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); } void MainWindow::printProgressChanged(int progress) { - ui->printingProgress->setValue(progress); + printingProgress->setValue(progress); if (progress > 0) { QTime temp(0, 0, 0); - ui->timeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); + lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); } else { - ui->timeLeft->setText(QStringLiteral("??:??:??")); + lblTimeLeft->setText(QStringLiteral("??:??:??")); } } -void MainWindow::toggleDockTitles() -{ - if (ui->actionShowDockTitles->isChecked()) { - delete ui->connectDock->titleBarWidget(); - delete ui->logDock->titleBarWidget(); - delete ui->tempTimelineDock->titleBarWidget(); - delete ui->commandDock->titleBarWidget(); - delete ui->moveDock->titleBarWidget(); - delete ui->tempControlsDock->titleBarWidget(); - delete ui->printDock->titleBarWidget(); - delete ui->sdDock->titleBarWidget(); +void MainWindow::toggleDockTitles(bool checked) +{ + if (checked) { + delete connectDock->titleBarWidget(); + delete logDock->titleBarWidget(); + delete tempTimelineDock->titleBarWidget(); + delete commandDock->titleBarWidget(); + delete moveDock->titleBarWidget(); + delete tempControlsDock->titleBarWidget(); + delete printDock->titleBarWidget(); + delete sdDock->titleBarWidget(); } else { - ui->connectDock->setTitleBarWidget(new QWidget()); - ui->logDock->setTitleBarWidget(new QWidget()); - ui->tempTimelineDock->setTitleBarWidget(new QWidget()); - ui->commandDock->setTitleBarWidget(new QWidget()); - ui->moveDock->setTitleBarWidget(new QWidget()); - ui->tempControlsDock->setTitleBarWidget(new QWidget()); - ui->printDock->setTitleBarWidget(new QWidget()); - ui->sdDock->setTitleBarWidget(new QWidget()); + connectDock->setTitleBarWidget(new QWidget()); + logDock->setTitleBarWidget(new QWidget()); + tempTimelineDock->setTitleBarWidget(new QWidget()); + commandDock->setTitleBarWidget(new QWidget()); + moveDock->setTitleBarWidget(new QWidget()); + tempControlsDock->setTitleBarWidget(new QWidget()); + printDock->setTitleBarWidget(new QWidget()); + sdDock->setTitleBarWidget(new QWidget()); } } -void MainWindow::about() -{ - About *aboutDialog = new About(this); - aboutDialog->exec(); -} - void MainWindow::axisControlClicked(QLatin1Char axis, int value) { core->setRelativePosition(); @@ -599,7 +936,7 @@ void MainWindow::sdChanged(bool mounted) { QString labelText = mounted ? QStringLiteral("SD") : QString(); - ui->lbl_sd->setText(labelText); + lblSd->setText(labelText); } void MainWindow::getSdList() @@ -609,19 +946,19 @@ void MainWindow::sdPrintPBClicked() { - if (ui->sdFileListView->currentRow() < 0) { + if (listSdFiles->currentRow() < 0) { QMessageBox::information(this, QStringLiteral("Print Error"), QStringLiteral("You must Select a file from the list")); } else { - core->print(ui->sdFileListView->currentItem()->text(), true); + core->print(listSdFiles->currentItem()->text(), true); } } void MainWindow::sdDelPBClicked() { - if (ui->sdFileListView->currentRow() < 0) { + if (listSdFiles->currentRow() < 0) { QMessageBox::information(this, QStringLiteral("Delete Error"), QStringLiteral("You must Select a file from the list")); } else { - core->sdDelete(ui->sdFileListView->currentItem()->text()); - ui->sdFileListView->setCurrentRow(-1); + core->sdDelete(listSdFiles->currentItem()->text()); + listSdFiles->setCurrentRow(-1); } } diff --git a/testclient/mainwindow.ui b/testclient/mainwindow.ui deleted file mode 100644 --- a/testclient/mainwindow.ui +++ /dev/null @@ -1,1069 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 0 - 0 - - - - AtCore - Test Client - - - - - - 6 - 418 - 801 - 46 - - - - - 100 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - AtCoreState: - - - - - - - Not Connected - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true - - - 0 - - - - - - - Stop Print Job - - - - - - - .. - - - - - - - <html><head/><body><p>Elapsed Time</p></body></html> - - - 00:00:00 - - - Qt::AlignCenter - - - - - - - / - - - - - - - <html><head/><body><p>Remaining Time</p></body></html> - - - 00:00:00 - - - Qt::AlignCenter - - - - - - - - - - - false - - - - 10 - 0 - 473 - 243 - - - - - 0 - 0 - - - - &Print - - - - - - - - - Print File - - - - - - - - 0 - 0 - - - - Emergency Stop - - - - - - - - - - - On Pause: - - - - - - - G91,G0 Z1,G90,G1 X0 Y195 - - - - - - - - - - - - 0 - 0 - - - - Printer Speed - - - - - - - % - - - - - - 300 - - - 100 - - - - - - - - 0 - 0 - - - - Set - - - - - - - - - - - - 0 - 0 - - - - Flow Rate - - - - - - - % - - - 300 - - - 100 - - - - - - - - 0 - 0 - - - - Set - - - - - - - - - - - false - - - - 0 - 240 - 485 - 146 - - - - - 0 - 0 - - - - Comma&nds - - - - - - - - - Send Command - - - - - - - Send - - - - - - - - - - - Show Message - - - - - - - Send - - - - - - - - - - - false - - - - 0 - 42 - 515 - 317 - - - - S&d Card - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Get List - - - - - - - Print Selected - - - - - - - Delete Selected - - - - - - - - - - Files On Sd Card. - - - - - - - - - - - - - - - - 0 - 0 - - - - Temperat&ure Timeline - - - 2 - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - - - - 0 - 0 - - - - &Connection Settings - - - 1 - - - - - - - - 0 - 0 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - Port: - - - - - - - - - - - - - - - 0 - 0 - - - - Baud Rate: - - - - - - - true - - - - - - - - - - - Use Plugin - - - - - - - - 0 - 0 - - - - - - - - - - - 0 - 0 - - - - Connect - - - - - - - - - - - - - 0 - 0 - - - - Session &Log - - - 2 - - - - - - - - 0 - 0 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true - - - - 0 - 0 - - - - true - - - 1000 - - - - - - - Save Session Log - - - - .. - - - - - - - - - - - - Qt::NoContextMenu - - - false - - - - - false - - - - 0 - 0 - - - - &Movement - - - 1 - - - - - - - - - Home All - - - - - - - Home X - - - - - - - Home Y - - - - - - - Home Z - - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - Move X Axis to - - - - - Move Y Axis to - - - - - Move Z Axis to - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::AlignCenter - - - 0 - - - 200.000000000000000 - - - - - - - - 0 - 0 - - - - Go - - - - - - - - - Disable Motors - - - - - - - - - false - - - - 0 - 0 - - - - &Temperatures - - - 1 - - - - - - - Wait Untill Temperature Stablizes - - - - - - - - - - 0 - 0 - - - - Bed Temp - - - - - - - Qt::AlignCenter - - - °C - - - 0 - - - 100.000000000000000 - - - - - - - Set - - - - - - - - - - - - 0 - 0 - - - - - - - - Qt::AlignCenter - - - °C - - - 0 - - - 275.000000000000000 - - - - - - - Set - - - - - - - - - - - - 0 - 0 - - - - - - - - Qt::AlignCenter - - - % - - - 100 - - - - - - - - 0 - 0 - - - - Set - - - - - - - - - - - - 0 - 0 - 767 - 37 - - - - - &File - - - - - - &View - - - - - - - &Help - - - - - - - - - - &Quit - - - - - true - - - true - - - &Show Dock Titles - - - - - &About - - - F1 - - - - - - PlotWidget - QWidget -
plotwidget.h
- 1 -
-
- - -