diff --git a/README.md b/README.md index 5fcdf07..bcdf61e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # RepRaptor A Qt RepRap gcode sender/host controller aimed to be fast and minimalistic. -Right now the project is in early stage, nigtly builds are available. +Right now the project is in early stage. ## Screenshots ![RepRaptor printing a file](http://reprap.org/mediawiki/images/2/2d/RepRaptor_screenshot0.png) diff --git a/RepRaptor.pro b/RepRaptor.pro index d856118..44ef6c1 100644 --- a/RepRaptor.pro +++ b/RepRaptor.pro @@ -16,15 +16,20 @@ CONFIG += static SOURCES += main.cpp\ mainwindow.cpp \ settingswindow.cpp \ - aboutwindow.cpp + aboutwindow.cpp \ + errorwindow.cpp \ + erroricon.cpp HEADERS += mainwindow.h \ settingswindow.h \ - aboutwindow.h + aboutwindow.h \ + errorwindow.h \ + erroricon.h FORMS += mainwindow.ui \ settingswindow.ui \ - aboutwindow.ui + aboutwindow.ui \ + errorwindow.ui RESOURCES += \ graphics.qrc diff --git a/erroricon.cpp b/erroricon.cpp new file mode 100644 index 0000000..7bd00fc --- /dev/null +++ b/erroricon.cpp @@ -0,0 +1,38 @@ +#include "erroricon.h" + +ErrorIcon::ErrorIcon(QWidget *parent) : QWidget(parent) +{ + framenum = 0; + frame = ":icons/error_a.png"; + animation.setInterval(300); + animation.start(); + + connect(&animation, SIGNAL(timeout()), this, SLOT(changeFrame())); +} + +void ErrorIcon::paintEvent(QPaintEvent *pe) +{ + QPainter painter(this); + painter.drawPixmap(0,0,128,87,QPixmap(frame)); +} + +void ErrorIcon::changeFrame() +{ + if(framenum == 0) + { + frame = ":icons/error_a.png"; + framenum = 1; + } + else if(framenum == 1) + { + frame = ":icons/error_b.png"; + framenum = 0; + } + this->update(); +} + +ErrorIcon::~ErrorIcon() +{ + +} + diff --git a/erroricon.h b/erroricon.h new file mode 100644 index 0000000..c338334 --- /dev/null +++ b/erroricon.h @@ -0,0 +1,27 @@ +#ifndef ERRORICON_H +#define ERRORICON_H + +#include +#include +#include + +class ErrorIcon : public QWidget +{ + Q_OBJECT +public: + explicit ErrorIcon(QWidget *parent = 0); + ~ErrorIcon(); + QTimer animation; + QString frame; + int framenum; + +protected: + virtual void paintEvent(QPaintEvent *pe); + +signals: + +public slots: + void changeFrame(); +}; + +#endif // ERRORICON_H diff --git a/errorwindow.cpp b/errorwindow.cpp new file mode 100644 index 0000000..c6787df --- /dev/null +++ b/errorwindow.cpp @@ -0,0 +1,15 @@ +#include "errorwindow.h" +#include "ui_errorwindow.h" + +ErrorWindow::ErrorWindow(QWidget *parent, QString errorText) : + QDialog(parent), + ui(new Ui::ErrorWindow) +{ + ui->setupUi(this); + ui->errorlabel->setText(errorText); +} + +ErrorWindow::~ErrorWindow() +{ + delete ui; +} diff --git a/errorwindow.h b/errorwindow.h new file mode 100644 index 0000000..20a8558 --- /dev/null +++ b/errorwindow.h @@ -0,0 +1,24 @@ +#ifndef ERRORWINDOW_H +#define ERRORWINDOW_H + +#include + +#include "erroricon.h" + +namespace Ui { +class ErrorWindow; +} + +class ErrorWindow : public QDialog +{ + Q_OBJECT + +public: + explicit ErrorWindow(QWidget *parent = 0, QString errorText = "Unknown error"); + ~ErrorWindow(); + +private: + Ui::ErrorWindow *ui; +}; + +#endif // ERRORWINDOW_H diff --git a/errorwindow.ui b/errorwindow.ui new file mode 100644 index 0000000..e8f9d3c --- /dev/null +++ b/errorwindow.ui @@ -0,0 +1,130 @@ + + + ErrorWindow + + + + 0 + 0 + 350 + 139 + + + + Error + + + + + 90 + 100 + 171 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + 10 + 10 + 128 + 87 + + + + + 0 + 0 + + + + + 128 + 87 + + + + + + + 180 + 10 + 121 + 31 + + + + Serial port error: + + + Qt::AutoText + + + + + + 180 + 40 + 151 + 41 + + + + NaN + + + + + + ErrorIcon + QWidget +
erroricon.h
+ 1 +
+
+ + + + buttonBox + accepted() + ErrorWindow + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ErrorWindow + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/graphics.qrc b/graphics.qrc index 758ce20..1cfb75b 100644 --- a/graphics.qrc +++ b/graphics.qrc @@ -2,5 +2,7 @@ icons/icon.png icons/logo.png + icons/error_a.png + icons/error_b.png diff --git a/icons/error_a.png b/icons/error_a.png new file mode 100644 index 0000000..b9f6252 Binary files /dev/null and b/icons/error_a.png differ diff --git a/icons/error_b.png b/icons/error_b.png new file mode 100644 index 0000000..964f9b3 Binary files /dev/null and b/icons/error_b.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index e901808..ce62a46 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -39,6 +39,7 @@ MainWindow::MainWindow(QWidget *parent) : serialupdate(); + connect(&printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError))); connect(&printer, SIGNAL(readyRead()), this, SLOT(readSerial())); connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus())); connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext())); @@ -199,6 +200,7 @@ void MainWindow::serialconnect() ui->progressBar->setValue(0); ui->controlBox->setDisabled(true); ui->consoleGroup->setDisabled(true); + } } @@ -440,6 +442,7 @@ void MainWindow::sendNext() currentLine = 0; ui->sendBtn->setText("Send"); ui->pauseBtn->setDisabled("true"); + ui->filelines->setText(QString::number(gcode.size()) + QString("/") + QString::number(currentLine) + QString(" Lines")); return; } sendLine(gcode.at(currentLine)); @@ -505,5 +508,59 @@ void MainWindow::injectCommand(QString command) void MainWindow::updateRecent() { - + //TODO +} + +void MainWindow::serialError(QSerialPort::SerialPortError error) +{ + if(error == QSerialPort::NoError) return; + + if(printer.isOpen()) printer.close(); + + if(sending) paused = true; + + ui->connectBtn->setText("Connect"); + ui->sendBtn->setDisabled(true); + ui->pauseBtn->setDisabled(true); + ui->progressBar->setValue(0); + ui->controlBox->setDisabled(true); + ui->consoleGroup->setDisabled(true); + + qDebug() << error; + + QString errorMsg; + switch(error) + { + case QSerialPort::DeviceNotFoundError: + errorMsg = "Device not found"; + break; + + case QSerialPort::PermissionError: + errorMsg = "Insufficient permissions\nAlready opened?"; + break; + + case QSerialPort::OpenError: + errorMsg = "Cant open port\nAlready opened?"; + break; + + case QSerialPort::TimeoutError: + errorMsg = "Serial connection timed out"; + break; + + case QSerialPort::WriteError: + case QSerialPort::ReadError: + errorMsg = "I/O Error"; + break; + + case QSerialPort::ResourceError: + errorMsg = "Disconnected"; + break; + + default: + errorMsg = "Unknown error\nSomething went wrong"; + break; + } + + ErrorWindow errorwindow(this, errorMsg); + errorwindow.exec(); } diff --git a/mainwindow.h b/mainwindow.h index 9b57a8f..a5f6d91 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,6 +14,7 @@ #include "settingswindow.h" #include "aboutwindow.h" +#include "errorwindow.h" namespace Ui { @@ -95,6 +96,7 @@ private slots: void on_actionSettings_triggered(); void on_releasebtn_clicked(); void on_actionAbout_triggered(); + void serialError(QSerialPort::SerialPortError error); }; #endif // MAINWINDOW_H