Fix tst_qlineedit.

- Fix key handling in QWidgetLineControl according to
  the keyboard scheme returned by the QPlatformTheme,
  remove #ifdefs.
- Do the same in the test.

Task-number: QTBUG-21402

Change-Id: I36d836584e7122309061af72819a4147cadd0a74
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
bb10
Friedemann Kleint 2012-02-23 17:27:47 +01:00 committed by Qt by Nokia
parent 219a688ac1
commit ed7f78acba
4 changed files with 82 additions and 56 deletions

View File

@ -45,6 +45,8 @@
#include "qabstractitemview.h"
#include "qclipboard.h"
#include <private/qguiapplication_p.h>
#include <qplatformtheme_qpa.h>
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
#endif
@ -374,6 +376,14 @@ void QWidgetLineControl::init(const QString &txt)
m_text = txt;
updateDisplayText();
m_cursor = m_text.length();
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt();
// Generalize for X11
if (m_keyboardScheme == QPlatformTheme::KdeKeyboardScheme
|| m_keyboardScheme == QPlatformTheme::GnomeKeyboardScheme
|| m_keyboardScheme == QPlatformTheme::CdeKeyboardScheme) {
m_keyboardScheme = QPlatformTheme::X11KeyboardScheme;
}
}
/*!
@ -1630,10 +1640,11 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
else if (event == QKeySequence::Paste) {
if (!isReadOnly()) {
QClipboard::Mode mode = QClipboard::Clipboard;
#ifdef Q_WS_X11
if (event->modifiers() == (Qt::CTRL | Qt::SHIFT) && event->key() == Qt::Key_Insert)
if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme
&& event->modifiers() == (Qt::CTRL | Qt::SHIFT)
&& event->key() == Qt::Key_Insert) {
mode = QClipboard::Selection;
#endif
}
paste(mode);
}
}
@ -1664,12 +1675,14 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
end(1);
}
else if (event == QKeySequence::MoveToNextChar) {
#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
if (hasSelectedText()) {
#if defined(QT_NO_COMPLETER)
const bool inlineCompletion = false;
#else
if (hasSelectedText() && m_completer
&& m_completer->completionMode() == QCompleter::InlineCompletion) {
const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion;
#endif
if (hasSelectedText()
&& (m_keyboardScheme != QPlatformTheme::WindowsKeyboardScheme
|| inlineCompletion)) {
moveCursor(selectionEnd(), false);
} else {
cursorForward(0, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1));
@ -1679,12 +1692,14 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
cursorForward(1, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1));
}
else if (event == QKeySequence::MoveToPreviousChar) {
#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
if (hasSelectedText()) {
#if defined(QT_NO_COMPLETER)
const bool inlineCompletion = false;
#else
if (hasSelectedText() && m_completer
&& m_completer->completionMode() == QCompleter::InlineCompletion) {
const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion;
#endif
if (hasSelectedText()
&& (m_keyboardScheme != QPlatformTheme::WindowsKeyboardScheme
|| inlineCompletion)) {
moveCursor(selectionStart(), false);
} else {
cursorForward(0, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1));
@ -1737,8 +1752,8 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
#endif // QT_NO_SHORTCUT
else {
bool handled = false;
#ifdef Q_WS_MAC
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
if (m_keyboardScheme == QPlatformTheme::MacKeyboardScheme
&& (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)) {
Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier);
if (myModifiers & Qt::ShiftModifier) {
if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier)
@ -1756,7 +1771,6 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
}
handled = true;
}
#endif
if (event->modifiers() & Qt::ControlModifier) {
switch (event->key()) {
case Qt::Key_Backspace:
@ -1771,13 +1785,13 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
complete(event->key());
break;
#endif
#if defined(Q_WS_X11)
case Qt::Key_E:
end(0);
if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme)
end(0);
break;
case Qt::Key_U:
if (!isReadOnly()) {
if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme && !isReadOnly()) {
setSelection(0, text().size());
#ifndef QT_NO_CLIPBOARD
copy();
@ -1785,7 +1799,6 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
del();
}
break;
#endif
default:
if (!handled)
unknown = true;

View File

@ -100,6 +100,7 @@ public:
, m_threadChecks(false)
, m_textLayoutThread(0)
#endif
, m_keyboardScheme(0)
{
init(txt);
}
@ -527,6 +528,8 @@ private Q_SLOTS:
void _q_clipboardChanged();
void _q_deleteSelected();
private:
int m_keyboardScheme;
};
QT_END_NAMESPACE

View File

@ -1,6 +1,4 @@
CONFIG += testcase
TARGET = tst_qlineedit
QT += widgets testlib
QT += gui-private core-private widgets testlib
SOURCES += tst_qlineedit.cpp
CONFIG += insignificant_test # QTBUG-21402

View File

@ -48,6 +48,8 @@
#include "qvalidator.h"
#include "qcompleter.h"
#include "qstandarditemmodel.h"
#include "qplatformtheme_qpa.h"
#include <private/qguiapplication_p.h>
#ifndef QT_NO_CLIPBOARD
#include "qclipboard.h"
@ -300,6 +302,7 @@ private:
int lastCursorPos;
int newCursorPos;
QLineEdit *testWidget;
int m_keyboardScheme;
};
typedef QList<int> IntList;
@ -327,9 +330,16 @@ void tst_QLineEdit::getSetCheck()
QCOMPARE(true, obj1.dragEnabled());
}
tst_QLineEdit::tst_QLineEdit()
tst_QLineEdit::tst_QLineEdit() : validInput(false), m_keyboardScheme(0)
{
validInput = false;
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt();
// Generalize for X11
if (m_keyboardScheme == QPlatformTheme::KdeKeyboardScheme
|| m_keyboardScheme == QPlatformTheme::GnomeKeyboardScheme
|| m_keyboardScheme == QPlatformTheme::CdeKeyboardScheme) {
m_keyboardScheme = QPlatformTheme::X11KeyboardScheme;
}
}
tst_QLineEdit::~tst_QLineEdit()
@ -1071,25 +1081,26 @@ void tst_QLineEdit::undo()
QVERIFY(!testWidget->isUndoAvailable());
QVERIFY(testWidget->text().isEmpty());
#ifdef Q_WS_WIN
// Repeat the test using shortcut instead of undo()
for (i=0; i<insertString.size(); ++i) {
if (insertIndex[i] > -1)
testWidget->setCursorPosition(insertIndex[i]);
if (insertMode[i] == REPLACE_UNTIL_END) {
testWidget->setSelection(insertIndex[i], 8);
if (m_keyboardScheme == QPlatformTheme::WindowsKeyboardScheme) {
// Repeat the test using shortcut instead of undo()
for (i=0; i<insertString.size(); ++i) {
if (insertIndex[i] > -1)
testWidget->setCursorPosition(insertIndex[i]);
if (insertMode[i] == REPLACE_UNTIL_END)
testWidget->setSelection(insertIndex[i], 8);
if (use_keys)
QTest::keyClicks(testWidget, insertString[i]);
else
testWidget->insert(insertString[i]);
}
for (i=0; i<expectedString.size()-1; ++i) {
QCOMPARE(testWidget->text(), expectedString[i]);
QVERIFY(testWidget->isUndoAvailable());
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
}
if (use_keys)
QTest::keyClicks(testWidget, insertString[i]);
else
testWidget->insert(insertString[i]);
}
for (i=0; i<expectedString.size()-1; ++i) {
QCOMPARE(testWidget->text(), expectedString[i]);
QVERIFY(testWidget->isUndoAvailable());
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
}
#endif
}
void tst_QLineEdit::redo_data()
@ -1152,21 +1163,22 @@ void tst_QLineEdit::redo()
QVERIFY(!testWidget->isRedoAvailable());
#ifdef Q_WS_WIN
// repeat test, this time using shortcuts instead of undo()/redo()
while (!testWidget->text().isEmpty())
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
if (m_keyboardScheme == QPlatformTheme::WindowsKeyboardScheme) {
// repeat test, this time using shortcuts instead of undo()/redo()
for (i = 0; i < expectedString.size(); ++i) {
QVERIFY(testWidget->isRedoAvailable());
QTest::keyClick(testWidget, Qt::Key_Backspace,
Qt::ShiftModifier | Qt::AltModifier);
QCOMPARE(testWidget->text() , expectedString[i]);
while (!testWidget->text().isEmpty())
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
for (i = 0; i < expectedString.size(); ++i) {
QVERIFY(testWidget->isRedoAvailable());
QTest::keyClick(testWidget, Qt::Key_Backspace,
Qt::ShiftModifier | Qt::AltModifier);
QCOMPARE(testWidget->text() , expectedString[i]);
}
QVERIFY(!testWidget->isRedoAvailable());
}
QVERIFY(!testWidget->isRedoAvailable());
#endif
}
void tst_QLineEdit::undo_keypressevents_data()
@ -1263,7 +1275,7 @@ void tst_QLineEdit::undo_keypressevents_data()
// unselect any current selection
keys.addKeyClick(Qt::Key_Right);
#ifdef Q_WS_WIN //Mac has a specialcase to handle jumping to the end of a selection
#ifdef Q_OS_WIN //Mac has a specialcase to handle jumping to the end of a selection
keys.addKeyClick(Qt::Key_Left);
#endif
@ -3080,6 +3092,7 @@ void tst_QLineEdit::leftKeyOnSelectedText()
#ifdef Q_OS_WIN
QCOMPARE(testWidget->cursorPosition(), 1);
#else
// Selection is cleared ands cursor remains at position 2.
// X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
// resulted in an inadvertant change in behavior
QCOMPARE(testWidget->cursorPosition(), 2);
@ -3624,9 +3637,8 @@ void tst_QLineEdit::taskQTBUG_7395_readOnlyShortcut()
void tst_QLineEdit::QTBUG697_paletteCurrentColorGroup()
{
#ifndef Q_WS_X11
QSKIP("Only tested on X11");
#endif
if (m_keyboardScheme != QPlatformTheme::X11KeyboardScheme)
QSKIP("Only tested on X11");
QLineEdit le;
le.setText(" ");
QPalette p = le.palette();