WIP: Instant color setting, buttons removed

Code cleanup by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
k1-801 2020-08-19 09:30:23 +04:00 committed by Adam Honse
parent a2a394492b
commit bbc3c1de5b
4 changed files with 222 additions and 425 deletions

View file

@ -508,4 +508,5 @@ void DeviceView::setSelectionColor(RGBColor color)
controller->SetLED(led_idx, color);
}
}
controller->UpdateLEDs();
}

View file

@ -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<int> indices)

View file

@ -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);

View file

@ -14,257 +14,45 @@
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="0">
<widget class="QLabel" name="SpeedLabel">
<property name="text">
<string>Speed:</string>
</property>
</widget>
<item row="10" column="1" colspan="4">
<widget class="QComboBox" name="DirectionBox"/>
</item>
<item row="6" column="6" colspan="2">
<widget class="QSpinBox" name="RedSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="ZoneLabel">
<property name="text">
<string>Zone:</string>
</property>
</widget>
</item>
<item row="7" column="8">
<widget class="QLabel" name="SatLabel">
<property name="text">
<string>S:</string>
</property>
</widget>
</item>
<item row="11" column="6">
<widget class="QPushButton" name="ButtonYellow">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="5">
<widget class="QLabel" name="GreenLabel">
<property name="text">
<string>G:</string>
</property>
</widget>
</item>
<item row="11" column="8">
<widget class="QPushButton" name="ButtonCyan">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QRadioButton" name="PerLEDCheck">
<property name="text">
<string>Per-LED</string>
</property>
</widget>
</item>
<item row="7" column="2" colspan="2">
<widget class="QRadioButton" name="ModeSpecificCheck">
<property name="text">
<string>Mode-Specific</string>
</property>
</widget>
</item>
<item row="6" column="5">
<widget class="QLabel" name="RedLabel">
<property name="text">
<string>R:</string>
</property>
</widget>
</item>
<item row="7" column="4">
<widget class="QRadioButton" name="RandomCheck">
<property name="text">
<string>Random</string>
</property>
</widget>
</item>
<item row="11" column="10">
<widget class="QPushButton" name="ButtonMagenta">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="ModeLabel">
<property name="text">
<string>Mode:</string>
</property>
</widget>
</item>
<item row="8" column="9" colspan="2">
<widget class="QSpinBox" name="ValSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="8" column="6" colspan="2">
<item row="7" column="6" colspan="2">
<widget class="QSpinBox" name="BlueSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="7" column="6" colspan="2">
<widget class="QSpinBox" name="GreenSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="SetLEDButton">
<item row="10" column="10">
<widget class="QPushButton" name="ButtonMagenta">
<property name="text">
<string>LED</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LEDLabel">
<property name="text">
<string>LED:</string>
<string/>
</property>
</widget>
</item>
<item row="6" column="8">
<widget class="QLabel" name="HueLabel">
<widget class="QLabel" name="SatLabel">
<property name="text">
<string>H:</string>
<string>S:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="ColorLabel">
<property name="text">
<string>Colors:</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="4">
<widget class="QComboBox" name="ModeBox"/>
</item>
<item row="4" column="1" colspan="4">
<widget class="QPushButton" name="SetAllButton">
<property name="text">
<string>Set All Devices</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="4">
<item row="7" column="1" colspan="4">
<widget class="QSlider" name="SpeedSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="DirectionLabel">
<property name="text">
<string>Dir:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="SetLabel">
<property name="text">
<string>Set:</string>
</property>
</widget>
</item>
<item row="8" column="8">
<widget class="QLabel" name="ValLabel">
<property name="text">
<string>V:</string>
</property>
</widget>
</item>
<item row="11" column="7">
<widget class="QPushButton" name="ButtonGreen">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="11" column="9">
<widget class="QPushButton" name="ButtonBlue">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="SetDeviceButton">
<property name="text">
<string>Device</string>
</property>
</widget>
</item>
<item row="8" column="5">
<widget class="QLabel" name="BlueLabel">
<property name="text">
<string>B:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QComboBox" name="ZoneBox"/>
</item>
<item row="11" column="1" colspan="4">
<widget class="QComboBox" name="DirectionBox"/>
</item>
<item row="3" column="2" colspan="2">
<widget class="QPushButton" name="SetZoneButton">
<property name="text">
<string>Zone</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="4">
<widget class="QComboBox" name="LEDBox"/>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="ResizeButton">
<property name="text">
<string>Resize</string>
</property>
</widget>
</item>
<item row="11" column="5">
<widget class="QPushButton" name="ButtonRed">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="9" colspan="2">
<widget class="QSpinBox" name="SatSpinBox">
<widget class="QSpinBox" name="ValSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="6" column="9" colspan="2">
<widget class="QSpinBox" name="HueSpinBox">
<property name="maximum">
<number>359</number>
</property>
</widget>
</item>
<item row="1" column="5" rowspan="4" colspan="6">
<item row="1" column="5" rowspan="3" colspan="6">
<widget class="ColorWheel" name="ColorWheelBox" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -274,6 +62,121 @@
</property>
</widget>
</item>
<item row="6" column="5">
<widget class="QLabel" name="GreenLabel">
<property name="text">
<string>G:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="ColorLabel">
<property name="text">
<string>Colors:</string>
</property>
</widget>
</item>
<item row="5" column="9" colspan="2">
<widget class="QSpinBox" name="HueSpinBox">
<property name="maximum">
<number>359</number>
</property>
</widget>
</item>
<item row="6" column="6" colspan="2">
<widget class="QSpinBox" name="GreenSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QRadioButton" name="PerLEDCheck">
<property name="text">
<string>Per-LED</string>
</property>
</widget>
</item>
<item row="5" column="8">
<widget class="QLabel" name="HueLabel">
<property name="text">
<string>H:</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="4">
<widget class="QComboBox" name="ModeBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="ModeLabel">
<property name="text">
<string>Mode:</string>
</property>
</widget>
</item>
<item row="10" column="6">
<widget class="QPushButton" name="ButtonYellow">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="10" column="7">
<widget class="QPushButton" name="ButtonGreen">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="5">
<widget class="QLabel" name="RedLabel">
<property name="text">
<string>R:</string>
</property>
</widget>
</item>
<item row="7" column="8">
<widget class="QLabel" name="ValLabel">
<property name="text">
<string>V:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="SpeedLabel">
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="4">
<widget class="QPushButton" name="SetAllButton">
<property name="text">
<string>Set All Devices</string>
</property>
</widget>
</item>
<item row="7" column="5">
<widget class="QLabel" name="BlueLabel">
<property name="text">
<string>B:</string>
</property>
</widget>
</item>
<item row="10" column="5">
<widget class="QPushButton" name="ButtonRed">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="9" colspan="2">
<widget class="QSpinBox" name="SatSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="0" column="0" colspan="11">
<widget class="DeviceView" name="DeviceViewBox" native="true">
<property name="sizePolicy">
@ -290,6 +193,75 @@
</property>
</widget>
</item>
<item row="10" column="9">
<widget class="QPushButton" name="ButtonBlue">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1" colspan="4">
<widget class="QComboBox" name="LEDBox"/>
</item>
<item row="1" column="1" colspan="3">
<widget class="QComboBox" name="ZoneBox"/>
</item>
<item row="6" column="2" colspan="2">
<widget class="QRadioButton" name="ModeSpecificCheck">
<property name="text">
<string>Mode-Specific</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LEDLabel">
<property name="text">
<string>LED:</string>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="QRadioButton" name="RandomCheck">
<property name="text">
<string>Random</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="DirectionLabel">
<property name="text">
<string>Dir:</string>
</property>
</widget>
</item>
<item row="5" column="6" colspan="2">
<widget class="QSpinBox" name="RedSpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="ResizeButton">
<property name="text">
<string>Resize</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="ZoneLabel">
<property name="text">
<string>Zone:</string>
</property>
</widget>
</item>
<item row="10" column="8">
<widget class="QPushButton" name="ButtonCyan">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -313,9 +285,6 @@
<tabstop>ZoneBox</tabstop>
<tabstop>ResizeButton</tabstop>
<tabstop>LEDBox</tabstop>
<tabstop>SetDeviceButton</tabstop>
<tabstop>SetZoneButton</tabstop>
<tabstop>SetLEDButton</tabstop>
<tabstop>SetAllButton</tabstop>
<tabstop>ModeBox</tabstop>
<tabstop>PerLEDCheck</tabstop>