From 23e2fd1e2b13f4a6587152d8e26bb5de5d75a231 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 20 Feb 2020 14:53:32 +0100 Subject: PDF single-page example: move search field to the footer As with a2be3a7a79dc4fabe8675ea80a6ba550e0e4deec, this makes the search feature more discoverable and touch-friendly. Change-Id: I47e37273c583121d60985cc27c22f56e6d655ab0 Reviewed-by: Shawn Rutledge --- examples/pdf/pdfviewer/viewer.qml | 142 +++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 71 deletions(-) (limited to 'examples/pdf/pdfviewer') diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml index 777a9660b..e3bb4b474 100644 --- a/examples/pdf/pdfviewer/viewer.qml +++ b/examples/pdf/pdfviewer/viewer.qml @@ -170,6 +170,10 @@ ApplicationWindow { onTriggered: view.copySelectionToClipboard() } } + Shortcut { + sequence: StandardKey.Find + onActivated: searchField.forceActiveFocus() + } Shortcut { sequence: StandardKey.Quit onActivated: Qt.quit() @@ -214,89 +218,85 @@ ApplicationWindow { id: searchDrawer edge: Qt.LeftEdge modal: false - width: searchLayout.implicitWidth + width: 300 y: root.header.height - height: root.contentItem.height + height: view.height dim: false - Shortcut { - sequence: StandardKey.Find - onActivated: { - searchDrawer.open() - searchField.forceActiveFocus() + clip: true + ListView { + id: searchResultsList + anchors.fill: parent + anchors.margins: 2 + model: view.searchModel + ScrollBar.vertical: ScrollBar { } + delegate: ItemDelegate { + width: parent ? parent.width : 0 + text: "page " + (page + 1) + ": " + context + highlighted: ListView.isCurrentItem + onClicked: { + searchResultsList.currentIndex = index + view.goToLocation(page, location, 0) + view.searchModel.currentResult = indexOnPage + } } } - ColumnLayout { - id: searchLayout + } + + footer: ToolBar { + height: footerRow.implicitHeight + RowLayout { + id: footerRow anchors.fill: parent - anchors.margins: 2 - RowLayout { - ToolButton { - action: Action { - icon.source: "resources/go-up-search.svg" - shortcut: StandardKey.FindPrevious - onTriggered: view.searchBack() - } - ToolTip.visible: enabled && hovered - ToolTip.delay: 2000 - ToolTip.text: "find previous" + ToolButton { + action: Action { + icon.source: "resources/go-up-search.svg" + shortcut: StandardKey.FindPrevious + onTriggered: view.searchBack() } - TextField { - id: searchField - placeholderText: "search" - Layout.minimumWidth: 200 - Layout.fillWidth: true - Image { - visible: searchField.text !== "" - source: "resources/edit-clear.svg" - anchors { - right: parent.right - top: parent.top - bottom: parent.bottom - margins: 3 - rightMargin: 5 - } - TapHandler { - onTapped: searchField.clear() - } + ToolTip.visible: enabled && hovered + ToolTip.delay: 2000 + ToolTip.text: "find previous" + } + TextField { + id: searchField + placeholderText: "search" + Layout.minimumWidth: 150 + Layout.maximumWidth: 300 + Layout.fillWidth: true + onAccepted: searchDrawer.open() + Image { + visible: searchField.text !== "" + source: "resources/edit-clear.svg" + anchors { + right: parent.right + top: parent.top + bottom: parent.bottom + margins: 3 + rightMargin: 5 } - } - ToolButton { - action: Action { - icon.source: "resources/go-down-search.svg" - shortcut: StandardKey.FindNext - onTriggered: view.searchForward() + TapHandler { + onTapped: searchField.clear() } - ToolTip.visible: enabled && hovered - ToolTip.delay: 2000 - ToolTip.text: "find next" } } - ListView { - id: searchResultsList - Layout.fillWidth: true - Layout.fillHeight: true - clip: true - model: view.searchModel - ScrollBar.vertical: ScrollBar { } - delegate: ItemDelegate { - width: parent ? parent.width : 0 - text: "page " + (page + 1) + ": " + context - highlighted: ListView.isCurrentItem - onClicked: { - searchResultsList.currentIndex = index - view.goToLocation(page, location, 0) - view.searchModel.currentResult = indexOnPage - } + ToolButton { + action: Action { + icon.source: "resources/go-down-search.svg" + shortcut: StandardKey.FindNext + onTriggered: view.searchForward() } + ToolTip.visible: enabled && hovered + ToolTip.delay: 2000 + ToolTip.text: "find next" + } + Label { + Layout.fillWidth: true + property size implicitPointSize: document.pagePointSize(view.currentPage) + text: "page " + (view.currentPage + 1) + " of " + document.pageCount + + " scale " + view.renderScale.toFixed(2) + + " original " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1) + "pts" + visible: document.status === PdfDocument.Ready } } } - - footer: Label { - property size implicitPointSize: document.pagePointSize(view.currentPage) - text: "page " + (view.currentPage + 1) + " of " + document.pageCount + - " scale " + view.renderScale.toFixed(2) + - " original " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1) + "pts" - visible: document.status === PdfDocument.Ready - } } -- cgit v1.2.3