From 0a7849bf4647c9bc3f7503de63b4083681535ab1 Mon Sep 17 00:00:00 2001 From: nicola02nb <61830443+nicola02nb@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:58:15 +0200 Subject: [PATCH 1/2] Optimized darkmode code and fixed window position --- src/UI/dialoginfo.ui | 11 +--------- src/UI/loaddevicewindow.ui | 12 +++-------- src/UI/mainwindow.cpp | 42 ++++++++++++++++++++------------------ src/UI/mainwindow.h | 4 ++-- src/UI/mainwindow.ui | 4 ++-- src/UI/settingswindow.ui | 17 ++++----------- 6 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/UI/dialoginfo.ui b/src/UI/dialoginfo.ui index c3db3f9..2a7ac48 100644 --- a/src/UI/dialoginfo.ui +++ b/src/UI/dialoginfo.ui @@ -16,13 +16,6 @@ 0 - - Dialog - - - - :/icons/headphones-inv.png:/icons/headphones-inv.png - @@ -103,9 +96,7 @@ - - - + buttonBox diff --git a/src/UI/loaddevicewindow.ui b/src/UI/loaddevicewindow.ui index cd34f27..983f92a 100644 --- a/src/UI/loaddevicewindow.ui +++ b/src/UI/loaddevicewindow.ui @@ -6,8 +6,8 @@ 0 0 - 174 - 112 + 184 + 114 @@ -19,10 +19,6 @@ Select device to load - - - :/icons/headphones-inv.png:/icons/headphones-inv.png - @@ -71,9 +67,7 @@ - - - + buttonBox diff --git a/src/UI/mainwindow.cpp b/src/UI/mainwindow.cpp index 2234ffb..02a441a 100644 --- a/src/UI/mainwindow.cpp +++ b/src/UI/mainwindow.cpp @@ -4,6 +4,8 @@ #include "dialoginfo.h" #include "settingswindow.h" #include "loaddevicewindow.h" +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -13,18 +15,9 @@ MainWindow::MainWindow(QWidget *parent) this->bindEvents(); settings=loadSettingsFromFile(PROGRAM_SETTINGS_FILENAME); - darkMode = isOsDarkMode(); - if(darkMode){ - this->setWindowIcon(QIcon(":/icons/headphones-inv.png")); - trayIconPath = ":/icons/headphones-inv.png"; - } - else{ - this->setWindowIcon(QIcon(":/icons/headphones.png")); - trayIconPath = ":/icons/headphones.png"; - } + updateIcons(); - tray->setIcon(QIcon(trayIconPath)); tray->show(); tray->setToolTip("HeadsetControl"); @@ -109,7 +102,6 @@ void MainWindow::changeEvent(QEvent* e) { switch (e->type()){ case QEvent::PaletteChange: - darkMode = isOsDarkMode(); updateIcons(); break; case QEvent::WindowStateChange: @@ -135,6 +127,7 @@ void MainWindow::toggleWindow(){ if(this->isHidden()){ this->show(); if(firstShow){ + this->moveToBottomRight(); checkForUpdates(firstShow); firstShow = false; } @@ -143,19 +136,27 @@ void MainWindow::toggleWindow(){ } } -bool MainWindow::isOsDarkMode(){ - // Check if the application is using a dark palette - QPalette palette = QApplication::palette(); - QColor textColor = palette.color(QPalette::WindowText); - QColor backgroundColor = palette.color(QPalette::Window); +void MainWindow::moveToBottomRight(){ + QScreen *screen = QGuiApplication::primaryScreen(); + QRect screenGeometry = screen->availableGeometry(); + + int x = screenGeometry.width() - width(); + int y = screenGeometry.height() - height(); - // If text is brighter than background, it's likely a dark theme - return textColor.lightness() > backgroundColor.lightness(); + move(x, y); +} + +bool MainWindow::isAppDarkMode(){ + // Check if the application is using a dark palette + Qt::ColorScheme scheme = qApp->styleHints()->colorScheme(); + if(scheme == Qt::ColorScheme::Dark) + return true; + return false; } void MainWindow::updateIcons(){ QString inv = ""; - if(darkMode){ + if(isAppDarkMode()){ inv = "-inv"; trayIconPath.replace(".png", "-inv.png"); } @@ -164,6 +165,7 @@ void MainWindow::updateIcons(){ } this->setWindowIcon(QIcon(":/icons/headphones"+inv+".png")); + qApp->setWindowIcon(QIcon(":/icons/headphones"+inv+".png")); tray->setIcon(QIcon(trayIconPath)); } @@ -483,7 +485,7 @@ void MainWindow::setBatteryStatus() trayIconPath = ":/icons/headphones-inv.png"; } - if(!darkMode){ + if(!isAppDarkMode()){ trayIconPath.replace("-inv", ""); } tray->setIcon(QIcon(trayIconPath)); diff --git a/src/UI/mainwindow.h b/src/UI/mainwindow.h index 323bfc5..e333803 100644 --- a/src/UI/mainwindow.h +++ b/src/UI/mainwindow.h @@ -37,7 +37,6 @@ class MainWindow : public QMainWindow int n_connected = 0, n_saved = 0; Settings settings; - bool darkMode; QString trayIconPath; QMenu *menu; @@ -57,8 +56,9 @@ private slots: void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void toggleWindow(); + void moveToBottomRight(); - bool isOsDarkMode(); + bool isAppDarkMode(); void updateIcons(); void disableFrames(); diff --git a/src/UI/mainwindow.ui b/src/UI/mainwindow.ui index f2731d4..b64bd59 100644 --- a/src/UI/mainwindow.ui +++ b/src/UI/mainwindow.ui @@ -22,7 +22,7 @@ - HeadsetControl - GUI + HeadsetControl-GUI @@ -1659,7 +1659,7 @@ 0 0 488 - 26 + 25 diff --git a/src/UI/settingswindow.ui b/src/UI/settingswindow.ui index 20572e6..c36affa 100644 --- a/src/UI/settingswindow.ui +++ b/src/UI/settingswindow.ui @@ -7,16 +7,12 @@ 0 0 352 - 206 + 209 Settings - - - :/icons/headphones-inv.png:/icons/headphones-inv.png - @@ -29,9 +25,6 @@ 0 - - text-align: left; - QFrame::StyledPanel @@ -51,8 +44,8 @@ Qt::RightToLeft - - text-align: end + + false @@ -177,9 +170,7 @@ - - - + buttonBox From caab662c2d36f182fdcd80d72db25dd357f8e03d Mon Sep 17 00:00:00 2001 From: nicola02nb <61830443+nicola02nb@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:00:16 +0200 Subject: [PATCH 2/2] Updated version inside main.cpp --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 21b23ec..03076e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include #include -const QString GUI_VERSION = "0.15.0"; +const QString GUI_VERSION = "0.15.1"; int main(int argc, char *argv[]) {