From 6b9a97f78f8c42d9a8af20152b0498663590b366 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 14 Jul 2021 23:02:01 -0500 Subject: [PATCH] Add settings page for configuring E1.31 devices --- .../E131Controller/E131ControllerDetect.cpp | 145 ++++----- OpenRGB.pro | 6 + qt/OpenRGBDialog2.cpp | 34 +++ qt/OpenRGBDialog2.h | 3 + qt/OpenRGBE131SettingsEntry.cpp | 74 +++++ qt/OpenRGBE131SettingsEntry.h | 28 ++ qt/OpenRGBE131SettingsEntry.ui | 169 +++++++++++ qt/OpenRGBE131SettingsPage.cpp | 282 ++++++++++++++++++ qt/OpenRGBE131SettingsPage.h | 34 +++ qt/OpenRGBE131SettingsPage.ui | 45 +++ 10 files changed, 752 insertions(+), 68 deletions(-) create mode 100644 qt/OpenRGBE131SettingsEntry.cpp create mode 100644 qt/OpenRGBE131SettingsEntry.h create mode 100644 qt/OpenRGBE131SettingsEntry.ui create mode 100644 qt/OpenRGBE131SettingsPage.cpp create mode 100644 qt/OpenRGBE131SettingsPage.h create mode 100644 qt/OpenRGBE131SettingsPage.ui diff --git a/Controllers/E131Controller/E131ControllerDetect.cpp b/Controllers/E131Controller/E131ControllerDetect.cpp index 0b8a56a1b..964127086 100644 --- a/Controllers/E131Controller/E131ControllerDetect.cpp +++ b/Controllers/E131Controller/E131ControllerDetect.cpp @@ -87,39 +87,42 @@ void DetectE131Controllers(std::vector &rgb_controllers) if(e131_settings["devices"][device_idx].contains("matrix_order")) { - std::string matrix_order_val = e131_settings["devices"][device_idx]["matrix_order"]; + if(e131_settings["devices"][device_idx]["matrix_order"].is_string()) + { + std::string matrix_order_val = e131_settings["devices"][device_idx]["matrix_order"]; - if(matrix_order_val == "HORIZONTAL_TOP_LEFT") - { - dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT; - } - else if(matrix_order_val == "HORIZONTAL_TOP_RIGHT") - { - dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_RIGHT; - } - else if(matrix_order_val == "HORIZONTAL_BOTTOM_LEFT") - { - dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT; - } - else if(matrix_order_val == "HORIZONTAL_BOTTOM_RIGHT") - { - dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT; - } - else if(matrix_order_val == "VERTICAL_TOP_LEFT") - { - dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_LEFT; - } - else if(matrix_order_val == "VERTICAL_TOP_RIGHT") - { - dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_RIGHT; - } - else if(matrix_order_val == "VERTICAL_BOTTOM_LEFT") - { - dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_LEFT; - } - else if(matrix_order_val == "VERTICAL_BOTTOM_RIGHT") - { - dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT; + if(matrix_order_val == "HORIZONTAL_TOP_LEFT") + { + dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT; + } + else if(matrix_order_val == "HORIZONTAL_TOP_RIGHT") + { + dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_RIGHT; + } + else if(matrix_order_val == "HORIZONTAL_BOTTOM_LEFT") + { + dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT; + } + else if(matrix_order_val == "HORIZONTAL_BOTTOM_RIGHT") + { + dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT; + } + else if(matrix_order_val == "VERTICAL_TOP_LEFT") + { + dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_LEFT; + } + else if(matrix_order_val == "VERTICAL_TOP_RIGHT") + { + dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_RIGHT; + } + else if(matrix_order_val == "VERTICAL_BOTTOM_LEFT") + { + dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_LEFT; + } + else if(matrix_order_val == "VERTICAL_BOTTOM_RIGHT") + { + dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT; + } } else { @@ -129,31 +132,34 @@ void DetectE131Controllers(std::vector &rgb_controllers) if(e131_settings["devices"][device_idx].contains("rgb_order")) { - std::string rgb_order_val = e131_settings["devices"][device_idx]["rgb_order"]; + if(e131_settings["devices"][device_idx]["rgb_order"].is_string()) + { + std::string rgb_order_val = e131_settings["devices"][device_idx]["rgb_order"]; - if(rgb_order_val == "RGB") - { - dev.rgb_order = E131_RGB_ORDER_RGB; - } - else if(rgb_order_val == "RBG") - { - dev.rgb_order = E131_RGB_ORDER_RBG; - } - else if(rgb_order_val == "GRB") - { - dev.rgb_order = E131_RGB_ORDER_GRB; - } - else if(rgb_order_val == "GBR") - { - dev.rgb_order = E131_RGB_ORDER_GBR; - } - else if(rgb_order_val == "BRG") - { - dev.rgb_order = E131_RGB_ORDER_BGR; - } - else if(rgb_order_val == "BGR") - { - dev.rgb_order = E131_RGB_ORDER_BGR; + if(rgb_order_val == "RGB") + { + dev.rgb_order = E131_RGB_ORDER_RGB; + } + else if(rgb_order_val == "RBG") + { + dev.rgb_order = E131_RGB_ORDER_RBG; + } + else if(rgb_order_val == "GRB") + { + dev.rgb_order = E131_RGB_ORDER_GRB; + } + else if(rgb_order_val == "GBR") + { + dev.rgb_order = E131_RGB_ORDER_GBR; + } + else if(rgb_order_val == "BRG") + { + dev.rgb_order = E131_RGB_ORDER_BGR; + } + else if(rgb_order_val == "BGR") + { + dev.rgb_order = E131_RGB_ORDER_BGR; + } } else { @@ -178,19 +184,22 @@ void DetectE131Controllers(std::vector &rgb_controllers) if(e131_settings["devices"][device_idx].contains("type")) { - std::string type_val = e131_settings["devices"][device_idx]["type"]; + if(e131_settings["devices"][device_idx]["type"].is_string()) + { + std::string type_val = e131_settings["devices"][device_idx]["type"]; - if(type_val == "SINGLE") - { - dev.type = ZONE_TYPE_SINGLE; - } - else if(type_val == "LINEAR") - { - dev.type = ZONE_TYPE_LINEAR; - } - else if(type_val == "MATRIX") - { - dev.type = ZONE_TYPE_MATRIX; + if(type_val == "SINGLE") + { + dev.type = ZONE_TYPE_SINGLE; + } + else if(type_val == "LINEAR") + { + dev.type = ZONE_TYPE_LINEAR; + } + else if(type_val == "MATRIX") + { + dev.type = ZONE_TYPE_MATRIX; + } } else { diff --git a/OpenRGB.pro b/OpenRGB.pro index 11c52c2bc..587469d8d 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -164,6 +164,8 @@ HEADERS += pci_ids/pci_ids.h \ qt/DeviceView.h \ qt/OpenRGBDialog2.h \ + qt/OpenRGBE131SettingsEntry.h \ + qt/OpenRGBE131SettingsPage.h \ qt/OpenRGBPluginContainer.h \ qt/OpenRGBProfileSaveDialog.h \ qt/OpenRGBServerInfoPage.h \ @@ -460,6 +462,8 @@ SOURCES += net_port/net_port.cpp \ qt/DeviceView.cpp \ qt/OpenRGBDialog2.cpp \ + qt/OpenRGBE131SettingsEntry.cpp \ + qt/OpenRGBE131SettingsPage.cpp \ qt/OpenRGBPluginContainer.cpp \ qt/OpenRGBProfileSaveDialog.cpp \ qt/OpenRGBServerInfoPage.cpp \ @@ -778,6 +782,8 @@ FORMS += qt/OpenRGBDevicePage.ui \ qt/OpenRGBDialog.ui \ qt/OpenRGBDialog2.ui \ + qt/OpenRGBE131SettingsEntry.ui \ + qt/OpenRGBE131SettingsPage.ui \ qt/OpenRGBPluginContainer.ui \ qt/OpenRGBProfileSaveDialog.ui \ qt/OpenRGBServerInfoPage.ui \ diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index b2ece6928..3c77e9209 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -401,6 +401,11 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op \*-----------------------------------------------------*/ AddSettingsPage(); + /*-----------------------------------------------------*\ + | Add the E1.31 settings page | + \*-----------------------------------------------------*/ + AddE131SettingsPage(); + /*-----------------------------------------------------*\ | Add the SMBus Tools page if enabled | \*-----------------------------------------------------*/ @@ -564,6 +569,35 @@ void OpenRGBDialog2::AddSettingsPage() ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel); } +void OpenRGBDialog2::AddE131SettingsPage() +{ + /*-----------------------------------------------------*\ + | Create the Settings page | + \*-----------------------------------------------------*/ + E131SettingsPage = new OpenRGBE131SettingsPage(); + + ui->SettingsTabBar->addTab(E131SettingsPage, ""); + + QString SettingsLabelString = "
E1.31 Devices
"; + + QLabel *SettingsTabLabel = new QLabel(); + SettingsTabLabel->setText(SettingsLabelString); + SettingsTabLabel->setIndent(20); + if(IsDarkTheme()) + { + SettingsTabLabel->setGeometry(0, 25, 200, 50); + } + else + { + SettingsTabLabel->setGeometry(0, 0, 200, 25); + } + + ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel); +} + void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_index) { /*-----------------------------------------------------*\ diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index f82f3649c..e5c1a4877 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -8,6 +8,7 @@ #include "OpenRGBSystemInfoPage.h" #include "OpenRGBSupportedDevicesPage.h" #include "OpenRGBSettingsPage.h" +#include "OpenRGBE131SettingsPage.h" #include "PluginManager.h" #include @@ -55,6 +56,7 @@ private: OpenRGBSoftwareInfoPage *SoftInfoPage; OpenRGBSupportedDevicesPage *SupportedPage; OpenRGBSettingsPage *SettingsPage; + OpenRGBE131SettingsPage *E131SettingsPage; bool ShowI2CTools = false; @@ -72,6 +74,7 @@ private: void AddSoftwareInfoPage(); void AddSupportedDevicesPage(); void AddSettingsPage(); + void AddE131SettingsPage(); void AddPluginTab(PluginManager* plugin_manager,int plugin_index); void ClearDevicesList(); diff --git a/qt/OpenRGBE131SettingsEntry.cpp b/qt/OpenRGBE131SettingsEntry.cpp new file mode 100644 index 000000000..1d53e6efd --- /dev/null +++ b/qt/OpenRGBE131SettingsEntry.cpp @@ -0,0 +1,74 @@ +#include "OpenRGBE131SettingsEntry.h" +#include "ui_OpenRGBE131SettingsEntry.h" + +using namespace Ui; + +OpenRGBE131SettingsEntry::OpenRGBE131SettingsEntry(QWidget *parent) : + QWidget(parent), + ui(new Ui::OpenRGBE131SettingsEntryUi) +{ + ui->setupUi(this); + + ui->TypeComboBox->addItem("Single"); + ui->TypeComboBox->addItem("Linear"); + ui->TypeComboBox->addItem("Matrix"); + + ui->MatrixOrderComboBox->addItem("Horizontal Top Left"); + ui->MatrixOrderComboBox->addItem("Horizontal Top Right"); + ui->MatrixOrderComboBox->addItem("Horizontal Bottom Left"); + ui->MatrixOrderComboBox->addItem("Horizontal Bottom Right"); + ui->MatrixOrderComboBox->addItem("Vertical Top Left"); + ui->MatrixOrderComboBox->addItem("Vertical Top Right"); + ui->MatrixOrderComboBox->addItem("Vertical Bottom Left"); + ui->MatrixOrderComboBox->addItem("Vertical Bottom Right"); + + ui->RGBOrderComboBox->addItem("RGB"); + ui->RGBOrderComboBox->addItem("RBG"); + ui->RGBOrderComboBox->addItem("GRB"); + ui->RGBOrderComboBox->addItem("GBR"); + ui->RGBOrderComboBox->addItem("BRG"); + ui->RGBOrderComboBox->addItem("BGR"); + + HideMatrixSettings(); +} + +OpenRGBE131SettingsEntry::~OpenRGBE131SettingsEntry() +{ + delete ui; +} + +void Ui::OpenRGBE131SettingsEntry::HideMatrixSettings() +{ + ui->MatrixWidthLabel->setDisabled(true); + ui->MatrixWidthEdit->setDisabled(true); + + ui->MatrixHeightLabel->setDisabled(true); + ui->MatrixHeightEdit->setDisabled(true); + + ui->MatrixOrderLabel->setDisabled(true); + ui->MatrixOrderComboBox->setDisabled(true); +} + +void Ui::OpenRGBE131SettingsEntry::ShowMatrixSettings() +{ + ui->MatrixWidthLabel->setDisabled(false); + ui->MatrixWidthEdit->setDisabled(false); + + ui->MatrixHeightLabel->setDisabled(false); + ui->MatrixHeightEdit->setDisabled(false); + + ui->MatrixOrderLabel->setDisabled(false); + ui->MatrixOrderComboBox->setDisabled(false); +} + +void Ui::OpenRGBE131SettingsEntry::on_TypeComboBox_currentIndexChanged(int index) +{ + if(index == 2) + { + ShowMatrixSettings(); + } + else + { + HideMatrixSettings(); + } +} diff --git a/qt/OpenRGBE131SettingsEntry.h b/qt/OpenRGBE131SettingsEntry.h new file mode 100644 index 000000000..5fa856108 --- /dev/null +++ b/qt/OpenRGBE131SettingsEntry.h @@ -0,0 +1,28 @@ +#ifndef OPENRGBE131SETTINGSENTRY_H +#define OPENRGBE131SETTINGSENTRY_H + +#include "ui_OpenRGBE131SettingsEntry.h" +#include + +namespace Ui { +class OpenRGBE131SettingsEntry; +} + +class Ui::OpenRGBE131SettingsEntry : public QWidget +{ + Q_OBJECT + +public: + explicit OpenRGBE131SettingsEntry(QWidget *parent = nullptr); + ~OpenRGBE131SettingsEntry(); + Ui::OpenRGBE131SettingsEntryUi *ui; + +private: + void HideMatrixSettings(); + void ShowMatrixSettings(); + +private slots: + void on_TypeComboBox_currentIndexChanged(int index); +}; + +#endif // OPENRGBE131SETTINGSENTRY_H diff --git a/qt/OpenRGBE131SettingsEntry.ui b/qt/OpenRGBE131SettingsEntry.ui new file mode 100644 index 000000000..9a4b4cdad --- /dev/null +++ b/qt/OpenRGBE131SettingsEntry.ui @@ -0,0 +1,169 @@ + + + OpenRGBE131SettingsEntryUi + + + + 0 + 0 + 531 + 237 + + + + + 0 + 0 + + + + Form + + + + + + + + + + + + + + + + + + + + + Start Channel: + + + + + + + Number of LEDs: + + + + + + + + + + + + + + + + Start Universe: + + + + + + + + + + Name: + + + + + + + Matrix Order: + + + + + + + + + + + + + Matrix Height: + + + + + + + Matrix Width: + + + + + + + Type: + + + + + + + IP (Unicast): + + + + + + + Universe Size: + + + + + + + + + + Keepalive Time: + + + + + + + + + + RGB Order: + + + + + + + + + + + + + NameEdit + IPEdit + StartUniverseEdit + StartChannelEdit + NumLEDsEdit + TypeComboBox + MatrixWidthEdit + MatrixHeightEdit + MatrixOrderComboBox + UniverseSizeEdit + KeepaliveTimeEdit + + + + diff --git a/qt/OpenRGBE131SettingsPage.cpp b/qt/OpenRGBE131SettingsPage.cpp new file mode 100644 index 000000000..b36527553 --- /dev/null +++ b/qt/OpenRGBE131SettingsPage.cpp @@ -0,0 +1,282 @@ +#include "OpenRGBE131SettingsPage.h" +#include "ui_OpenRGBE131SettingsPage.h" +#include "ResourceManager.h" + +using namespace Ui; + +OpenRGBE131SettingsPage::OpenRGBE131SettingsPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::OpenRGBE131SettingsPageUi) +{ + ui->setupUi(this); + + json e131_settings; + + /*-------------------------------------------------*\ + | Get E1.31 settings from settings manager | + \*-------------------------------------------------*/ + e131_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("E131Devices"); + + /*-------------------------------------------------*\ + | If the E1.31 settings contains devices, process | + \*-------------------------------------------------*/ + if(e131_settings.contains("devices")) + { + for(unsigned int device_idx = 0; device_idx < e131_settings["devices"].size(); device_idx++) + { + OpenRGBE131SettingsEntry* entry = new OpenRGBE131SettingsEntry; + + if(e131_settings["devices"][device_idx].contains("name")) + { + entry->ui->NameEdit->setText(QString::fromStdString(e131_settings["devices"][device_idx]["name"])); + } + + if(e131_settings["devices"][device_idx].contains("ip")) + { + entry->ui->IPEdit->setText(QString::fromStdString(e131_settings["devices"][device_idx]["ip"])); + } + + if(e131_settings["devices"][device_idx].contains("start_universe")) + { + entry->ui->StartUniverseEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["start_universe"])); + } + + if(e131_settings["devices"][device_idx].contains("start_channel")) + { + entry->ui->StartChannelEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["start_channel"])); + } + + if(e131_settings["devices"][device_idx].contains("num_leds")) + { + entry->ui->NumLEDsEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["num_leds"])); + } + + if(e131_settings["devices"][device_idx].contains("type")) + { + if(e131_settings["devices"][device_idx]["type"].is_string()) + { + std::string type_val = e131_settings["devices"][device_idx]["type"]; + + if(type_val == "SINGLE") + { + entry->ui->TypeComboBox->setCurrentIndex(0); + } + else if(type_val == "LINEAR") + { + entry->ui->TypeComboBox->setCurrentIndex(1); + } + else if(type_val == "MATRIX") + { + entry->ui->TypeComboBox->setCurrentIndex(2); + } + } + else + { + entry->ui->TypeComboBox->setCurrentIndex(e131_settings["devices"][device_idx]["type"]); + } + } + + if(e131_settings["devices"][device_idx].contains("rgb_order")) + { + if(e131_settings["devices"][device_idx]["rgb_order"].is_string()) + { + std::string rgb_order_val = e131_settings["devices"][device_idx]["rgb_order"]; + + if(rgb_order_val == "RGB") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(0); + } + else if(rgb_order_val == "RBG") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(1); + } + else if(rgb_order_val == "GRB") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(2); + } + else if(rgb_order_val == "GBR") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(3); + } + else if(rgb_order_val == "BRG") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(4); + } + else if(rgb_order_val == "BGR") + { + entry->ui->RGBOrderComboBox->setCurrentIndex(5); + } + } + else + { + entry->ui->RGBOrderComboBox->setCurrentIndex(e131_settings["devices"][device_idx]["rgb_order"]); + } + } + + if(e131_settings["devices"][device_idx].contains("matrix_width")) + { + entry->ui->MatrixWidthEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["matrix_width"])); + } + + if(e131_settings["devices"][device_idx].contains("matrix_height")) + { + entry->ui->MatrixWidthEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["matrix_height"])); + } + + if(e131_settings["devices"][device_idx].contains("matrix_order")) + { + if(e131_settings["devices"][device_idx]["matrix_order"].is_string()) + { + std::string matrix_order_val = e131_settings["devices"][device_idx]["matrix_order"]; + + if(matrix_order_val == "HORIZONTAL_TOP_LEFT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(0); + } + else if(matrix_order_val == "HORIZONTAL_TOP_RIGHT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(1); + } + else if(matrix_order_val == "HORIZONTAL_BOTTOM_LEFT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(2); + } + else if(matrix_order_val == "HORIZONTAL_BOTTOM_RIGHT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(3); + } + else if(matrix_order_val == "VERTICAL_TOP_LEFT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(4); + } + else if(matrix_order_val == "VERTICAL_TOP_RIGHT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(5); + } + else if(matrix_order_val == "VERTICAL_BOTTOM_LEFT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(6); + } + else if(matrix_order_val == "VERTICAL_BOTTOM_RIGHT") + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(7); + } + } + else + { + entry->ui->MatrixOrderComboBox->setCurrentIndex(e131_settings["devices"][device_idx]["matrix_order"]); + } + } + + if(e131_settings["devices"][device_idx].contains("universe_size")) + { + entry->ui->UniverseSizeEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["universe_size"])); + } + + if(e131_settings["devices"][device_idx].contains("keepalive_time")) + { + entry->ui->KeepaliveTimeEdit->setText(QString::number((int)e131_settings["devices"][device_idx]["keepalive_time"])); + } + + entries.push_back(entry); + + QListWidgetItem* item = new QListWidgetItem; + + item->setSizeHint(entry->sizeHint()); + + ui->E131DeviceList->addItem(item); + ui->E131DeviceList->setItemWidget(item, entry); + ui->E131DeviceList->show(); + } + } +} + +OpenRGBE131SettingsPage::~OpenRGBE131SettingsPage() +{ + delete ui; +} + +void Ui::OpenRGBE131SettingsPage::on_AddE131DeviceButton_clicked() +{ + OpenRGBE131SettingsEntry* entry = new OpenRGBE131SettingsEntry; + entries.push_back(entry); + + QListWidgetItem* item = new QListWidgetItem; + + item->setSizeHint(entry->sizeHint()); + + ui->E131DeviceList->addItem(item); + ui->E131DeviceList->setItemWidget(item, entry); + ui->E131DeviceList->show(); +} + +void Ui::OpenRGBE131SettingsPage::on_RemoveE131DeviceButton_clicked() +{ + int cur_row = ui->E131DeviceList->currentRow(); + + if(cur_row < 0) + { + return; + } + + QListWidgetItem* item = ui->E131DeviceList->takeItem(cur_row); + + ui->E131DeviceList->removeItemWidget(item); + delete item; + + delete entries[cur_row]; + entries.erase(entries.begin() + cur_row); +} + +void Ui::OpenRGBE131SettingsPage::on_SaveE131ConfigurationButton_clicked() +{ + json e131_settings; + + /*-------------------------------------------------*\ + | Get E1.31 settings from settings manager | + \*-------------------------------------------------*/ + e131_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("E131Devices"); + + e131_settings["devices"].clear(); + + for(unsigned int device_idx = 0; device_idx < entries.size(); device_idx++) + { + /*-------------------------------------------------*\ + | Required parameters | + \*-------------------------------------------------*/ + e131_settings["devices"][device_idx]["name"] = entries[device_idx]->ui->NameEdit->text().toStdString(); + e131_settings["devices"][device_idx]["start_universe"] = entries[device_idx]->ui->StartUniverseEdit->text().toUInt(); + e131_settings["devices"][device_idx]["start_channel"] = entries[device_idx]->ui->StartChannelEdit->text().toUInt(); + e131_settings["devices"][device_idx]["num_leds"] = entries[device_idx]->ui->NumLEDsEdit->text().toUInt(); + e131_settings["devices"][device_idx]["type"] = entries[device_idx]->ui->TypeComboBox->currentIndex(); + e131_settings["devices"][device_idx]["rgb_order"] = entries[device_idx]->ui->RGBOrderComboBox->currentIndex(); + + /*-------------------------------------------------*\ + | Optional parameters | + \*-------------------------------------------------*/ + if(entries[device_idx]->ui->IPEdit->text() != "") + { + e131_settings["devices"][device_idx]["ip"] = entries[device_idx]->ui->IPEdit->text().toStdString(); + } + + if(e131_settings["devices"][device_idx]["type"] == 2) + { + e131_settings["devices"][device_idx]["matrix_width"] = entries[device_idx]->ui->MatrixWidthEdit->text().toUInt(); + e131_settings["devices"][device_idx]["matrix_height"] = entries[device_idx]->ui->MatrixHeightEdit->text().toUInt(); + e131_settings["devices"][device_idx]["matrix_order"] = entries[device_idx]->ui->MatrixOrderComboBox->currentIndex(); + } + + if(entries[device_idx]->ui->UniverseSizeEdit->text() != "") + { + e131_settings["devices"][device_idx]["universe_size"] = entries[device_idx]->ui->UniverseSizeEdit->text().toUInt(); + } + + if(entries[device_idx]->ui->KeepaliveTimeEdit->text() != "") + { + e131_settings["devices"][device_idx]["keepalive_time"] = entries[device_idx]->ui->KeepaliveTimeEdit->text().toUInt(); + } + } + + ResourceManager::get()->GetSettingsManager()->SetSettings("E131Devices", e131_settings); + ResourceManager::get()->GetSettingsManager()->SaveSettings(); +} diff --git a/qt/OpenRGBE131SettingsPage.h b/qt/OpenRGBE131SettingsPage.h new file mode 100644 index 000000000..3886a657a --- /dev/null +++ b/qt/OpenRGBE131SettingsPage.h @@ -0,0 +1,34 @@ +#ifndef OPENRGBE131SETTINGSPAGE_H +#define OPENRGBE131SETTINGSPAGE_H + +#include "ui_OpenRGBE131SettingsPage.h" +#include + +#include "OpenRGBE131SettingsEntry.h" + +namespace Ui { +class OpenRGBE131SettingsPage; +} + +class Ui::OpenRGBE131SettingsPage : public QWidget +{ + Q_OBJECT + +public: + explicit OpenRGBE131SettingsPage(QWidget *parent = nullptr); + ~OpenRGBE131SettingsPage(); + +private slots: + void on_AddE131DeviceButton_clicked(); + + void on_RemoveE131DeviceButton_clicked(); + + void on_SaveE131ConfigurationButton_clicked(); + +private: + Ui::OpenRGBE131SettingsPageUi *ui; + std::vector entries; + +}; + +#endif // OPENRGBE131SETTINGSPAGE_H diff --git a/qt/OpenRGBE131SettingsPage.ui b/qt/OpenRGBE131SettingsPage.ui new file mode 100644 index 000000000..64ae79934 --- /dev/null +++ b/qt/OpenRGBE131SettingsPage.ui @@ -0,0 +1,45 @@ + + + OpenRGBE131SettingsPageUi + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Add + + + + + + + Remove + + + + + + + Save + + + + + + + + + + +