1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qinputcontrol_p.h" |
5 | #include <QtGui/qevent.h> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | QInputControl::QInputControl(Type type, QObject *parent) |
10 | : QObject(parent) |
11 | , m_type(type) |
12 | { |
13 | } |
14 | |
15 | QInputControl::QInputControl(Type type, QObjectPrivate &dd, QObject *parent) |
16 | : QObject(dd, parent) |
17 | , m_type(type) |
18 | { |
19 | } |
20 | |
21 | bool QInputControl::isAcceptableInput(const QKeyEvent *event) const |
22 | { |
23 | const QString text = event->text(); |
24 | if (text.isEmpty()) |
25 | return false; |
26 | |
27 | const QChar c = text.at(i: 0); |
28 | |
29 | // Formatting characters such as ZWNJ, ZWJ, RLM, etc. This needs to go before the |
30 | // next test, since CTRL+SHIFT is sometimes used to input it on Windows. |
31 | if (c.category() == QChar::Other_Format) |
32 | return true; |
33 | |
34 | // QTBUG-35734: ignore Ctrl/Ctrl+Shift; accept only AltGr (Alt+Ctrl) on German keyboards |
35 | if (event->modifiers() == Qt::ControlModifier |
36 | || event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { |
37 | return false; |
38 | } |
39 | |
40 | if (c.isPrint()) |
41 | return true; |
42 | |
43 | if (c.category() == QChar::Other_PrivateUse) |
44 | return true; |
45 | |
46 | if (c.isHighSurrogate() && text.size() > 1 && text.at(i: 1).isLowSurrogate()) |
47 | return true; |
48 | |
49 | if (m_type == TextEdit && c == u'\t') |
50 | return true; |
51 | |
52 | return false; |
53 | } |
54 | |
55 | bool QInputControl::isCommonTextEditShortcut(const QKeyEvent *ke) |
56 | { |
57 | if (ke->modifiers() == Qt::NoModifier |
58 | || ke->modifiers() == Qt::ShiftModifier |
59 | || ke->modifiers() == Qt::KeypadModifier) { |
60 | if (ke->key() < Qt::Key_Escape) { |
61 | return true; |
62 | } else { |
63 | switch (ke->key()) { |
64 | case Qt::Key_Return: |
65 | case Qt::Key_Enter: |
66 | case Qt::Key_Delete: |
67 | case Qt::Key_Home: |
68 | case Qt::Key_End: |
69 | case Qt::Key_Backspace: |
70 | case Qt::Key_Left: |
71 | case Qt::Key_Right: |
72 | case Qt::Key_Up: |
73 | case Qt::Key_Down: |
74 | case Qt::Key_Tab: |
75 | return true; |
76 | default: |
77 | break; |
78 | } |
79 | } |
80 | #if QT_CONFIG(shortcut) |
81 | } else if (ke->matches(key: QKeySequence::Copy) |
82 | || ke->matches(key: QKeySequence::Paste) |
83 | || ke->matches(key: QKeySequence::Cut) |
84 | || ke->matches(key: QKeySequence::Redo) |
85 | || ke->matches(key: QKeySequence::Undo) |
86 | || ke->matches(key: QKeySequence::MoveToNextWord) |
87 | || ke->matches(key: QKeySequence::MoveToPreviousWord) |
88 | || ke->matches(key: QKeySequence::MoveToStartOfDocument) |
89 | || ke->matches(key: QKeySequence::MoveToEndOfDocument) |
90 | || ke->matches(key: QKeySequence::SelectNextWord) |
91 | || ke->matches(key: QKeySequence::SelectPreviousWord) |
92 | || ke->matches(key: QKeySequence::SelectStartOfLine) |
93 | || ke->matches(key: QKeySequence::SelectEndOfLine) |
94 | || ke->matches(key: QKeySequence::SelectStartOfBlock) |
95 | || ke->matches(key: QKeySequence::SelectEndOfBlock) |
96 | || ke->matches(key: QKeySequence::SelectStartOfDocument) |
97 | || ke->matches(key: QKeySequence::SelectEndOfDocument) |
98 | || ke->matches(key: QKeySequence::SelectAll) |
99 | ) { |
100 | return true; |
101 | #endif |
102 | } |
103 | return false; |
104 | } |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #include "moc_qinputcontrol_p.cpp" |
109 | |