Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cfc5a12b1 | ||
|
|
6d8fb3348a | ||
|
|
0fd6893ee5 | ||
|
|
60d42b118e | ||
|
|
bb4c56af2d | ||
|
|
67ae1a2078 |
@@ -3,8 +3,10 @@
|
||||
#include "ENESMBusInterface_i2c_smbus.h"
|
||||
#include "ENESMBusInterface_SpectrixS40G.h"
|
||||
#include "LogManager.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_ENESMBus.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include "pci_ids.h"
|
||||
#include <vector>
|
||||
@@ -329,6 +331,22 @@ void DetectENESMBusGPUControllers(i2c_smbus_interface* bus, uint8_t i2c_addr, co
|
||||
}
|
||||
} /* DetectENESMBusGPUControllers() */
|
||||
|
||||
void RegisterENESettings()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create ENESMBusSettings settings prototype |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string ene_smbus_string = "ENESMBusSettings";
|
||||
json ene_smbus_proto;
|
||||
|
||||
ene_smbus_proto["enable_save"]["name"] = "Enable Save";
|
||||
ene_smbus_proto["enable_save"]["type"] = "boolean";
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->RegisterSettingsPrototype(ene_smbus_string, ene_smbus_proto);
|
||||
}
|
||||
|
||||
REGISTER_DYNAMIC_DETECTOR("ENE Devices", RegisterENESettings);
|
||||
|
||||
REGISTER_I2C_DETECTOR("ENE SMBus DRAM", DetectENESMBusDRAMControllers);
|
||||
REGISTER_I2C_DETECTOR("ASUS Aura SMBus Motherboard", DetectENESMBusMotherboardControllers);
|
||||
|
||||
|
||||
@@ -309,6 +309,8 @@ HEADERS +=
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsEntry.h \
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsPage.h \
|
||||
qt/OpenRGBServerInfoPage/OpenRGBServerInfoPage.h \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerEntry.h \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerPage.h \
|
||||
qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h \
|
||||
qt/OpenRGBSoftwareInfoPage/OpenRGBSoftwareInfoPage.h \
|
||||
qt/OpenRGBSupportedDevicesPage/OpenRGBSupportedDevicesPage.h \
|
||||
@@ -912,6 +914,8 @@ SOURCES +=
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsEntry.cpp \
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsPage.cpp \
|
||||
qt/OpenRGBServerInfoPage/OpenRGBServerInfoPage.cpp \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerEntry.cpp \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerPage.cpp \
|
||||
qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp \
|
||||
qt/OpenRGBSoftwareInfoPage/OpenRGBSoftwareInfoPage.cpp \
|
||||
qt/OpenRGBSupportedDevicesPage/OpenRGBSupportedDevicesPage.cpp \
|
||||
@@ -1606,6 +1610,8 @@ FORMS +=
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsEntry.ui \
|
||||
qt/OpenRGBSerialSettingsPage/OpenRGBSerialSettingsPage.ui \
|
||||
qt/OpenRGBServerInfoPage/OpenRGBServerInfoPage.ui \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerEntry.ui \
|
||||
qt/OpenRGBSettingsManagerPage/OpenRGBSettingsManagerPage.ui \
|
||||
qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui \
|
||||
qt/OpenRGBSoftwareInfoPage/OpenRGBSoftwareInfoPage.ui \
|
||||
qt/OpenRGBSupportedDevicesPage/OpenRGBSupportedDevicesPage.ui \
|
||||
|
||||
@@ -110,3 +110,13 @@ void SettingsManager::SaveSettings()
|
||||
settings_file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::RegisterSettingsPrototype(std::string settings_key, json new_prototype)
|
||||
{
|
||||
settings_prototype[settings_key] = new_prototype;
|
||||
}
|
||||
|
||||
json SettingsManager::GetSettingsPrototype()
|
||||
{
|
||||
return(settings_prototype);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
virtual void LoadSettings(const filesystem::path& filename) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
|
||||
virtual void RegisterSettingsPrototype(std::string settings_key, json new_prototype) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~SettingsManagerInterface() {};
|
||||
};
|
||||
@@ -41,6 +43,9 @@ public:
|
||||
void LoadSettings(const filesystem::path& filename) override;
|
||||
void SaveSettings() override;
|
||||
|
||||
void RegisterSettingsPrototype(std::string settings_key, json new_prototype) override;
|
||||
json GetSettingsPrototype();
|
||||
|
||||
private:
|
||||
json settings_data;
|
||||
json settings_prototype;
|
||||
|
||||
@@ -168,14 +168,83 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
||||
setWindowIcon(logo);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set window geometry from config (if available) |
|
||||
| Get Settings Manager pointer |
|
||||
\*-----------------------------------------------------*/
|
||||
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get UserInterface settings |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string ui_string = "UserInterface";
|
||||
json ui_settings;
|
||||
|
||||
ui_settings = settings_manager->GetSettings(ui_string);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create UserInterface settings prototype |
|
||||
\*-----------------------------------------------------*/
|
||||
json ui_settings_proto;
|
||||
|
||||
ui_settings_proto["numerical_labels"]["name"] = "Numerical Labels";
|
||||
ui_settings_proto["numerical_labels"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["disable_key_expansion"]["name"] = "Disable Key Expansion";
|
||||
ui_settings_proto["disable_key_expansion"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["greyscale_tray_icon"]["name"] = "Greyscale Tray Icon";
|
||||
ui_settings_proto["greyscale_tray_icon"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["minimize_on_close"]["name"] = "Minimize On Close";
|
||||
ui_settings_proto["minimize_on_close"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["geometry"]["name"] = "Geometry";
|
||||
ui_settings_proto["geometry"]["type"] = "group";
|
||||
|
||||
ui_settings_proto["geometry"]["load_geometry"]["name"] = "Load Geometry";
|
||||
ui_settings_proto["geometry"]["load_geometry"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["geometry"]["save_on_exit"]["name"] = "Save On Exit";
|
||||
ui_settings_proto["geometry"]["save_on_exit"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["geometry"]["x"]["name"] = "X";
|
||||
ui_settings_proto["geometry"]["x"]["type"] = "integer";
|
||||
|
||||
ui_settings_proto["geometry"]["y"]["name"] = "Y";
|
||||
ui_settings_proto["geometry"]["y"]["type"] = "integer";
|
||||
|
||||
ui_settings_proto["geometry"]["width"]["name"] = "Width";
|
||||
ui_settings_proto["geometry"]["width"]["type"] = "integer";
|
||||
|
||||
ui_settings_proto["geometry"]["height"]["name"] = "Height";
|
||||
ui_settings_proto["geometry"]["height"]["type"] = "integer";
|
||||
|
||||
ui_settings_proto["exit_profile"]["name"] = "Exit Profile";
|
||||
ui_settings_proto["exit_profile"]["type"] = "group";
|
||||
|
||||
ui_settings_proto["exit_profile"]["set_on_exit"]["name"] = "Set On Exit";
|
||||
ui_settings_proto["exit_profile"]["set_on_exit"]["type"] = "boolean";
|
||||
|
||||
ui_settings_proto["exit_profile"]["profile_name"]["name"] = "Profile";
|
||||
ui_settings_proto["exit_profile"]["profile_name"]["type"] = "string";
|
||||
|
||||
settings_manager->RegisterSettingsPrototype(ui_string, ui_settings_proto);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get LogManager settings |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string log_manager_string = "LogManager";
|
||||
json log_manager_settings;
|
||||
log_manager_settings = settings_manager->GetSettings(log_manager_string);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create LogManager settings prototype |
|
||||
\*-----------------------------------------------------*/
|
||||
json log_manager_proto;
|
||||
|
||||
log_manager_proto["log_console"]["name"] = "Enable Log Console";
|
||||
log_manager_proto["log_console"]["type"] = "boolean";
|
||||
|
||||
settings_manager->RegisterSettingsPrototype(log_manager_string, log_manager_proto);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If geometry info doesn't exist, write it to config |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -413,6 +482,11 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
||||
\*-----------------------------------------------------*/
|
||||
AddSettingsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the settings manager page |
|
||||
\*-----------------------------------------------------*/
|
||||
AddSettingsManagerPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the Supported Devices page |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -494,11 +568,6 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
||||
AddI2CToolsPage();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If log console is enabled in settings, enable it |
|
||||
\*-----------------------------------------------------*/
|
||||
json log_manager_settings = settings_manager->GetSettings("LogManager");
|
||||
|
||||
bool log_console_enabled = false;
|
||||
if(log_manager_settings.contains("log_console"))
|
||||
{
|
||||
@@ -716,6 +785,23 @@ void OpenRGBDialog2::AddSettingsPage()
|
||||
connect(this, SIGNAL(ProfileListChanged()), SettingsPage, SLOT(UpdateProfiles()));
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddSettingsManagerPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the SettingsManager page |
|
||||
\*-----------------------------------------------------*/
|
||||
SettingsManagerPage = new OpenRGBSettingsManagerPage();
|
||||
|
||||
ui->SettingsTabBar->addTab(SettingsManagerPage, "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the tab label |
|
||||
\*-----------------------------------------------------*/
|
||||
TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::options, tr("Settings Manager"), (char *)"Settings Manager", (char *)context);
|
||||
|
||||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddDMXSettingsPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "OpenRGBPhilipsWizSettingsPage/OpenRGBPhilipsWizSettingsPage.h"
|
||||
#include "OpenRGBQMKORGBSettingsPage/OpenRGBQMKORGBSettingsPage.h"
|
||||
#include "OpenRGBSerialSettingsPage/OpenRGBSerialSettingsPage.h"
|
||||
#include "OpenRGBSettingsManagerPage/OpenRGBSettingsManagerPage.h"
|
||||
#include "OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.h"
|
||||
#include "OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.h"
|
||||
#include "PluginManager.h"
|
||||
@@ -94,6 +95,7 @@ private:
|
||||
OpenRGBPhilipsWizSettingsPage *PhilipsWizSettingsPage;
|
||||
OpenRGBQMKORGBSettingsPage *QMKORGBSettingsPage;
|
||||
OpenRGBSerialSettingsPage *SerialSettingsPage;
|
||||
OpenRGBSettingsManagerPage *SettingsManagerPage;
|
||||
OpenRGBYeelightSettingsPage *YeelightSettingsPage;
|
||||
OpenRGBNanoleafSettingsPage *NanoleafSettingsPage;
|
||||
|
||||
@@ -114,6 +116,7 @@ private:
|
||||
void AddSoftwareInfoPage();
|
||||
void AddSupportedDevicesPage();
|
||||
void AddSettingsPage();
|
||||
void AddSettingsManagerPage();
|
||||
void AddDMXSettingsPage();
|
||||
void AddE131SettingsPage();
|
||||
void AddElgatoKeyLightSettingsPage();
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
#include "OpenRGBSettingsManagerEntry.h"
|
||||
#include "ui_OpenRGBSettingsManagerEntry.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
#include <QLabel>
|
||||
#include <QSignalMapper>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QCheckBox>
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
class SettingsManagerEntryPointer : public QObject
|
||||
{
|
||||
public:
|
||||
SettingsManagerEntryPointer(json & proto_ref, json & data_ref) : proto(proto_ref), data(data_ref)
|
||||
{
|
||||
QObject();
|
||||
}
|
||||
std::string key;
|
||||
json & proto;
|
||||
json & data;
|
||||
QWidget * widget;
|
||||
};
|
||||
|
||||
OpenRGBSettingsManagerEntry::OpenRGBSettingsManagerEntry(std::string settings_key, json settings_proto, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBSettingsManagerEntryUi)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Store settings key, prototype, and data |
|
||||
\*-----------------------------------------------------*/
|
||||
key = settings_key;
|
||||
proto = settings_proto;
|
||||
data = ResourceManager::get()->GetSettingsManager()->GetSettings(key);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the title of the group to the settings key |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->SettingsGroupBox->setTitle(QString::fromStdString(key));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a vertical layout to hold the settings controls|
|
||||
\*-----------------------------------------------------*/
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
ui->SettingsGroupBox->setLayout(layout);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up a signal mapper to handle settings changes |
|
||||
\*-----------------------------------------------------*/
|
||||
mapper = new QSignalMapper(this);
|
||||
connect(mapper, SIGNAL(mapped(QObject *)), this, SLOT(onSettingChanged(QObject *)));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Loop through all settings in this key |
|
||||
\*-----------------------------------------------------*/
|
||||
for(json::const_iterator it = proto.begin(); it != proto.end(); it++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create widget pointer for this setting |
|
||||
\*-------------------------------------------------*/
|
||||
QWidget* item;
|
||||
|
||||
item = CreateWidget(it.key(), proto, data);
|
||||
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Add widget to the vertical layout |
|
||||
\*-------------------------------------------------*/
|
||||
layout->addWidget(item);
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBSettingsManagerEntry::~OpenRGBSettingsManagerEntry()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QWidget * OpenRGBSettingsManagerEntry::CreateWidget(std::string key, json & proto, json & data)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Gather information about this setting |
|
||||
\*-------------------------------------------------*/
|
||||
std::string name = proto[key]["name"];
|
||||
std::string type = proto[key]["type"];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create widget pointer for this setting |
|
||||
\*-------------------------------------------------*/
|
||||
QWidget* item;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create settings manager entry pointer to map |
|
||||
| settings widget events to their keys |
|
||||
\*-------------------------------------------------*/
|
||||
SettingsManagerEntryPointer * new_arg = new SettingsManagerEntryPointer(proto, data);
|
||||
new_arg->key = key;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create widgets for group settings |
|
||||
| This is a special case that recursively calls |
|
||||
| CreateWidget to create nested groups of settings |
|
||||
| under a nested JSON object |
|
||||
\*-------------------------------------------------*/
|
||||
if(type == "group")
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Group settings use a groupbox widget |
|
||||
\*---------------------------------------------*/
|
||||
item = new QGroupBox;
|
||||
|
||||
((QGroupBox*)item)->setTitle(QString::fromStdString(name));
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create a vertical layout to hold the settings |
|
||||
| controls |
|
||||
\*---------------------------------------------*/
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
((QGroupBox*)item)->setLayout(layout);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Loop through all settings in this key |
|
||||
\*---------------------------------------------*/
|
||||
for(json::const_iterator it = proto[key].begin(); it != proto[key].end(); it++)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Skip reserved keys |
|
||||
\*-----------------------------------------*/
|
||||
if(it.key() == "name" || it.key() == "type")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Create widget pointer for this setting |
|
||||
\*-----------------------------------------*/
|
||||
QWidget * sub_item;
|
||||
|
||||
sub_item = CreateWidget(it.key(), proto[key], data[key]);
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Add widget to the vertical layout |
|
||||
\*-----------------------------------------*/
|
||||
layout->addWidget(sub_item);
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------*\
|
||||
| Create widgets for boolean settings |
|
||||
\*-------------------------------------------------*/
|
||||
else if(type == "boolean")
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Boolean settings use a checkbox widget |
|
||||
\*---------------------------------------------*/
|
||||
item = new QCheckBox;
|
||||
new_arg->widget = item;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the checkbox label to the setting name |
|
||||
\*---------------------------------------------*/
|
||||
((QCheckBox*)item)->setText(QString::fromStdString(name));
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the checkbox state based on the current |
|
||||
| value of the setting |
|
||||
\*---------------------------------------------*/
|
||||
if(data.contains(key))
|
||||
{
|
||||
((QCheckBox*)item)->setChecked(data[key]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Connect widget to signal mapper to handle |
|
||||
| changes to this setting |
|
||||
\*---------------------------------------------*/
|
||||
connect(item, SIGNAL(clicked()), mapper, SLOT(map()));
|
||||
mapper->setMapping(item, new_arg);
|
||||
}
|
||||
/*-------------------------------------------------*\
|
||||
| Create widgets for integer settings |
|
||||
\*-------------------------------------------------*/
|
||||
else if(type == "integer")
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Create a widget to hold the layout |
|
||||
\*---------------------------------------------*/
|
||||
item = new QWidget;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create a horizontal layout to hold the |
|
||||
| settings controls |
|
||||
\*---------------------------------------------*/
|
||||
QHBoxLayout * layout = new QHBoxLayout;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Integer settings use both a label widget and |
|
||||
| a line edit widget in a horizontal layout |
|
||||
\*---------------------------------------------*/
|
||||
QLabel * label = new QLabel;
|
||||
QLineEdit * edit = new QLineEdit;
|
||||
new_arg->widget = edit;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the line edit label to the setting name |
|
||||
\*---------------------------------------------*/
|
||||
((QLabel*)label)->setText(QString::fromStdString(name));
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the checkbox state based on the current |
|
||||
| value of the setting |
|
||||
\*---------------------------------------------*/
|
||||
if(data.contains(key))
|
||||
{
|
||||
int value = data[key];
|
||||
((QLineEdit*)edit)->setText(QString::number(value));
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Add widgets to the horizontal layout |
|
||||
\*---------------------------------------------*/
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(edit);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Add layout to top level widget |
|
||||
\*---------------------------------------------*/
|
||||
item->setLayout(layout);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Connect widget to signal mapper to handle |
|
||||
| changes to this setting |
|
||||
\*---------------------------------------------*/
|
||||
connect(edit, SIGNAL(editingFinished()), mapper, SLOT(map()));
|
||||
mapper->setMapping(edit, new_arg);
|
||||
}
|
||||
/*-------------------------------------------------*\
|
||||
| Create widgets for string settings |
|
||||
\*-------------------------------------------------*/
|
||||
else if(type == "string")
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Create a widget to hold the layout |
|
||||
\*---------------------------------------------*/
|
||||
item = new QWidget;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create a horizontal layout to hold the |
|
||||
| settings controls |
|
||||
\*---------------------------------------------*/
|
||||
QHBoxLayout * layout = new QHBoxLayout;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| String settings use both a label widget and |
|
||||
| a line edit widget in a horizontal layout |
|
||||
\*---------------------------------------------*/
|
||||
QLabel * label = new QLabel;
|
||||
QLineEdit * edit = new QLineEdit;
|
||||
new_arg->widget = edit;
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the line edit label to the setting name |
|
||||
\*---------------------------------------------*/
|
||||
((QLabel*)label)->setText(QString::fromStdString(name));
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Set the checkbox state based on the current |
|
||||
| value of the setting |
|
||||
\*---------------------------------------------*/
|
||||
if(data.contains(key))
|
||||
{
|
||||
((QLineEdit*)edit)->setText(QString::fromStdString(data[key]));
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Add widgets to the horizontal layout |
|
||||
\*---------------------------------------------*/
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(edit);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Add layout to top level widget |
|
||||
\*---------------------------------------------*/
|
||||
item->setLayout(layout);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Connect widget to signal mapper to handle |
|
||||
| changes to this setting |
|
||||
\*---------------------------------------------*/
|
||||
connect(edit, SIGNAL(editingFinished()), mapper, SLOT(map()));
|
||||
mapper->setMapping(edit, new_arg);
|
||||
}
|
||||
|
||||
return(item);
|
||||
}
|
||||
|
||||
void OpenRGBSettingsManagerEntry::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBSettingsManagerEntry::onSettingChanged(QObject * arg)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Read information from argument |
|
||||
\*-----------------------------------------------------*/
|
||||
SettingsManagerEntryPointer * setting = (SettingsManagerEntryPointer *)arg;
|
||||
std::string item_key = setting->key;
|
||||
std::string type = setting->proto[item_key]["type"];
|
||||
|
||||
printf("updating key %s\r\n", item_key.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Handle boolean settings changes |
|
||||
\*-----------------------------------------------------*/
|
||||
if(type == "boolean")
|
||||
{
|
||||
bool value = ((QCheckBox *)setting->widget)->isChecked();
|
||||
|
||||
setting->data[item_key] = value;
|
||||
}
|
||||
else if(type == "integer")
|
||||
{
|
||||
int value = ((QLineEdit *)setting->widget)->text().toInt();
|
||||
|
||||
setting->data[item_key] = value;
|
||||
}
|
||||
else if(type == "string")
|
||||
{
|
||||
std::string value = ((QLineEdit *)setting->widget)->text().toStdString();
|
||||
|
||||
setting->data[item_key] = value;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set and save the updated settings |
|
||||
\*-----------------------------------------------------*/
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings(key, data);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef OPENRGBSETTINGSMANAGERENTRY_H
|
||||
#define OPENRGBSETTINGSMANAGERENTRY_H
|
||||
|
||||
#include "ui_OpenRGBSettingsManagerEntry.h"
|
||||
#include <QWidget>
|
||||
#include <QSignalMapper>
|
||||
#include "ResourceManager.h"
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBSettingsManagerEntry;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBSettingsManagerEntry : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBSettingsManagerEntry(std::string settings_key, json settings_proto, QWidget *parent = nullptr);
|
||||
~OpenRGBSettingsManagerEntry();
|
||||
Ui::OpenRGBSettingsManagerEntryUi *ui;
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void onSettingChanged(QObject * arg);
|
||||
|
||||
private:
|
||||
std::string key;
|
||||
json data;
|
||||
json proto;
|
||||
QSignalMapper * mapper;
|
||||
|
||||
QWidget * CreateWidget(std::string key, json & proto, json & data);
|
||||
};
|
||||
|
||||
#endif // OPENRGBSETTINGSMANAGERENTRY_H
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBSettingsManagerEntryUi</class>
|
||||
<widget class="QWidget" name="OpenRGBSettingsManagerEntryUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>199</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>E131 settings entry</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="SettingsGroupBox">
|
||||
<property name="title">
|
||||
<string>SettingsKey</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "OpenRGBSettingsManagerPage.h"
|
||||
#include "ui_OpenRGBSettingsManagerPage.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBSettingsManagerPage::OpenRGBSettingsManagerPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBSettingsManagerPageUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
json settings_prototype = ResourceManager::get()->GetSettingsManager()->GetSettingsPrototype();
|
||||
|
||||
for(json::const_iterator it = settings_prototype.begin(); it != settings_prototype.end(); it++)
|
||||
{
|
||||
OpenRGBSettingsManagerEntry* new_entry = new OpenRGBSettingsManagerEntry(it.key(), settings_prototype[it.key()]);
|
||||
|
||||
entries.push_back(new_entry);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(new_entry->sizeHint());
|
||||
|
||||
ui->SettingsEntryList->addItem(item);
|
||||
ui->SettingsEntryList->setItemWidget(item, new_entry);
|
||||
ui->SettingsEntryList->show();
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBSettingsManagerPage::~OpenRGBSettingsManagerPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBSettingsManagerPage::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef OPENRGBSETTINGSMANAGERPAGE_H
|
||||
#define OPENRGBSETTINGSMANAGERPAGE_H
|
||||
|
||||
#include "ui_OpenRGBSettingsManagerPage.h"
|
||||
#include <QWidget>
|
||||
|
||||
#include "OpenRGBSettingsManagerEntry.h"
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBSettingsManagerPage;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBSettingsManagerPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBSettingsManagerPage(QWidget *parent = nullptr);
|
||||
~OpenRGBSettingsManagerPage();
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
Ui::OpenRGBSettingsManagerPageUi* ui;
|
||||
std::vector<OpenRGBSettingsManagerEntry*> entries;
|
||||
|
||||
};
|
||||
|
||||
#endif // OPENRGBSETTINGSMANAGERPAGE_H
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBSettingsManagerPageUi</class>
|
||||
<widget class="QWidget" name="OpenRGBSettingsManagerPageUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>E131 settings page</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="SettingsEntryList">
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user