Don't clear the entire tab bar, instead add new controller tabs only if missing and sort existing ones, then delete only those that no longer have an associated controller in the controllers list. Disabled software info and i2c tools pages for now
This commit is contained in:
parent
86034a9ce5
commit
9c9dff41c3
5 changed files with 142 additions and 62 deletions
|
|
@ -6,6 +6,8 @@ OpenRGBDeviceInfoPage::OpenRGBDeviceInfoPage(RGBController *dev, QWidget *parent
|
|||
QFrame(parent),
|
||||
ui(new Ui::OpenRGBDeviceInfoPageUi)
|
||||
{
|
||||
controller = dev;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->TypeValue->setText(device_type_to_str(dev->type).c_str());
|
||||
|
|
@ -21,3 +23,8 @@ OpenRGBDeviceInfoPage::~OpenRGBDeviceInfoPage()
|
|||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
RGBController* OpenRGBDeviceInfoPage::GetController()
|
||||
{
|
||||
return controller;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ public:
|
|||
explicit OpenRGBDeviceInfoPage(RGBController *dev, QWidget *parent = nullptr);
|
||||
~OpenRGBDeviceInfoPage();
|
||||
|
||||
RGBController* GetController();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBDeviceInfoPageUi *ui;
|
||||
RGBController* controller;
|
||||
Ui::OpenRGBDeviceInfoPageUi* ui;
|
||||
};
|
||||
|
||||
#endif // OPENRGBDEVICEINFOPAGE_H
|
||||
|
|
|
|||
|
|
@ -121,6 +121,11 @@ OpenRGBDevicePage::~OpenRGBDevicePage()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
RGBController* Ui::OpenRGBDevicePage::GetController()
|
||||
{
|
||||
return device;
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ public:
|
|||
explicit OpenRGBDevicePage(RGBController *dev, QWidget *parent = nullptr);
|
||||
~OpenRGBDevicePage();
|
||||
|
||||
RGBController* GetController();
|
||||
|
||||
void SetDevice(unsigned char red, unsigned char green, unsigned char blue); // Could be moved to private
|
||||
void SetCustomMode(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void UpdateDevice();
|
||||
|
|
|
|||
|
|
@ -309,91 +309,154 @@ void OpenRGBDialog2::ClearDevicesList()
|
|||
void OpenRGBDialog2::UpdateDevicesList()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Clear on each update |
|
||||
| Loop through each controller in the list. |
|
||||
\*-----------------------------------------------------*/
|
||||
ClearDevicesList();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up list of devices |
|
||||
\*-----------------------------------------------------*/
|
||||
QTabBar *DevicesTabBar = ui->DevicesTabBar->tabBar();
|
||||
|
||||
for(std::size_t dev_idx = 0; dev_idx < controllers.size(); dev_idx++)
|
||||
for(unsigned int controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
|
||||
{
|
||||
OpenRGBDevicePage *NewPage = new OpenRGBDevicePage(controllers[dev_idx]);
|
||||
ui->DevicesTabBar->addTab(NewPage, "");
|
||||
/*-----------------------------------------------------*\
|
||||
| Loop through each tab in the devices tab bar |
|
||||
\*-----------------------------------------------------*/
|
||||
bool found = false;
|
||||
|
||||
for(unsigned int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++)
|
||||
{
|
||||
OpenRGBDevicePage* page = (OpenRGBDevicePage*) ui->DevicesTabBar->widget(tab_idx);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the current tab matches the current controller, |
|
||||
| move the tab to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
if(controllers[controller_idx] == page->GetController())
|
||||
{
|
||||
found = true;
|
||||
ui->DevicesTabBar->tabBar()->moveTab(tab_idx, controller_idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| The controller does not have a tab already created |
|
||||
| Create a new tab and move it to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBDevicePage *NewPage = new OpenRGBDevicePage(controllers[controller_idx]);
|
||||
ui->DevicesTabBar->addTab(NewPage, "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Connect the page's Set All button to the Set All slot |
|
||||
\*-----------------------------------------------------*/
|
||||
connect(NewPage,
|
||||
SIGNAL(SetAllDevices(unsigned char, unsigned char, unsigned char)),
|
||||
this,
|
||||
SLOT(on_SetAllDevices(unsigned char, unsigned char, unsigned char)));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Connect the page's Resize signal to the Save Size slot|
|
||||
\*-----------------------------------------------------*/
|
||||
connect(NewPage,
|
||||
SIGNAL(SaveSizeProfile()),
|
||||
this,
|
||||
SLOT(on_SaveSizeProfile()));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Use Qt's HTML capabilities to display both icon and |
|
||||
| text in the tab label. Choose icon based on device |
|
||||
| type and append device name string. |
|
||||
\*-----------------------------------------------------*/
|
||||
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
|
||||
NewLabelString += GetIconString(controllers[controller_idx]->type, darkTheme);
|
||||
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[controller_idx]->name) + "</td></tr></table></html>";
|
||||
|
||||
QLabel *NewTabLabel = new QLabel();
|
||||
NewTabLabel->setText(NewLabelString);
|
||||
NewTabLabel->setIndent(20);
|
||||
NewTabLabel->setGeometry(0, 0, 200, 20);
|
||||
|
||||
ui->DevicesTabBar->tabBar()->setTabButton(ui->DevicesTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Now move the new tab to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->DevicesTabBar->tabBar()->moveTab(ui->DevicesTabBar->count() - 1, controller_idx);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Connect the page's Set All button to the Set All slot |
|
||||
| Loop through each tab in the information tab bar |
|
||||
\*-----------------------------------------------------*/
|
||||
connect(NewPage,
|
||||
SIGNAL(SetAllDevices(unsigned char, unsigned char, unsigned char)),
|
||||
this,
|
||||
SLOT(on_SetAllDevices(unsigned char, unsigned char, unsigned char)));
|
||||
found = false;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Connect the page's Resize signal to the Save Size slot|
|
||||
\*-----------------------------------------------------*/
|
||||
connect(NewPage,
|
||||
SIGNAL(SaveSizeProfile()),
|
||||
this,
|
||||
SLOT(on_SaveSizeProfile()));
|
||||
for(unsigned int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++)
|
||||
{
|
||||
OpenRGBDeviceInfoPage* page = (OpenRGBDeviceInfoPage*) ui->InformationTabBar->widget(tab_idx);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Use Qt's HTML capabilities to display both icon and |
|
||||
| text in the tab label. Choose icon based on device |
|
||||
| type and append device name string. |
|
||||
\*-----------------------------------------------------*/
|
||||
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
|
||||
NewLabelString += GetIconString(controllers[dev_idx]->type, darkTheme);
|
||||
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[dev_idx]->name) + "</td></tr></table></html>";
|
||||
/*-----------------------------------------------------*\
|
||||
| If the current tab matches the current controller, |
|
||||
| move the tab to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
if(controllers[controller_idx] == page->GetController())
|
||||
{
|
||||
found = true;
|
||||
ui->InformationTabBar->tabBar()->moveTab(tab_idx, controller_idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QLabel *NewTabLabel = new QLabel();
|
||||
NewTabLabel->setText(NewLabelString);
|
||||
NewTabLabel->setIndent(20);
|
||||
NewTabLabel->setGeometry(0, 0, 200, 20);
|
||||
if(!found)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| The controller does not have a tab already created |
|
||||
| Create a new tab and move it to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBDeviceInfoPage *NewPage = new OpenRGBDeviceInfoPage(controllers[controller_idx]);
|
||||
ui->InformationTabBar->addTab(NewPage, "");
|
||||
|
||||
DevicesTabBar->setTabButton(dev_idx, QTabBar::LeftSide, NewTabLabel);
|
||||
/*-----------------------------------------------------*\
|
||||
| Use Qt's HTML capabilities to display both icon and |
|
||||
| text in the tab label. Choose icon based on device |
|
||||
| type and append device name string. |
|
||||
\*-----------------------------------------------------*/
|
||||
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
|
||||
NewLabelString += GetIconString(controllers[controller_idx]->type, darkTheme);
|
||||
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[controller_idx]->name) + "</td></tr></table></html>";
|
||||
|
||||
QLabel *NewTabLabel = new QLabel();
|
||||
NewTabLabel->setText(NewLabelString);
|
||||
NewTabLabel->setIndent(20);
|
||||
NewTabLabel->setGeometry(0, 0, 200, 20);
|
||||
|
||||
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Now move the new tab to the correct position |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->InformationTabBar->tabBar()->moveTab(ui->InformationTabBar->count() - 1, controller_idx);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up list of information |
|
||||
\*-----------------------------------------------------*/
|
||||
QTabBar *InformationTabBar = ui->InformationTabBar->tabBar();
|
||||
|
||||
for(std::size_t dev_idx = 0; dev_idx < controllers.size(); dev_idx++)
|
||||
unsigned int tab_count = ui->DevicesTabBar->count();
|
||||
for(unsigned int tab_idx = controllers.size(); tab_idx < tab_count; tab_idx++)
|
||||
{
|
||||
OpenRGBDeviceInfoPage *NewPage = new OpenRGBDeviceInfoPage(controllers[dev_idx]);
|
||||
ui->InformationTabBar->addTab(NewPage, "");
|
||||
ui->DevicesTabBar->removeTab(ui->DevicesTabBar->count() - 1);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Use Qt's HTML capabilities to display both icon and |
|
||||
| text in the tab label. Choose icon based on device |
|
||||
| type and append device name string. |
|
||||
\*-----------------------------------------------------*/
|
||||
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
|
||||
NewLabelString += GetIconString(controllers[dev_idx]->type, darkTheme);
|
||||
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[dev_idx]->name) + "</td></tr></table></html>";
|
||||
|
||||
QLabel *NewTabLabel = new QLabel();
|
||||
NewTabLabel->setText(NewLabelString);
|
||||
NewTabLabel->setIndent(20);
|
||||
NewTabLabel->setGeometry(0, 0, 200, 20);
|
||||
|
||||
InformationTabBar->setTabButton(dev_idx, QTabBar::LeftSide, NewTabLabel);
|
||||
tab_count = ui->InformationTabBar->count();
|
||||
for(unsigned int tab_idx = controllers.size(); tab_idx < tab_count; tab_idx++)
|
||||
{
|
||||
ui->InformationTabBar->removeTab(ui->InformationTabBar->count() - 1);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the Software Info page |
|
||||
\*-----------------------------------------------------*/
|
||||
AddSoftwareInfoPage();
|
||||
//AddSoftwareInfoPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the SMBus Tools page if enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
if(ShowI2CTools)
|
||||
{
|
||||
AddI2CToolsPage();
|
||||
//AddI2CToolsPage();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue