Skip to content

Commit

Permalink
core/toolmenumanager: Handle devicePressed signal.
Browse files Browse the repository at this point in the history
The signal is emitted by the ToolMenuHeader widget and it is forwarded
by the ToolMenuManager to the scopymainwindow.

Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Nov 25, 2024
1 parent 6a677bb commit 9bb1fbc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/include/core/scopymainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion core/include/core/toolmenumanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Q_SLOTS:

Q_SIGNALS:
void requestToolSelect(QString id);
void requestDevicePage(QString id);

private Q_SLOTS:
void updateTool(QWidget *old);
Expand All @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ 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,
SLOT(deviceDisconnected(QString)));
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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions core/src/toolmenumanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -297,9 +297,11 @@ MenuSectionCollapseWidget *ToolMenuManager::createMenuSectionItem(QString devNam
if(collapseHeader) {
ToolMenuHeaderWidget *thw = dynamic_cast<ToolMenuHeaderWidget *>(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);
}
Expand Down

0 comments on commit 9bb1fbc

Please sign in to comment.