diff --git a/mainwindow.cpp b/mainwindow.cpp index 8cd0e53..2eb363f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,6 +29,13 @@ MainWindow::MainWindow(QWidget *parent) : ui->etmpspin->installEventFilter(this); ui->btmpspin->installEventFilter(this); recentMenu = new QMenu(this); + trayIcon = new QSystemTrayIcon(this); + trayIcon->setIcon(QIcon(":icons/repraptor.png")); + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(ui->actionOpen); + trayIconMenu->addAction(ui->actionExit); + trayIcon->setToolTip(tr("RepRaptor running in the background")); + trayIcon->setContextMenu(trayIconMenu); recentMenu->setTitle("Recent files"); ui->menuFile->insertMenu(ui->actionSettings, recentMenu); ui->menuFile->insertSeparator(ui->actionSettings); @@ -79,6 +86,7 @@ MainWindow::MainWindow(QWidget *parent) : statusTimer->setInterval(settings.value("core/statusinterval", 3000).toInt()); feedrate = settings.value("feedrate", 1500).toInt(); extruderFeedrate = settings.value("extruderfeedrate", 200).toInt(); + trayIconEnabled = settings.value("core/trayiconenabled", 1).toBool(); int size = settings.beginReadArray("user/recentfiles"); for(int i = 0; i < size; ++i) { @@ -107,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent) : //Internal signal-slots connect(statusTimer, &QTimer::timeout, this, &MainWindow::checkStatus); connect(progressSDTimer, &QTimer::timeout, this, &MainWindow::checkSDStatus); + connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconClicked); //Parser thread signal-slots and init parserWorker->moveToThread(parserThread); @@ -157,6 +166,10 @@ MainWindow::MainWindow(QWidget *parent) : //Update recent files list updateRecent(); + + //Update icon + if(trayIconEnabled) trayIcon->show(); + else trayIcon->hide(); } MainWindow::~MainWindow() @@ -189,6 +202,7 @@ MainWindow::~MainWindow() void MainWindow::open() { + if(this->isHidden()) this->show(); sdprinting = false; QString filename; QDir home; @@ -851,6 +865,8 @@ void MainWindow::receivedSDDone() { sdprinting=false; ui->progressBar->setValue(0); + if(trayIconEnabled && (this->isMinimized() || this->isHidden())) + trayIcon->showMessage(tr("Done"), tr("Finished printing")); ui->filename->setText(""); ui->fileBox->setDisabled(true); } @@ -862,6 +878,8 @@ void MainWindow::updateFileProgress(FileProgress p) { ui->sendBtn->setText(tr("Send")); ui->pauseBtn->setDisabled(true); + if(trayIconEnabled && (this->isMinimized() || this->isHidden())) + trayIcon->showMessage(tr("Done"), tr("Finished printing")); sending = false; paused = false; emit pause(paused); @@ -981,6 +999,16 @@ void MainWindow::closeEvent(QCloseEvent *event) else event->accept(); } +void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason) +{ + if(trayIconEnabled && reason == QSystemTrayIcon::Trigger) + { + if(this->isHidden()) this->show(); + else this->hide(); + } + else return; +} + void MainWindow::recentClicked() { //Actually a dirty hack, but it is fast and simple diff --git a/mainwindow.h b/mainwindow.h index ebc3df5..e3c76c8 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,9 @@ protected: QQueue userCommands; QTimer *progressSDTimer; QTimer *statusTimer; + QSystemTrayIcon *trayIcon; QMenu *recentMenu; + QMenu *trayIconMenu; QElapsedTimer *sinceLastTemp; QElapsedTimer *sinceLastSDStatus; QSettings settings; @@ -73,6 +76,7 @@ private: bool sdprinting; bool echo; bool chekingSDStatus; + bool trayIconEnabled; int firmware; int feedrate; int extruderFeedrate; @@ -103,6 +107,7 @@ private slots: void recentClicked(); void updateFileProgress(FileProgress); void baudrateSetFailed(int b); + void trayIconClicked(QSystemTrayIcon::ActivationReason reason); void xplus(); void yplus(); diff --git a/settingswindow.cpp b/settingswindow.cpp index 1a39335..2813ee6 100644 --- a/settingswindow.cpp +++ b/settingswindow.cpp @@ -14,7 +14,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : ui->flowcontrolbox->setCurrentIndex(settings.value("core/flowcontrol", 0).toInt()); ui->senderbox->setValue(settings.value("core/senderinterval", 2).toInt()); - ui->echobox->setChecked(settings.value("core/echo", 0).toBool()); + ui->traybox->setChecked(settings.value("core/trayiconenabled", 1).toBool()); ui->statusbox->setValue(settings.value("core/statusinterval", 2000).toInt()); ui->bedxbox->setValue(settings.value("printer/bedx", 200).toInt()); ui->bedybox->setValue(settings.value("printer/bedy", 200).toInt()); @@ -47,13 +47,13 @@ SettingsWindow::~SettingsWindow() void SettingsWindow::on_buttonBox_accepted() { settings.setValue("core/flowcontrol", ui->flowcontrolbox->currentIndex()); + settings.setValue("core/trayiconenabled", ui->traybox->isChecked()); settings.setValue("core/senderinterval", ui->senderbox->value()); settings.setValue("core/statusinterval", ui->statusbox->value()); settings.setValue("printer/bedy", ui->bedybox->value()); settings.setValue("printer/bedx", ui->bedxbox->value()); settings.setValue("printer/feedrate", ui->feedrateBox->value()); settings.setValue("printer/extruderfeedrate", ui->extruderFeedrateBox->value()); - settings.setValue("core/echo", ui->echobox->isChecked()); settings.setValue("core/lockcontrols", ui->lockbox->isChecked()); settings.setValue("core/checksums", ui->checksumbox->isChecked()); settings.setValue("core/checksdstatus", ui->sdbox->isChecked()); diff --git a/settingswindow.ui b/settingswindow.ui index 8a0060d..f155e87 100644 --- a/settingswindow.ui +++ b/settingswindow.ui @@ -24,16 +24,38 @@ Internal - - - - false - - - Show every sent command in console - + + - Echo commands + Sender + + + + + + + + + + + + + + Flow control + + + + + + + DTR + + + + + + + ms @@ -62,20 +84,6 @@ - - - - ms - - - - - - - Status - - - @@ -99,28 +107,7 @@ - - - - Lock controls when printing - - - - - - - Sender - - - - - - - Check SD printing status - - - - + true @@ -152,24 +139,37 @@ - - + + - DTR + Status - - + + - Flow control + Check SD printing status - - + + + + Lock controls when printing + + + + + + + true + - + Show tray icon + + + Tray icon