From 93b85255a6a1fcdb8c37eac584b90315777a4751 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 28 Apr 2022 17:55:26 +0900 Subject: [PATCH 1/5] Add more shortcuts --- README.md | 14 +++++++++++++ bt_editor/graphic_container.cpp | 10 ++++++++++ bt_editor/graphic_container.h | 4 ++++ bt_editor/mainwindow.cpp | 35 ++++++++++++++++++++++++++------- bt_editor/sidepanel_editor.cpp | 27 ++++++++++++++----------- bt_editor/sidepanel_editor.h | 2 ++ 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2677a5bd..33529322 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,20 @@ project is compiled with with _catkin_. rosdep install --from-paths src --ignore-src catkin_make +# Shortcuts +| Key | Action | +| :-: | :-: | +| CTRL-S | Save Tree | +| CTRL-L | Load Tree | +| CTRL-Z | Undo | +| CTRL-SHIFT-Z | Redo | +| C | Center View | +| L | Toggle Layout | +| R | Reorder Nodes | +| N | New Node | +| + | Zoom In | +| - | Zoom Out | + # Licence Copyright (c) 2018-2019 FUNDACIO EURECAT diff --git a/bt_editor/graphic_container.cpp b/bt_editor/graphic_container.cpp index 3dfce1b6..df48f56b 100644 --- a/bt_editor/graphic_container.cpp +++ b/bt_editor/graphic_container.cpp @@ -178,6 +178,16 @@ void GraphicContainer::zoomHomeView() _view->scale(0.9, 0.9); } +void GraphicContainer::zoomIn() +{ + _view->scale(1.1, 1.1); +} + +void GraphicContainer::zoomOut() +{ + _view->scale(0.9, 0.9); +} + bool GraphicContainer::containsValidTree() const { if( _scene->nodes().empty()) diff --git a/bt_editor/graphic_container.h b/bt_editor/graphic_container.h index b725e8bf..dddeed13 100644 --- a/bt_editor/graphic_container.h +++ b/bt_editor/graphic_container.h @@ -35,6 +35,10 @@ class GraphicContainer : public QObject void zoomHomeView(); + void zoomIn(); + + void zoomOut(); + bool containsValidTree() const; void clearScene(); diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 3fdd611f..0754fc78 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -112,14 +112,32 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : dynamic_cast(ui->leftFrame->layout())->setStretch(1,1); - auto arrange_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A), this); - - connect( arrange_shortcut, &QShortcut::activated, - this, &MainWindow::onAutoArrange ); - ui->splitter->setStretchFactor(0, 1); ui->splitter->setStretchFactor(1, 4); + // Shortcuts + QShortcut* rearrange_shortcut = new QShortcut(QKeySequence(Qt::Key_R), this); + QShortcut* centerview_shortcut = new QShortcut(QKeySequence(Qt::Key_C), this); + QShortcut* layout_shortcut = new QShortcut(QKeySequence(Qt::Key_L), this); + QShortcut* newnode_shortcut = new QShortcut(QKeySequence(Qt::Key_N), this); + + connect( rearrange_shortcut, &QShortcut::activated, + this, &MainWindow::on_toolButtonReorder_pressed ); + connect( centerview_shortcut, &QShortcut::activated, + this, &MainWindow::on_toolButtonCenterView_pressed ); + connect( layout_shortcut, &QShortcut::activated, + this, &MainWindow::on_toolButtonLayout_clicked ); + connect( newnode_shortcut, &QShortcut::activated, + _editor_widget, &SidepanelEditor::addNode ); + + QShortcut* zoomin_shortcut = new QShortcut(QKeySequence(Qt::Key_Plus), this); + QShortcut* zoomout_shortcut = new QShortcut(QKeySequence(Qt::Key_Minus), this); + + connect( zoomin_shortcut, &QShortcut::activated, + this, [this] () { currentTabInfo()->zoomIn(); } ); + connect( zoomout_shortcut, &QShortcut::activated, + this, [this] () { currentTabInfo()->zoomOut(); } ); + QShortcut* undo_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z), this); connect( undo_shortcut, &QShortcut::activated, this, &MainWindow::onUndoInvoked ); @@ -127,7 +145,12 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : connect( redo_shortcut, &QShortcut::activated, this, &MainWindow::onRedoInvoked ); QShortcut* save_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this); + connect( save_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSave_triggered ); + QShortcut* load_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this); + connect( load_shortcut, &QShortcut::activated, this, &MainWindow::on_actionLoad_triggered ); + + // Other connections connect( _editor_widget, &SidepanelEditor::nodeModelEdited, this, &MainWindow::onTreeNodeEdited); @@ -178,8 +201,6 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : connect( ui->toolButtonSaveFile, &QToolButton::clicked, this, &MainWindow::on_actionSave_triggered ); - connect( save_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSave_triggered ); - connect( _replay_widget, &SidepanelReplay::changeNodeStyle, this, &MainWindow::onChangeNodesStatus); diff --git a/bt_editor/sidepanel_editor.cpp b/bt_editor/sidepanel_editor.cpp index 7f5c433b..6a57870c 100644 --- a/bt_editor/sidepanel_editor.cpp +++ b/bt_editor/sidepanel_editor.cpp @@ -103,6 +103,21 @@ void SidepanelEditor::clear() } +void SidepanelEditor::addNode() +{ + CustomNodeDialog dialog(_tree_nodes_model, QString(), this); + if( dialog.exec() == QDialog::Accepted) + { + auto new_model = dialog.getTreeNodeModel(); + if( new_model.type == NodeType::SUBTREE ) + { + emit addSubtree( new_model.registration_ID ); + } + emit addNewModel( new_model ); + } + updateTreeView(); +} + void SidepanelEditor::on_paletteTreeWidget_itemSelectionChanged() { auto selected_items = ui->paletteTreeWidget->selectedItems(); @@ -150,17 +165,7 @@ void SidepanelEditor::on_lineEditFilter_textChanged(const QString &text) void SidepanelEditor::on_buttonAddNode_clicked() { - CustomNodeDialog dialog(_tree_nodes_model, QString(), this); - if( dialog.exec() == QDialog::Accepted) - { - auto new_model = dialog.getTreeNodeModel(); - if( new_model.type == NodeType::SUBTREE ) - { - emit addSubtree( new_model.registration_ID ); - } - emit addNewModel( new_model ); - } - updateTreeView(); + addNode(); } void SidepanelEditor::onRemoveModel(QString selected_name) diff --git a/bt_editor/sidepanel_editor.h b/bt_editor/sidepanel_editor.h index 8897d4bc..b12e063c 100644 --- a/bt_editor/sidepanel_editor.h +++ b/bt_editor/sidepanel_editor.h @@ -25,6 +25,8 @@ class SidepanelEditor : public QFrame void clear(); + void addNode(); + public slots: void onRemoveModel(QString selected_name); From 8535f6e5e97308f71ca99b94a7caa0a8245f7b35 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 28 Apr 2022 18:32:17 +0900 Subject: [PATCH 2/5] Switch load shortcut function according to mode --- bt_editor/mainwindow.cpp | 33 +++++++++++++++++++++++++++++++-- bt_editor/mainwindow.h | 4 +++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 0754fc78..a5fb531a 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -147,8 +147,16 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : QShortcut* save_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this); connect( save_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSave_triggered ); - QShortcut* load_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this); - connect( load_shortcut, &QShortcut::activated, this, &MainWindow::on_actionLoad_triggered ); + + _load_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this); + if ( _current_mode == GraphicMode::EDITOR ) { + connect( _load_shortcut, &QShortcut::activated, + this, &MainWindow::on_actionLoad_triggered ); + } + if ( _current_mode == GraphicMode::REPLAY ) { + connect( _load_shortcut, &QShortcut::activated, + _replay_widget, &SidepanelReplay::on_LoadLog); + } // Other connections connect( _editor_widget, &SidepanelEditor::nodeModelEdited, @@ -1299,18 +1307,39 @@ void MainWindow::updateCurrentMode() if( _current_mode == GraphicMode::EDITOR ) { + // Load Button connect( ui->toolButtonLoadFile, &QToolButton::clicked, this, &MainWindow::on_actionLoad_triggered ); disconnect( ui->toolButtonLoadFile, &QToolButton::clicked, _replay_widget, &SidepanelReplay::on_LoadLog ); + // Load Shortcut + disconnect( _load_shortcut, &QShortcut::activated, + _replay_widget, &SidepanelReplay::on_LoadLog); + connect( _load_shortcut, &QShortcut::activated, + this, &MainWindow::on_actionLoad_triggered ); } else if( _current_mode == GraphicMode::REPLAY ) { + // Load Button disconnect( ui->toolButtonLoadFile, &QToolButton::clicked, this, &MainWindow::on_actionLoad_triggered ); connect( ui->toolButtonLoadFile, &QToolButton::clicked, _replay_widget, &SidepanelReplay::on_LoadLog ); + // Load Shortcut + disconnect( _load_shortcut, &QShortcut::activated, + this, &MainWindow::on_actionLoad_triggered ); + connect( _load_shortcut, &QShortcut::activated, + _replay_widget, &SidepanelReplay::on_LoadLog); } + else if( _current_mode == GraphicMode::MONITOR ) + { + // Load Shortcut + disconnect( _load_shortcut, &QShortcut::activated, + this, &MainWindow::on_actionLoad_triggered ); + disconnect( _load_shortcut, &QShortcut::activated, + _replay_widget, &SidepanelReplay::on_LoadLog); + } + lockEditing( NOT_EDITOR ); if( _current_mode == GraphicMode::EDITOR) diff --git a/bt_editor/mainwindow.h b/bt_editor/mainwindow.h index ebfd2c70..56d9ad10 100644 --- a/bt_editor/mainwindow.h +++ b/bt_editor/mainwindow.h @@ -197,7 +197,9 @@ private slots: #ifdef ZMQ_FOUND SidepanelMonitor* _monitor_widget; #endif - + + QShortcut* _load_shortcut; + MainWindow::SavedState saveCurrentState(); void clearUndoStacks(); }; From 603d201722c7fc19db7e7e3ec46c7fcf939d13f3 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 28 Apr 2022 22:49:37 +0900 Subject: [PATCH 3/5] Add redundant shortcut alternatives --- README.md | 2 ++ bt_editor/mainwindow.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 33529322..bbb2c9be 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,9 @@ project is compiled with with _catkin_. | :-: | :-: | | CTRL-S | Save Tree | | CTRL-L | Load Tree | +| CTRL-O | Load Tree | | CTRL-Z | Undo | +| CTRL-Y | Redo | | CTRL-SHIFT-Z | Redo | | C | Center View | | L | Toggle Layout | diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index a5fb531a..1383a623 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -158,6 +158,13 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : _replay_widget, &SidepanelReplay::on_LoadLog); } + QShortcut* load_shortcut_option = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_O), this); + connect(load_shortcut_option, &QShortcut::activated, _load_shortcut, &QShortcut::activated); + + QShortcut* redo_shortcut_option = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y), this); + connect(redo_shortcut_option, &QShortcut::activated, redo_shortcut, &QShortcut::activated); + + // Other connections connect( _editor_widget, &SidepanelEditor::nodeModelEdited, this, &MainWindow::onTreeNodeEdited); From 4d79400c9c235c2ee878d9d06925abda6a717396 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Sun, 9 Oct 2022 17:53:55 +0900 Subject: [PATCH 4/5] Add previous arrange shortcut --- README.md | 5 +++-- bt_editor/mainwindow.cpp | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bbb2c9be..872abcc0 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,10 @@ project is compiled with with _catkin_. | CTRL-Z | Undo | | CTRL-Y | Redo | | CTRL-SHIFT-Z | Redo | -| C | Center View | +| CTRL-A | Reorder (Arrange) Nodes | +| R | Reorder (Arrange) Nodes | | L | Toggle Layout | -| R | Reorder Nodes | +| C | Center View | | N | New Node | | + | Zoom In | | - | Zoom Out | diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 1383a623..41914bf8 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -116,13 +116,16 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : ui->splitter->setStretchFactor(1, 4); // Shortcuts + QShortcut* arrange_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A), this); QShortcut* rearrange_shortcut = new QShortcut(QKeySequence(Qt::Key_R), this); QShortcut* centerview_shortcut = new QShortcut(QKeySequence(Qt::Key_C), this); QShortcut* layout_shortcut = new QShortcut(QKeySequence(Qt::Key_L), this); QShortcut* newnode_shortcut = new QShortcut(QKeySequence(Qt::Key_N), this); + connect( arrange_shortcut, &QShortcut::activated, + this, &MainWindow::onAutoArrange ); connect( rearrange_shortcut, &QShortcut::activated, - this, &MainWindow::on_toolButtonReorder_pressed ); + this, &MainWindow::onAutoArrange ); connect( centerview_shortcut, &QShortcut::activated, this, &MainWindow::on_toolButtonCenterView_pressed ); connect( layout_shortcut, &QShortcut::activated, From f43a22bf99254fad938d7d7f4fabf7b4ea906d91 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Sun, 9 Oct 2022 20:38:48 +0900 Subject: [PATCH 5/5] Setup _load_shortcut before updateCurrentMode --- bt_editor/mainwindow.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 41914bf8..c6dfcc97 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -108,6 +108,7 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : ui->actionMonitor_mode->setVisible(false); #endif + _load_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this); updateCurrentMode(); dynamic_cast(ui->leftFrame->layout())->setStretch(1,1); @@ -150,17 +151,6 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) : QShortcut* save_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this); connect( save_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSave_triggered ); - - _load_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this); - if ( _current_mode == GraphicMode::EDITOR ) { - connect( _load_shortcut, &QShortcut::activated, - this, &MainWindow::on_actionLoad_triggered ); - } - if ( _current_mode == GraphicMode::REPLAY ) { - connect( _load_shortcut, &QShortcut::activated, - _replay_widget, &SidepanelReplay::on_LoadLog); - } - QShortcut* load_shortcut_option = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_O), this); connect(load_shortcut_option, &QShortcut::activated, _load_shortcut, &QShortcut::activated);