Skip to content

Commit

Permalink
added tooltips & auto start at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizar06001 committed Mar 10, 2024
1 parent 0af6ad2 commit 0338061
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
40 changes: 39 additions & 1 deletion Qt/AidaToSerial/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QCloseEvent>
#include <QSettings>
#include <QFile>
#include <QTimer>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<std::string, std::string> lst = scanSerialPorts();
ui->boxPorts->clear();
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions Qt/AidaToSerial/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private slots:
void onStopButtonClicked();
void onUpdateList();
void onAccept();
void onStartupCheck();

protected:
void changeEvent(QEvent *event) override;
Expand All @@ -49,6 +50,7 @@ private slots:
void createNewWorker();
void saveSettings();
void loadSettings();
bool isLaunchedAtStartup();

Worker *worker;
std::map<std::string, QLabel*> sensorLabels;
Expand Down
42 changes: 41 additions & 1 deletion Qt/AidaToSerial/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>The frequency at which data is sent to seral</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
Expand Down Expand Up @@ -776,6 +779,9 @@
<height>31</height>
</rect>
</property>
<property name="toolTip">
<string>Scan for COM ports</string>
</property>
<property name="text">
<string>Scan</string>
</property>
Expand Down Expand Up @@ -1084,6 +1090,9 @@
<bold>false</bold>
</font>
</property>
<property name="toolTip">
<string>Update sensor list</string>
</property>
<property name="text">
<string>Check New Sensors</string>
</property>
Expand All @@ -1103,6 +1112,9 @@
<bold>false</bold>
</font>
</property>
<property name="toolTip">
<string>Confirm the changes made</string>
</property>
<property name="text">
<string>Accept Changes</string>
</property>
Expand All @@ -1116,6 +1128,9 @@
<height>22</height>
</rect>
</property>
<property name="toolTip">
<string>Show data read from Aida64</string>
</property>
<property name="text">
<string>Live Input Data Visualization</string>
</property>
Expand Down Expand Up @@ -1181,19 +1196,44 @@
</property>
<property name="geometry">
<rect>
<x>510</x>
<x>400</x>
<y>530</y>
<width>121</width>
<height>22</height>
</rect>
</property>
<property name="toolTip">
<string>Auto connect when starting the app</string>
</property>
<property name="text">
<string>Connect at launch</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox" name="boxStartup">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>540</x>
<y>530</y>
<width>101</width>
<height>22</height>
</rect>
</property>
<property name="toolTip">
<string>Run when Windows starts</string>
</property>
<property name="text">
<string>Run at Startup</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down

0 comments on commit 0338061

Please sign in to comment.