diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.cpp b/src/lib_gui/qt/graphics/QtGraphicsView.cpp index 60ef4395..fdabf8d7 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.cpp +++ b/src/lib_gui/qt/graphics/QtGraphicsView.cpp @@ -14,8 +14,9 @@ #include "qt/element/QtIconButton.h" #include "qt/view/graphElements/QtGraphEdge.h" #include "qt/view/graphElements/QtGraphNode.h" -#include "qt/view/graphElements/QtGraphNodeData.h" #include "qt/view/graphElements/QtGraphNodeBundle.h" +#include "qt/view/graphElements/QtGraphNodeData.h" +#include "qt/view/graphElements/QtGraphNodeExpandToggle.h" #include "qt/utility/QtContextMenu.h" #include "qt/utility/QtFileDialog.h" #include "qt/utility/utilityQt.h" @@ -23,6 +24,7 @@ #include "utility/messaging/type/activation/MessageActivateLegend.h" #include "utility/messaging/type/code/MessageCodeShowDefinition.h" #include "utility/messaging/type/MessageDisplayBookmarkCreator.h" +#include "utility/messaging/type/MessageGraphNodeExpand.h" #include "utility/messaging/type/MessageGraphNodeHide.h" #include "utility/ResourcePaths.h" #include "utility/utilityApp.h" @@ -63,6 +65,16 @@ QtGraphicsView::QtGraphicsView(QWidget* parent) m_copyNodeNameAction->setToolTip("Copies the name of this node to the clipboard"); connect(m_copyNodeNameAction, &QAction::triggered, this, &QtGraphicsView::copyNodeName); + m_collapseAction = new QAction("Collapse Node (Shift + Left Click)", this); + m_collapseAction->setStatusTip("Hide the unconnected members of the node"); + m_collapseAction->setToolTip("Hide the unconnected members of the node"); + connect(m_collapseAction, &QAction::triggered, this, &QtGraphicsView::collapseNode); + + m_expandAction = new QAction("Expand Node (Shift + Left Click)", this); + m_expandAction->setStatusTip("Show unconnected members of the node"); + m_expandAction->setToolTip("Show unconnected members of the node"); + connect(m_expandAction, &QAction::triggered, this, &QtGraphicsView::expandNode); + m_showDefinitionAction = new QAction("Show Definition (Ctrl + Left Click)", this); #if defined(Q_OS_MAC) m_showDefinitionAction->setText("Show Definition (Cmd + Left Click)"); @@ -334,6 +346,8 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event) void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event) { m_clipboardNodeName = L""; + m_collapseNodeId = 0; + m_expandNodeId = 0; m_hideNodeId = 0; m_hideEdgeId = 0; m_bookmarkNodeId = 0; @@ -344,20 +358,42 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event) { while (node) { - m_hideNodeId = node->getTokenId(); - - QtGraphNodeData* dataNode = dynamic_cast(node); - if (dataNode) + if (!m_hideNodeId) { - m_clipboardNodeName = dataNode->getName(); - m_bookmarkNodeId = dataNode->getTokenId(); - clipboardFilePath = dataNode->getFilePath(); - break; + m_hideNodeId = node->getTokenId(); } - else if (dynamic_cast(node)) + + if (!m_clipboardNodeName.size()) { - m_clipboardNodeName = node->getName(); - break; + QtGraphNodeData* dataNode = dynamic_cast(node); + if (dataNode) + { + m_clipboardNodeName = dataNode->getName(); + m_bookmarkNodeId = dataNode->getTokenId(); + clipboardFilePath = dataNode->getFilePath(); + } + else if (dynamic_cast(node)) + { + m_clipboardNodeName = node->getName(); + } + } + + if (!m_collapseNodeId && !m_expandNodeId) + { + for (auto subNode : node->getSubNodes()) + { + if (subNode->isExpandToggleNode()) + { + if (dynamic_cast(subNode)->isExpanded()) + { + m_collapseNodeId = node->getTokenId(); + } + else + { + m_expandNodeId = node->getTokenId(); + } + } + } } node = node->getParent(); @@ -372,6 +408,8 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event) } } + m_collapseAction->setEnabled(m_collapseNodeId); + m_expandAction->setEnabled(m_expandNodeId); m_showDefinitionAction->setEnabled(m_hideNodeId); m_hideNodeAction->setEnabled(m_hideNodeId); m_hideEdgeAction->setEnabled(m_hideEdgeId); @@ -385,6 +423,16 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event) menu.addAction(m_exportGraphAction); menu.addSeparator(); + + if (m_collapseNodeId) + { + menu.addAction(m_collapseAction); + } + else + { + menu.addAction(m_expandAction); + } + menu.addAction(m_showDefinitionAction); menu.addAction(m_hideNodeAction); menu.addAction(m_hideEdgeAction); @@ -541,6 +589,16 @@ void QtGraphicsView::copyNodeName() QApplication::clipboard()->setText(QString::fromStdWString(m_clipboardNodeName)); } +void QtGraphicsView::collapseNode() +{ + MessageGraphNodeExpand(m_collapseNodeId, false).dispatch(); +} + +void QtGraphicsView::expandNode() +{ + MessageGraphNodeExpand(m_expandNodeId, true).dispatch(); +} + void QtGraphicsView::showDefinition() { MessageCodeShowDefinition(m_hideNodeId).dispatch(); diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.h b/src/lib_gui/qt/graphics/QtGraphicsView.h index ff61e6c8..58f262f3 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.h +++ b/src/lib_gui/qt/graphics/QtGraphicsView.h @@ -57,6 +57,10 @@ private slots: void exportGraph(); void copyNodeName(); + + void collapseNode(); + void expandNode(); + void showDefinition(); void hideNode(); void hideEdge(); @@ -90,6 +94,8 @@ private: Id m_hideNodeId; Id m_hideEdgeId; Id m_bookmarkNodeId; + Id m_collapseNodeId; + Id m_expandNodeId; std::shared_ptr m_timer; std::shared_ptr m_timerStopper; @@ -97,6 +103,8 @@ private: QAction* m_exportGraphAction; QAction* m_copyNodeNameAction; + QAction* m_collapseAction; + QAction* m_expandAction; QAction* m_showDefinitionAction; QAction* m_hideNodeAction; QAction* m_hideEdgeAction; diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp index 7ffa3ebf..cd1d9007 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp @@ -11,7 +11,9 @@ #include "qt/utility/utilityQt.h" #include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h" #include "qt/view/graphElements/QtGraphEdge.h" +#include "qt/view/graphElements/QtGraphNodeExpandToggle.h" #include "utility/messaging/type/code/MessageCodeShowDefinition.h" +#include "utility/messaging/type/MessageGraphNodeExpand.h" #include "utility/messaging/type/MessageGraphNodeHide.h" #include "utility/messaging/type/MessageGraphNodeMove.h" #include "utility/ResourcePaths.h" @@ -394,6 +396,23 @@ void QtGraphNode::onHide() } } +void QtGraphNode::onCollapseExpand() +{ + for (auto subNode : getSubNodes()) + { + if (subNode->isExpandToggleNode()) + { + MessageGraphNodeExpand(getTokenId(), !dynamic_cast(subNode)->isExpanded()).dispatch(); + return; + } + } + + if (getParent()) + { + getParent()->onCollapseExpand(); + } +} + void QtGraphNode::onShowDefinition() { Id tokenId = getTokenId(); diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.h b/src/lib_gui/qt/view/graphElements/QtGraphNode.h index 06c4ad84..8386449b 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.h +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.h @@ -95,8 +95,11 @@ public: virtual void addSubNode(QtGraphNode* node); virtual void onClick(); - virtual void onHide(); - virtual void onShowDefinition(); + + void onHide(); + void onCollapseExpand(); + void onShowDefinition(); + virtual void moved(const Vec2i& oldPosition); virtual void updateStyle() = 0; diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.cpp b/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.cpp index fe7504b8..6105c782 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.cpp @@ -89,3 +89,8 @@ void QtGraphNodeExpandToggle::updateStyle() m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.color.icon.c_str())); } + +bool QtGraphNodeExpandToggle::isExpanded() const +{ + return m_expanded; +} diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.h b/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.h index a6f545fd..63acc57b 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.h +++ b/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.h @@ -19,6 +19,8 @@ public: virtual void onClick(); virtual void updateStyle(); + bool isExpanded() const; + protected: virtual void matchName(const std::wstring& query, std::vector* matchedNodes) {} diff --git a/src/lib_gui/qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.cpp b/src/lib_gui/qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.cpp index e749f1f9..11d18040 100644 --- a/src/lib_gui/qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.cpp +++ b/src/lib_gui/qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.cpp @@ -39,6 +39,10 @@ void QtGraphNodeComponentClickable::nodeMouseReleaseEvent(QGraphicsSceneMouseEve { m_graphNode->onHide(); } + else if (event->modifiers() & Qt::ShiftModifier) + { + m_graphNode->onCollapseExpand(); + } else if (event->modifiers() & Qt::ControlModifier) { m_graphNode->onShowDefinition();