Added tray icon
This commit is contained in:
parent
7e18e2fd2f
commit
1294d65618
@ -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
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFileDialog>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QtSerialPort/QtSerialPort>
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
@ -48,7 +49,9 @@ protected:
|
||||
QQueue <QString> 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();
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -24,16 +24,38 @@
|
||||
<string>Internal</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="echobox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Show every sent command in console</string>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Echo commands</string>
|
||||
<string>Sender</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="flowcontrolbox">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Flow control</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="dtrbox">
|
||||
<property name="text">
|
||||
<string>DTR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -62,20 +84,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="statusbox">
|
||||
<property name="toolTip">
|
||||
@ -99,28 +107,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="lockbox">
|
||||
<property name="text">
|
||||
<string>Lock controls when printing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Sender</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="sdbox">
|
||||
<property name="text">
|
||||
<string>Check SD printing status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="checksumbox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
@ -152,24 +139,37 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="dtrbox">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>DTR</string>
|
||||
<string>Status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<item row="8" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="sdbox">
|
||||
<property name="text">
|
||||
<string>Flow control</string>
|
||||
<string>Check SD printing status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="flowcontrolbox">
|
||||
<item row="7" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="lockbox">
|
||||
<property name="text">
|
||||
<string>Lock controls when printing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="traybox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
<string>Show tray icon</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Tray icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user