diff --git a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp index 087b16367..e4664ed7d 100644 --- a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp @@ -2026,7 +2026,7 @@ void OpenRGBDevicePage::UpdateInterface(unsigned int update_reason) case RGBCONTROLLER_UPDATE_REASON_HIDDEN: case RGBCONTROLLER_UPDATE_REASON_UNHIDDEN: case RGBCONTROLLER_UPDATE_REASON_CONFIGUREDEVICE: - emit RefreshList(); + emit ShowHideList(); break; case RGBCONTROLLER_UPDATE_REASON_UPDATELEDS: diff --git a/qt/OpenRGBDevicePage/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage/OpenRGBDevicePage.h index 74c69dda5..c8951c5f0 100644 --- a/qt/OpenRGBDevicePage/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage/OpenRGBDevicePage.h @@ -129,5 +129,7 @@ private slots: signals: void RefreshList(); + void ShowHideList(); + void SetAllDevices(unsigned char red, unsigned char green, unsigned char blue); }; diff --git a/qt/OpenRGBDialog/OpenRGBDialog.cpp b/qt/OpenRGBDialog/OpenRGBDialog.cpp index 910dd8bb0..c0c762b04 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.cpp +++ b/qt/OpenRGBDialog/OpenRGBDialog.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,15 @@ static void OpenRGBDialogResourceManagerCallback(void * this_ptr, unsigned int u break; case RESOURCEMANAGER_UPDATE_REASON_DEVICE_LIST_UPDATED: - QMetaObject::invokeMethod(this_obj, "onDeviceListUpdated", Qt::BlockingQueuedConnection); + if(QThread::currentThread() != qApp->thread()) + { + printf("invoking onDeviceListUpdated\n"); + QMetaObject::invokeMethod(this_obj, "onDeviceListUpdated", Qt::BlockingQueuedConnection); + } + else + { + this_obj->onDeviceListUpdated(); + } break; } } @@ -960,6 +969,84 @@ void OpenRGBDialog::ClearDevicesList() } } +void OpenRGBDialog::UpdateDevicesListShowHide() +{ + /*-----------------------------------------------------*\ + | Loop through each controller in the tab list and hide | + | any controller marked as hidden. | + \*-----------------------------------------------------*/ + for(int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++) + { + /*-------------------------------------------------*\ + | Get a pointer to the page at this index in the | + | tab bar | + \*-------------------------------------------------*/ + QWidget* page = ui->DevicesTabBar->widget(tab_idx); + + /*-------------------------------------------------*\ + | Verify this page is an OpenRGBDevicePage | + \*-------------------------------------------------*/ + if(dynamic_cast(page) != nullptr) + { + /*---------------------------------------------*\ + | If the controller for this page is hidden, | + | remove the page from the tab bar and store it | + | in the hidden pages vector | + \*---------------------------------------------*/ + if(((OpenRGBDevicePage*)page)->GetController()->GetHidden()) + { + hidden_pages.push_back((OpenRGBDevicePage*)page); + ui->DevicesTabBar->removeTab(tab_idx); + + /*-----------------------------------------*\ + | Decrement tab index to account for | + | removing tab | + \*-----------------------------------------*/ + tab_idx--; + } + } + } + + /*-----------------------------------------------------*\ + | Loop through each controller in the hidden pages | + | vector and restore any controller marked as not | + | hidden. | + \*-----------------------------------------------------*/ + for(std::size_t page_idx = 0; page_idx < hidden_pages.size(); page_idx++) + { + /*-----------------------------------------*\ + | Get a pointer to the page at this index | + | in the hidden pages vector | + \*-----------------------------------------*/ + OpenRGBDevicePage* page = (OpenRGBDevicePage*)hidden_pages[page_idx]; + RGBController* controller = page->GetController(); + + /*-----------------------------------------*\ + | If the current tab matches the current | + | controller, check if it is hidden | + \*-----------------------------------------*/ + if(!(controller->GetHidden())) + { + ui->DevicesTabBar->addTab((QWidget*)page, ""); + + /*---------------------------------*\ + | Create the tab label | + \*---------------------------------*/ + TabLabel* NewTabLabel = new TabLabel(OpenRGBFont::GetIconIDFromDeviceType(controller->GetDeviceType()), (char *)controller->GetDisplayName().c_str(), (char *)context, false); + + ui->DevicesTabBar->tabBar()->setTabButton(ui->DevicesTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel); + + hidden_pages.erase(hidden_pages.begin() + page_idx); + + /*---------------------------------*\ + | Decrement page index to account | + | for removing page | + \*---------------------------------*/ + page_idx--; + } + } +} + void OpenRGBDialog::UpdateDevicesList() { std::vector controllers = ResourceManager::get()->GetRGBControllers(); @@ -1142,6 +1229,11 @@ void OpenRGBDialog::UpdateDevicesList() this, SLOT(onDeviceListUpdated())); + connect(NewPage, + SIGNAL(ShowHideList()), + this, + SLOT(onDeviceListShowHide())); + if(controllers[controller_idx]->GetHidden()) { hidden_pages.push_back(NewPage); @@ -1475,6 +1567,11 @@ void OpenRGBDialog::onDeviceListUpdated() UpdateDevicesList(); } +void OpenRGBDialog::onDeviceListShowHide() +{ + UpdateDevicesListShowHide(); +} + void OpenRGBDialog::onDetectionProgressUpdated() { ui->DetectionProgressBar->setValue(ResourceManager::get()->GetDetectionPercent()); diff --git a/qt/OpenRGBDialog/OpenRGBDialog.h b/qt/OpenRGBDialog/OpenRGBDialog.h index 34ab74202..1fa5cabc3 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.h +++ b/qt/OpenRGBDialog/OpenRGBDialog.h @@ -148,6 +148,7 @@ private: void ClearDevicesList(); void UpdateDevicesList(); + void UpdateDevicesListShowHide(); void closeEvent(QCloseEvent *event) override; bool SelectConfigProfile(const std::string name); @@ -166,6 +167,9 @@ private: void UpdateTabs(); bool isCompactTabMode(); +public slots: + void onDeviceListUpdated(); + private slots: void on_Exit(); void on_LightsOff(); @@ -176,7 +180,7 @@ private slots: void on_QuickBlue(); void on_QuickMagenta(); void on_QuickWhite(); - void onDeviceListUpdated(); + void onDeviceListShowHide(); void onDetectionProgressUpdated(); void onDetectionStarted(); void onDetectionEnded();