Skip to content

Commit

Permalink
Plugin shortcuts (swri-robotics#824)
Browse files Browse the repository at this point in the history
* Added hotkey for plugin remove (Ctrl + X)

* Added key shortcut for plugin rename (CTRL + R)

* Added Ctrl + N shortcut for adding new plugin.
  • Loading branch information
rjb0026 authored Aug 11, 2024
1 parent 102a288 commit 9634e79
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mapviz/include/mapviz/mapviz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <QWidget>
#include <QStringList>
#include <QMainWindow>
#include <QShortcut>

#include <swri_transform_util/transform_manager.h>
#include <mapviz_interfaces/srv/add_mapviz_display.hpp> // Service
Expand Down Expand Up @@ -98,6 +99,8 @@ public Q_SLOTS:
void SelectNewDisplay();
void RemoveDisplay();
void RemoveDisplay(QListWidgetItem* item);
void RenameDisplay();
void RenameDisplay(QListWidgetItem* item);
void ReorderDisplays();
void FixedFrameSelected(const QString& text);
void TargetFrameSelected(const QString& text);
Expand Down
2 changes: 2 additions & 0 deletions mapviz/src/config_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ namespace mapviz
ui_.setupUi(this);

edit_name_action_ = new QAction("Edit Name", this);
edit_name_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
remove_item_action_ = new QAction("Remove", this);
remove_item_action_->setIcon(QIcon(":/images/remove-icon-th.png"));
remove_item_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_X));

connect(edit_name_action_, SIGNAL(triggered()), this, SLOT(EditName()));
connect(remove_item_action_, SIGNAL(triggered()), this, SLOT(Remove()));
Expand Down
22 changes: 22 additions & 0 deletions mapviz/src/mapviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ Mapviz::Mapviz(bool is_standalone, int argc, char** argv, QWidget *parent, Qt::W

ui_.bg_color->setColor(background_);
canvas_->SetBackground(background_);

// Keyboard shortcuts for the main window
QShortcut * remove_display_shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_X), this);
connect(remove_display_shortcut, SIGNAL(activated()), this, SLOT(RemoveDisplay()));
QShortcut * rename_display_shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_R), this);
connect(rename_display_shortcut, SIGNAL(activated()), this, SLOT(RenameDisplay()));
QShortcut * add_display_shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_N), this);
connect(add_display_shortcut, SIGNAL(activated()), this, SLOT(SelectNewDisplay()));
}

Mapviz::~Mapviz()
Expand Down Expand Up @@ -1449,6 +1457,20 @@ void Mapviz::RemoveDisplay(QListWidgetItem* item)
}
}

void Mapviz::RenameDisplay()
{
QListWidgetItem* item = ui_.configs->currentItem();
RenameDisplay(item);
}

void Mapviz::RenameDisplay(QListWidgetItem* item)
{
if (item) {
ConfigItem* config_item = static_cast<ConfigItem*>(ui_.configs->itemWidget(item));
config_item->EditName();
}
}

void Mapviz::ClearDisplays()
{
while (ui_.configs->count() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions mapviz/ui/mapviz.ui
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
</size>
</property>
<property name="toolTip">
<string>Add a new display</string>
<string>Add a new display (Ctrl + N)</string>
</property>
<property name="text">
<string>Add</string>
Expand All @@ -327,7 +327,7 @@
</size>
</property>
<property name="toolTip">
<string>Remove the selected display</string>
<string>Remove the selected display (Ctrl + X)</string>
</property>
<property name="text">
<string>Remove</string>
Expand Down

0 comments on commit 9634e79

Please sign in to comment.