diff --git a/core/include/core/browsemenu.h b/core/include/core/browsemenu.h index 03da7910e2..26a8afbdb4 100644 --- a/core/include/core/browsemenu.h +++ b/core/include/core/browsemenu.h @@ -46,6 +46,9 @@ class SCOPY_CORE_EXPORT BrowseMenu : public QWidget ToolMenu *toolMenu() const; +public Q_SLOTS: + void onToolStackChanged(QString id); + Q_SIGNALS: void requestTool(QString tool); void requestSave(); @@ -65,7 +68,12 @@ class SCOPY_CORE_EXPORT BrowseMenu : public QWidget QSpacerItem *m_spacer; ToolMenu *m_toolMenu; QPushButton *m_btnCollapse; + QMap m_btnsMap; bool m_collapsed; + + const QString HOME_ID = "home"; + const QString PREFERENCES_ID = "preferences"; + const QString ABOUT_ID = "about"; }; } // namespace scopy diff --git a/core/include/core/toolmenuitem.h b/core/include/core/toolmenuitem.h index 2dc1a7f8ca..7c8c621085 100644 --- a/core/include/core/toolmenuitem.h +++ b/core/include/core/toolmenuitem.h @@ -40,14 +40,12 @@ class ToolMenuItem : public QPushButton bool eventFilter(QObject *watched, QEvent *event); void setName(QString str); - void setSelected(bool en); QString getId() const; Q_SIGNALS: void doubleclick(); public Q_SLOTS: - void setDisabled(bool disabled); void updateItem(); protected: @@ -55,7 +53,6 @@ public Q_SLOTS: void leaveEvent(QEvent *event); private: - // QPushButton *m_toolBtn; CustomPushButton *m_toolRunBtn; QString m_uuid; diff --git a/core/include/core/toolmenumanager.h b/core/include/core/toolmenumanager.h index 930ec2983f..aa72d77331 100644 --- a/core/include/core/toolmenumanager.h +++ b/core/include/core/toolmenumanager.h @@ -55,9 +55,11 @@ public Q_SLOTS: Q_SIGNALS: void requestToolSelect(QString id); + void toolStackChanged(QString id); private Q_SLOTS: void updateTool(QWidget *old); + void updateMenuAfterDetach(ToolMenuItem *toolMenuItem, QString id); void updateToolAttached(bool oldAttach, ToolMenuItem *toolMenuItem); private: @@ -66,7 +68,6 @@ private Q_SLOTS: void detachSuccesful(ToolMenuItem *toolMenuItem); void attachSuccesful(ToolMenuItem *toolMenuItem); void showTool(ToolMenuItem *toolMenuItem); - void selectTool(ToolMenuItem *toolMenuItem, bool on); void setTmeAttached(ToolMenuEntry *tme); MenuSectionCollapseWidget *createMenuSectionItem(QString deviceName, QString uri = ""); ToolMenuItem *createToolMenuItem(ToolMenuEntry *tme, QWidget *parent = nullptr); diff --git a/core/src/browsemenu.cpp b/core/src/browsemenu.cpp index 576496570b..bc9801744d 100644 --- a/core/src/browsemenu.cpp +++ b/core/src/browsemenu.cpp @@ -62,7 +62,8 @@ BrowseMenu::BrowseMenu(QWidget *parent) homeBtn->setCheckable(true); homeBtn->setIconSize(QSize(32, 32)); homeBtn->setStyleSheet("text-align: left"); - connect(homeBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool("home"); }); + connect(homeBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool(HOME_ID); }); + m_btnsMap[HOME_ID] = homeBtn; QWidget *saveLoadWidget = new QWidget(m_content); saveLoadWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); @@ -87,14 +88,16 @@ BrowseMenu::BrowseMenu(QWidget *parent) ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/preferences.svg", m_content); - connect(preferencesBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool("preferences"); }); + connect(preferencesBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool(PREFERENCES_ID); }); preferencesBtn->setCheckable(true); + m_btnsMap[PREFERENCES_ID] = preferencesBtn; QPushButton *aboutBtn = createBtn( "About", ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/info.svg", m_content); - connect(aboutBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool("about"); }); + connect(aboutBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool(ABOUT_ID); }); aboutBtn->setCheckable(true); + m_btnsMap[ABOUT_ID] = aboutBtn; QLabel *logo = createScopyLogo(m_content); @@ -121,6 +124,13 @@ BrowseMenu::~BrowseMenu() {} ToolMenu *BrowseMenu::toolMenu() const { return m_toolMenu; } +void BrowseMenu::onToolStackChanged(QString id) +{ + if(m_btnsMap.contains(id)) { + m_btnsMap[id]->setChecked(true); + } +} + void BrowseMenu::add(QWidget *w, QString name, MenuAlignment position) { int spacerIndex = m_contentLay->indexOf(m_spacer); diff --git a/core/src/scopymainwindow.cpp b/core/src/scopymainwindow.cpp index f3c6b3f016..4aa9196e74 100644 --- a/core/src/scopymainwindow.cpp +++ b/core/src/scopymainwindow.cpp @@ -182,6 +182,7 @@ 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::toolStackChanged, browseMenu, &BrowseMenu::onToolStackChanged); connect(hp, &ScopyHomePage::displayNameChanged, m_toolMenuManager, &ToolMenuManager::onDisplayNameChanged); connect(hp, &ScopyHomePage::newDeviceAvailable, dm, &DeviceManager::addDevice); diff --git a/core/src/toolmenuitem.cpp b/core/src/toolmenuitem.cpp index 9c46a243d1..6cefb013a6 100644 --- a/core/src/toolmenuitem.cpp +++ b/core/src/toolmenuitem.cpp @@ -126,10 +126,6 @@ void ToolMenuItem::setName(QString str) setText(m_name); } -void ToolMenuItem::setSelected(bool en) { setDynamicProperty(this, "selected", en); } - -void ToolMenuItem::setDisabled(bool disabled) { setDisabled(disabled); } - void ToolMenuItem::updateItem() { ToolMenuEntry *tme = dynamic_cast(QObject::sender()); diff --git a/core/src/toolmenumanager.cpp b/core/src/toolmenumanager.cpp index 3ada849ba9..1d9dda4061 100644 --- a/core/src/toolmenumanager.cpp +++ b/core/src/toolmenumanager.cpp @@ -161,6 +161,13 @@ void ToolMenuManager::updateTool(QWidget *old) qDebug(CAT_TOOLMENUMANAGER) << "updating tool for " << tme->name() << " - " << id; } +void ToolMenuManager::updateMenuAfterDetach(ToolMenuItem *toolMenuItem, QString id) +{ + if(id == toolMenuItem->getId()) { + toolMenuItem->setChecked(true); + } +} + void ToolMenuManager::updateToolAttached(bool oldAttach, ToolMenuItem *toolMenuItem) { ToolMenuEntry *tme = dynamic_cast(QObject::sender()); @@ -192,14 +199,14 @@ void ToolMenuManager::updateToolAttached(bool oldAttach, ToolMenuItem *toolMenuI // the selected tool just attached, so it will be at the top of the stack, therefore highlighted if(toolMenuItem) { toolMenuItem->setChecked(true); - toolMenuItem->setSelected(true); } } else { - // the top tool just detached, so we need to find the tool that is positioned at the new top of the - // stack. - if(toolMenuItem) { - toolMenuItem->toggle(); + QWidget *wAfterDetach = m_ts->currentWidget(); + if(!wAfterDetach) { + return; } + QString toolMenuItemId = m_ts->getKey(wAfterDetach); + Q_EMIT toolStackChanged(toolMenuItemId); } } @@ -231,7 +238,7 @@ void ToolMenuManager::detachSuccesful(ToolMenuItem *toolMenuItem) { QButtonGroup *menuBtnGroup = m_toolMenu->btnGroup(); if(toolMenuItem) { - toolMenuItem->setSelected(false); + toolMenuItem->setCheckable(false); menuBtnGroup->removeButton(toolMenuItem); } } @@ -240,6 +247,7 @@ void ToolMenuManager::attachSuccesful(ToolMenuItem *toolMenuItem) { QButtonGroup *menuBtnGroup = m_toolMenu->btnGroup(); if(toolMenuItem) { + toolMenuItem->setCheckable(true); menuBtnGroup->addButton(toolMenuItem); } } @@ -252,14 +260,6 @@ void ToolMenuManager::showTool(ToolMenuItem *toolMenuItem) Q_EMIT requestToolSelect(toolMenuItem->getId()); } -void ToolMenuManager::selectTool(ToolMenuItem *toolMenuItem, bool on) -{ - QButtonGroup *menuBtnGroup = m_toolMenu->btnGroup(); - if(menuBtnGroup->id(toolMenuItem) != -1) { - toolMenuItem->setSelected(on); - } -} - void ToolMenuManager::setTmeAttached(ToolMenuEntry *tme) { Preferences *p = Preferences::GetInstance(); @@ -296,9 +296,9 @@ ToolMenuItem *ToolMenuManager::createToolMenuItem(ToolMenuEntry *tme, QWidget *p connect(toolMenuItem->getToolRunBtn(), &QPushButton::toggled, tme, &ToolMenuEntry::runToggled); connect(toolMenuItem->getToolRunBtn(), &QPushButton::clicked, tme, &ToolMenuEntry::runClicked); connect(toolMenuItem, &QPushButton::clicked, this, [=]() { Q_EMIT requestToolSelect(toolMenuItem->getId()); }); - connect(toolMenuItem, &QPushButton::toggled, this, - [this, toolMenuItem](bool on) { selectTool(toolMenuItem, on); }); connect(toolMenuItem, &ToolMenuItem::doubleclick, this, [this, tme]() { setTmeAttached(tme); }); + connect(this, &ToolMenuManager::toolStackChanged, this, + [this, toolMenuItem](QString id) { updateMenuAfterDetach(toolMenuItem, id); }); connect(tme, &ToolMenuEntry::updateToolEntry, toolMenuItem, &ToolMenuItem::updateItem); return toolMenuItem;