From 6d3d44835ac435e85346c4fccaad0669edd2afa1 Mon Sep 17 00:00:00 2001 From: Scott Furry Date: Fri, 28 Jun 2019 09:17:24 -0600 Subject: [PATCH] Add keyboard shortcuts for CodeEditor Widget (#1931) Functionality for `copy` and `select all` text already exists as part of widget construction. Commit adds connection of those existing functions to execution with keyboard shortcuts user would normally expect. (e.g. CTRL+C for copy text) Qt does translation of keyboard shortcuts for platform (i.e. Mac OS uses command key rather than control). --- gui/codeeditor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index 3c48d83e1..9219008b6 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -1,5 +1,5 @@ #include - +#include #include "codeeditor.h" @@ -200,8 +200,13 @@ CodeEditor::CodeEditor(QWidget *parent) : setObjectName("CodeEditor"); setStyleSheet(generateStyleString()); + QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this); + QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this); + connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); + connect(copyText, SIGNAL(activated()), this, SLOT(copy())); + connect(allText, SIGNAL(activated()), this, SLOT(selectAll())); updateLineNumberAreaWidth(0); }