summaryrefslogtreecommitdiffstats
path: root/src/pdf/quick/qml
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-02-10 10:49:33 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-02-17 17:50:01 +0100
commit0b6a4d94945a975390b2574e6aff2568ebb7f061 (patch)
tree480d54e4146ee0d23dd3f2ce69877408162bb512 /src/pdf/quick/qml
parente5a33355798d3277c631b0024f389cdca2f2c683 (diff)
PdfSearchModel: be QALM and find search results on all pages
It's a QAbstractListModel, so now PdfMultiPageView has a ListView in a left-side Drawer showing all results found so far. - In PdfMultiPageView, multiple pages exist at once, so it makes sense to use the same searchmodel for all. - It's faster and saves memory. - Search results on each page can be cached. - It's possible to show search results in a ListView or QListView. Change-Id: I66fba6975954a09a4d23262be87ff8cc25ee7478 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/pdf/quick/qml')
-rw-r--r--src/pdf/quick/qml/PdfMultiPageView.qml76
-rw-r--r--src/pdf/quick/qml/PdfPageView.qml39
2 files changed, 55 insertions, 60 deletions
diff --git a/src/pdf/quick/qml/PdfMultiPageView.qml b/src/pdf/quick/qml/PdfMultiPageView.qml
index bc5134267..b64f44576 100644
--- a/src/pdf/quick/qml/PdfMultiPageView.qml
+++ b/src/pdf/quick/qml/PdfMultiPageView.qml
@@ -104,39 +104,10 @@ Item {
}
// text search
+ property alias searchModel: searchModel
property alias searchString: searchModel.searchString
- property bool searchBackEnabled: searchModel.currentResult > 0
- property bool searchForwardEnabled: searchModel.currentResult < searchModel.matchGeometry.length - 1
- function searchBack() {
- if (searchModel.currentResult > 0) {
- --searchModel.currentResult
- } else {
- searchModel.deferRendering = true // save time while we are searching
- while (searchModel.currentResult <= 0) {
- if (navigationStack.currentPage > 0)
- goToPage(navigationStack.currentPage - 1)
- else
- goToPage(document.pageCount - 1)
- searchModel.currentResult = searchModel.matchGeometry.length - 1
- }
- searchModel.deferRendering = false
- }
- }
- function searchForward() {
- if (searchModel.currentResult < searchModel.matchGeometry.length - 1) {
- ++searchModel.currentResult
- } else {
- searchModel.deferRendering = true // save time while we are searching
- while (searchModel.currentResult >= searchModel.matchGeometry.length - 1) {
- searchModel.currentResult = 0
- if (navigationStack.currentPage < document.pageCount - 1)
- goToPage(navigationStack.currentPage + 1)
- else
- goToPage(0)
- }
- searchModel.deferRendering = false
- }
- }
+ function searchBack() { --searchModel.currentResult }
+ function searchForward() { ++searchModel.currentResult }
id: root
ListView {
@@ -159,7 +130,7 @@ Item {
property real pageScale: image.paintedWidth / pagePointSize.width
Image {
id: image
- source: searchModel.deferRendering ? "" : document.source
+ source: document.source
currentFrame: index
asynchronous: true
fillMode: Image.PreserveAspectFit
@@ -178,31 +149,36 @@ Item {
Shape {
anchors.fill: parent
opacity: 0.25
- visible: image.status === Image.Ready && searchModel.page == index
+ visible: image.status === Image.Ready
ShapePath {
strokeWidth: 1
- strokeColor: "steelblue"
- fillColor: "lightsteelblue"
+ strokeColor: "cyan"
+ fillColor: "steelblue"
scale: Qt.size(paper.pageScale, paper.pageScale)
PathMultiline {
- paths: searchModel.matchGeometry
+ paths: searchModel.boundingPolygonsOnPage(index)
}
}
ShapePath {
- strokeWidth: 1
- strokeColor: "blue"
- fillColor: "cyan"
+ fillColor: "orange"
scale: Qt.size(paper.pageScale, paper.pageScale)
- PathPolyline {
- path: searchModel.matchGeometry[searchModel.currentResult]
+ PathMultiline {
+ id: selectionBoundaries
+ paths: selection.geometry
}
}
+ }
+ Shape {
+ anchors.fill: parent
+ opacity: 0.5
+ visible: image.status === Image.Ready && searchModel.currentPage === index
ShapePath {
- fillColor: "orange"
+ strokeWidth: 1
+ strokeColor: "blue"
+ fillColor: "cyan"
scale: Qt.size(paper.pageScale, paper.pageScale)
PathMultiline {
- id: selectionBoundaries
- paths: selection.geometry
+ paths: searchModel.currentResultBoundingPolygons
}
}
}
@@ -297,7 +273,10 @@ Item {
PdfNavigationStack {
id: navigationStack
onJumped: listView.currentIndex = page
- onCurrentPageChanged: listView.positionViewAtIndex(currentPage, ListView.Beginning)
+ onCurrentPageChanged: {
+ listView.positionViewAtIndex(currentPage, ListView.Beginning)
+ searchModel.currentPage = currentPage
+ }
onCurrentLocationChanged: listView.contentY += currentLocation.y // currentPageChanged() MUST occur first!
onCurrentZoomChanged: root.renderScale = currentZoom
// TODO deal with horizontal location (need another Flickable probably)
@@ -305,9 +284,6 @@ Item {
PdfSearchModel {
id: searchModel
document: root.document === undefined ? null : root.document
- page: navigationStack.currentPage
- searchString: root.searchString
- property int currentResult: 0
- property bool deferRendering: false
+ onCurrentPageChanged: root.goToPage(currentPage)
}
}
diff --git a/src/pdf/quick/qml/PdfPageView.qml b/src/pdf/quick/qml/PdfPageView.qml
index d03e9dc9d..f4d7da0af 100644
--- a/src/pdf/quick/qml/PdfPageView.qml
+++ b/src/pdf/quick/qml/PdfPageView.qml
@@ -50,15 +50,18 @@ Rectangle {
property alias sourceSize: image.sourceSize
property alias currentPage: navigationStack.currentPage
property alias pageCount: image.frameCount
- property alias searchString: searchModel.searchString
property alias selectedText: selection.text
property alias status: image.status
property alias backEnabled: navigationStack.backAvailable
property alias forwardEnabled: navigationStack.forwardAvailable
function back() { navigationStack.back() }
function forward() { navigationStack.forward() }
- function goToPage(page) { navigationStack.push(page, Qt.point(0, 0), renderScale) }
- signal currentPageReallyChanged(page: int)
+ function goToPage(page) { goToLocation(page, Qt.point(0, 0), 0) }
+ function goToLocation(page, location, zoom) {
+ if (zoom > 0)
+ paper.renderScale = zoom
+ navigationStack.push(page, location, zoom)
+ }
property real __pageScale: image.paintedWidth / document.pagePointSize(navigationStack.currentPage).width
@@ -107,6 +110,12 @@ Rectangle {
paper.scale = 1
}
+ // text search
+ property alias searchModel: searchModel
+ property alias searchString: searchModel.searchString
+ function searchBack() { --searchModel.currentResult }
+ function searchForward() { ++searchModel.currentResult }
+
PdfSelection {
id: selection
document: paper.document
@@ -121,13 +130,16 @@ Rectangle {
PdfSearchModel {
id: searchModel
- document: paper.document
- page: navigationStack.currentPage
+ document: paper.document === undefined ? null : paper.document
+ currentPage: navigationStack.currentPage
+ onCurrentPageChanged: paper.goToPage(currentPage)
}
PdfNavigationStack {
id: navigationStack
- onCurrentPageChanged: paper.currentPageReallyChanged(navigationStack.currentPage)
+ // TODO onCurrentLocationChanged: position currentLocation.x and .y in middle // currentPageChanged() MUST occur first!
+ onCurrentZoomChanged: paper.renderScale = currentZoom
+ // TODO deal with horizontal location (need WheelHandler or Flickable probably)
}
Image {
@@ -168,19 +180,26 @@ Rectangle {
visible: image.status === Image.Ready
ShapePath {
strokeWidth: 1
- strokeColor: "blue"
+ strokeColor: "cyan"
+ fillColor: "steelblue"
+ scale: Qt.size(paper.__pageScale, paper.__pageScale)
+ PathMultiline {
+ paths: searchModel.currentPageBoundingPolygons
+ }
+ }
+ ShapePath {
+ strokeWidth: 1
+ strokeColor: "orange"
fillColor: "cyan"
scale: Qt.size(paper.__pageScale, paper.__pageScale)
PathMultiline {
- id: searchResultBoundaries
- paths: searchModel.matchGeometry
+ paths: searchModel.currentResultBoundingPolygons
}
}
ShapePath {
fillColor: "orange"
scale: Qt.size(paper.__pageScale, paper.__pageScale)
PathMultiline {
- id: selectionBoundaries
paths: selection.geometry
}
}