diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-03-23 17:13:10 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-03-27 11:32:30 +0000 |
commit | 0ec871dac839ea2b2661f1333dad39534e83f19d (patch) | |
tree | 208a647f8ab5920d743c8486b96a826bdf02225a /src/gui/text | |
parent | 9ccc3070dd284947fc68e9f7964b6bd3ed8123ed (diff) |
Introduce QInputControl::isCommonTextEditShortcut
For handling ShortcutOverride events in text-edit-like controls one must
know if a key event matches a common text edit short cut. The code that
was formerly in QWidgetTextControl is now moved into
QInputControl::isCommonTextEditShortcut to remove duplicated code in
QtQuick and to avoid adding adding a third duplicate in QtWebEngine.
Task-number: QTBUG-59053
Change-Id: I18723bb0224acd33c8ea4a8d0a601bb5e274a7a9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qinputcontrol.cpp | 51 | ||||
-rw-r--r-- | src/gui/text/qinputcontrol_p.h | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/gui/text/qinputcontrol.cpp b/src/gui/text/qinputcontrol.cpp index 2f7dcfcd2b..3381fdb673 100644 --- a/src/gui/text/qinputcontrol.cpp +++ b/src/gui/text/qinputcontrol.cpp @@ -85,4 +85,55 @@ bool QInputControl::isAcceptableInput(const QKeyEvent *event) const return false; } +bool QInputControl::isCommonTextEditShortcut(const QKeyEvent *ke) +{ + if (ke->modifiers() == Qt::NoModifier + || ke->modifiers() == Qt::ShiftModifier + || ke->modifiers() == Qt::KeypadModifier) { + if (ke->key() < Qt::Key_Escape) { + return true; + } else { + switch (ke->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + case Qt::Key_Delete: + case Qt::Key_Home: + case Qt::Key_End: + case Qt::Key_Backspace: + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_Tab: + return true; + default: + break; + } + } +#if QT_CONFIG(shortcut) + } else if (ke->matches(QKeySequence::Copy) + || ke->matches(QKeySequence::Paste) + || ke->matches(QKeySequence::Cut) + || ke->matches(QKeySequence::Redo) + || ke->matches(QKeySequence::Undo) + || ke->matches(QKeySequence::MoveToNextWord) + || ke->matches(QKeySequence::MoveToPreviousWord) + || ke->matches(QKeySequence::MoveToStartOfDocument) + || ke->matches(QKeySequence::MoveToEndOfDocument) + || ke->matches(QKeySequence::SelectNextWord) + || ke->matches(QKeySequence::SelectPreviousWord) + || ke->matches(QKeySequence::SelectStartOfLine) + || ke->matches(QKeySequence::SelectEndOfLine) + || ke->matches(QKeySequence::SelectStartOfBlock) + || ke->matches(QKeySequence::SelectEndOfBlock) + || ke->matches(QKeySequence::SelectStartOfDocument) + || ke->matches(QKeySequence::SelectEndOfDocument) + || ke->matches(QKeySequence::SelectAll) + ) { + return true; +#endif + } + return false; +} + QT_END_NAMESPACE diff --git a/src/gui/text/qinputcontrol_p.h b/src/gui/text/qinputcontrol_p.h index e5709b5e54..b4c1ca8f8f 100644 --- a/src/gui/text/qinputcontrol_p.h +++ b/src/gui/text/qinputcontrol_p.h @@ -69,6 +69,7 @@ public: explicit QInputControl(Type type, QObject *parent = nullptr); bool isAcceptableInput(const QKeyEvent *event) const; + static bool isCommonTextEditShortcut(const QKeyEvent *ke); protected: explicit QInputControl(Type type, QObjectPrivate &dd, QObject *parent = nullptr); |