MCPcopy Create free account
hub / github.com/Adaptix-Framework/AdaptixC2 / contextMenuEvent

Method contextMenuEvent

AdaptixClient/Source/UI/Graph/GraphScene.cpp:37–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void 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 }

Callers

nothing calls this directly

Calls 15

itemsFunction · 0.85
QMenuClass · 0.85
MessageErrorFunction · 0.85
HttpReqAgentRemoveAsyncFunction · 0.85
HttpReqAgentSetMarkAsyncFunction · 0.85
HttpReqAgentSetTagAsyncFunction · 0.85
emptyMethod · 0.80
setCheckableMethod · 0.80
GetLayoutDirectionMethod · 0.80
execMethod · 0.80
SetLayoutDirectionMethod · 0.80

Tested by

no test coverage detected