| 35 | } |
| 36 | |
| 37 | void GraphScene::contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) |
| 38 | { |
| 39 | auto adaptixWidget = qobject_cast<AdaptixWidget*>( mainWidget ); |
| 40 | if (!adaptixWidget) |
| 41 | return; |
| 42 | |
| 43 | auto graphics_items = selectedItems(); |
| 44 | if(graphics_items.empty()) { |
| 45 | if( (graphics_items = items(event->scenePos())).empty() ) { |
| 46 | auto* sessionsGraph = qobject_cast<SessionsGraph*>(parent()); |
| 47 | if (!sessionsGraph) |
| 48 | return QGraphicsScene::contextMenuEvent( event ); |
| 49 | |
| 50 | auto layoutMenu = QMenu("Layout"); |
| 51 | auto* actionLeftToRight = layoutMenu.addAction("Left to Right"); |
| 52 | auto* actionTopToBottom = layoutMenu.addAction("Top to Bottom"); |
| 53 | |
| 54 | actionLeftToRight->setCheckable(true); |
| 55 | actionTopToBottom->setCheckable(true); |
| 56 | actionLeftToRight->setChecked(sessionsGraph->GetLayoutDirection() == LayoutLeftToRight); |
| 57 | actionTopToBottom->setChecked(sessionsGraph->GetLayoutDirection() == LayoutTopToBottom); |
| 58 | |
| 59 | auto ctxMenu = QMenu(); |
| 60 | ctxMenu.addMenu(&layoutMenu); |
| 61 | |
| 62 | const auto action = ctxMenu.exec(event->screenPos()); |
| 63 | if (action == actionLeftToRight) { |
| 64 | sessionsGraph->SetLayoutDirection(LayoutLeftToRight); |
| 65 | } else if (action == actionTopToBottom) { |
| 66 | sessionsGraph->SetLayoutDirection(LayoutTopToBottom); |
| 67 | } |
| 68 | return; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | QStringList agentIds; |
| 73 | for ( const auto& _graphics_item : graphics_items ) { |
| 74 | const auto item = dynamic_cast<GraphItem*>( _graphics_item ); |
| 75 | if ( item && item->agent ) |
| 76 | agentIds.append(item->agent->data.Id); |
| 77 | } |
| 78 | if (agentIds.size() == 0) |
| 79 | return; |
| 80 | |
| 81 | |
| 82 | QMenu ctxMenu; |
| 83 | |
| 84 | auto agentMenu = ctxMenu.addMenu("Agent"); |
| 85 | agentMenu->addAction("Execute command", this, [graphics_items]() { |
| 86 | bool ok = false; |
| 87 | QString cmd = QInputDialog::getText(nullptr, "Execute Command", "Command", QLineEdit::Normal, "", &ok); |
| 88 | if (!ok) |
| 89 | return; |
| 90 | const auto item = dynamic_cast<GraphItem*>(graphics_items[0]); |
| 91 | if (item && item->agent) { |
| 92 | item->agent->Console->SetInput(cmd); |
| 93 | item->agent->Console->processInput(); |
| 94 | } |
nothing calls this directly
no test coverage detected