summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-03-06 17:59:32 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-04-30 11:06:17 +0200
commit8d13facbd88d821cc89b21f43708cc1a81ac79f3 (patch)
tree4732dd861938f974fe77366bdeab63db76e842cb /examples
parent685430b66ab2830d5e0e5ebafc17294ff1ce1f48 (diff)
Support text selection handles in PDF views
Testing only on iOS so far; QtPdf doesn't work on Android because of QTBUG-83459, so we can only hope that this might perhaps be cross-platform, if only text selection handles actually existed on all platforms. As usual, text selection begins with a long-press; the iOS platform plugin intercepts that, and we get QInputMethodEvent::Cursor. There is no cursor, but we use the opportunity to do hit-testing, because the Cursor event is the only way that we receive the pixel location where the user is interacting. Then a popover menu appears, which contains Select and Select All, and either Copy or Paste depending on the qt_im_readonly property workaround. You don't get handles until you choose Select, which will select a word. That makes the popover menu disappear. You can use the toolbar button to copy to the clipboard. After that, you can drag either handle. inputMethodQuery(query, argument) is only ever called with ImCursorPosition regardless which handle is being dragged, so it doesn't make sense to change the selection there, even though that would be easy if we were given that information. Instead, the iOS platform figures out the character range for itself and sends a QInputMethodEvent::Selection event to tell us which text to select. And yet it still doesn't move the handles without being told: QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle) makes that happen. Then the popover menu will appear again, and now you can use the Copy function on it as an alternative way to copy text to the clipboard. By default, when the user does the initial long-press to start selecting text, the popover menu has Select, Select All, and Paste. In editable controls there is a second possible menu that normally has Cut, Copy, Paste and Delete. We are not able to enter that mode. So as a workaround, to substitute Copy instead of Paste, we set the qt_im_readonly property so that QIOSTextResponder::canPerformAction() can detect it and make the substition. Of course that won't work without the patch to 5.15; so you still get a useless Paste action on earlier Qt versions. Selecting a word via the Select popover menu item happens because iOS sends QKeySequence::MoveToPreviousWord and then QKeySequence::SelectNextWord. We spend time calling getSelectionAtIndex() twice because of that. With an actual keyboard, it should be possible to use keystrokes to extend the selection, but it doesn't seem to work yet with shift-arrows on a physical bluetooth keyboard on iOS. Select All on the popover menu works via inputMethodEvent() with attr QInputMethodEvent::Selection. Copy sends the standard copy key sequence, so keyReleaseEvent() handles it. We must rename the geometryChanged signal to selectedAreaChanged now that we're inheriting from QQuickItem, to avoid shadowing QQuickItem::geometryChanged. For this kind of text selection to work even when the rendering is scaled, it became necessary to inform PdfSelection of the rendering scale; so a renderScale property is added. Thus it is sensible (and a nice simplification in QML code) to use it for the fromPoint and toPoint properties, such that those are now expressed in pixels rather than points. Fixes: QTBUG-82441 Task-number: QTBUG-83811 Change-Id: I16ecd2db55c6a834be6139ce4f3aae23446fed54 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/pdf/pdfviewer/viewer.qml4
1 files changed, 2 insertions, 2 deletions
diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml
index f4c913154..38d62740a 100644
--- a/examples/pdf/pdfviewer/viewer.qml
+++ b/examples/pdf/pdfviewer/viewer.qml
@@ -226,11 +226,11 @@ ApplicationWindow {
Drawer {
id: searchDrawer
edge: Qt.LeftEdge
- modal: false
+// modal: false
+// dim: false // commented out as workaround for QTBUG-83859
width: 300
y: root.header.height
height: view.height
- dim: false
clip: true
ListView {
id: searchResultsList