From 42a17726d9fb6b69bad9e92b0e871818c561ea4d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 7 Jan 2025 02:07:55 -0500 Subject: [PATCH] feat: Allow users to pick mono color (based on isDarkMode) or colorful icon --- src/apps/deskflow-gui/MainWindow.cpp | 19 +++++---- .../deskflow-gui/dialogs/SettingsDialog.cpp | 12 ++++++ .../deskflow-gui/dialogs/SettingsDialog.ui | 39 ++++++++++++++++++- src/lib/gui/config/AppConfig.cpp | 12 ++++++ src/lib/gui/config/AppConfig.h | 4 ++ 5 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index e7f16e1f1..d95e5c701 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -32,6 +32,7 @@ #include "gui/diagnostic.h" #include "gui/messages.h" #include "gui/string_utils.h" +#include "gui/style_utils.h" #include "gui/styles.h" #include "gui/tls/TlsFingerprint.h" #include "platform/wayland.h" @@ -66,12 +67,9 @@ using CoreMode = CoreProcess::Mode; using CoreConnectionState = CoreProcess::ConnectionState; using CoreProcessState = CoreProcess::ProcessState; -const auto kIconFile = ":/icons/128x128/tray.png"; - -#ifdef Q_OS_MAC +const auto kColorfulIconFile = ":/icons/128x128/tray.png"; const auto kLightIconFile = ":/icons/128x128/tray-light.png"; const auto kDarkIconFile = ":/icons/128x128/tray-dark.png"; -#endif // Q_OS_MAC MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) : ui{std::make_unique()}, @@ -673,6 +671,7 @@ void MainWindow::applyConfig() ui->lineHostname->setText(m_AppConfig.serverHostname()); ui->lineClientIp->setText(m_ServerConfig.getClientAddress()); updateLocalFingerprint(); + setIcon(); } void MainWindow::saveSettings() @@ -687,12 +686,16 @@ void MainWindow::saveSettings() void MainWindow::setIcon() { - QIcon icon; #ifdef Q_OS_MAC - icon.addFile(kDarkIconFile); - icon.setIsMask(true); + QIcon icon; + if (appConfig().colorfulTrayIcon()) + icon.addFile(kColorfulIconFile); + else { + icon.addFile(kDarkIconFile); + icon.setIsMask(true); + } #else - QIcon icon(kIconFile); + QIcon icon(appConfig().colorfulTrayIcon() ? kColorfulIconFile : isDarkMode() ? kDarkIconFile : kLightIconFile); #endif m_trayIcon->setIcon(icon); } diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp index 021008663..b285be416 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp @@ -21,6 +21,7 @@ #include "gui/core/CoreProcess.h" #include "gui/messages.h" +#include "gui/style_utils.h" #include "gui/tls/TlsCertificate.h" #include "gui/tls/TlsUtility.h" #include "gui/validators/ScreenNameValidator.h" @@ -197,6 +198,7 @@ void SettingsDialog::accept() m_appConfig.setEnableService(ui->m_pCheckBoxServiceEnabled->isChecked()); m_appConfig.setCloseToTray(ui->m_pCheckBoxCloseToTray->isChecked()); m_appConfig.setInvertConnection(ui->m_pInvertConnection->isChecked()); + m_appConfig.setColorfulTrayIcon(ui->rb_icon_colorful->isChecked()); QDialog::accept(); } @@ -242,6 +244,16 @@ void SettingsDialog::loadFromConfig() ui->m_pInvertConnection->setChecked(m_appConfig.invertConnection()); + if (m_appConfig.colorfulTrayIcon()) + ui->rb_icon_colorful->setChecked(true); + else + ui->rb_icon_mono->setChecked(true); + + ui->rb_icon_mono->setIcon( + isDarkMode() ? QIcon(QStringLiteral(":/icons/128x128/tray-dark.png")) + : QIcon(QStringLiteral(":/icons/128x128/tray-light.png")) + ); + updateTlsControls(); } diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.ui b/src/apps/deskflow-gui/dialogs/SettingsDialog.ui index c39ac4930..92694c4a7 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.ui +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 550 - 625 + 652 @@ -160,6 +160,39 @@ + + + + + + Tray icon style + + + + + + + Colorful + + + + :/icons/128x128/tray.png:/icons/128x128/tray.png + + + + + + + Monocolor + + + + :/icons/128x128/tray-dark.png:/icons/128x128/tray-dark.png + + + + + @@ -761,7 +794,9 @@ m_pRadioSystemScope m_pComboElevate - + + + m_pButtonBox diff --git a/src/lib/gui/config/AppConfig.cpp b/src/lib/gui/config/AppConfig.cpp index dc43b063d..94f0b1d90 100644 --- a/src/lib/gui/config/AppConfig.cpp +++ b/src/lib/gui/config/AppConfig.cpp @@ -592,6 +592,11 @@ bool AppConfig::logExpanded() const return m_logExpanded; } +bool AppConfig::colorfulTrayIcon() const +{ + return m_colorfulTrayIcon; +} + /////////////////////////////////////////////////////////////////////////////// // End getters /////////////////////////////////////////////////////////////////////////////// @@ -772,6 +777,13 @@ void AppConfig::setLogExpanded(bool expanded) m_logExpanded = expanded; } +void AppConfig::setColorfulTrayIcon(bool colorful) +{ + if (colorful == m_colorfulTrayIcon) + return; + m_colorfulTrayIcon = colorful; +} + /////////////////////////////////////////////////////////////////////////////// // End setters /////////////////////////////////////////////////////////////////////////////// diff --git a/src/lib/gui/config/AppConfig.h b/src/lib/gui/config/AppConfig.h index 8d37b3529..61c8c7d1d 100644 --- a/src/lib/gui/config/AppConfig.h +++ b/src/lib/gui/config/AppConfig.h @@ -110,6 +110,7 @@ private: kShowCloseReminder = 42, kEnableUpdateCheck = 43, kLogExpanded = 44, + kColorIcon = 45 }; public: @@ -185,6 +186,7 @@ public: bool showCloseReminder() const; std::optional enableUpdateCheck() const; bool logExpanded() const; + bool colorfulTrayIcon() const; // // Setters (overrides) @@ -226,6 +228,7 @@ public: void setShowCloseReminder(bool show); void setEnableUpdateCheck(bool value); void setLogExpanded(bool expanded); + void setColorfulTrayIcon(bool color); /// @brief Sets the user preference to load from SystemScope. /// @param [in] value @@ -332,6 +335,7 @@ private: bool m_ShowCloseReminder = true; std::optional m_EnableUpdateCheck; bool m_logExpanded = true; + bool m_colorfulTrayIcon = false; /** * @brief Flag is set when any TLS is setting is changed, and is reset