From 94ca670cbe0e58d549dcfa83f3e161b7007985ff Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 6 May 2023 22:51:47 -0500 Subject: [PATCH] Add a UI option to disable expanding keys in the device view --- qt/DeviceView.cpp | 117 +++++++++------- qt/OpenRGBSettingsPage.cpp | 17 ++- qt/OpenRGBSettingsPage.h | 1 + qt/OpenRGBSettingsPage.ui | 265 +++++++++++++++++++------------------ 4 files changed, 222 insertions(+), 178 deletions(-) diff --git a/qt/DeviceView.cpp b/qt/DeviceView.cpp index 36b804e0..a00cc2df 100644 --- a/qt/DeviceView.cpp +++ b/qt/DeviceView.cpp @@ -7,8 +7,10 @@ \*-----------------------------------------------------*/ #include "DeviceView.h" +#include "ResourceManager.h" #include "RGBControllerKeyNames.h" #include "RGBController.h" +#include "SettingsManager.h" #include #include #include @@ -251,6 +253,22 @@ void DeviceView::InitDeviceView() unsigned int segment_count = 0; float totalHeight = 0; + /*-----------------------------------------------------*\ + | Get device view settings | + \*-----------------------------------------------------*/ + SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager(); + std::string ui_string = "UserInterface"; + json ui_settings; + + bool disable_expansion = false; + + ui_settings = settings_manager->GetSettings(ui_string); + + if(ui_settings.contains("disable_key_expansion")) + { + disable_expansion = ui_settings["disable_key_expansion"]; + } + /*-----------------------------------------------------*\ | Determine the total height (in LEDs) of all zones | \*-----------------------------------------------------*/ @@ -342,60 +360,63 @@ void DeviceView::InitDeviceView() led_pos[color_idx].matrix_w = (1 - (2 * PAD_LED)); led_pos[color_idx].matrix_h = (1 - (2 * PAD_LED)); - /*-----------------------------------------------------*\ - | Expand large keys to fill empty spaces in matrix, if | - | possible. Large keys can fill left, down, up, or wide| - | Fill Left: | - | Tab | - | Caps Lock | - | Left Shift | - | Right Shift | - | Backspace | - | Number Pad 0 | - | | - | Fill Up or Down: | - | Number Pad Enter | - | Number Pad + | - | | - | Fill Wide: | - | Space | - \*-----------------------------------------------------*/ - if(led_x < map->width - 1 && map->map[map_idx + 1] == 0xFFFFFFFF) + if(!disable_expansion) { - if( ( controller->leds[color_idx].name == KEY_EN_TAB ) - || ( controller->leds[color_idx].name == KEY_EN_CAPS_LOCK ) - || ( controller->leds[color_idx].name == KEY_EN_LEFT_SHIFT ) - || ( controller->leds[color_idx].name == KEY_EN_RIGHT_SHIFT) - || ( controller->leds[color_idx].name == KEY_EN_BACKSPACE ) - || ( controller->leds[color_idx].name == KEY_EN_NUMPAD_0 ) ) + /*-----------------------------------------------------*\ + | Expand large keys to fill empty spaces in matrix, if | + | possible. Large keys can fill left, down, up, or wide| + | Fill Left: | + | Tab | + | Caps Lock | + | Left Shift | + | Right Shift | + | Backspace | + | Number Pad 0 | + | | + | Fill Up or Down: | + | Number Pad Enter | + | Number Pad + | + | | + | Fill Wide: | + | Space | + \*-----------------------------------------------------*/ + if(led_x < map->width - 1 && map->map[map_idx + 1] == 0xFFFFFFFF) { - led_pos[color_idx].matrix_w += 1; + if( ( controller->leds[color_idx].name == KEY_EN_TAB ) + || ( controller->leds[color_idx].name == KEY_EN_CAPS_LOCK ) + || ( controller->leds[color_idx].name == KEY_EN_LEFT_SHIFT ) + || ( controller->leds[color_idx].name == KEY_EN_RIGHT_SHIFT) + || ( controller->leds[color_idx].name == KEY_EN_BACKSPACE ) + || ( controller->leds[color_idx].name == KEY_EN_NUMPAD_0 ) ) + { + led_pos[color_idx].matrix_w += 1; + } } - } - if( ( controller->leds[color_idx].name == KEY_EN_NUMPAD_ENTER ) - || ( controller->leds[color_idx].name == KEY_EN_NUMPAD_PLUS ) ) - { - if(led_y < map->height - 1 && map->map[map_idx + map->width] == 0xFFFFFFFF) + if( ( controller->leds[color_idx].name == KEY_EN_NUMPAD_ENTER ) + || ( controller->leds[color_idx].name == KEY_EN_NUMPAD_PLUS ) ) { - led_pos[color_idx].matrix_h += 1; + if(led_y < map->height - 1 && map->map[map_idx + map->width] == 0xFFFFFFFF) + { + led_pos[color_idx].matrix_h += 1; + } + /* TODO: check if there isn't another widened key above */ + else if(led_y > 0 && map->map[map_idx - map->width] == 0xFFFFFFFF) + { + led_pos[color_idx].matrix_y -= 1; + led_pos[color_idx].matrix_h += 1; + } } - /* TODO: check if there isn't another widened key above */ - else if(led_y > 0 && map->map[map_idx - map->width] == 0xFFFFFFFF) + else if(controller->leds[color_idx].name == KEY_EN_SPACE) { - led_pos[color_idx].matrix_y -= 1; - led_pos[color_idx].matrix_h += 1; - } - } - else if(controller->leds[color_idx].name == KEY_EN_SPACE) - { - for(unsigned int map_idx2 = map_idx - 1; map_idx2 > led_y * map->width && map->map[map_idx2] == 0xFFFFFFFF; --map_idx2) - { - led_pos[color_idx].matrix_x -= 1; - led_pos[color_idx].matrix_w += 1; - } - for(unsigned int map_idx2 = map_idx + 1; map_idx2 < (led_y + 1) * map->width && map->map[map_idx2] == 0xFFFFFFFF; ++map_idx2) - { - led_pos[color_idx].matrix_w += 1; + for(unsigned int map_idx2 = map_idx - 1; map_idx2 > led_y * map->width && map->map[map_idx2] == 0xFFFFFFFF; --map_idx2) + { + led_pos[color_idx].matrix_x -= 1; + led_pos[color_idx].matrix_w += 1; + } + for(unsigned int map_idx2 = map_idx + 1; map_idx2 < (led_y + 1) * map->width && map->map[map_idx2] == 0xFFFFFFFF; ++map_idx2) + { + led_pos[color_idx].matrix_w += 1; + } } } } diff --git a/qt/OpenRGBSettingsPage.cpp b/qt/OpenRGBSettingsPage.cpp index 67d19e3c..b45eb591 100644 --- a/qt/OpenRGBSettingsPage.cpp +++ b/qt/OpenRGBSettingsPage.cpp @@ -129,6 +129,15 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : ui->CheckboxRunZoneChecks->setChecked(true); } + if(ui_settings.contains("disable_key_expansion")) + { + ui->CheckboxDisableKeyExpansion->setChecked(ui_settings["disable_key_expansion"]); + } + else + { + ui->CheckboxDisableKeyExpansion->setChecked(false); + } + /*---------------------------------------------------------*\ | Load LogManager settings | \*---------------------------------------------------------*/ @@ -796,4 +805,10 @@ void Ui::OpenRGBSettingsPage::on_CheckboxSharedSMBusAccess_clicked() SaveSettings(); } - +void Ui::OpenRGBSettingsPage::on_CheckboxDisableKeyExpansion_clicked() +{ + json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + ui_settings["disable_key_expansion"] = ui->CheckboxDisableKeyExpansion->isChecked(); + ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + SaveSettings(); +} diff --git a/qt/OpenRGBSettingsPage.h b/qt/OpenRGBSettingsPage.h index 12ece198..aff4a33c 100644 --- a/qt/OpenRGBSettingsPage.h +++ b/qt/OpenRGBSettingsPage.h @@ -70,6 +70,7 @@ private slots: void on_CheckboxSetOnExit_clicked(bool checked); void on_ComboBoxExitProfile_currentTextChanged(const QString exit_profile_name); + void on_CheckboxDisableKeyExpansion_clicked(); }; #endif // OPENRGBSETTINGSPAGE_H diff --git a/qt/OpenRGBSettingsPage.ui b/qt/OpenRGBSettingsPage.ui index 3890a686..9615eaae 100644 --- a/qt/OpenRGBSettingsPage.ui +++ b/qt/OpenRGBSettingsPage.ui @@ -31,56 +31,59 @@ 0 0 - 427 - 764 + 395 + 654 - + + + + Drivers Settings + + + + + + + + + + + + + Set Server Port + + + + + + + + + + Run zone checks on rescan + + + + Log Manager Settings: - - - - - + + - User Interface Settings: + Language - - + + - Enable Log Console (restart required) - - - - - - - Start Server - - - - - - - - - - Start At Login - - - - - - - Start At Login Settings: + Start at Login Status @@ -91,14 +94,51 @@ - - + + + + + - Drivers Settings + Set Profile on Exit - + + + + Start Server + + + + + + + 90000 + + + + + + + + + + + + + Start Client + + + + + + + Set Server Host + + + + Qt::Vertical @@ -114,6 +154,33 @@ + + + + Start At Login + + + + + + + Shared SMBus Access (restart required) + + + + + + + + + + + + + User Interface Settings: + + + @@ -121,48 +188,10 @@ - - - - Start Client - - - - - - - + - Load Profile - - - - - - - Greyscale Tray Icon - - - - - - - Start at Login Status - - - - - - - AMD SMBus: Reduce CPU Usage (restart required) - - - - - - - Start Minimized + Custom Arguments @@ -173,36 +202,24 @@ - - - - - - - 90000 - + + - - - - + Enable Log Console (restart required) - - - - - + + - Set Profile on Exit + Start Minimized - - + + - Custom Arguments + Start At Login Settings: @@ -213,47 +230,37 @@ + + + + + + + Greyscale Tray Icon + + + - + - Shared SMBus Access (restart required) + AMD SMBus: Reduce CPU Usage (restart required) - - - - - + + - Set Server Host + Load Profile - - + + - Set Server Port + Disable key expansion in device view - - - - Run zone checks on rescan - - - - - - - Language - - - - - -