KB shortcuts in context menu

This commit is contained in:
Joey Yakimowich-Payne 2026-01-30 07:34:30 -07:00
commit 3a8450cb70
2 changed files with 75 additions and 0 deletions

View file

@ -192,6 +192,51 @@ GraphEditorWidget::GraphEditorWidget(warppipe::Client *client,
});
m_view->addAction(autoArrangeAction);
auto *selectAllAction =
new QAction(QStringLiteral("Select All"), m_view);
selectAllAction->setShortcut(QKeySequence::SelectAll);
selectAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(selectAllAction, &QAction::triggered, this, [this]() {
for (auto *item : m_scene->items()) {
item->setSelected(true);
}
});
m_view->addAction(selectAllAction);
auto *deselectAllAction =
new QAction(QStringLiteral("Deselect All"), m_view);
deselectAllAction->setShortcut(
QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_A));
deselectAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(deselectAllAction, &QAction::triggered, m_scene,
&QGraphicsScene::clearSelection);
m_view->addAction(deselectAllAction);
auto *zoomFitAllAction =
new QAction(QStringLiteral("Zoom Fit All"), m_view);
zoomFitAllAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F));
zoomFitAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(zoomFitAllAction, &QAction::triggered, m_view,
&QtNodes::GraphicsView::zoomFitAll);
m_view->addAction(zoomFitAllAction);
auto *zoomFitSelectedAction =
new QAction(QStringLiteral("Zoom Fit Selected"), m_view);
zoomFitSelectedAction->setShortcut(QKeySequence(Qt::Key_F));
zoomFitSelectedAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(zoomFitSelectedAction, &QAction::triggered, m_view,
&QtNodes::GraphicsView::zoomFitSelected);
m_view->addAction(zoomFitSelectedAction);
auto *refreshAction =
new QAction(QStringLiteral("Refresh Graph"), m_view);
refreshAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
refreshAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(refreshAction, &QAction::triggered, this, [this]() {
m_model->refreshFromClient();
});
m_view->addAction(refreshAction);
connect(m_model, &WarpGraphModel::nodePositionUpdated, this,
&GraphEditorWidget::scheduleSaveLayout);
@ -351,7 +396,20 @@ void GraphEditorWidget::showCanvasContextMenu(const QPoint &screenPos,
QStringLiteral(
"application/warppipe-virtual-graph"))));
menu.addSeparator();
QAction *selectAll = menu.addAction(QStringLiteral("Select All"));
selectAll->setShortcut(QKeySequence::SelectAll);
QAction *deselectAll = menu.addAction(QStringLiteral("Deselect All"));
deselectAll->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_A));
menu.addSeparator();
QAction *zoomFitAll = menu.addAction(QStringLiteral("Zoom Fit All"));
zoomFitAll->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F));
QAction *zoomFitSelected = menu.addAction(QStringLiteral("Zoom Fit Selected"));
zoomFitSelected->setShortcut(QKeySequence(Qt::Key_F));
menu.addSeparator();
QAction *autoArrange = menu.addAction(QStringLiteral("Auto-Arrange"));
autoArrange->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_L));
QAction *refreshGraph = menu.addAction(QStringLiteral("Refresh Graph"));
refreshGraph->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
QAction *chosen = menu.exec(screenPos);
if (chosen == createSink) {
@ -360,8 +418,20 @@ void GraphEditorWidget::showCanvasContextMenu(const QPoint &screenPos,
createVirtualNode(false, scenePos);
} else if (chosen == pasteAction) {
pasteSelection(QPointF(0, 0));
} else if (chosen == selectAll) {
for (auto *item : m_scene->items()) {
item->setSelected(true);
}
} else if (chosen == deselectAll) {
m_scene->clearSelection();
} else if (chosen == zoomFitAll) {
m_view->zoomFitAll();
} else if (chosen == zoomFitSelected) {
m_view->zoomFitSelected();
} else if (chosen == autoArrange) {
m_model->autoArrange();
} else if (chosen == refreshGraph) {
m_model->refreshFromClient();
}
}

View file

@ -515,6 +515,11 @@ TEST_CASE("GraphEditorWidget registers custom keyboard actions") {
REQUIRE(actionTexts.contains("Paste Selection"));
REQUIRE(actionTexts.contains("Duplicate Selection"));
REQUIRE(actionTexts.contains("Auto-Arrange"));
REQUIRE(actionTexts.contains("Select All"));
REQUIRE(actionTexts.contains("Deselect All"));
REQUIRE(actionTexts.contains("Zoom Fit All"));
REQUIRE(actionTexts.contains("Zoom Fit Selected"));
REQUIRE(actionTexts.contains("Refresh Graph"));
}
TEST_CASE("GraphEditorWidget reflects injected nodes") {