Skip to content

Commit

Permalink
[office] Add a toolbar to access pages and ToC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed Apr 23, 2015
1 parent 90ac1fb commit f273848
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
15 changes: 13 additions & 2 deletions plugin/DocumentPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@ Page {

property url source;
property int indexCount;
property bool _forceNavigation: false

allowedOrientations: Orientation.All;
backNavigation: drawer.opened;
forwardNavigation: drawer.opened;
backNavigation: drawer.opened || _forceNavigation;
forwardNavigation: drawer.opened || _forceNavigation;

function pushAttachedPage() {
if (pageStack.nextPage(base) === null) {
pageStack.push(base.attachedPage)
} else {
_forceNavigation = true
pageStack.navigateForward()
_forceNavigation = false
}
}

BusyIndicator { id: busyIndicator; anchors.centerIn: parent; size: BusyIndicatorSize.Large; }

Expand Down
34 changes: 33 additions & 1 deletion plugin/PDFDocumentPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DocumentPage {
attachedPage: Component {
PDFDocumentToCPage {
tocModel: pdfDocument.tocModel
pageCount: pdfDocument.pageCount
onPageSelected: view.goToPage( pageNumber );
}
}
Expand Down Expand Up @@ -93,8 +94,39 @@ DocumentPage {
// Toolbar contain.
Row {
id: row
width: parent.width
height: parent.height

Item {
anchors.verticalCenter: parent.verticalCenter
width: pageCount.width
height: pageCount.height
Row {
id: pageCount
Image {
source: "image://theme/icon-m-document"
anchors.verticalCenter: parent.verticalCenter
}
Label {
anchors.verticalCenter: parent.verticalCenter
text: view.currentPage + " / " + view.document.pageCount
}
}
MouseArea {
anchors.fill: parent
onClicked: base.pushAttachedPage()
}
}
Item {
// Spacer, to be replaced later with a search field.
width: toolbar.width - pageCount.width - pdfTOC.width
height: parent.height
}
IconButton {
id: pdfTOC
anchors.verticalCenter: parent.verticalCenter
icon.source: "image://theme/icon-m-menu"
onClicked: base.pushAttachedPage()
}
}
}

Expand Down
32 changes: 31 additions & 1 deletion plugin/PDFDocumentToCPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ Page {
id: page;
signal pageSelected(int pageNumber);

property int pageCount
property alias tocModel: tocListView.model;

allowedOrientations: Orientation.All;

SilicaListView {
id: tocListView
anchors.fill: parent;
width: parent.width
height: parent.height - gotoPage.height
clip: true

//: Page with PDF index
//% "Index"
Expand Down Expand Up @@ -68,4 +71,31 @@ Page {
}
}
}

PanelBackground {
id: gotoPage
anchors.top: tocListView.bottom
width: parent.width
height: Theme.itemSizeMedium

TextField {
x: Theme.paddingLarge
width: parent.width - Theme.paddingMedium - Theme.paddingLarge
anchors.verticalCenter: parent.verticalCenter

//% "Go to page"
placeholderText: qsTrId("sailfish-office-lb-goto-page")
//% "document has %n pages"
label: qsTrId("sailfish-office-lb-%n-pages", page.pageCount)

// We enter page numbers
inputMethodHints: Qt.ImhDigitsOnly
EnterKey.enabled: text.length > 0 && Math.round(text) > 0 && Math.round(text) <= page.pageCount
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
page.pageSelected(Math.round(text) - 1);
pageStack.navigateBack(PageStackAction.Animated);
}
}
}
}
1 change: 1 addition & 0 deletions plugin/PDFView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SilicaFlickable {
property alias itemWidth: pdfCanvas.width;
property alias itemHeight: pdfCanvas.height;
property alias document: pdfCanvas.document;
property alias currentPage: pdfCanvas.currentPage

property bool scaled: pdfCanvas.width != width;

Expand Down

0 comments on commit f273848

Please sign in to comment.