Qt: disable battery LED settings if the pad handler doesn't support it

This commit is contained in:
Megamouse 2024-07-06 17:47:54 +02:00
parent 4c11554d2c
commit 6948c0a30a
4 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,7 @@
#include <QPixmap> #include <QPixmap>
#include <QPainterPath> #include <QPainterPath>
pad_led_settings_dialog::pad_led_settings_dialog(QDialog* parent, int colorR, int colorG, int colorB, bool has_rgb, bool has_player_led, bool player_led_enabled, bool has_battery, bool led_low_battery_blink, bool led_battery_indicator, int led_battery_indicator_brightness) pad_led_settings_dialog::pad_led_settings_dialog(QDialog* parent, int colorR, int colorG, int colorB, bool has_rgb, bool has_player_led, bool player_led_enabled, bool has_battery, bool has_battery_led, bool led_low_battery_blink, bool led_battery_indicator, int led_battery_indicator_brightness)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::pad_led_settings_dialog) , ui(new Ui::pad_led_settings_dialog)
, m_initial{colorR, colorG, colorB, player_led_enabled, led_low_battery_blink, led_battery_indicator, led_battery_indicator_brightness} , m_initial{colorR, colorG, colorB, player_led_enabled, led_low_battery_blink, led_battery_indicator, led_battery_indicator_brightness}
@ -23,8 +23,8 @@ pad_led_settings_dialog::pad_led_settings_dialog(QDialog* parent, int colorR, in
ui->gb_player_led->setEnabled(has_player_led); ui->gb_player_led->setEnabled(has_player_led);
ui->gb_led_color->setEnabled(has_rgb); ui->gb_led_color->setEnabled(has_rgb);
ui->gb_battery_status->setEnabled(has_battery); ui->gb_battery_status->setEnabled(has_battery && has_battery_led);
ui->gb_indicator_brightness->setEnabled(has_battery && has_rgb); // Let's restrict this to rgb capable devices for now ui->gb_indicator_brightness->setEnabled(has_battery && has_battery_led && has_rgb); // Let's restrict this to rgb capable devices for now
connect(ui->bb_dialog_buttons, &QDialogButtonBox::clicked, [this](QAbstractButton* button) connect(ui->bb_dialog_buttons, &QDialogButtonBox::clicked, [this](QAbstractButton* button)
{ {
@ -61,10 +61,20 @@ pad_led_settings_dialog::pad_led_settings_dialog(QDialog* parent, int colorR, in
redraw_color_sample(); redraw_color_sample();
} }
}); });
if (ui->gb_battery_status->isEnabled())
{
connect(ui->hs_indicator_brightness, &QAbstractSlider::valueChanged, this, &pad_led_settings_dialog::update_slider_label); connect(ui->hs_indicator_brightness, &QAbstractSlider::valueChanged, this, &pad_led_settings_dialog::update_slider_label);
}
if (ui->cb_led_indicate->isEnabled())
{
connect(ui->cb_led_indicate, &QCheckBox::toggled, this, &pad_led_settings_dialog::battery_indicator_checked); connect(ui->cb_led_indicate, &QCheckBox::toggled, this, &pad_led_settings_dialog::battery_indicator_checked);
} }
battery_indicator_checked(ui->cb_led_indicate->isChecked());
}
// Draw color sample after showing the dialog, in order to have proper dimensions // Draw color sample after showing the dialog, in order to have proper dimensions
show(); show();
redraw_color_sample(); redraw_color_sample();

View File

@ -14,7 +14,7 @@ class pad_led_settings_dialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit pad_led_settings_dialog(QDialog* parent, int colorR, int colorG, int colorB, bool has_rgb, bool has_player_led, bool player_led_enabled, bool has_battery, bool led_low_battery_blink, bool led_battery_indicator, int led_battery_indicator_brightness); explicit pad_led_settings_dialog(QDialog* parent, int colorR, int colorG, int colorB, bool has_rgb, bool has_player_led, bool player_led_enabled, bool has_battery, bool has_battery_led, bool led_low_battery_blink, bool led_battery_indicator, int led_battery_indicator_brightness);
~pad_led_settings_dialog(); ~pad_led_settings_dialog();
struct led_settings struct led_settings

View File

@ -404,7 +404,7 @@ void pad_settings_dialog::InitButtons()
ensure(m_handler); ensure(m_handler);
const cfg_pad& cfg = GetPlayerConfig(); const cfg_pad& cfg = GetPlayerConfig();
SetPadData(0, 0, cfg.led_battery_indicator.get()); SetPadData(0, 0, cfg.led_battery_indicator.get());
pad_led_settings_dialog dialog(this, cfg.colorR, cfg.colorG, cfg.colorB, m_handler->has_rgb(), m_handler->has_player_led(), cfg.player_led_enabled.get(), m_handler->has_battery(), cfg.led_low_battery_blink.get(), cfg.led_battery_indicator.get(), cfg.led_battery_indicator_brightness); pad_led_settings_dialog dialog(this, cfg.colorR, cfg.colorG, cfg.colorB, m_handler->has_rgb(), m_handler->has_player_led(), cfg.player_led_enabled.get(), m_handler->has_battery(), m_handler->has_battery_led(), cfg.led_low_battery_blink.get(), cfg.led_battery_indicator.get(), cfg.led_battery_indicator_brightness);
connect(&dialog, &pad_led_settings_dialog::pass_led_settings, this, [this](const pad_led_settings_dialog::led_settings& settings) connect(&dialog, &pad_led_settings_dialog::pass_led_settings, this, [this](const pad_led_settings_dialog::led_settings& settings)
{ {
ensure(m_handler); ensure(m_handler);
@ -1220,6 +1220,7 @@ void pad_settings_dialog::UpdateLabels(bool is_reset)
// Apply stored/default LED settings to the device // Apply stored/default LED settings to the device
m_enable_led = m_handler->has_led(); m_enable_led = m_handler->has_led();
m_enable_battery_led = m_handler->has_battery_led();
SetPadData(0, 0); SetPadData(0, 0);
// Enable battery and LED group box // Enable battery and LED group box

View File

@ -118,6 +118,7 @@ private:
bool m_enable_deadzones{ false }; bool m_enable_deadzones{ false };
bool m_enable_led{ false }; bool m_enable_led{ false };
bool m_enable_battery{ false }; bool m_enable_battery{ false };
bool m_enable_battery_led{ false };
bool m_enable_motion{ false }; bool m_enable_motion{ false };
bool m_enable_pressure_intensity_button{ true }; bool m_enable_pressure_intensity_button{ true };