1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qinputcontrol_p.h"
41#include <QtGui/qevent.h>
42
43QT_BEGIN_NAMESPACE
44
45QInputControl::QInputControl(Type type, QObject *parent)
46 : QObject(parent)
47 , m_type(type)
48{
49}
50
51QInputControl::QInputControl(Type type, QObjectPrivate &dd, QObject *parent)
52 : QObject(dd, parent)
53 , m_type(type)
54{
55}
56
57bool QInputControl::isAcceptableInput(const QKeyEvent *event) const
58{
59 const QString text = event->text();
60 if (text.isEmpty())
61 return false;
62
63 const QChar c = text.at(i: 0);
64
65 // Formatting characters such as ZWNJ, ZWJ, RLM, etc. This needs to go before the
66 // next test, since CTRL+SHIFT is sometimes used to input it on Windows.
67 if (c.category() == QChar::Other_Format)
68 return true;
69
70 // QTBUG-35734: ignore Ctrl/Ctrl+Shift; accept only AltGr (Alt+Ctrl) on German keyboards
71 if (event->modifiers() == Qt::ControlModifier
72 || event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) {
73 return false;
74 }
75
76 if (c.isPrint())
77 return true;
78
79 if (c.category() == QChar::Other_PrivateUse)
80 return true;
81
82 if (c.isHighSurrogate() && text.length() > 1 && text.at(i: 1).isLowSurrogate())
83 return true;
84
85 if (m_type == TextEdit && c == QLatin1Char('\t'))
86 return true;
87
88 return false;
89}
90
91bool QInputControl::isCommonTextEditShortcut(const QKeyEvent *ke)
92{
93 if (ke->modifiers() == Qt::NoModifier
94 || ke->modifiers() == Qt::ShiftModifier
95 || ke->modifiers() == Qt::KeypadModifier) {
96 if (ke->key() < Qt::Key_Escape) {
97 return true;
98 } else {
99 switch (ke->key()) {
100 case Qt::Key_Return:
101 case Qt::Key_Enter:
102 case Qt::Key_Delete:
103 case Qt::Key_Home:
104 case Qt::Key_End:
105 case Qt::Key_Backspace:
106 case Qt::Key_Left:
107 case Qt::Key_Right:
108 case Qt::Key_Up:
109 case Qt::Key_Down:
110 case Qt::Key_Tab:
111 return true;
112 default:
113 break;
114 }
115 }
116#if QT_CONFIG(shortcut)
117 } else if (ke->matches(key: QKeySequence::Copy)
118 || ke->matches(key: QKeySequence::Paste)
119 || ke->matches(key: QKeySequence::Cut)
120 || ke->matches(key: QKeySequence::Redo)
121 || ke->matches(key: QKeySequence::Undo)
122 || ke->matches(key: QKeySequence::MoveToNextWord)
123 || ke->matches(key: QKeySequence::MoveToPreviousWord)
124 || ke->matches(key: QKeySequence::MoveToStartOfDocument)
125 || ke->matches(key: QKeySequence::MoveToEndOfDocument)
126 || ke->matches(key: QKeySequence::SelectNextWord)
127 || ke->matches(key: QKeySequence::SelectPreviousWord)
128 || ke->matches(key: QKeySequence::SelectStartOfLine)
129 || ke->matches(key: QKeySequence::SelectEndOfLine)
130 || ke->matches(key: QKeySequence::SelectStartOfBlock)
131 || ke->matches(key: QKeySequence::SelectEndOfBlock)
132 || ke->matches(key: QKeySequence::SelectStartOfDocument)
133 || ke->matches(key: QKeySequence::SelectEndOfDocument)
134 || ke->matches(key: QKeySequence::SelectAll)
135 ) {
136 return true;
137#endif
138 }
139 return false;
140}
141
142QT_END_NAMESPACE
143

source code of qtbase/src/gui/text/qinputcontrol.cpp