Suppress Ctrl/Ctrl+Shift keypresses in line/text edits.
Ctrl/Ctrl+Shift should not cause any characters to be input (as opposed to AltGr(Alt+Ctrl) as used on German keyboards). Extend the tests in QLineEdit and QPlainTextEdit to check the modifiers, remove test from QTextEdit since it is handled by QWidgetTextControl. Task-number: QTBUG-35734 Change-Id: Ie0004fac68cf840c68247f27547e84b021355cd2 Reviewed-by: Gatis Paeglis <gatis.paeglis@digia.com>
This commit is contained in:
parent
912f1ebaad
commit
b85b78f17d
@ -1879,7 +1879,10 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
|
||||
unknown = false;
|
||||
}
|
||||
|
||||
if (unknown && !isReadOnly()) {
|
||||
// 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);
|
||||
|
@ -1339,6 +1339,12 @@ 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 (overwriteMode
|
||||
|
@ -249,6 +249,7 @@ private slots:
|
||||
|
||||
void editInvalidText();
|
||||
|
||||
void charWithAltOrCtrlModifier_data();
|
||||
void charWithAltOrCtrlModifier();
|
||||
|
||||
void inlineCompletion();
|
||||
@ -3224,19 +3225,35 @@ void tst_QLineEdit::editInvalidText()
|
||||
testWidget->setValidator(0);
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Qt::KeyboardModifiers)
|
||||
|
||||
void tst_QLineEdit::charWithAltOrCtrlModifier_data()
|
||||
{
|
||||
QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
|
||||
QTest::addColumn<bool>("textExpected");
|
||||
QTest::newRow("no-modifiers") << Qt::KeyboardModifiers() << true;
|
||||
// Ctrl, Ctrl+Shift: No text (QTBUG-35734)
|
||||
QTest::newRow("ctrl") << Qt::KeyboardModifiers(Qt::ControlModifier)
|
||||
<< false;
|
||||
QTest::newRow("ctrl-shift") << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::ControlModifier)
|
||||
<< false;
|
||||
QTest::newRow("alt") << Qt::KeyboardModifiers(Qt::AltModifier) << true;
|
||||
// Alt-Ctrl (Alt-Gr on German keyboards, Task 129098): Expect text
|
||||
QTest::newRow("alt-ctrl") << (Qt::AltModifier | Qt::ControlModifier) << true;
|
||||
}
|
||||
|
||||
void tst_QLineEdit::charWithAltOrCtrlModifier()
|
||||
{
|
||||
QFETCH(Qt::KeyboardModifiers, modifiers);
|
||||
QFETCH(bool, textExpected);
|
||||
|
||||
QLineEdit *testWidget = ensureTestWidget();
|
||||
testWidget->clear();
|
||||
QCOMPARE(testWidget->text(), QString(""));
|
||||
QTest::keyPress(testWidget, Qt::Key_Plus);
|
||||
QCOMPARE(testWidget->text(), QString("+"));
|
||||
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::ControlModifier);
|
||||
QCOMPARE(testWidget->text(), QString("++"));
|
||||
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier);
|
||||
QCOMPARE(testWidget->text(), QString("+++"));
|
||||
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier | Qt::ControlModifier);
|
||||
QCOMPARE(testWidget->text(), QString("++++"));
|
||||
QVERIFY(testWidget->text().isEmpty());
|
||||
|
||||
QTest::keyPress(testWidget, Qt::Key_Plus, modifiers);
|
||||
const QString expectedText = textExpected ? QLatin1String("+") : QString();
|
||||
QCOMPARE(testWidget->text(), expectedText);
|
||||
}
|
||||
|
||||
void tst_QLineEdit::leftKeyOnSelectedText()
|
||||
|
@ -99,7 +99,8 @@ private slots:
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
void copyAndSelectAllInReadonly();
|
||||
#endif
|
||||
void ctrlAltInput();
|
||||
void charWithAltOrCtrlModifier_data();
|
||||
void charWithAltOrCtrlModifier();
|
||||
void noPropertiesOnDefaultTextEditCharFormat();
|
||||
void setPlainTextShouldEmitTextChangedOnce();
|
||||
void overwriteMode();
|
||||
@ -691,10 +692,34 @@ void tst_QPlainTextEdit::copyAndSelectAllInReadonly()
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QPlainTextEdit::ctrlAltInput()
|
||||
Q_DECLARE_METATYPE(Qt::KeyboardModifiers)
|
||||
|
||||
// Test how QWidgetTextControlPrivate (used in QPlainTextEdit, QTextEdit)
|
||||
// handles input with modifiers.
|
||||
void tst_QPlainTextEdit::charWithAltOrCtrlModifier_data()
|
||||
{
|
||||
QTest::keyClick(ed, Qt::Key_At, Qt::ControlModifier | Qt::AltModifier);
|
||||
QCOMPARE(ed->toPlainText(), QString("@"));
|
||||
QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
|
||||
QTest::addColumn<bool>("textExpected");
|
||||
|
||||
QTest::newRow("no-modifiers") << Qt::KeyboardModifiers() << true;
|
||||
// Ctrl, Ctrl+Shift: No text (QTBUG-35734)
|
||||
QTest::newRow("ctrl") << Qt::KeyboardModifiers(Qt::ControlModifier)
|
||||
<< false;
|
||||
QTest::newRow("ctrl-shift") << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::ControlModifier)
|
||||
<< false;
|
||||
QTest::newRow("alt") << Qt::KeyboardModifiers(Qt::AltModifier) << true;
|
||||
// Alt-Ctrl (Alt-Gr on German keyboards, Task 129098): Expect text
|
||||
QTest::newRow("alt-ctrl") << (Qt::AltModifier | Qt::ControlModifier) << true;
|
||||
}
|
||||
|
||||
void tst_QPlainTextEdit::charWithAltOrCtrlModifier()
|
||||
{
|
||||
QFETCH(Qt::KeyboardModifiers, modifiers);
|
||||
QFETCH(bool, textExpected);
|
||||
|
||||
QTest::keyClick(ed, Qt::Key_At, modifiers);
|
||||
const QString expectedText = textExpected ? QLatin1String("@") : QString();
|
||||
QCOMPARE(ed->toPlainText(), expectedText);
|
||||
}
|
||||
|
||||
void tst_QPlainTextEdit::noPropertiesOnDefaultTextEditCharFormat()
|
||||
|
@ -122,7 +122,6 @@ private slots:
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
void copyAndSelectAllInReadonly();
|
||||
#endif
|
||||
void ctrlAltInput();
|
||||
void noPropertiesOnDefaultTextEditCharFormat();
|
||||
void setPlainTextShouldUseCurrentCharFormat();
|
||||
void setPlainTextShouldEmitTextChangedOnce();
|
||||
@ -1042,12 +1041,6 @@ void tst_QTextEdit::copyAndSelectAllInReadonly()
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QTextEdit::ctrlAltInput()
|
||||
{
|
||||
QTest::keyClick(ed, Qt::Key_At, Qt::ControlModifier | Qt::AltModifier);
|
||||
QCOMPARE(ed->toPlainText(), QString("@"));
|
||||
}
|
||||
|
||||
void tst_QTextEdit::noPropertiesOnDefaultTextEditCharFormat()
|
||||
{
|
||||
// there should be no properties set on the default/initial char format
|
||||
|
Loading…
Reference in New Issue
Block a user