Skip to content

Commit 7d4de07

Browse files
committed
Add shortcut for keyword insertion.
1 parent 856e428 commit 7d4de07

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/gui/map/map_find_feature.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <functional>
2525

26+
#include <Qt>
2627
#include <QAbstractButton>
2728
#include <QAction>
2829
#include <QCheckBox>
@@ -35,6 +36,7 @@
3536
#include <QMenu>
3637
#include <QPoint>
3738
#include <QPushButton>
39+
#include <QRect>
3840
#include <QStackedLayout>
3941
#include <QTextCursor>
4042
#include <QVariant>
@@ -352,9 +354,27 @@ void MapFindTextEdit::insertKeyword(QAction* action)
352354
// override
353355
void MapFindTextEdit::contextMenuEvent(QContextMenuEvent* event)
354356
{
355-
QMenu* menu = createStandardContextMenu(event->globalPos());
357+
showCustomContextMenu(event->globalPos());
358+
}
359+
360+
// override
361+
void MapFindTextEdit::keyPressEvent(QKeyEvent* event)
362+
{
363+
if (event->key() == tr("K") && (event->modifiers() & Qt::ControlModifier))
364+
{
365+
showCustomContextMenu(viewport()->mapToGlobal(cursorRect().center()));
366+
}
367+
else
368+
{
369+
QTextEdit::keyPressEvent(event);
370+
}
371+
}
372+
373+
void MapFindTextEdit::showCustomContextMenu(const QPoint& globalPos)
374+
{
375+
QMenu* menu = createStandardContextMenu(globalPos);
356376
menu->addSeparator();
357-
auto* insert_menu = new QMenu(tr("Insert keyword..."), menu);
377+
auto* insert_menu = new QMenu(tr("Insert keyword...\tCtrl+K"), menu);
358378
insert_menu->menuAction()->setMenuRole(QAction::NoRole);
359379
auto* keyword_actions_group = new QActionGroup(this);
360380

@@ -374,7 +394,7 @@ void MapFindTextEdit::contextMenuEvent(QContextMenuEvent* event)
374394
menu->addMenu(insert_menu);
375395
connect(keyword_actions_group, &QActionGroup::triggered, this, &MapFindTextEdit::insertKeyword);
376396

377-
menu->exec(event->globalPos());
397+
menu->exec(globalPos);
378398
delete menu;
379399
}
380400

src/gui/map/map_find_feature.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QCheckBox;
3232
class QContextMenuEvent;
3333
class QDialog;
3434
class QLabel;
35+
class QPoint;
3536
class QPushButton;
3637
class QStackedLayout;
3738
class QWidget;
@@ -44,7 +45,7 @@ class ObjectQuery;
4445
class TagSelectWidget;
4546

4647
/**
47-
* The context menu (right click) is extended by the possibility
48+
* The context menu (right click or Ctrl+K) is extended by the possibility
4849
* to select and insert one of the keywords (e.g., SYMBOL, AND...)
4950
*/
5051
class MapFindTextEdit : public QTextEdit
@@ -53,6 +54,8 @@ class MapFindTextEdit : public QTextEdit
5354

5455
private:
5556
void contextMenuEvent(QContextMenuEvent* event) override;
57+
void keyPressEvent(QKeyEvent* event) override;
58+
void showCustomContextMenu(const QPoint& globalPos);
5659

5760
private slots:
5861
void insertKeyword(QAction* action);

0 commit comments

Comments
 (0)