diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index 9790386c..dac3de06 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -603,6 +603,8 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : connect(partTreeWidget, &SkeletonPartTreeWidget::lockDescendantComponents, m_document, &SkeletonDocument::lockDescendantComponents); connect(partTreeWidget, &SkeletonPartTreeWidget::unlockDescendantComponents, m_document, &SkeletonDocument::unlockDescendantComponents); + connect(partTreeWidget, &SkeletonPartTreeWidget::addPartToSelection, graphicsWidget, &SkeletonGraphicsWidget::addPartToSelection); + connect(m_document, &SkeletonDocument::componentNameChanged, partTreeWidget, &SkeletonPartTreeWidget::componentNameChanged); connect(m_document, &SkeletonDocument::componentChildrenChanged, partTreeWidget, &SkeletonPartTreeWidget::componentChildrenChanged); connect(m_document, &SkeletonDocument::componentRemoved, partTreeWidget, &SkeletonPartTreeWidget::componentRemoved); diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 9d0744a9..b5d831d8 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -1939,6 +1939,41 @@ void SkeletonGraphicsWidget::addSelectEdge(QUuid edgeId) hoverPart(QUuid()); } +void SkeletonGraphicsWidget::addPartToSelection(QUuid partId) +{ + SkeletonProfile choosenProfile = SkeletonProfile::Main; + if (m_hoveredNodeItem) { + choosenProfile = m_hoveredNodeItem->profile(); + } else if (m_hoveredEdgeItem) { + choosenProfile = m_hoveredEdgeItem->profile(); + } + QUuid choosenPartId = partId; + for (const auto &it: nodeItemMap) { + SkeletonGraphicsNodeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second; + const SkeletonNode *node = m_document->findNode(item->id()); + if (!node) + continue; + if (choosenPartId.isNull()) { + choosenPartId = node->partId; + } + if (node->partId != choosenPartId) + continue; + addItemToRangeSelection(item); + } + for (const auto &it: edgeItemMap) { + SkeletonGraphicsEdgeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second; + const SkeletonEdge *edge = m_document->findEdge(item->id()); + if (!edge) + continue; + if (choosenPartId.isNull()) { + choosenPartId = edge->partId; + } + if (edge->partId != choosenPartId) + continue; + addItemToRangeSelection(item); + } +} + void SkeletonGraphicsWidget::selectPartAll() { unselectAll(); diff --git a/src/skeletongraphicswidget.h b/src/skeletongraphicswidget.h index 86ed3426..92d43241 100644 --- a/src/skeletongraphicswidget.h +++ b/src/skeletongraphicswidget.h @@ -433,6 +433,7 @@ public slots: void selectAll(); void unselectAll(); void selectPartAll(); + void addPartToSelection(QUuid partId); void cut(); void copy(); void flipHorizontally(); diff --git a/src/skeletonparttreewidget.cpp b/src/skeletonparttreewidget.cpp index 7c44ecb5..87440501 100644 --- a/src/skeletonparttreewidget.cpp +++ b/src/skeletonparttreewidget.cpp @@ -97,6 +97,7 @@ void SkeletonPartTreeWidget::showContextMenu(const QPoint &pos) QAction unlockAction(tr("Unlock"), this); QAction invertAction(tr("Invert"), this); QAction cancelInverseAction(tr("Cancel Inverse"), this); + QAction selectAction(tr("Select"), this); if (!component->linkToPartId.isNull()) { emit checkPart(component->linkToPartId); @@ -128,6 +129,15 @@ void SkeletonPartTreeWidget::showContextMenu(const QPoint &pos) } } else { if (!component->childrenIds.empty()) { + connect(&selectAction, &QAction::triggered, [=]() { + std::vector partIds; + m_document->collectComponentDescendantParts(componentId, partIds); + for (const auto &partId: partIds) { + emit addPartToSelection(partId); + } + }); + contextMenu.addAction(&selectAction); + connect(&showAction, &QAction::triggered, [=]() { emit showDescendantComponents(componentId); }); diff --git a/src/skeletonparttreewidget.h b/src/skeletonparttreewidget.h index c88cab28..94505e9f 100644 --- a/src/skeletonparttreewidget.h +++ b/src/skeletonparttreewidget.h @@ -37,6 +37,7 @@ signals: void showDescendantComponents(QUuid componentId); void lockDescendantComponents(QUuid componentId); void unlockDescendantComponents(QUuid componentId); + void addPartToSelection(QUuid partId); public: SkeletonPartTreeWidget(const SkeletonDocument *document, QWidget *parent); QTreeWidgetItem *findComponentItem(QUuid componentId);