From 59b234028fc09c0f17b0b67e41e2c7fd86a400d5 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sat, 21 Jun 2025 10:43:09 +0200 Subject: [PATCH] Core: Add preselect on hovered menu items in PickGeometry tool Co-authored-by: realthunder --- src/Gui/Selection/SelectionView.cpp | 34 +++++++++++++++++++++++++---- src/Gui/Selection/SelectionView.h | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Gui/Selection/SelectionView.cpp b/src/Gui/Selection/SelectionView.cpp index a28d420d95..46ef5a4493 100644 --- a/src/Gui/Selection/SelectionView.cpp +++ b/src/Gui/Selection/SelectionView.cpp @@ -707,8 +707,9 @@ void SelectionView::onEnablePickList() // SelectionMenu implementation SelectionMenu::SelectionMenu(QWidget *parent) - : QMenu(parent) + : QMenu(parent), currentSelections(nullptr) { + connect(this, &QMenu::hovered, this, &SelectionMenu::onHover); } struct ElementInfo { @@ -727,6 +728,9 @@ PickData SelectionMenu::doPick(const std::vector &sels) { clear(); + // store reference to selections for use in onHover + currentSelections = &sels; + std::map> typeGroups; // Group selections by element type @@ -777,6 +781,8 @@ PickData SelectionMenu::doPick(const std::vector &sels) QAction *action; if (typeMenu) { action = typeMenu->addAction(icon, text); + // Connect submenu hovered signals as well + connect(typeMenu, &QMenu::hovered, this, &SelectionMenu::onHover); } else { action = addAction(icon, text); } @@ -809,12 +815,32 @@ PickData SelectionMenu::onPicked(QAction *picked, const std::vector &s void SelectionMenu::onHover(QAction *action) { - if (!action) + if (!action || !currentSelections) return; - // For now, just clear preselection on hover - // Could be enhanced to preselect the hovered item + // Clear previous preselection Gui::Selection().rmvPreselect(); + + // Get the selection index from the action data + bool ok; + int index = action->data().toInt(&ok); + if (!ok || index < 0 || index >= (int)currentSelections->size()) + return; + + const auto &sel = (*currentSelections)[index]; + if (!sel.obj) + return; + + // extract just the element name (e.g., "Face1") from subName for preselection + std::string elementName = sel.element; + if (!elementName.empty()) { + // use TreeView as message source for menu hover + Gui::Selection().setPreselect(sel.docName.c_str(), + sel.objName.c_str(), + elementName.c_str(), + 0, 0, 0, + SelectionChanges::MsgSource::TreeView); + } } bool SelectionMenu::eventFilter(QObject *obj, QEvent *event) diff --git a/src/Gui/Selection/SelectionView.h b/src/Gui/Selection/SelectionView.h index 28389691b7..a5584a0cce 100644 --- a/src/Gui/Selection/SelectionView.h +++ b/src/Gui/Selection/SelectionView.h @@ -150,6 +150,7 @@ protected: private: QPointer activeMenu; QPointer activeAction; + const std::vector* currentSelections; }; } // namespace Gui