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 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | QInputControl::QInputControl(Type type, QObject *parent) |
46 | : QObject(parent) |
47 | , m_type(type) |
48 | { |
49 | } |
50 | |
51 | QInputControl::QInputControl(Type type, QObjectPrivate &dd, QObject *parent) |
52 | : QObject(dd, parent) |
53 | , m_type(type) |
54 | { |
55 | } |
56 | |
57 | bool 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(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 (m_type == TextEdit && c == QLatin1Char('\t')) |
83 | return true; |
84 | |
85 | return false; |
86 | } |
87 | |
88 | bool QInputControl::isCommonTextEditShortcut(const QKeyEvent *ke) |
89 | { |
90 | if (ke->modifiers() == Qt::NoModifier |
91 | || ke->modifiers() == Qt::ShiftModifier |
92 | || ke->modifiers() == Qt::KeypadModifier) { |
93 | if (ke->key() < Qt::Key_Escape) { |
94 | return true; |
95 | } else { |
96 | switch (ke->key()) { |
97 | case Qt::Key_Return: |
98 | case Qt::Key_Enter: |
99 | case Qt::Key_Delete: |
100 | case Qt::Key_Home: |
101 | case Qt::Key_End: |
102 | case Qt::Key_Backspace: |
103 | case Qt::Key_Left: |
104 | case Qt::Key_Right: |
105 | case Qt::Key_Up: |
106 | case Qt::Key_Down: |
107 | case Qt::Key_Tab: |
108 | return true; |
109 | default: |
110 | break; |
111 | } |
112 | } |
113 | #if QT_CONFIG(shortcut) |
114 | } else if (ke->matches(QKeySequence::Copy) |
115 | || ke->matches(QKeySequence::Paste) |
116 | || ke->matches(QKeySequence::Cut) |
117 | || ke->matches(QKeySequence::Redo) |
118 | || ke->matches(QKeySequence::Undo) |
119 | || ke->matches(QKeySequence::MoveToNextWord) |
120 | || ke->matches(QKeySequence::MoveToPreviousWord) |
121 | || ke->matches(QKeySequence::MoveToStartOfDocument) |
122 | || ke->matches(QKeySequence::MoveToEndOfDocument) |
123 | || ke->matches(QKeySequence::SelectNextWord) |
124 | || ke->matches(QKeySequence::SelectPreviousWord) |
125 | || ke->matches(QKeySequence::SelectStartOfLine) |
126 | || ke->matches(QKeySequence::SelectEndOfLine) |
127 | || ke->matches(QKeySequence::SelectStartOfBlock) |
128 | || ke->matches(QKeySequence::SelectEndOfBlock) |
129 | || ke->matches(QKeySequence::SelectStartOfDocument) |
130 | || ke->matches(QKeySequence::SelectEndOfDocument) |
131 | || ke->matches(QKeySequence::SelectAll) |
132 | ) { |
133 | return true; |
134 | #endif |
135 | } |
136 | return false; |
137 | } |
138 | |
139 | QT_END_NAMESPACE |
140 | |