Commit a2be3a7a authored by Shawn Rutledge's avatar Shawn Rutledge
Browse files

PDF multipage example: move search field to the footer


Hiding the search feature in a closed Drawer might not have been
sufficiently touch-friendly and discoverable, for example on iOS where
the user is not going to press control-F to start searching.
But the top toolbar is too full to put the search field back up there.
It's familiar from Firefox to have the search field at the bottom,
and we have enough space for it there.  So now you can search and
jump around the search results without opening the drawer; but pressing
Enter in the search field opens the drawer.  Hopefully swiping to open
the drawer is also convenient enough on touch platforms; otherwise we
could add another button for that, perhaps at the left of the footer.

Change-Id: Iaec63bc22b03e29156fee817d197daae5b0cf9d5
Reviewed-by: default avatarShawn Rutledge <shawn.rutledge@qt.io>
Showing with 69 additions and 76 deletions
...@@ -167,6 +167,10 @@ ApplicationWindow { ...@@ -167,6 +167,10 @@ ApplicationWindow {
onTriggered: view.copySelectionToClipboard() onTriggered: view.copySelectionToClipboard()
} }
} }
Shortcut {
sequence: StandardKey.Find
onActivated: searchField.forceActiveFocus()
}
Shortcut { Shortcut {
sequence: StandardKey.Quit sequence: StandardKey.Quit
onActivated: Qt.quit() onActivated: Qt.quit()
...@@ -240,95 +244,84 @@ ApplicationWindow { ...@@ -240,95 +244,84 @@ ApplicationWindow {
id: searchDrawer id: searchDrawer
edge: Qt.LeftEdge edge: Qt.LeftEdge
modal: false modal: false
width: searchLayout.implicitWidth width: 300
y: root.header.height y: root.header.height
height: view.height height: view.height
dim: false dim: false
Shortcut { ListView {
sequence: StandardKey.Find id: searchResultsList
onActivated: { anchors.fill: parent
searchDrawer.open() anchors.margins: 2
searchField.forceActiveFocus() 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.fill: parent
anchors.margins: 2 ToolButton {
RowLayout { action: Action {
ToolButton { icon.source: "resources/go-up-search.svg"
action: Action { shortcut: StandardKey.FindPrevious
icon.source: "resources/go-up-search.svg" onTriggered: view.searchBack()
shortcut: StandardKey.FindPrevious
onTriggered: view.searchBack()
}
ToolTip.visible: enabled && hovered
ToolTip.delay: 2000
ToolTip.text: "find previous"
} }
TextField { ToolTip.visible: enabled && hovered
id: searchField ToolTip.delay: 2000
placeholderText: "search" ToolTip.text: "find previous"
Layout.minimumWidth: 200 }
Layout.fillWidth: true TextField {
Image { id: searchField
visible: searchField.text !== "" placeholderText: "search"
source: "resources/edit-clear.svg" Layout.minimumWidth: 200
anchors { Layout.fillWidth: true
right: parent.right onAccepted: searchDrawer.open()
top: parent.top Image {
bottom: parent.bottom visible: searchField.text !== ""
margins: 3 source: "resources/edit-clear.svg"
rightMargin: 5 anchors {
} right: parent.right
TapHandler { top: parent.top
onTapped: searchField.clear() bottom: parent.bottom
} margins: 3
rightMargin: 5
} }
} TapHandler {
ToolButton { onTapped: searchField.clear()
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"
} }
} }
ListView { ToolButton {
id: searchResultsList action: Action {
Layout.fillWidth: true icon.source: "resources/go-down-search.svg"
Layout.fillHeight: true shortcut: StandardKey.FindNext
clip: true onTriggered: view.searchForward()
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
}
} }
ToolTip.visible: enabled && hovered
ToolTip.delay: 2000
ToolTip.text: "find next"
}
Label {
id: statusLabel
Layout.fillWidth: true
property size implicitPointSize: document.pagePointSize(view.currentPage)
text: "page " + (currentPageSB.value) + " of " + document.pageCount +
" scale " + view.renderScale.toFixed(2) +
" original size " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1) + " pt"
visible: document.pageCount > 0
} }
}
}
footer: ToolBar {
height: statusLabel.implicitHeight * 1.5
Label {
id: statusLabel
anchors.verticalCenter: parent.verticalCenter
x: 6
property size implicitPointSize: document.pagePointSize(view.currentPage)
text: "page " + (currentPageSB.value) + " of " + document.pageCount +
" scale " + view.renderScale.toFixed(2) +
" original size " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1) + " pt"
visible: document.pageCount > 0
} }
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment