mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
LineEdit: translate Ctrl+[ to Esc
This commit is contained in:
parent
4e7cac6aef
commit
19b5163d0b
@ -1,6 +1,7 @@
|
|||||||
#include "lineedit.h"
|
#include "lineedit.h"
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include <utils/widgetutils.h>
|
#include <utils/widgetutils.h>
|
||||||
|
|
||||||
@ -21,19 +22,35 @@ void LineEdit::keyPressEvent(QKeyEvent *p_event)
|
|||||||
// Note that QKeyEvent starts with isAccepted() == true, so you do not
|
// Note that QKeyEvent starts with isAccepted() == true, so you do not
|
||||||
// need to call QKeyEvent::accept() - just do not call the base class
|
// need to call QKeyEvent::accept() - just do not call the base class
|
||||||
// implementation if you act upon the key.
|
// implementation if you act upon the key.
|
||||||
bool accept = false;
|
bool accepted = false;
|
||||||
int modifiers = p_event->modifiers();
|
int modifiers = p_event->modifiers();
|
||||||
switch (p_event->key()) {
|
switch (p_event->key()) {
|
||||||
case Qt::Key_H:
|
case Qt::Key_BracketLeft:
|
||||||
// Backspace.
|
{
|
||||||
if (WidgetUtils::isViControlModifier(modifiers)) {
|
if (WidgetUtils::isViControlModifier(modifiers)) {
|
||||||
backspace();
|
auto escEvent = new QKeyEvent(QEvent::KeyPress,
|
||||||
accept = true;
|
Qt::Key_Escape,
|
||||||
|
Qt::NoModifier);
|
||||||
|
QCoreApplication::postEvent(this, escEvent);
|
||||||
|
accepted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Qt::Key_H:
|
||||||
|
{
|
||||||
|
// Backspace.
|
||||||
|
if (WidgetUtils::isViControlModifier(modifiers)) {
|
||||||
|
backspace();
|
||||||
|
accepted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Qt::Key_W:
|
case Qt::Key_W:
|
||||||
|
{
|
||||||
// Delete one word backward.
|
// Delete one word backward.
|
||||||
if (WidgetUtils::isViControlModifier(modifiers)) {
|
if (WidgetUtils::isViControlModifier(modifiers)) {
|
||||||
if (!hasSelectedText()) {
|
if (!hasSelectedText()) {
|
||||||
@ -41,10 +58,11 @@ void LineEdit::keyPressEvent(QKeyEvent *p_event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
backspace();
|
backspace();
|
||||||
accept = true;
|
accepted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Qt::Key_U:
|
case Qt::Key_U:
|
||||||
{
|
{
|
||||||
@ -59,7 +77,7 @@ void LineEdit::keyPressEvent(QKeyEvent *p_event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accept = true;
|
accepted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -69,7 +87,7 @@ void LineEdit::keyPressEvent(QKeyEvent *p_event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accept) {
|
if (!accepted) {
|
||||||
QLineEdit::keyPressEvent(p_event);
|
QLineEdit::keyPressEvent(p_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user