From 7e75e9b80249f553fcfbdb2716c93707b40f8c48 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 26 Feb 2020 11:09:09 +0100 Subject: PdfMultiPageView: update search highlights when results change In the single-page view, we bind to the PdfSearchModel.currentPageBoundingPolygons property, which is convenient because it has a changed signal, so it stays updated in all cases: when the user changes the search string, when a different document is loaded, or when changing the current page. In the multi-page view, we need to invoke a function to get the search results on each page, because results are different on each page, and we often need to show multiple pages at the same time. The challenge then is how to ensure that it gets re-evaluated often enough. It requires connecting to more than one signal; but there isn't any way to "kick" a binding when some signal occurs, so the solution isn't very declarative, unfortunately. Change-Id: I72e7dad01b8cb6c43abcccf4fa46e443409b39e0 Reviewed-by: Shawn Rutledge --- src/pdf/quick/qml/PdfMultiPageView.qml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pdf/quick/qml/PdfMultiPageView.qml b/src/pdf/quick/qml/PdfMultiPageView.qml index d50763a64..5efad39f0 100644 --- a/src/pdf/quick/qml/PdfMultiPageView.qml +++ b/src/pdf/quick/qml/PdfMultiPageView.qml @@ -183,21 +183,33 @@ Item { image.sourceSize.width = paper.pagePointSize.width * renderScale image.sourceSize.height = 0 paper.scale = 1 + searchHighlights.update() } } Shape { anchors.fill: parent opacity: 0.25 visible: image.status === Image.Ready + onVisibleChanged: searchHighlights.update() ShapePath { strokeWidth: 1 strokeColor: "cyan" fillColor: "steelblue" scale: Qt.size(paper.pageScale, paper.pageScale) PathMultiline { - paths: searchModel.boundingPolygonsOnPage(index) + id: searchHighlights + function update() { + // paths could be a binding, but we need to be able to "kick" it sometimes + paths = searchModel.boundingPolygonsOnPage(index) + } } } + Connections { + target: searchModel + // whenever the highlights on the _current_ page change, they actually need to change on _all_ pages + // (usually because the search string has changed) + function onCurrentPageBoundingPolygonsChanged() { searchHighlights.update() } + } ShapePath { fillColor: "orange" scale: Qt.size(paper.pageScale, paper.pageScale) -- cgit v1.2.3