Skip to content

Commit

Permalink
Merge pull request #5 from nicola02nb/main
Browse files Browse the repository at this point in the history
Merging latest modifications
  • Loading branch information
nicola02nb authored Sep 3, 2024
2 parents 3eeecfc + caab662 commit 1b23519
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 57 deletions.
11 changes: 1 addition & 10 deletions src/UI/dialoginfo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="../Resources/icons.qrc">
<normaloff>:/icons/headphones-inv.png</normaloff>:/icons/headphones-inv.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
Expand Down Expand Up @@ -103,9 +96,7 @@
</item>
</layout>
</widget>
<resources>
<include location="../Resources/icons.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
Expand Down
12 changes: 3 additions & 9 deletions src/UI/loaddevicewindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>112</height>
<width>184</width>
<height>114</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -19,10 +19,6 @@
<property name="windowTitle">
<string>Select device to load</string>
</property>
<property name="windowIcon">
<iconset resource="../Resources/icons.qrc">
<normaloff>:/icons/headphones-inv.png</normaloff>:/icons/headphones-inv.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
Expand Down Expand Up @@ -71,9 +67,7 @@
</item>
</layout>
</widget>
<resources>
<include location="../Resources/icons.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
Expand Down
42 changes: 22 additions & 20 deletions src/UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "dialoginfo.h"
#include "settingswindow.h"
#include "loaddevicewindow.h"
#include <QScreen>
#include <QStyleHints>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Expand All @@ -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");

Expand Down Expand Up @@ -109,7 +102,6 @@ void MainWindow::changeEvent(QEvent* e)
{
switch (e->type()){
case QEvent::PaletteChange:
darkMode = isOsDarkMode();
updateIcons();
break;
case QEvent::WindowStateChange:
Expand All @@ -135,6 +127,7 @@ void MainWindow::toggleWindow(){
if(this->isHidden()){
this->show();
if(firstShow){
this->moveToBottomRight();
checkForUpdates(firstShow);
firstShow = false;
}
Expand All @@ -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");
}
Expand All @@ -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));
}

Expand Down Expand Up @@ -483,7 +485,7 @@ void MainWindow::setBatteryStatus()
trayIconPath = ":/icons/headphones-inv.png";
}

if(!darkMode){
if(!isAppDarkMode()){
trayIconPath.replace("-inv", "");
}
tray->setIcon(QIcon(trayIconPath));
Expand Down
4 changes: 2 additions & 2 deletions src/UI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class MainWindow : public QMainWindow
int n_connected = 0, n_saved = 0;

Settings settings;
bool darkMode;
QString trayIconPath;

QMenu *menu;
Expand All @@ -57,8 +56,9 @@ private slots:
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);

void toggleWindow();
void moveToBottomRight();

bool isOsDarkMode();
bool isAppDarkMode();
void updateIcons();

void disableFrames();
Expand Down
4 changes: 2 additions & 2 deletions src/UI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</font>
</property>
<property name="windowTitle">
<string>HeadsetControl - GUI</string>
<string>HeadsetControl-GUI</string>
</property>
<property name="windowIcon">
<iconset resource="../Resources/icons.qrc">
Expand Down Expand Up @@ -1659,7 +1659,7 @@
<x>0</x>
<y>0</y>
<width>488</width>
<height>26</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down
17 changes: 4 additions & 13 deletions src/UI/settingswindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
<x>0</x>
<y>0</y>
<width>352</width>
<height>206</height>
<height>209</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<property name="windowIcon">
<iconset resource="../Resources/icons.qrc">
<normaloff>:/icons/headphones-inv.png</normaloff>:/icons/headphones-inv.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame_3">
Expand All @@ -29,9 +25,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">text-align: left;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand All @@ -51,8 +44,8 @@
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="styleSheet">
<string notr="true">text-align: end</string>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string/>
Expand Down Expand Up @@ -177,9 +170,7 @@
</item>
</layout>
</widget>
<resources>
<include location="../Resources/icons.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QApplication>
#include <QTranslator>

const QString GUI_VERSION = "0.15.0";
const QString GUI_VERSION = "0.15.1";

int main(int argc, char *argv[])
{
Expand Down

0 comments on commit 1b23519

Please sign in to comment.