Allow switching format for hex color code entry box between RGB (HTML) and BGR (RGBColor)

This commit is contained in:
Adam Honse 2024-11-10 16:06:34 -06:00
parent 330f6d6014
commit 5b7cdf786b
5 changed files with 237 additions and 156 deletions

View file

@ -78,7 +78,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Get the UserInterface settings and check the | | Get the UserInterface settings and check the |
| numerical labels setting | | numerical labels and hex format settings |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager(); SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
std::string ui_string = "UserInterface"; std::string ui_string = "UserInterface";
@ -93,6 +93,18 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
ui->DeviceViewBox->setNumericalLabels(numerical_labels); ui->DeviceViewBox->setNumericalLabels(numerical_labels);
} }
if(ui_settings.contains("hex_format"))
{
if(ui_settings["hex_format"] == "RGB")
{
HexFormatRGB = true;
}
else if(ui_settings["hex_format"] == "BGR")
{
HexFormatRGB = false;
}
}
ui->DeviceViewBox->setController(device); ui->DeviceViewBox->setController(device);
ui->DeviceViewBoxFrame->hide(); ui->DeviceViewBoxFrame->hide();
@ -1458,10 +1470,22 @@ void Ui::OpenRGBDevicePage::on_HexLineEdit_textChanged(const QString &arg1)
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Store new color into the current color QColor | | Store new color into the current color QColor |
| Because RGBColor stores color in BGR format, we have |
| to reverse the R and B channels if the hex format is |
| RGB. |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
current_color.setRed(RGBGetRValue(color)); if(HexFormatRGB)
current_color.setGreen(RGBGetGValue(color)); {
current_color.setBlue(RGBGetBValue(color)); current_color.setRed(RGBGetBValue(color));
current_color.setGreen(RGBGetGValue(color));
current_color.setBlue(RGBGetRValue(color));
}
else
{
current_color.setRed(RGBGetRValue(color));
current_color.setGreen(RGBGetGValue(color));
current_color.setBlue(RGBGetBValue(color));
}
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Update the color UI, but set the UpdateHex flag to | | Update the color UI, but set the UpdateHex flag to |
@ -1832,8 +1856,21 @@ void Ui::OpenRGBDevicePage::updateColorUi()
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
if(UpdateHex) if(UpdateHex)
{ {
RGBColor color = (0x00FFFFFF & current_color.rgb());
/*-------------------------------------------------*\
| If the hex format is BGR, swap R and B before |
| displaying as hex |
\*-------------------------------------------------*/
if(!HexFormatRGB)
{
color = RGBGetRValue(color) << 16
| RGBGetGValue(color) << 8
| RGBGetBValue(color);
}
ui->HexLineEdit->blockSignals(true); ui->HexLineEdit->blockSignals(true);
ui->HexLineEdit->setText(QString().asprintf("%06X", (0x00FFFFFF & current_color.rgb()))); ui->HexLineEdit->setText(QString().asprintf("%06X", color));
ui->HexLineEdit->blockSignals(false); ui->HexLineEdit->blockSignals(false);
} }
} }

View file

@ -78,6 +78,7 @@ private:
bool MultipleSelected = false; bool MultipleSelected = false;
bool DeviceViewShowing = false; bool DeviceViewShowing = false;
bool UpdateHex = true; bool UpdateHex = true;
bool HexFormatRGB = true;
QColor current_color; QColor current_color;
void updateColorUi(); void updateColorUi();

View file

@ -62,6 +62,14 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) :
} }
ui->ComboBoxLanguage->blockSignals(false); ui->ComboBoxLanguage->blockSignals(false);
/*---------------------------------------------------------*\
| Populate hex format combo box |
\*---------------------------------------------------------*/
ui->ComboBoxHexFormat->addItem("RGB");
ui->ComboBoxHexFormat->addItem("BGR");
hex_format_initialized = true;
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Load theme settings | | Load theme settings |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -158,6 +166,18 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) :
ui->CheckboxShowLEDView->setChecked(false); ui->CheckboxShowLEDView->setChecked(false);
} }
if(ui_settings.contains("hex_format"))
{
if(ui_settings["hex_format"] == "RGB")
{
ui->ComboBoxHexFormat->setCurrentIndex(0);
}
else if(ui_settings["hex_format"] == "BGR")
{
ui->ComboBoxHexFormat->setCurrentIndex(1);
}
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Load LogManager settings | | Load LogManager settings |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -386,6 +406,17 @@ void OpenRGBSettingsPage::on_ComboBoxTheme_currentTextChanged(const QString them
} }
} }
void OpenRGBSettingsPage::on_ComboBoxHexFormat_currentTextChanged(const QString hex_format)
{
if(hex_format_initialized)
{
json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface");
ui_settings["hex_format"] = hex_format.toStdString();
ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface",ui_settings);
SaveSettings();
}
}
void OpenRGBSettingsPage::on_CheckboxTrayIconGreyscale_clicked() void OpenRGBSettingsPage::on_CheckboxTrayIconGreyscale_clicked()
{ {
json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface");

View file

@ -50,12 +50,14 @@ private:
bool theme_initialized = false; bool theme_initialized = false;
bool autostart_initialized = false; bool autostart_initialized = false;
bool hex_format_initialized = false;
QTranslator translator; QTranslator translator;
private slots: private slots:
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
void on_ComboBoxLanguage_currentTextChanged(const QString); void on_ComboBoxLanguage_currentTextChanged(const QString);
void on_ComboBoxTheme_currentTextChanged(const QString); void on_ComboBoxTheme_currentTextChanged(const QString);
void on_ComboBoxHexFormat_currentTextChanged(const QString);
void on_CheckboxMinimizeOnClose_clicked(); void on_CheckboxMinimizeOnClose_clicked();
void on_CheckboxTrayIconGreyscale_clicked(); void on_CheckboxTrayIconGreyscale_clicked();
void on_CheckboxLoadGeometry_clicked(); void on_CheckboxLoadGeometry_clicked();

View file

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>432</width> <width>475</width>
<height>500</height> <height>500</height>
</rect> </rect>
</property> </property>
@ -31,30 +31,31 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>678</width> <width>441</width>
<height>980</height> <height>856</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="28" column="0"> <item row="29" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartProfile"> <widget class="QCheckBox" name="CheckboxAutoStartProfile">
<property name="text"> <property name="text">
<string>Load Profile</string> <string>Load Profile</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="29" column="0"> <item row="28" column="0">
<widget class="QCheckBox" name="CheckboxSetOnExit"> <widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text"> <property name="text">
<string>Set Profile on Exit</string> <string>Custom Arguments</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="27" column="1"> <item row="19" column="0">
<widget class="QLineEdit" name="TextCustomArgs"/> <widget class="QCheckBox" name="CheckboxAutoStart">
</item> <property name="text">
<item row="26" column="1"> <string>Start At Login</string>
<widget class="QLineEdit" name="TextClientHost"/> </property>
</widget>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QCheckBox" name="CheckboxTrayIconGreyscale"> <widget class="QCheckBox" name="CheckboxTrayIconGreyscale">
@ -63,131 +64,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="27" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text">
<string>Custom Arguments</string>
</property>
</widget>
</item>
<item row="24" column="1">
<widget class="QLineEdit" name="TextServerHost"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="LabelLanguage">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="CheckboxLoadGeometry">
<property name="text">
<string>Load Window Geometry</string>
</property>
</widget>
</item>
<item row="22" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
<property name="text">
<string>Start Minimized</string>
</property>
</widget>
</item>
<item row="30" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="24" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerHost">
<property name="text">
<string>Set Server Host</string>
</property>
</widget>
</item>
<item row="29" column="1">
<widget class="QComboBox" name="ComboBoxExitProfile"/>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text">
<string>Save Geometry On Close</string>
</property>
</widget>
</item>
<item row="16" column="0"> <item row="16" column="0">
<widget class="QCheckBox" name="CheckboxSharedSMBusAccess">
<property name="text">
<string>Shared SMBus Access (restart required)</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxLanguage"/>
</item>
<item row="18" column="0">
<widget class="QCheckBox" name="CheckboxAutoStart">
<property name="text">
<string>Start At Login</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<property name="text">
<string>User Interface Settings:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="CheckboxMinimizeOnClose">
<property name="text">
<string>Minimize On Close</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QCheckBox" name="CheckboxLogConsole">
<property name="text">
<string>Enable Log Console (restart required)</string>
</property>
</widget>
</item>
<item row="25" column="1">
<widget class="QLineEdit" name="TextServerPort">
<property name="inputMask">
<string>90000</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="28" column="1">
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="15" column="0">
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU"> <widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
<property name="text"> <property name="text">
<string>AMD SMBus: Reduce CPU Usage (restart required)</string> <string>AMD SMBus: Reduce CPU Usage (restart required)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="18" column="0">
<widget class="QComboBox" name="ComboBoxTheme"/> <widget class="QLabel" name="AutoStartLabel">
<property name="text">
<string>Start At Login Settings:</string>
</property>
</widget>
</item>
<item row="24" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartServer">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="30" column="0">
<widget class="QCheckBox" name="CheckboxSetOnExit">
<property name="text">
<string>Set Profile on Exit</string>
</property>
</widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="ThemeLabel"> <widget class="QLabel" name="ThemeLabel">
@ -196,19 +99,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="23" column="0"> <item row="29" column="1">
<widget class="QCheckBox" name="CheckboxAutoStartServer"> <widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="11" column="0">
<widget class="QCheckBox" name="CheckboxShowLEDView">
<property name="text"> <property name="text">
<string>Start Server</string> <string>Show LED view by default</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="26" column="0"> <item row="28" column="1">
<widget class="QCheckBox" name="CheckboxAutoStartClient"> <widget class="QLineEdit" name="TextCustomArgs"/>
<property name="text">
<string>Start Client</string>
</property>
</widget>
</item> </item>
<item row="9" column="0"> <item row="9" column="0">
<widget class="QCheckBox" name="CheckboxRunZoneChecks"> <widget class="QCheckBox" name="CheckboxRunZoneChecks">
@ -217,7 +119,41 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="30" column="1">
<widget class="QComboBox" name="ComboBoxExitProfile"/>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="CheckboxLogConsole">
<property name="text">
<string>Enable Log Console (restart required)</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="ComboBoxTheme"/>
</item>
<item row="27" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartClient">
<property name="text">
<string>Start Client</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="CheckboxDisableKeyExpansion">
<property name="text">
<string>Disable key expansion in device view</string>
</property>
</widget>
</item>
<item row="31" column="0"> <item row="31" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="32" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -233,41 +169,115 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="10" column="0"> <item row="25" column="1">
<widget class="QCheckBox" name="CheckboxDisableKeyExpansion"> <widget class="QLineEdit" name="TextServerHost"/>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text"> <property name="text">
<string>Disable key expansion in device view</string> <string>Save Geometry On Close</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="0"> <item row="5" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel"> <widget class="QCheckBox" name="CheckboxMinimizeOnClose">
<property name="text"> <property name="text">
<string>Log Manager Settings:</string> <string>Minimize On Close</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="23" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
<property name="text">
<string>Start Minimized</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<property name="text">
<string>User Interface Settings:</string>
</property>
</widget>
</item>
<item row="27" column="1">
<widget class="QLineEdit" name="TextClientHost"/>
</item>
<item row="17" column="0"> <item row="17" column="0">
<widget class="QLabel" name="AutoStartLabel"> <widget class="QCheckBox" name="CheckboxSharedSMBusAccess">
<property name="text"> <property name="text">
<string>Start At Login Settings:</string> <string>Shared SMBus Access (restart required)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="25" column="0"> <item row="15" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxLanguage"/>
</item>
<item row="26" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort"> <widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
<property name="text"> <property name="text">
<string>Set Server Port</string> <string>Set Server Port</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0"> <item row="7" column="0">
<widget class="QCheckBox" name="CheckboxShowLEDView"> <widget class="QCheckBox" name="CheckboxLoadGeometry">
<property name="text"> <property name="text">
<string>Show LED view by default</string> <string>Load Window Geometry</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="26" column="1">
<widget class="QLineEdit" name="TextServerPort">
<property name="inputMask">
<string>90000</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel">
<property name="text">
<string>Log Manager Settings:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="LabelLanguage">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="25" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerHost">
<property name="text">
<string>Set Server Host</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="HexFormatLabel">
<property name="text">
<string>Hex Format</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QComboBox" name="ComboBoxHexFormat"/>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>