Skip to content

Commit 8a88573

Browse files
k1-801CalcProgrammer1
authored andcommitted
Add settings page to enable and disable devices
Commits squashed and amended to read information only from settings manager by Adam Honse <calcprogrammer1@gmail.com>
1 parent a90edce commit 8a88573

9 files changed

Lines changed: 374 additions & 9 deletions

OpenRGB.pro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ HEADERS +=
117117
SettingsManager.h \
118118
Detector.h \
119119
DeviceDetector.h \
120+
qt/DetectorTableModel.h \
120121
qt/OpenRGBClientInfoPage.h \
121122
qt/OpenRGBDeviceInfoPage.h \
122123
qt/OpenRGBDevicePage.h \
@@ -130,6 +131,7 @@ HEADERS +=
130131
qt/OpenRGBProfileSaveDialog.h \
131132
qt/OpenRGBServerInfoPage.h \
132133
qt/OpenRGBSoftwareInfoPage.h \
134+
qt/OpenRGBSupportedDevicesPage.h \
133135
qt/OpenRGBSystemInfoPage.h \
134136
qt/OpenRGBZoneResizeDialog.h \
135137
serial_port/find_usb_serial_port.h \
@@ -290,6 +292,7 @@ SOURCES +=
290292
ProfileManager.cpp \
291293
ResourceManager.cpp \
292294
SettingsManager.cpp \
295+
qt/DetectorTableModel.cpp \
293296
qt/OpenRGBClientInfoPage.cpp \
294297
qt/OpenRGBDeviceInfoPage.cpp \
295298
qt/OpenRGBDevicePage.cpp \
@@ -302,6 +305,7 @@ SOURCES +=
302305
qt/OpenRGBProfileSaveDialog.cpp \
303306
qt/OpenRGBServerInfoPage.cpp \
304307
qt/OpenRGBSoftwareInfoPage.cpp \
308+
qt/OpenRGBSupportedDevicesPage.cpp \
305309
qt/OpenRGBSystemInfoPage.cpp \
306310
qt/OpenRGBZoneResizeDialog.cpp \
307311
qt/hsv.cpp \
@@ -510,6 +514,7 @@ FORMS +=
510514
qt/OpenRGBProfileSaveDialog.ui \
511515
qt/OpenRGBServerInfoPage.ui \
512516
qt/OpenRGBSoftwareInfoPage.ui \
517+
qt/OpenRGBSupportedDevicesPage.ui \
513518
qt/OpenRGBSystemInfoPage.ui \
514519
qt/OpenRGBZoneResizeDialog.ui \
515520

qt/DetectorTableModel.cpp

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include "DetectorTableModel.h"
2+
3+
DetectorTableModel::DetectorTableModel(QObject* parent) : QAbstractTableModel(parent)
4+
{
5+
detectors.clear();
6+
7+
/*-----------------------------------------------------*\
8+
| Read the detector list from the settings manager |
9+
\*-----------------------------------------------------*/
10+
json settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Detectors");
11+
12+
if(settings.contains("detectors"))
13+
{
14+
for(json::const_iterator it = settings["detectors"].begin(); it != settings["detectors"].end(); it++)
15+
{
16+
DetectorTableValue new_entry;
17+
18+
new_entry.key = it.key();
19+
new_entry.value = it.value();
20+
21+
detectors.push_back(new_entry);
22+
}
23+
}
24+
25+
/*-----------------------------------------------------*\
26+
| If settings contains the detectors list, fill in rows |
27+
\*-----------------------------------------------------*/
28+
beginInsertRows(QModelIndex(), 0, detectors.size());
29+
endInsertRows();
30+
}
31+
32+
int DetectorTableModel::columnCount(const QModelIndex&) const
33+
{
34+
/*-----------------------------------------------------*\
35+
| The table has two columns - detector name and enable |
36+
\*-----------------------------------------------------*/
37+
return 2;
38+
}
39+
40+
int DetectorTableModel::rowCount(const QModelIndex&) const
41+
{
42+
/*-----------------------------------------------------*\
43+
| The number of rows is equal to the number of detectors|
44+
\*-----------------------------------------------------*/
45+
return detectors.size();
46+
}
47+
48+
QVariant DetectorTableModel::data(const QModelIndex& index, int role) const
49+
{
50+
switch(role)
51+
{
52+
/*-----------------------------------------------------*\
53+
| Column 0 is the detector name, 1 is the enable flag |
54+
\*-----------------------------------------------------*/
55+
case Qt::DisplayRole:
56+
switch(index.column())
57+
{
58+
case 0:
59+
return detectors[index.row()].key.c_str();
60+
case 1:
61+
return detectors[index.row()].value;
62+
}
63+
return QVariant();
64+
65+
case Qt::CheckStateRole:
66+
switch(index.column())
67+
{
68+
case 1:
69+
return 2 * detectors[index.row()].value;
70+
}
71+
return QVariant();
72+
}
73+
return QVariant();
74+
}
75+
76+
bool DetectorTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
77+
{
78+
/*-----------------------------------------------------*\
79+
| Update detector value for column 1 |
80+
\*-----------------------------------------------------*/
81+
if(index.column() == 1 && role == Qt::CheckStateRole)
82+
{
83+
detectors[index.row()].value = value.toBool();
84+
emit dataChanged(index, index);
85+
}
86+
return false;
87+
}
88+
89+
QVariant DetectorTableModel::headerData(int index, Qt::Orientation orientation, int role) const
90+
{
91+
if(role == Qt::DisplayRole)
92+
{
93+
switch(orientation)
94+
{
95+
case Qt::Vertical:
96+
return index + 1;
97+
98+
case Qt::Horizontal:
99+
switch(index)
100+
{
101+
case 0:
102+
return "Name";
103+
case 1:
104+
return "Enabled";
105+
}
106+
}
107+
}
108+
return QVariant();
109+
}
110+
111+
Qt::ItemFlags DetectorTableModel::flags(const QModelIndex& index) const
112+
{
113+
Qt::ItemFlags fl = Qt::ItemIsEnabled;
114+
115+
if(index.column() == 1)
116+
{
117+
fl |= Qt::ItemIsUserCheckable;
118+
}
119+
120+
return fl;
121+
}
122+
123+
void DetectorTableModel::applySettings()
124+
{
125+
/*-----------------------------------------------------*\
126+
| Read the detector list from the settings manager |
127+
\*-----------------------------------------------------*/
128+
json settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Detectors");
129+
130+
/*-----------------------------------------------------*\
131+
| Loop through all detectors in the list and update the |
132+
| value in the settings |
133+
\*-----------------------------------------------------*/
134+
if(settings.contains("detectors"))
135+
{
136+
for(unsigned int detector_idx = 0; detector_idx < detectors.size(); detector_idx++)
137+
{
138+
settings["detectors"][detectors[detector_idx].key] = detectors[detector_idx].value;
139+
}
140+
}
141+
142+
/*-----------------------------------------------------*\
143+
| Set and save the settings |
144+
\*-----------------------------------------------------*/
145+
ResourceManager::get()->GetSettingsManager()->SetSettings("Detectors", settings);
146+
ResourceManager::get()->GetSettingsManager()->SaveSettings();
147+
}

qt/DetectorTableModel.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef DETECTORTABLEMODEL_H
2+
#define DETECTORTABLEMODEL_H
3+
4+
#include <QAbstractTableModel>
5+
#include "ResourceManager.h"
6+
7+
typedef struct
8+
{
9+
std::string key;
10+
bool value;
11+
} DetectorTableValue;
12+
13+
class DetectorTableModel : public QAbstractTableModel
14+
{
15+
Q_OBJECT
16+
17+
private:
18+
std::vector<DetectorTableValue> detectors;
19+
20+
public:
21+
DetectorTableModel(QObject *parent = nullptr);
22+
int columnCount(const QModelIndex&) const override;
23+
int rowCount(const QModelIndex&) const override;
24+
QVariant data(const QModelIndex& index, int role) const override;
25+
bool setData(const QModelIndex& index, const QVariant&, int role) override;
26+
QVariant headerData(int index, Qt::Orientation orientation, int role) const override;
27+
Qt::ItemFlags flags(const QModelIndex& index) const override;
28+
29+
public slots:
30+
void applySettings();
31+
};
32+
33+
#endif // DETECTORTABLEMODEL_H

qt/OpenRGBDialog2.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,25 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
261261
UpdateDevicesList();
262262

263263
/*-----------------------------------------------------*\
264-
| Add Server Tab |
264+
| Add Client Tab |
265265
\*-----------------------------------------------------*/
266-
AddServerTab();
266+
AddClientTab();
267267

268268
/*-----------------------------------------------------*\
269-
| Add Client Tab |
269+
| Add Server Tab |
270270
\*-----------------------------------------------------*/
271-
AddClientTab();
271+
AddServerTab();
272272

273273
/*-----------------------------------------------------*\
274274
| Add the Software Info page |
275275
\*-----------------------------------------------------*/
276276
AddSoftwareInfoPage();
277277

278+
/*-----------------------------------------------------*\
279+
| Add the upported Devices page |
280+
\*-----------------------------------------------------*/
281+
AddSupportedDevicesPage();
282+
278283
/*-----------------------------------------------------*\
279284
| Add the SMBus Tools page if enabled |
280285
\*-----------------------------------------------------*/
@@ -324,6 +329,35 @@ void OpenRGBDialog2::AddSoftwareInfoPage()
324329
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel);
325330
}
326331

332+
void OpenRGBDialog2::AddSupportedDevicesPage()
333+
{
334+
/*-----------------------------------------------------*\
335+
| Create the Supported Devices page |
336+
\*-----------------------------------------------------*/
337+
SupportedPage = new OpenRGBSupportedDevicesPage();
338+
339+
ui->SettingsTabBar->addTab(SupportedPage, "");
340+
341+
QString SupportedLabelString = "<html><table><tr><td width='30'><img src='";
342+
SupportedLabelString += ":/software";
343+
if(IsDarkTheme()) SupportedLabelString += "_dark";
344+
SupportedLabelString += ".png' height='16' width='16'></td><td>Supported Devices</td></tr></table></html>";
345+
346+
QLabel *SupportedTabLabel = new QLabel();
347+
SupportedTabLabel->setText(SupportedLabelString);
348+
SupportedTabLabel->setIndent(20);
349+
if(IsDarkTheme())
350+
{
351+
SupportedTabLabel->setGeometry(0, 25, 200, 50);
352+
}
353+
else
354+
{
355+
SupportedTabLabel->setGeometry(0, 0, 200, 25);
356+
}
357+
358+
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SupportedTabLabel);
359+
}
360+
327361
void OpenRGBDialog2::AddI2CToolsPage()
328362
{
329363
ShowI2CTools = true;
@@ -365,7 +399,7 @@ void OpenRGBDialog2::AddClientTab()
365399
if(ClientInfoPage == NULL)
366400
{
367401
ClientInfoPage = new OpenRGBClientInfoPage();
368-
ui->MainTabBar->addTab(ClientInfoPage, "SDK Client");
402+
ui->MainTabBar->insertTab(2, ClientInfoPage, "SDK Client");
369403

370404
/*-----------------------------------------------------*\
371405
| Connect the page's Set All button to the Set All slot |
@@ -394,7 +428,7 @@ void OpenRGBDialog2::AddServerTab()
394428
| Add server information tab if there is a server |
395429
\*-----------------------------------------------------*/
396430
OpenRGBServerInfoPage *ServerInfoPage = new OpenRGBServerInfoPage(ResourceManager::get()->GetServer());
397-
ui->MainTabBar->addTab(ServerInfoPage, "SDK Server");
431+
ui->MainTabBar->insertTab(2, ServerInfoPage, "SDK Server");
398432
}
399433

400434
void OpenRGBDialog2::ClearDevicesList()
@@ -426,7 +460,7 @@ void OpenRGBDialog2::UpdateDevicesList()
426460
\*-----------------------------------------------------*/
427461
bool found = false;
428462

429-
for(unsigned int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++)
463+
for(int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++)
430464
{
431465
OpenRGBDevicePage* page = (OpenRGBDevicePage*) ui->DevicesTabBar->widget(tab_idx);
432466

@@ -501,7 +535,7 @@ void OpenRGBDialog2::UpdateDevicesList()
501535
\*-----------------------------------------------------*/
502536
found = false;
503537

504-
for(unsigned int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++)
538+
for(int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++)
505539
{
506540
/*-----------------------------------------------------*\
507541
| If type is a device info page, check it |
@@ -581,7 +615,7 @@ void OpenRGBDialog2::UpdateDevicesList()
581615
| Remove all remaining device information tabs, leaving |
582616
| other information tabs alone |
583617
\*-----------------------------------------------------*/
584-
for(unsigned int tab_idx = controllers.size(); tab_idx < ui->InformationTabBar->count(); tab_idx++)
618+
for(int tab_idx = controllers.size(); tab_idx < ui->InformationTabBar->count(); tab_idx++)
585619
{
586620
std::string type_str = ui->InformationTabBar->widget(tab_idx)->metaObject()->className();
587621
if(type_str == "Ui::OpenRGBDeviceInfoPage")

qt/OpenRGBDialog2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "OpenRGBClientInfoPage.h"
77
#include "OpenRGBSoftwareInfoPage.h"
88
#include "OpenRGBSystemInfoPage.h"
9+
#include "OpenRGBSupportedDevicesPage.h"
910

1011
#include <vector>
1112
#include "i2c_smbus.h"
@@ -48,6 +49,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
4849
OpenRGBClientInfoPage *ClientInfoPage;
4950
OpenRGBSystemInfoPage *SMBusToolsPage;
5051
OpenRGBSoftwareInfoPage *SoftInfoPage;
52+
OpenRGBSupportedDevicesPage *SupportedPage;
5153

5254
bool ShowI2CTools = false;
5355

@@ -63,6 +65,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
6365
Ui::OpenRGBDialog2Ui *ui;
6466

6567
void AddSoftwareInfoPage();
68+
void AddSupportedDevicesPage();
6669

6770
void ClearDevicesList();
6871
void UpdateDevicesList();

qt/OpenRGBDialog2.ui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@
6060
</item>
6161
</layout>
6262
</widget>
63+
<widget class="QWidget" name="TabSettings">
64+
<attribute name="title">
65+
<string>Settings</string>
66+
</attribute>
67+
<layout class="QGridLayout" name="gridLayout_4">
68+
<item row="0" column="0">
69+
<widget class="QTabWidget" name="SettingsTabBar">
70+
<property name="tabPosition">
71+
<enum>QTabWidget::West</enum>
72+
</property>
73+
<property name="currentIndex">
74+
<number>-1</number>
75+
</property>
76+
</widget>
77+
</item>
78+
</layout>
79+
</widget>
6380
</widget>
6481
</item>
6582
<item row="6" column="0" colspan="5">

0 commit comments

Comments
 (0)