From 9bb1fbc0df65d0e0102e4244af4365cedace82f6 Mon Sep 17 00:00:00 2001 From: andreidanila1 Date: Mon, 25 Nov 2024 15:48:00 +0200 Subject: [PATCH] core/toolmenumanager: Handle devicePressed signal. The signal is emitted by the ToolMenuHeader widget and it is forwarded by the ToolMenuManager to the scopymainwindow. Signed-off-by: andreidanila1 --- core/include/core/scopymainwindow.h | 1 + core/include/core/toolmenumanager.h | 3 ++- core/src/scopymainwindow.cpp | 10 +++++++++- core/src/toolmenumanager.cpp | 12 +++++++----- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/include/core/scopymainwindow.h b/core/include/core/scopymainwindow.h index 5e4263e017..027b3e2b4d 100644 --- a/core/include/core/scopymainwindow.h +++ b/core/include/core/scopymainwindow.h @@ -108,6 +108,7 @@ public Q_SLOTS: void handleScanner(); void enableScanner(); void deviceAutoconnect(); + void showDevicePage(QString id, ToolStack *ts); protected: void closeEvent(QCloseEvent *event) override; diff --git a/core/include/core/toolmenumanager.h b/core/include/core/toolmenumanager.h index e1dae027ad..d737b302f5 100644 --- a/core/include/core/toolmenumanager.h +++ b/core/include/core/toolmenumanager.h @@ -65,6 +65,7 @@ public Q_SLOTS: Q_SIGNALS: void requestToolSelect(QString id); + void requestDevicePage(QString id); private Q_SLOTS: void updateTool(QWidget *old); @@ -78,7 +79,7 @@ private Q_SLOTS: void showTool(ToolMenuItem *toolMenuItem); void selectTool(ToolMenuItem *toolMenuItem, bool on); void setTmeAttached(ToolMenuEntry *tme); - MenuSectionCollapseWidget *createMenuSectionItem(QString devName, QString uri, QPixmap icon); + MenuSectionCollapseWidget *createMenuSectionItem(QString deviceId, DeviceInfo dInfo); ToolMenuItem *createToolMenuItem(ToolMenuEntry *tme, QWidget *parent = nullptr); MenuCollapseHeader *getCollapseSectionHeader(MenuSectionCollapseWidget *section); diff --git a/core/src/scopymainwindow.cpp b/core/src/scopymainwindow.cpp index 40281db829..f6baa1b820 100644 --- a/core/src/scopymainwindow.cpp +++ b/core/src/scopymainwindow.cpp @@ -175,7 +175,6 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent) } enableScanner(); - connect(dm, &DeviceManager::deviceChangedToolList, m_toolMenuManager, &ToolMenuManager::changeToolListContents); connect(dm, SIGNAL(deviceConnected(QString, Device *)), m_toolMenuManager, SLOT(deviceConnected(QString))); connect(dm, SIGNAL(deviceDisconnected(QString, Device *)), m_toolMenuManager, @@ -183,6 +182,8 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent) connect(dm, &DeviceManager::requestTool, m_toolMenuManager, &ToolMenuManager::showMenuItem); connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, ts, &ToolStack::show); connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, dtm, &DetachedToolWindowManager::show); + connect(m_toolMenuManager, &ToolMenuManager::requestDevicePage, this, + [this, ts](QString id) { showDevicePage(id, ts); }); connect(hp, &ScopyHomePage::displayNameChanged, m_toolMenuManager, &ToolMenuManager::onDisplayNameChanged); connect(hp, &ScopyHomePage::newDeviceAvailable, dm, &DeviceManager::addDevice); @@ -255,6 +256,13 @@ void ScopyMainWindow::deviceAutoconnect() } } +void ScopyMainWindow::showDevicePage(QString id, ToolStack *ts) +{ + QString hpKey = ts->getKey(hp); + ts->show(hpKey); + hp->viewDevice(id); +} + void ScopyMainWindow::save() { QString selectedFilter; diff --git a/core/src/toolmenumanager.cpp b/core/src/toolmenumanager.cpp index b02c62d98b..5039a57979 100644 --- a/core/src/toolmenumanager.cpp +++ b/core/src/toolmenumanager.cpp @@ -44,7 +44,7 @@ ToolMenuManager::~ToolMenuManager() {} void ToolMenuManager::addMenuItem(QString deviceId, DeviceInfo dInfo, int itemIndex) { - MenuSectionCollapseWidget *devSection = createMenuSectionItem(dInfo.name, dInfo.param, dInfo.icon); + MenuSectionCollapseWidget *devSection = createMenuSectionItem(deviceId, dInfo); QButtonGroup *menuBtnGroup = m_toolMenu->btnGroup(); for(ToolMenuEntry *tme : qAsConst(dInfo.tools)) { ToolMenuItem *toolMenuItem = createToolMenuItem(tme, devSection); @@ -285,10 +285,10 @@ void ToolMenuManager::setTmeAttached(ToolMenuEntry *tme) tme->setAttached(!tme->attached()); } -MenuSectionCollapseWidget *ToolMenuManager::createMenuSectionItem(QString devName, QString uri, QPixmap icon) +MenuSectionCollapseWidget *ToolMenuManager::createMenuSectionItem(QString deviceId, DeviceInfo dInfo) { MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget( - devName, MenuCollapseSection::MHCW_ARROW, MenuCollapseSection::MHW_TOOLMENUWIDGET, m_toolMenu); + dInfo.name, MenuCollapseSection::MHCW_ARROW, MenuCollapseSection::MHW_TOOLMENUWIDGET, m_toolMenu); section->contentLayout()->setSpacing(0); section->menuSection()->layout()->setMargin(0); section->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); @@ -297,9 +297,11 @@ MenuSectionCollapseWidget *ToolMenuManager::createMenuSectionItem(QString devNam if(collapseHeader) { ToolMenuHeaderWidget *thw = dynamic_cast(collapseHeader->headerWidget()); if(thw) { - thw->setUri(uri); - thw->setDeviceIcon(icon); + thw->setUri(dInfo.param); + thw->setDeviceIcon(dInfo.icon); thw->layout()->setContentsMargins(Style::getDimension(json::global::unit_1), 0, 0, 0); + connect(thw, &ToolMenuHeaderWidget::devicePressed, this, + [this, deviceId]() { Q_EMIT requestDevicePage(deviceId); }); } Style::setStyle(collapseHeader, style::properties::widget::bottomBorder); }