diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2016-12-07 13:12:26 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2016-12-12 11:13:53 +0000 |
commit | 7896ae052ad2c0c6ae2ebfc64cc2f525185198a8 (patch) | |
tree | a78f830a205ea16690f8d6940a1a6059fea36bf6 /src/widgets/widgets | |
parent | 87fefbc08e80119dba24767bfc9b6ecc64be5fcd (diff) |
Accept ZWNJ, ZWJ and PUA characters in input widgets
Private Use Area characters are quite valid input characters when used
in combination with a custom font. Joiners also serve an important language
purpose in semitic writing systems.
Note that there is a hack where we disregard any character produced
using CTRL or CTRL+SHIFT specifically because of German keyboards. I have chosen to
keep the hack in this patch to limit the change (though I have made an exception
for ZWJ and ZWNJ since both are produced using Ctrl+Shift on Windows), but it
will probably have to be reverted.
[ChangeLog][QtWidgets][Input] Accept characters in Private Use Area, as well as
zero-width joiners and zero-width non-joiners in input in QLineEdit and QTextEdit.
Task-number: QTBUG-42074
Task-number: QTBUG-57003
Change-Id: I73f3b7d587a8670de24e902dc52a51f7721dba5a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qwidgetlinecontrol.cpp | 18 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgetlinecontrol_p.h | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 17 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol_p.h | 3 |
4 files changed, 18 insertions, 26 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 9b65dc43d1..a862274a3d 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -1924,19 +1924,15 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) unknown = false; } - // QTBUG-35734: ignore Ctrl/Ctrl+Shift; accept only AltGr (Alt+Ctrl) on German keyboards - if (unknown && !isReadOnly() - && event->modifiers() != Qt::ControlModifier - && event->modifiers() != (Qt::ControlModifier | Qt::ShiftModifier)) { - QString t = event->text(); - if (!t.isEmpty() && t.at(0).isPrint()) { - insert(t); + if (unknown + && !isReadOnly() + && isAcceptableInput(event)) { + insert(event->text()); #ifndef QT_NO_COMPLETER - complete(event->key()); + complete(event->key()); #endif - event->accept(); - return; - } + event->accept(); + return; } if (unknown) diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index d4a4534fb5..b9340c0aff 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -64,6 +64,7 @@ #include "QtCore/qpoint.h" #include "QtWidgets/qcompleter.h" #include "QtCore/qthread.h" +#include "QtGui/private/qinputcontrol_p.h" #include "qplatformdefs.h" @@ -76,13 +77,14 @@ QT_BEGIN_NAMESPACE -class Q_WIDGETS_EXPORT QWidgetLineControl : public QObject +class Q_WIDGETS_EXPORT QWidgetLineControl : public QInputControl { Q_OBJECT public: QWidgetLineControl(const QString &txt = QString()) - : m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::LayoutDirectionAuto), + : QInputControl(LineEdit) + , m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::LayoutDirectionAuto), m_hideCursor(false), m_separator(0), m_readOnly(0), m_dragEnabled(0), m_echoMode(0), m_textDirty(0), m_selDirty(0), m_validInput(1), m_blinkStatus(0), m_blinkEnabled(false), m_blinkTimer(0), m_deleteAllTimer(0), diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 47806a194e..f5672bd87a 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -848,21 +848,21 @@ void QWidgetTextControl::redo() } QWidgetTextControl::QWidgetTextControl(QObject *parent) - : QObject(*new QWidgetTextControlPrivate, parent) + : QInputControl(QInputControl::TextEdit, *new QWidgetTextControlPrivate, parent) { Q_D(QWidgetTextControl); d->init(); } QWidgetTextControl::QWidgetTextControl(const QString &text, QObject *parent) - : QObject(*new QWidgetTextControlPrivate, parent) + : QInputControl(QInputControl::TextEdit, *new QWidgetTextControlPrivate, parent) { Q_D(QWidgetTextControl); d->init(Qt::RichText, text); } QWidgetTextControl::QWidgetTextControl(QTextDocument *doc, QObject *parent) - : QObject(*new QWidgetTextControlPrivate, parent) + : QInputControl(QInputControl::TextEdit, *new QWidgetTextControlPrivate, parent) { Q_D(QWidgetTextControl); d->init(Qt::RichText, QString(), doc); @@ -1361,14 +1361,7 @@ void QWidgetTextControlPrivate::keyPressEvent(QKeyEvent *e) process: { - // QTBUG-35734: ignore Ctrl/Ctrl+Shift; accept only AltGr (Alt+Ctrl) on German keyboards - if (e->modifiers() == Qt::ControlModifier - || e->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { - e->ignore(); - return; - } - QString text = e->text(); - if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) { + if (q->isAcceptableInput(e)) { if (overwriteMode // no need to call deleteChar() if we have a selection, insertText // does it already @@ -1376,7 +1369,7 @@ process: && !cursor.atBlockEnd()) cursor.deleteChar(); - cursor.insertText(text); + cursor.insertText(e->text()); selectionChanged(); } else { e->ignore(); diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h index b45f4fff74..f540a3c9ad 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p.h @@ -63,6 +63,7 @@ #include <QtGui/qtextdocumentfragment.h> #include <QtGui/qclipboard.h> #include <QtCore/qmimedata.h> +#include <QtGui/private/qinputcontrol_p.h> QT_BEGIN_NAMESPACE @@ -75,7 +76,7 @@ class QAbstractScrollArea; class QEvent; class QTimerEvent; -class Q_WIDGETS_EXPORT QWidgetTextControl : public QObject +class Q_WIDGETS_EXPORT QWidgetTextControl : public QInputControl { Q_OBJECT Q_DECLARE_PRIVATE(QWidgetTextControl) |