From bbc3c1de5bd1d67911260ea10b05b185c8336710 Mon Sep 17 00:00:00 2001 From: k1-801 Date: Wed, 19 Aug 2020 09:30:23 +0400 Subject: [PATCH] WIP: Instant color setting, buttons removed Code cleanup by Adam Honse --- qt/DeviceView.cpp | 1 + qt/OpenRGBDevicePage.cpp | 217 +++----------------- qt/OpenRGBDevicePage.h | 8 +- qt/OpenRGBDevicePage.ui | 421 ++++++++++++++++++--------------------- 4 files changed, 222 insertions(+), 425 deletions(-) diff --git a/qt/DeviceView.cpp b/qt/DeviceView.cpp index 809e0e8d..509e86a6 100644 --- a/qt/DeviceView.cpp +++ b/qt/DeviceView.cpp @@ -508,4 +508,5 @@ void DeviceView::setSelectionColor(RGBColor color) controller->SetLED(led_idx, color); } } + controller->UpdateLEDs(); } diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index 1296d90a..d962da93 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -122,12 +122,10 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/) { ui->LEDBox->addItem("Entire device"); ui->LEDBox->setEnabled(1); - ui->SetLEDButton->setEnabled(1); } else { ui->LEDBox->setDisabled(1); - ui->SetLEDButton->setDisabled(1); } for (std::size_t i = 0; i < device->leds.size(); i++) { @@ -154,12 +152,10 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/) { ui->LEDBox->addItem("Entire zone"); ui->LEDBox->setEnabled(1); - ui->SetLEDButton->setEnabled(1); } else { ui->LEDBox->setDisabled(1); - ui->SetLEDButton->setDisabled(1); } for (std::size_t led_idx = 0; led_idx < device->zones[selected_zone].leds_count; led_idx++) { @@ -575,12 +571,10 @@ void Ui::OpenRGBDevicePage::UpdateModeUi() { ui->ZoneBox->setEnabled(1); ui->ZoneBox->addItem("All Zones"); - ui->SetZoneButton->setEnabled(1); } else { ui->ZoneBox->setDisabled(1); - ui->SetZoneButton->setDisabled(1); } for (std::size_t i = 0; i < device->zones.size(); i++) @@ -758,8 +752,7 @@ void Ui::OpenRGBDevicePage::SetDevice(unsigned char red, unsigned char green, un UpdatingColor = false; updateHSV(); updateWheel(); - - on_SetDeviceButton_clicked(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::UpdateDevice() @@ -840,213 +833,34 @@ void Ui::OpenRGBDevicePage::SetCustomMode(unsigned char red, unsigned char green UpdateMode(); } -void Ui::OpenRGBDevicePage::on_SetDeviceButton_clicked() -{ - /*-----------------------------------------------------*\ - | Read selected mode | - \*-----------------------------------------------------*/ - unsigned int selected_mode = (unsigned int)ui->ModeBox->currentIndex(); - - switch(device->modes[selected_mode].color_mode) - { - case MODE_COLORS_PER_LED: - { - /*-----------------------------------------------------*\ - | Set all device LEDs to the current color | - \*-----------------------------------------------------*/ - RGBColor color = ToRGBColor( - ui->RedSpinBox->text().toInt(), - ui->GreenSpinBox->text().toInt(), - ui->BlueSpinBox->text().toInt() - ); - - device->SetAllLEDs(color); - - device->UpdateLEDs(); - } - break; - - case MODE_COLORS_MODE_SPECIFIC: - { - /*-----------------------------------------------------*\ - | Set all device LEDs to the current color | - \*-----------------------------------------------------*/ - RGBColor color = ToRGBColor( - ui->RedSpinBox->text().toInt(), - ui->GreenSpinBox->text().toInt(), - ui->BlueSpinBox->text().toInt() - ); - - for(std::size_t i = 0; i < device->modes[selected_mode].colors.size(); i++) - { - device->modes[selected_mode].colors[i] = color; - } - - device->UpdateMode(); - } - break; - } -} - -void Ui::OpenRGBDevicePage::on_SetZoneButton_clicked() -{ - /*-----------------------------------------------------*\ - | Read selected mode | - \*-----------------------------------------------------*/ - unsigned int selected_mode = (unsigned int)ui->ModeBox->currentIndex(); - - switch(device->modes[selected_mode].color_mode) - { - case MODE_COLORS_PER_LED: - { - unsigned int index = ui->ZoneBox->currentIndex(); - - if(index == 0) - { - on_SetDeviceButton_clicked(); - } - else - { - index = index - 1; - - /*-----------------------------------------------------*\ - | Set all LEDs in the selected zone to the current color| - \*-----------------------------------------------------*/ - RGBColor color = ToRGBColor( - ui->RedSpinBox->text().toInt(), - ui->GreenSpinBox->text().toInt(), - ui->BlueSpinBox->text().toInt() - ); - - device->SetAllZoneLEDs(index, color); - device->UpdateZoneLEDs(index); - } - } - break; - } -} - -void Ui::OpenRGBDevicePage::on_SetLEDButton_clicked() -{ - /*-----------------------------------------------------*\ - | Read selected mode | - \*-----------------------------------------------------*/ - unsigned int selected_mode = (unsigned int)ui->ModeBox->currentIndex(); - unsigned int index = ui->LEDBox->currentIndex(); - - switch(device->modes[selected_mode].color_mode) - { - case MODE_COLORS_PER_LED: - { - unsigned int selected_zone = ui->ZoneBox->currentIndex(); - - /*-----------------------------------------------------*\ - | Set the selected LED to the current color | - \*-----------------------------------------------------*/ - RGBColor color = ToRGBColor( - ui->RedSpinBox->text().toInt(), - ui->GreenSpinBox->text().toInt(), - ui->BlueSpinBox->text().toInt() - ); - - if(selected_zone == 0) - { - device->SetLED(index, color); - device->UpdateSingleLED(index); - } - else - { - selected_zone = selected_zone - 1; - - device->SetLED(device->zones[selected_zone].start_idx + index, color); - device->UpdateSingleLED(device->zones[selected_zone].start_idx + index); - } - } - break; - - case MODE_COLORS_MODE_SPECIFIC: - { - /*-----------------------------------------------------*\ - | Set all device LEDs to the current color | - \*-----------------------------------------------------*/ - RGBColor color = ToRGBColor( - ui->RedSpinBox->text().toInt(), - ui->GreenSpinBox->text().toInt(), - ui->BlueSpinBox->text().toInt() - ); - - device->modes[selected_mode].colors[index] = color; - - device->UpdateMode(); - } - break; - } -} - void Ui::OpenRGBDevicePage::on_ButtonRed_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(255); - ui->GreenSpinBox->setValue(0); - ui->BlueSpinBox->setValue(0); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(255, 0, 0); } void Ui::OpenRGBDevicePage::on_ButtonYellow_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(255); - ui->GreenSpinBox->setValue(255); - ui->BlueSpinBox->setValue(0); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(255, 255, 0); } void Ui::OpenRGBDevicePage::on_ButtonGreen_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(0); - ui->GreenSpinBox->setValue(255); - ui->BlueSpinBox->setValue(0); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(0, 255, 0); } void Ui::OpenRGBDevicePage::on_ButtonCyan_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(0); - ui->GreenSpinBox->setValue(255); - ui->BlueSpinBox->setValue(255); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(0, 255, 255); } void Ui::OpenRGBDevicePage::on_ButtonBlue_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(0); - ui->GreenSpinBox->setValue(0); - ui->BlueSpinBox->setValue(255); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(0, 0, 255); } void Ui::OpenRGBDevicePage::on_ButtonMagenta_clicked() { - UpdatingColor = true; - ui->RedSpinBox->setValue(255); - ui->GreenSpinBox->setValue(0); - ui->BlueSpinBox->setValue(255); - UpdatingColor = false; - updateHSV(); - updateWheel(); + SetDevice(255, 0, 255); } void Ui::OpenRGBDevicePage::on_ColorWheelBox_colorChanged(const QColor color) @@ -1063,6 +877,7 @@ void Ui::OpenRGBDevicePage::on_ColorWheelBox_colorChanged(const QColor color) UpdatingColor = false; updateHSV(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::updateRGB() @@ -1130,40 +945,56 @@ void Ui::OpenRGBDevicePage::updateWheel() UpdatingColor = false; } +void Ui::OpenRGBDevicePage::updateDeviceView() +{ + RGBColor qrgb = ToRGBColor + ( + ui->RedSpinBox->value(), + ui->GreenSpinBox->value(), + ui->BlueSpinBox->value()); + ui->DeviceViewBox->setSelectionColor(qrgb); +} + void Ui::OpenRGBDevicePage::on_RedSpinBox_valueChanged(int /*arg1*/) { updateHSV(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_HueSpinBox_valueChanged(int /*arg1*/) { updateRGB(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_GreenSpinBox_valueChanged(int /*arg1*/) { updateHSV(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_SatSpinBox_valueChanged(int /*arg1*/) { updateRGB(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_BlueSpinBox_valueChanged(int /*arg1*/) { updateHSV(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_ValSpinBox_valueChanged(int /*arg1*/) { updateRGB(); updateWheel(); + updateDeviceView(); } void Ui::OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(QVector indices) diff --git a/qt/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage.h index 35a75b5a..88c7246d 100644 --- a/qt/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage.h @@ -18,7 +18,7 @@ public: explicit OpenRGBDevicePage(RGBController *dev, QWidget *parent = nullptr); ~OpenRGBDevicePage(); - void SetDevice(unsigned char red, unsigned char green, unsigned char blue); + void SetDevice(unsigned char red, unsigned char green, unsigned char blue); // Could be moved to private void SetCustomMode(unsigned char red, unsigned char green, unsigned char blue); void UpdateDevice(); void UpdateMode(); @@ -47,9 +47,6 @@ private slots: void on_ButtonCyan_clicked(); void on_ButtonBlue_clicked(); void on_ButtonMagenta_clicked(); - void on_SetDeviceButton_clicked(); - void on_SetZoneButton_clicked(); - void on_SetLEDButton_clicked(); void on_SetAllButton_clicked(); void on_RandomCheck_clicked(); void on_PerLEDCheck_clicked(); @@ -64,10 +61,9 @@ private: bool InvertedSpeed = false; void updateRGB(); - void updateHSV(); - void updateWheel(); + void updateDeviceView(); signals: void SetAllDevices(unsigned char red, unsigned char green, unsigned char blue); diff --git a/qt/OpenRGBDevicePage.ui b/qt/OpenRGBDevicePage.ui index 13e082a8..92eeb39e 100644 --- a/qt/OpenRGBDevicePage.ui +++ b/qt/OpenRGBDevicePage.ui @@ -14,257 +14,45 @@ Frame - - - - Speed: - - + + - - - - 255 - - - - - - - Zone: - - - - - - - S: - - - - - - - - - - - - - - G: - - - - - - - - - - - - - - Per-LED - - - - - - - Mode-Specific - - - - - - - R: - - - - - - - Random - - - - - - - - - - - - - - Mode: - - - - - - - 255 - - - - + 255 - - - - 255 - - - - - + + - LED - - - - - - - LED: + - + - H: + S: - - - - Colors: - - - - - - - - - - Set All Devices - - - - + Qt::Horizontal - - - - Dir: - - - - - - - Set: - - - - - - - V: - - - - - - - - - - - - - - - - - - - - - Device - - - - - - - B: - - - - - - - - - - - - - Zone - - - - - - - - - - Resize - - - - - - - - - - - + 255 - - - - 359 - - - - + @@ -274,6 +62,121 @@ + + + + G: + + + + + + + Colors: + + + + + + + 359 + + + + + + + 255 + + + + + + + Per-LED + + + + + + + H: + + + + + + + + + + Mode: + + + + + + + + + + + + + + + + + + + + + R: + + + + + + + V: + + + + + + + Speed: + + + + + + + Set All Devices + + + + + + + B: + + + + + + + + + + + + + + 255 + + + @@ -290,6 +193,75 @@ + + + + + + + + + + + + + + + + + Mode-Specific + + + + + + + LED: + + + + + + + Random + + + + + + + Dir: + + + + + + + 255 + + + + + + + Resize + + + + + + + Zone: + + + + + + + + + + @@ -313,9 +285,6 @@ ZoneBox ResizeButton LEDBox - SetDeviceButton - SetZoneButton - SetLEDButton SetAllButton ModeBox PerLEDCheck