Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qinputcontrol.cpp
Go to the documentation of this file.
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
8
11 , m_type(type)
12{
13}
14
16 : QObject(dd, parent)
17 , m_type(type)
18{
19}
20
22{
23 const QString text = event->text();
24 if (text.isEmpty())
25 return false;
26
27 const QChar c = text.at(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(1).isLowSurrogate())
47 return true;
48
49 if (m_type == TextEdit && c == u'\t')
50 return true;
51
52 return false;
53}
54
56{
57 if (ke->modifiers() == Qt::NoModifier
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:
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(QKeySequence::Copy)
82 || ke->matches(QKeySequence::Paste)
83 || ke->matches(QKeySequence::Cut)
84 || ke->matches(QKeySequence::Redo)
85 || ke->matches(QKeySequence::Undo)
86 || ke->matches(QKeySequence::MoveToNextWord)
90 || ke->matches(QKeySequence::SelectNextWord)
93 || ke->matches(QKeySequence::SelectEndOfLine)
95 || ke->matches(QKeySequence::SelectEndOfBlock)
98 || ke->matches(QKeySequence::SelectAll)
99 ) {
100 return true;
101#endif
102 }
103 return false;
104}
105
107
108#include "moc_qinputcontrol_p.cpp"
\inmodule QtCore
Definition qchar.h:48
@ Other_PrivateUse
Definition qchar.h:120
@ Other_Format
Definition qchar.h:118
constexpr bool isLowSurrogate() const noexcept
Returns true if the QChar is the low part of a UTF16 surrogate (for example if its code point is in r...
Definition qchar.h:480
static bool isCommonTextEditShortcut(const QKeyEvent *ke)
bool isAcceptableInput(const QKeyEvent *event) const
QInputControl(Type type, QObject *parent=nullptr)
The QKeyEvent class describes a key event.
Definition qevent.h:423
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1465
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QString text
Combined button and popup list for selecting options.
@ Key_Escape
Definition qnamespace.h:658
@ Key_Tab
Definition qnamespace.h:659
@ Key_Return
Definition qnamespace.h:662
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_Backspace
Definition qnamespace.h:661
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_Delete
Definition qnamespace.h:665
@ Key_Home
Definition qnamespace.h:670
@ Key_End
Definition qnamespace.h:671
@ ShiftModifier
@ ControlModifier
@ KeypadModifier
@ NoModifier
GLenum type
struct _cl_event * event
const GLubyte * c
Definition moc.h:24
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent