From 0731d5f685e2c88ac3b79c1b681a61ee6f2aa6b6 Mon Sep 17 00:00:00 2001 From: Neil Horne <15316949+elecpower@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:19:18 +1100 Subject: [PATCH] feat(cpn): customisable simulator button clicked colour (#7178) --- companion/src/apppreferencesdialog.cpp | 30 + companion/src/apppreferencesdialog.h | 2 + companion/src/apppreferencesdialog.ui | 550 ++++++++++-------- .../src/simulation/widgets/buttonswidget.h | 21 +- companion/src/storage/appdata.h | 2 + 5 files changed, 351 insertions(+), 254 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 60c133305..828f753ac 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -182,6 +182,8 @@ void AppPreferencesDialog::accept() profile.splashFile(ui->SplashFileName->text()); profile.runSDSync(ui->chkPromptSDSync->isChecked()); profile.radioSimCaseColor(ui->lblRadioColorSample->palette().button().color()); + profile.simBtnClickedUseOSTheme(ui->chkSimBtnClickedUseOSTheme->isChecked()); + profile.simBtnClickedColor(ui->lblSimBtnClickedColorSample->palette().button().color()); profile.useSavedSettings(ui->chkUseSavedSettingsProfile->isChecked()); // The profile name may NEVER be empty @@ -380,6 +382,16 @@ void AppPreferencesDialog::initSettings() ui->lblGeneralSettings->setText(hwSettings); ui->chkPromptSDSync->setChecked(profile.runSDSync()); ui->lblRadioColorSample->setPalette(QPalette(profile.radioSimCaseColor())); + ui->chkSimBtnClickedUseOSTheme->setChecked(profile.simBtnClickedUseOSTheme()); + ui->lblSimBtnClickedColorSample->setPalette(QPalette(profile.simBtnClickedColor())); + + if (ui->chkSimBtnClickedUseOSTheme->isChecked()) { + ui->lblSimBtnClickedColorSample->setVisible(false); + ui->btnSimBtnClickedColor->setEnabled(false); + } else { + ui->lblSimBtnClickedColorSample->setVisible(true); + ui->btnSimBtnClickedColor->setEnabled(true); + } QString currType = QStringList(profile.fwType().split('-').mid(0, 2)).join('-'); foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) { @@ -907,3 +919,21 @@ void AppPreferencesDialog::onProfileBackupPathEditingFinished() ui->profileBackupEnable->setEnabled(false); } } +void AppPreferencesDialog::on_chkSimBtnClickedUseOSTheme_stateChanged() +{ + if (ui->chkSimBtnClickedUseOSTheme->isChecked()) { + ui->lblSimBtnClickedColorSample->setVisible(false); + ui->btnSimBtnClickedColor->setEnabled(false); + } else { + ui->lblSimBtnClickedColorSample->setVisible(true); + ui->btnSimBtnClickedColor->setEnabled(true); + } +} + +void AppPreferencesDialog::on_btnSimBtnClickedColor_clicked() +{ + QColorDialog *dlg = new QColorDialog(this); + QColor color = dlg->getColor(g.currentProfile().simBtnClickedColor(), this); + ui->lblSimBtnClickedColorSample->setPalette(QPalette(color)); + ui->lblSimBtnClickedColorSample->repaint(); +} diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h index 51739af7b..f6c8dbf85 100644 --- a/companion/src/apppreferencesdialog.h +++ b/companion/src/apppreferencesdialog.h @@ -80,6 +80,8 @@ class AppPreferencesDialog : public QDialog #endif void on_btnRadioColor_clicked(); + void on_chkSimBtnClickedUseOSTheme_stateChanged(); + void on_btnSimBtnClickedColor_clicked(); void onBackupPathEditingFinished(); void onProfileBackupPathEditingFinished(); diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index a9adc4d9f..44b50856a 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -26,6 +26,16 @@ true + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + @@ -35,48 +45,26 @@ - 1 + 0 Radio Profile - - + + + + true + 0 0 - - Qt::Orientation::Horizontal - - - - - - - - 0 - 0 - - - - Qt::Orientation::Horizontal - - - - - - - - true - - - Updates + Radio Settings Label @@ -134,8 +122,8 @@ Mode 4: - - + + 0 @@ -143,20 +131,7 @@ Mode 4: - Default Stick Mode - - - - - - - - 0 - 0 - - - - SD Structure path + Language Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter @@ -179,53 +154,7 @@ Mode 4: - - - - Default Int. Module - - - - - - - Qt::Orientation::Vertical - - - - 20 - 5 - - - - - - - - If set it will override the application general setting - - - false - - - true - - - - - - - - 0 - 0 - - - - Prompt to write firmware to radio after update - - - - + @@ -241,92 +170,37 @@ Mode 4: - - - - - 0 - 0 - - - - Options - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - - - - - - - Select Colour - - - - - + + 0 0 - - Language - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - true - - - - - - - - - - - - - true - - - - 0 - 0 - - - - Radio Settings Label - - - - - - - - - - - 0 - 0 - - true - Profile Name + Radio Type + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + + + 0 + 0 + + + + Prompt to write firmware to radio after update @@ -466,24 +340,24 @@ Mode 4: - - - - true - - - - - + + - Simulator Case Colour + Select Folder - - + + + + External Module + + + + + - + 0 0 @@ -494,10 +368,99 @@ Mode 4: - Radio Type + Profile Name + + + + + + + The profile specific folder, if set, will override general Backup folder + + + Select Folder + + + + + + + + 0 + 0 + + + + Options - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + + + + + Qt::Orientation::Vertical + + + + 20 + 5 + + + + + + + + + 0 + 0 + + + + Radio Settings + + + + + + + Simulator Button Clicked Colour + + + + + + + + 0 + 0 + + + + Qt::Orientation::Horizontal + + + + + + + If set it will override the application general setting + + + false + + + true + + + + + + + Prompt to run SD Sync after update @@ -531,22 +494,25 @@ Mode 4: - - + + + + + - + 0 0 - - Qt::Orientation::Horizontal + + SD Structure path + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - @@ -663,6 +629,25 @@ Mode 4: + + + + + + + true + + + + + + false + + + true + + + @@ -681,24 +666,33 @@ Mode 4: - - - - true + + + + + 0 + 0 + - - - - - false - - - true + + Qt::Orientation::Horizontal - - + + + + + true + + + + Updates + + + + + 0 @@ -706,21 +700,7 @@ Mode 4: - Radio Settings - - - - - - - Select Folder - - - - - - - Prompt to run SD Sync after update + Default Stick Mode @@ -740,20 +720,40 @@ Mode 4: - - + + - External Module + Default Int. Module - - - - The profile specific folder, if set, will override general Backup folder + + + + + + + + 0 + 0 + + + Qt::Orientation::Horizontal + + + + + - Select Folder + Simulator Radio Case Colour + + + + + + + Use settings backup for new models and settings files @@ -767,10 +767,92 @@ Mode 4: - - + + + + true + + + + + + + false + - Use settings backup for new models and settings files + Select Colour + + + + + + + + + Operating System theme + + + true + + + + + + + true + + + QFrame::Shape::Box + + + + + + + + + + + + + + + + + + + + + true + + + QFrame::Shape::Box + + + + + + + + + + + + + + + + + + + + + + + + + + Select Colour @@ -1717,16 +1799,6 @@ Mode 4: - - - - Qt::Orientation::Horizontal - - - QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - - - diff --git a/companion/src/simulation/widgets/buttonswidget.h b/companion/src/simulation/widgets/buttonswidget.h index c4c070d6d..d39fa67f4 100644 --- a/companion/src/simulation/widgets/buttonswidget.h +++ b/companion/src/simulation/widgets/buttonswidget.h @@ -23,6 +23,7 @@ #include "radiouiaction.h" #include "radiokeywidget.h" +#include "appdata.h" #include #include @@ -69,22 +70,12 @@ class ButtonsWidget : public QWidget connect(pushbtn, &QPushButton::pressed, rkw, &RadioKeyWidget::press); connect(pushbtn, &QPushButton::released, rkw, &RadioKeyWidget::release); - if (action) { + if (action && !g.currentProfile().simBtnClickedUseOSTheme()) { // blink push button on click or matching key(s) press - connect(action, static_cast(&RadioUiAction::pushed), [this, pushbtn] (void) { - // TODO: use a palette colors - // set to default -> blink -> default - QString csssave = pushbtn->styleSheet(); - QString blnkcol = "background-color: rgb(239, 41, 41)"; - // pressing the same key in rapid seccession can affect the order of the events see TODO - if (csssave != blnkcol) { - pushbtn->setStyleSheet(blnkcol); - QTimer * tim = new QTimer(this); - tim->setSingleShot(true); - connect(tim, &QTimer::timeout, [pushbtn, csssave]() { pushbtn->setStyleSheet(csssave); }); - tim->start(300); - } - }); + pushbtn->setStyleSheet(QString( + "QPushButton:pressed {background-color: %1; border-style: inset;}") + .arg(QVariant(g.currentProfile().simBtnClickedColor()).toString()) + ); } return rkw; diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 716a45436..3dcb7bb18 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -504,6 +504,8 @@ class Profile: public CompStoreObj PROPERTY(bool, telemSimPauseOnHide, true) PROPERTY(bool, telemSimResetRssiOnStop, false) PROPERTY(QColor, radioSimCaseColor, QColor(Qt::black)) + PROPERTY(bool, simBtnClickedUseOSTheme, true) + PROPERTY(QColor, simBtnClickedColor, QColor(Qt::red)) // General settings PROPERTYQBA(generalSettings)