From 03380615e62b3069e20215d5ce39de1c10385698 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 10 Mar 2024 17:39:35 +0100 Subject: [PATCH] added tooltips & auto start at boot --- Qt/AidaToSerial/mainwindow.cpp | 40 +++++++++++++++++++++++++++++++- Qt/AidaToSerial/mainwindow.h | 2 ++ Qt/AidaToSerial/mainwindow.ui | 42 +++++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/Qt/AidaToSerial/mainwindow.cpp b/Qt/AidaToSerial/mainwindow.cpp index 082fce8..ae621fb 100644 --- a/Qt/AidaToSerial/mainwindow.cpp +++ b/Qt/AidaToSerial/mainwindow.cpp @@ -18,6 +18,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -46,6 +47,7 @@ MainWindow::MainWindow(QWidget *parent) trayMenu->addAction(quitAction); trayIcon->setContextMenu(trayMenu); connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated); + trayIcon->setToolTip("AidaToSerial"); trayIcon->show(); createNewWorker(); @@ -55,12 +57,23 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->btnStop, &QPushButton::clicked, this, &MainWindow::onStopButtonClicked); connect(ui->btnUpdateList, &QPushButton::clicked, this, &MainWindow::onUpdateList); connect(ui->btnAccept, &QPushButton::clicked, this, &MainWindow::onAccept); + connect(ui->boxStartup, &QCheckBox::clicked, this, &MainWindow::onStartupCheck); setPortsList(); loadSettings(); onUpdateList(); + if (ui->boxAutoconnect->isChecked()) onStartButtonClicked(); + + // Minimize at startup + if (isLaunchedAtStartup()) { + if (ui->boxTray->isChecked()){ + QTimer::singleShot(100, this, &MainWindow::hide); + } else { + showMinimized(); + } + } } MainWindow::~MainWindow() @@ -72,6 +85,16 @@ MainWindow::~MainWindow() } } +bool MainWindow::isLaunchedAtStartup(){ + QStringList args = QCoreApplication::arguments(); + for (const QString &arg : args) { + if (arg == "-startup") { + return true; + } + } + return false; +} + void MainWindow::showNormal(){ QMainWindow::showNormal(); } @@ -113,6 +136,19 @@ void MainWindow::changeEvent(QEvent *event) QMainWindow::changeEvent(event); } +void MainWindow::onStartupCheck(){ + QString appName = "AidaToSerial"; + if (ui->boxStartup->isChecked()){ + QString appPath = QCoreApplication::applicationFilePath(); + appPath.replace('/', '\\'); + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + settings.setValue(appName, "\"" + appPath + "\""); + } else { + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + settings.remove(appName); + } +} + void MainWindow::setPortsList() { std::map lst = scanSerialPorts(); ui->boxPorts->clear(); @@ -368,6 +404,7 @@ void MainWindow::saveSettings(){ settings.setValue("RefreshRate", ui->boxUpdate->value()); settings.setValue("MinimizeToTray", ui->boxTray->isChecked()); settings.setValue("Autoconnect", ui->boxAutoconnect->isChecked()); + settings.setValue("AutoRun", ui->boxStartup->isChecked()); settings.setValue("SensorCount", sensorsSerialNames.size()); int i = 0; @@ -391,7 +428,8 @@ void MainWindow::loadSettings(){ ui->boxPorts->setCurrentText(settings.value("SerialPort").toString()); ui->boxUpdate->setValue(settings.value("RefreshRate", 500).toInt()); ui->boxTray->setChecked(settings.value("MinimizeToTray", 1).toBool()); - ui->boxAutoconnect->setChecked(settings.value("Autoconnect", 1).toBool()); + ui->boxAutoconnect->setChecked(settings.value("Autoconnect", 0).toBool()); + ui->boxStartup->setChecked(settings.value("AutoRun", 0).toBool()); int sensorCount = settings.value("SensorCount", 0).toInt(); diff --git a/Qt/AidaToSerial/mainwindow.h b/Qt/AidaToSerial/mainwindow.h index a471fb6..73fcd85 100644 --- a/Qt/AidaToSerial/mainwindow.h +++ b/Qt/AidaToSerial/mainwindow.h @@ -34,6 +34,7 @@ private slots: void onStopButtonClicked(); void onUpdateList(); void onAccept(); + void onStartupCheck(); protected: void changeEvent(QEvent *event) override; @@ -49,6 +50,7 @@ private slots: void createNewWorker(); void saveSettings(); void loadSettings(); + bool isLaunchedAtStartup(); Worker *worker; std::map sensorLabels; diff --git a/Qt/AidaToSerial/mainwindow.ui b/Qt/AidaToSerial/mainwindow.ui index 7e67024..3e8fca8 100644 --- a/Qt/AidaToSerial/mainwindow.ui +++ b/Qt/AidaToSerial/mainwindow.ui @@ -676,6 +676,9 @@ true + + The frequency at which data is sent to seral + Qt::AlignCenter @@ -776,6 +779,9 @@ 31 + + Scan for COM ports + Scan @@ -1084,6 +1090,9 @@ false + + Update sensor list + Check New Sensors @@ -1103,6 +1112,9 @@ false + + Confirm the changes made + Accept Changes @@ -1116,6 +1128,9 @@ 22 + + Show data read from Aida64 + Live Input Data Visualization @@ -1181,12 +1196,15 @@ - 510 + 400 530 121 22 + + Auto connect when starting the app + Connect at launch @@ -1194,6 +1212,28 @@ false + + + true + + + + 540 + 530 + 101 + 22 + + + + Run when Windows starts + + + Run at Startup + + + false + +