diff --git a/qt/OpenRGBDeviceInfoPage.cpp b/qt/OpenRGBDeviceInfoPage.cpp index bd1bee67..ecf348b2 100644 --- a/qt/OpenRGBDeviceInfoPage.cpp +++ b/qt/OpenRGBDeviceInfoPage.cpp @@ -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; +} diff --git a/qt/OpenRGBDeviceInfoPage.h b/qt/OpenRGBDeviceInfoPage.h index bb11951a..0940279c 100644 --- a/qt/OpenRGBDeviceInfoPage.h +++ b/qt/OpenRGBDeviceInfoPage.h @@ -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 diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index 854ab122..137dfabc 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -121,6 +121,11 @@ OpenRGBDevicePage::~OpenRGBDevicePage() delete ui; } +RGBController* Ui::OpenRGBDevicePage::GetController() +{ + return device; +} + void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/) { /*-----------------------------------------------------*\ diff --git a/qt/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage.h index a13223d1..cdb351e2 100644 --- a/qt/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage.h @@ -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(); diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 6bca416c..5cb8419e 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -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 = "
" + QString::fromStdString(controllers[controller_idx]->name) + "
"; + + 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 = "
" + QString::fromStdString(controllers[dev_idx]->name) + "
"; + /*-----------------------------------------------------*\ + | 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 = "
" + QString::fromStdString(controllers[controller_idx]->name) + "
"; + + 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 = "
" + QString::fromStdString(controllers[dev_idx]->name) + "
"; - - 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(); } }