From 2a6298bcf29104a4258992c7357a031f4ca9cc7f Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Wed, 5 Oct 2011 15:06:31 +0300 Subject: Copy and Cut are not available for some QML editors Copy and Cut actions do not appear in fullscreen VKB menu when a QML TextEdit or TextInput element is focused and has selected text. This happens because input method queries for cursor and anchor position in QCoeFepInputContext::CcpuCanCut() return zero in this case. It is probably related to focus changes when the options menu pops up. When menu pops up from native keyboard, window containing the QML elements is set as non-active, therefore it loses focus widget, which in turn causes queries about cursor and anchor positions to return zero. As a workaround, when there is no microfocus available, ask the "selectedText" property directly from QML elements. Task-number: QTBUG-21568 Reviewed-by: Miikka Heikkinen --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index ff74afe..8f13c53 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -1747,14 +1747,30 @@ TBool QCoeFepInputContext::CcpuCanCut() const if (m_inDestruction) return retval; QWidget *w = focusWidget(); - if (!w) + QObject *focusObject = 0; + if (!w) { w = m_lastFocusedEditor; - else - w = getQWidgetFromQGraphicsView(w); + focusObject = m_lastFocusedObject; + } else { + w = getQWidgetFromQGraphicsView(w, &focusObject); + } if (w) { - int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); - int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt(); - retval = cursor != anchor; + QRect microFocus = w->inputMethodQuery(Qt::ImMicroFocus).toRect(); + if (microFocus.isNull()) { + // For some reason, the editor does not have microfocus. Most probably, + // it is due to using native fullscreen editing mode with QML apps. + // Try accessing "selectedText" directly. + QObject *invokeTarget = w; + if (focusObject) + invokeTarget = focusObject; + + QString selectedText = invokeTarget->property("selectedText").toString(); + retval = !selectedText.isNull(); + } else { + int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); + int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt(); + retval = cursor != anchor; + } } return retval; } -- cgit v0.12