From ed7f78acba45e1142157e39154466a13f9d3ce4e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Feb 2012 17:27:47 +0100 Subject: 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 Reviewed-by: Bradley T. Hughes --- src/widgets/widgets/qwidgetlinecontrol.cpp | 49 +++++++++++++++++++----------- src/widgets/widgets/qwidgetlinecontrol_p.h | 3 ++ 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 2f5793bcba..73c3d14f9b 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -45,6 +45,8 @@ #include "qabstractitemview.h" #include "qclipboard.h" +#include +#include #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; diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index a0191188a7..72f25e9068 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -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 -- cgit v1.2.3