diff --git a/OpenRGB.pro b/OpenRGB.pro index 0b308bb9..3eebd5e1 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -117,6 +117,7 @@ HEADERS += SettingsManager.h \ Detector.h \ DeviceDetector.h \ + qt/DetectorTableModel.h \ qt/OpenRGBClientInfoPage.h \ qt/OpenRGBDeviceInfoPage.h \ qt/OpenRGBDevicePage.h \ @@ -130,6 +131,7 @@ HEADERS += qt/OpenRGBProfileSaveDialog.h \ qt/OpenRGBServerInfoPage.h \ qt/OpenRGBSoftwareInfoPage.h \ + qt/OpenRGBSupportedDevicesPage.h \ qt/OpenRGBSystemInfoPage.h \ qt/OpenRGBZoneResizeDialog.h \ serial_port/find_usb_serial_port.h \ @@ -290,6 +292,7 @@ SOURCES += ProfileManager.cpp \ ResourceManager.cpp \ SettingsManager.cpp \ + qt/DetectorTableModel.cpp \ qt/OpenRGBClientInfoPage.cpp \ qt/OpenRGBDeviceInfoPage.cpp \ qt/OpenRGBDevicePage.cpp \ @@ -302,6 +305,7 @@ SOURCES += qt/OpenRGBProfileSaveDialog.cpp \ qt/OpenRGBServerInfoPage.cpp \ qt/OpenRGBSoftwareInfoPage.cpp \ + qt/OpenRGBSupportedDevicesPage.cpp \ qt/OpenRGBSystemInfoPage.cpp \ qt/OpenRGBZoneResizeDialog.cpp \ qt/hsv.cpp \ @@ -510,6 +514,7 @@ FORMS += qt/OpenRGBProfileSaveDialog.ui \ qt/OpenRGBServerInfoPage.ui \ qt/OpenRGBSoftwareInfoPage.ui \ + qt/OpenRGBSupportedDevicesPage.ui \ qt/OpenRGBSystemInfoPage.ui \ qt/OpenRGBZoneResizeDialog.ui \ diff --git a/qt/DetectorTableModel.cpp b/qt/DetectorTableModel.cpp new file mode 100644 index 00000000..11eec08d --- /dev/null +++ b/qt/DetectorTableModel.cpp @@ -0,0 +1,147 @@ +#include "DetectorTableModel.h" + +DetectorTableModel::DetectorTableModel(QObject* parent) : QAbstractTableModel(parent) +{ + detectors.clear(); + + /*-----------------------------------------------------*\ + | Read the detector list from the settings manager | + \*-----------------------------------------------------*/ + json settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Detectors"); + + if(settings.contains("detectors")) + { + for(json::const_iterator it = settings["detectors"].begin(); it != settings["detectors"].end(); it++) + { + DetectorTableValue new_entry; + + new_entry.key = it.key(); + new_entry.value = it.value(); + + detectors.push_back(new_entry); + } + } + + /*-----------------------------------------------------*\ + | If settings contains the detectors list, fill in rows | + \*-----------------------------------------------------*/ + beginInsertRows(QModelIndex(), 0, detectors.size()); + endInsertRows(); +} + +int DetectorTableModel::columnCount(const QModelIndex&) const +{ + /*-----------------------------------------------------*\ + | The table has two columns - detector name and enable | + \*-----------------------------------------------------*/ + return 2; +} + +int DetectorTableModel::rowCount(const QModelIndex&) const +{ + /*-----------------------------------------------------*\ + | The number of rows is equal to the number of detectors| + \*-----------------------------------------------------*/ + return detectors.size(); +} + +QVariant DetectorTableModel::data(const QModelIndex& index, int role) const +{ + switch(role) + { + /*-----------------------------------------------------*\ + | Column 0 is the detector name, 1 is the enable flag | + \*-----------------------------------------------------*/ + case Qt::DisplayRole: + switch(index.column()) + { + case 0: + return detectors[index.row()].key.c_str(); + case 1: + return detectors[index.row()].value; + } + return QVariant(); + + case Qt::CheckStateRole: + switch(index.column()) + { + case 1: + return 2 * detectors[index.row()].value; + } + return QVariant(); + } + return QVariant(); +} + +bool DetectorTableModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + /*-----------------------------------------------------*\ + | Update detector value for column 1 | + \*-----------------------------------------------------*/ + if(index.column() == 1 && role == Qt::CheckStateRole) + { + detectors[index.row()].value = value.toBool(); + emit dataChanged(index, index); + } + return false; +} + +QVariant DetectorTableModel::headerData(int index, Qt::Orientation orientation, int role) const +{ + if(role == Qt::DisplayRole) + { + switch(orientation) + { + case Qt::Vertical: + return index + 1; + + case Qt::Horizontal: + switch(index) + { + case 0: + return "Name"; + case 1: + return "Enabled"; + } + } + } + return QVariant(); +} + +Qt::ItemFlags DetectorTableModel::flags(const QModelIndex& index) const +{ + Qt::ItemFlags fl = Qt::ItemIsEnabled; + + if(index.column() == 1) + { + fl |= Qt::ItemIsUserCheckable; + } + + return fl; +} + +void DetectorTableModel::applySettings() +{ + /*-----------------------------------------------------*\ + | Read the detector list from the settings manager | + \*-----------------------------------------------------*/ + json settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Detectors"); + + /*-----------------------------------------------------*\ + | Loop through all detectors in the list and update the | + | value in the settings | + \*-----------------------------------------------------*/ + if(settings.contains("detectors")) + { + for(unsigned int detector_idx = 0; detector_idx < detectors.size(); detector_idx++) + { + settings["detectors"][detectors[detector_idx].key] = detectors[detector_idx].value; + } + } + + /*-----------------------------------------------------*\ + | Set and save the settings | + \*-----------------------------------------------------*/ + ResourceManager::get()->GetSettingsManager()->SetSettings("Detectors", settings); + ResourceManager::get()->GetSettingsManager()->SaveSettings(); +} diff --git a/qt/DetectorTableModel.h b/qt/DetectorTableModel.h new file mode 100644 index 00000000..c82a598f --- /dev/null +++ b/qt/DetectorTableModel.h @@ -0,0 +1,33 @@ +#ifndef DETECTORTABLEMODEL_H +#define DETECTORTABLEMODEL_H + +#include +#include "ResourceManager.h" + +typedef struct +{ + std::string key; + bool value; +} DetectorTableValue; + +class DetectorTableModel : public QAbstractTableModel +{ + Q_OBJECT + +private: + std::vector detectors; + +public: + DetectorTableModel(QObject *parent = nullptr); + int columnCount(const QModelIndex&) const override; + int rowCount(const QModelIndex&) const override; + QVariant data(const QModelIndex& index, int role) const override; + bool setData(const QModelIndex& index, const QVariant&, int role) override; + QVariant headerData(int index, Qt::Orientation orientation, int role) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; + +public slots: + void applySettings(); +}; + +#endif // DETECTORTABLEMODEL_H diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index bf07571f..c609eb70 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -260,21 +260,26 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op \*-----------------------------------------------------*/ UpdateDevicesList(); - /*-----------------------------------------------------*\ - | Add Server Tab | - \*-----------------------------------------------------*/ - AddServerTab(); - /*-----------------------------------------------------*\ | Add Client Tab | \*-----------------------------------------------------*/ AddClientTab(); + /*-----------------------------------------------------*\ + | Add Server Tab | + \*-----------------------------------------------------*/ + AddServerTab(); + /*-----------------------------------------------------*\ | Add the Software Info page | \*-----------------------------------------------------*/ AddSoftwareInfoPage(); + /*-----------------------------------------------------*\ + | Add the upported Devices page | + \*-----------------------------------------------------*/ + AddSupportedDevicesPage(); + /*-----------------------------------------------------*\ | Add the SMBus Tools page if enabled | \*-----------------------------------------------------*/ @@ -324,6 +329,35 @@ void OpenRGBDialog2::AddSoftwareInfoPage() ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel); } +void OpenRGBDialog2::AddSupportedDevicesPage() +{ + /*-----------------------------------------------------*\ + | Create the Supported Devices page | + \*-----------------------------------------------------*/ + SupportedPage = new OpenRGBSupportedDevicesPage(); + + ui->SettingsTabBar->addTab(SupportedPage, ""); + + QString SupportedLabelString = "
Supported Devices
"; + + QLabel *SupportedTabLabel = new QLabel(); + SupportedTabLabel->setText(SupportedLabelString); + SupportedTabLabel->setIndent(20); + if(IsDarkTheme()) + { + SupportedTabLabel->setGeometry(0, 25, 200, 50); + } + else + { + SupportedTabLabel->setGeometry(0, 0, 200, 25); + } + + ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SupportedTabLabel); +} + void OpenRGBDialog2::AddI2CToolsPage() { ShowI2CTools = true; @@ -365,7 +399,7 @@ void OpenRGBDialog2::AddClientTab() if(ClientInfoPage == NULL) { ClientInfoPage = new OpenRGBClientInfoPage(); - ui->MainTabBar->addTab(ClientInfoPage, "SDK Client"); + ui->MainTabBar->insertTab(2, ClientInfoPage, "SDK Client"); /*-----------------------------------------------------*\ | Connect the page's Set All button to the Set All slot | @@ -394,7 +428,7 @@ void OpenRGBDialog2::AddServerTab() | Add server information tab if there is a server | \*-----------------------------------------------------*/ OpenRGBServerInfoPage *ServerInfoPage = new OpenRGBServerInfoPage(ResourceManager::get()->GetServer()); - ui->MainTabBar->addTab(ServerInfoPage, "SDK Server"); + ui->MainTabBar->insertTab(2, ServerInfoPage, "SDK Server"); } void OpenRGBDialog2::ClearDevicesList() @@ -426,7 +460,7 @@ void OpenRGBDialog2::UpdateDevicesList() \*-----------------------------------------------------*/ bool found = false; - for(unsigned int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++) + for(int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++) { OpenRGBDevicePage* page = (OpenRGBDevicePage*) ui->DevicesTabBar->widget(tab_idx); @@ -501,7 +535,7 @@ void OpenRGBDialog2::UpdateDevicesList() \*-----------------------------------------------------*/ found = false; - for(unsigned int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++) + for(int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++) { /*-----------------------------------------------------*\ | If type is a device info page, check it | @@ -581,7 +615,7 @@ void OpenRGBDialog2::UpdateDevicesList() | Remove all remaining device information tabs, leaving | | other information tabs alone | \*-----------------------------------------------------*/ - for(unsigned int tab_idx = controllers.size(); tab_idx < ui->InformationTabBar->count(); tab_idx++) + for(int tab_idx = controllers.size(); tab_idx < ui->InformationTabBar->count(); tab_idx++) { std::string type_str = ui->InformationTabBar->widget(tab_idx)->metaObject()->className(); if(type_str == "Ui::OpenRGBDeviceInfoPage") diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 650e7ff9..5f528caf 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -6,6 +6,7 @@ #include "OpenRGBClientInfoPage.h" #include "OpenRGBSoftwareInfoPage.h" #include "OpenRGBSystemInfoPage.h" +#include "OpenRGBSupportedDevicesPage.h" #include #include "i2c_smbus.h" @@ -48,6 +49,7 @@ private: OpenRGBClientInfoPage *ClientInfoPage; OpenRGBSystemInfoPage *SMBusToolsPage; OpenRGBSoftwareInfoPage *SoftInfoPage; + OpenRGBSupportedDevicesPage *SupportedPage; bool ShowI2CTools = false; @@ -63,6 +65,7 @@ private: Ui::OpenRGBDialog2Ui *ui; void AddSoftwareInfoPage(); + void AddSupportedDevicesPage(); void ClearDevicesList(); void UpdateDevicesList(); diff --git a/qt/OpenRGBDialog2.ui b/qt/OpenRGBDialog2.ui index c5b982d6..120d6b6e 100644 --- a/qt/OpenRGBDialog2.ui +++ b/qt/OpenRGBDialog2.ui @@ -60,6 +60,23 @@ + + + Settings + + + + + + QTabWidget::West + + + -1 + + + + + diff --git a/qt/OpenRGBSupportedDevicesPage.cpp b/qt/OpenRGBSupportedDevicesPage.cpp new file mode 100644 index 00000000..cfc0f6f1 --- /dev/null +++ b/qt/OpenRGBSupportedDevicesPage.cpp @@ -0,0 +1,49 @@ +#include "OpenRGBSupportedDevicesPage.h" +#include "ui_OpenRGBSupportedDevicesPage.h" + +using namespace Ui; + +OpenRGBSupportedDevicesPage::OpenRGBSupportedDevicesPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::OpenRGBSupportedDevicesPageUi) +{ + ui->setupUi(this); + + /*-----------------------------------------------------*\ + | Create a detector table model and a sort model and | + | set them | + \*-----------------------------------------------------*/ + detectorTableModel = new DetectorTableModel; + detectorSortModel = new QSortFilterProxyModel; + + detectorSortModel->setSourceModel(detectorTableModel); + ui->SupportedDevicesTable->setModel(detectorSortModel); + + /*-----------------------------------------------------*\ + | Disable header, enable sorting, and sort in ascending | + | order | + \*-----------------------------------------------------*/ + ui->SupportedDevicesTable->verticalHeader()->setVisible(0); + ui->SupportedDevicesTable->setSortingEnabled(true); + ui->SupportedDevicesTable->sortByColumn(0, Qt::AscendingOrder); + + /*-----------------------------------------------------*\ + | Resize columns to fit the contents | + \*-----------------------------------------------------*/ + ui->SupportedDevicesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); +} + +OpenRGBSupportedDevicesPage::~OpenRGBSupportedDevicesPage() +{ + delete ui; +} + +void OpenRGBSupportedDevicesPage::on_SaveButton_clicked() +{ + detectorTableModel->applySettings(); +} + +void OpenRGBSupportedDevicesPage::on_Filter_textChanged(const QString &arg1) +{ + detectorSortModel->setFilterRegExp(QRegExp(arg1, Qt::CaseInsensitive)); +} diff --git a/qt/OpenRGBSupportedDevicesPage.h b/qt/OpenRGBSupportedDevicesPage.h new file mode 100644 index 00000000..2cb826f9 --- /dev/null +++ b/qt/OpenRGBSupportedDevicesPage.h @@ -0,0 +1,32 @@ +#ifndef SUPPORTEDDEVICESPAGE_H +#define SUPPORTEDDEVICESPAGE_H + +#include "DetectorTableModel.h" +#include "ui_OpenRGBSupportedDevicesPage.h" +#include +#include + +namespace Ui { +class OpenRGBSupportedDevicesPage; +} + +class Ui::OpenRGBSupportedDevicesPage : public QWidget +{ + Q_OBJECT + +public: + explicit OpenRGBSupportedDevicesPage(QWidget *parent = nullptr); + ~OpenRGBSupportedDevicesPage(); + DetectorTableModel* detectorTableModel; + QSortFilterProxyModel* detectorSortModel; + +private slots: + void on_SaveButton_clicked(); + + void on_Filter_textChanged(const QString &arg1); + +private: + Ui::OpenRGBSupportedDevicesPageUi *ui; +}; + +#endif // SUPPORTEDDEVICESPAGE_H diff --git a/qt/OpenRGBSupportedDevicesPage.ui b/qt/OpenRGBSupportedDevicesPage.ui new file mode 100644 index 00000000..162eee2c --- /dev/null +++ b/qt/OpenRGBSupportedDevicesPage.ui @@ -0,0 +1,45 @@ + + + OpenRGBSupportedDevicesPageUi + + + + 0 + 0 + 400 + 300 + + + + Supported devices + + + + + + + + Filter: + + + + + + + + + + + + + + + Apply changes + + + + + + + +