Rework Debug controller and add manual settings entry for it, also remove graying out the settings save button as sometimes it prevents saving changes

This commit is contained in:
Adam Honse 2025-07-30 19:50:53 -05:00
parent a667bd456c
commit 43b97bca75
7 changed files with 919 additions and 716 deletions

View file

@ -0,0 +1,145 @@
/*---------------------------------------------------------*\
| DebugSettingsEntry.cpp |
| |
| User interface for OpenRGB Debug settings entry |
| |
| Adam Honse <calcprogrammer1@gmail.com> 30 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "DebugSettingsEntry.h"
#include "ui_DebugSettingsEntry.h"
#include "ManualDevicesTypeManager.h"
#include "nlohmann/json.hpp"
using json = nlohmann::json;
#define NUM_TYPES 6
const std::string types[] =
{
"motherboard",
"dram",
"gpu",
"keyboard",
"mouse",
"argb"
};
DebugSettingsEntry::DebugSettingsEntry(QWidget *parent) :
BaseManualDeviceEntry(parent),
ui(new Ui::DebugSettingsEntry)
{
ui->setupUi(this);
ui->TypeComboBox->addItem("motherboard");
ui->TypeComboBox->addItem("dram");
ui->TypeComboBox->addItem("gpu");
ui->TypeComboBox->addItem("keyboard");
ui->TypeComboBox->addItem("mouse");
ui->TypeComboBox->addItem("argb");
ui->LayoutComboBox->addItem("Default");
ui->LayoutComboBox->addItem("ANSI QWERTY");
ui->LayoutComboBox->addItem("ISO QWERTY");
ui->LayoutComboBox->addItem("ISO QWERTZ");
ui->LayoutComboBox->addItem("ISO AZERTY");
ui->LayoutComboBox->addItem("JIS");
}
DebugSettingsEntry::~DebugSettingsEntry()
{
delete ui;
}
void DebugSettingsEntry::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
void DebugSettingsEntry::loadFromSettings(const json& data)
{
if(data.contains("name"))
{
ui->NameEdit->setText(QString::fromStdString(data["name"]));
}
if(data.contains("type"))
{
for(unsigned int type_idx = 0; type_idx < NUM_TYPES; type_idx++)
{
if(data["type"] == types[type_idx])
{
ui->TypeComboBox->setCurrentIndex(type_idx);
break;
}
}
}
if(data.contains("layout"))
{
ui->LayoutComboBox->setCurrentIndex(data["layout"]);
}
if(data.contains("single"))
{
ui->SingleCheckBox->setChecked(data["single"]);
}
if(data.contains("linear"))
{
ui->LinearCheckBox->setChecked(data["linear"]);
}
if(data.contains("resizable"))
{
ui->ResizableCheckBox->setChecked(data["resizable"]);
}
if(data.contains("keyboard"))
{
ui->KeyboardCheckBox->setChecked(data["keyboard"]);
}
if(data.contains("underglow"))
{
ui->UnderglowCheckBox->setChecked(data["underglow"]);
}
}
json DebugSettingsEntry::saveSettings()
{
json result;
result["name"] = ui->NameEdit->text().toStdString();
result["type"] = types[ui->TypeComboBox->currentIndex()];
result["layout"] = ui->LayoutComboBox->currentIndex();
result["single"] = ui->SingleCheckBox->isChecked();
result["linear"] = ui->LinearCheckBox->isChecked();
result["resizable"] = ui->ResizableCheckBox->isChecked();
result["keyboard"] = ui->KeyboardCheckBox->isChecked();
result["underglow"] = ui->UnderglowCheckBox->isChecked();
return result;
}
bool DebugSettingsEntry::isDataValid()
{
return true;
}
static BaseManualDeviceEntry* SpawnDebugEntry(const json& data)
{
DebugSettingsEntry* entry = new DebugSettingsEntry;
entry->loadFromSettings(data);
return entry;
}
static const char* DebugDeviceName = QT_TRANSLATE_NOOP("ManualDevice", "Debug Device");
REGISTER_MANUAL_DEVICE_TYPE(DebugDeviceName, "DebugDevices", SpawnDebugEntry);

View file

@ -0,0 +1,37 @@
/*---------------------------------------------------------*\
| DebugSettingsEntry.h |
| |
| User interface for OpenRGB Debug settings entry |
| |
| Adam Honse <calcprogrammer1@gmail.com> 30 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include "BaseManualDeviceEntry.h"
namespace Ui
{
class DebugSettingsEntry;
}
class DebugSettingsEntry : public BaseManualDeviceEntry
{
Q_OBJECT
public:
explicit DebugSettingsEntry(QWidget *parent = nullptr);
~DebugSettingsEntry();
void loadFromSettings(const json& data);
json saveSettings() override;
bool isDataValid() override;
private:
Ui::DebugSettingsEntry *ui;
private slots:
void changeEvent(QEvent *event) override;
};

View file

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DebugSettingsEntry</class>
<widget class="QWidget" name="DebugSettingsEntry">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>293</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true">Debug Settings Entry</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Debug Device</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="TypeLabel">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="NameEdit">
<property name="placeholderText">
<string>Device Name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="TypeComboBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_Zones">
<property name="title">
<string>Zones</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QCheckBox" name="KeyboardCheckBox">
<property name="text">
<string>Keyboard</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="LinearCheckBox">
<property name="text">
<string>Linear</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="SingleCheckBox">
<property name="text">
<string>Single</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="ResizableCheckBox">
<property name="text">
<string>Resizable</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="UnderglowCheckBox">
<property name="text">
<string>Underglow</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="NameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LayoutLabel">
<property name="text">
<string>Layout:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="LayoutComboBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -184,7 +184,6 @@ void ManualDevicesSettingsPage::clearList()
void ManualDevicesSettingsPage::setUnsavedChanges(bool v)
{
unsavedChanges = v;
ui->saveConfigurationButton->setEnabled(v && checkValidToSave());
if(v)
{