Merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/uitk13-lok-page into lp:ubuntu-docviewer-app

Proposed by Stefano Verzegnassi
Status: Merged
Approved by: Roman Shchekin
Approved revision: 321
Merged at revision: 326
Proposed branch: lp:~verzegnassi-stefano/ubuntu-docviewer-app/uitk13-lok-page
Merge into: lp:ubuntu-docviewer-app
Diff against target: 548 lines (+207/-204)
4 files modified
src/app/qml/common/ViewerPage.qml (+32/-3)
src/app/qml/loView/KeybHelper.js (+23/-47)
src/app/qml/loView/LOViewDefaultHeader.qml (+41/-55)
src/app/qml/loView/LOViewPage.qml (+111/-99)
To merge this branch: bzr merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/uitk13-lok-page
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Roman Shchekin Needs Information
Review via email: mp+290048@code.launchpad.net

Commit message

* WORKAROUND: make the lok-viewer header static (avoid unpredictable binding)
* Use new PageHeader and ScrollView components
* UI: Show an empty header when loading LibreOffice

Description of the change

* WORKAROUND: make the lok-viewer header static (avoid unpredictable binding)
* Use new PageHeader and ScrollView components
* UI: Show an empty header when loading LibreOffice

To post a comment you must log in.
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Roman Shchekin (mrqtros) wrote :

See inline comments!

review: Needs Information
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

> Haha, are you enjoyed deleting this code? ;)
Ahah, you can be sure of it! :)

> Why did you switch it [PageHeader.flickable] off? Just for information.
I was having trouble in setting the anchors for the content of the ViewerPage[1], and the LibreOffice Viewer had strange bindings that were causing a continuous flickering and reloading of the document content, every time the header was changing its status (i.e. visible/hidden).

I spent some time on it again (after you review), and now it seems to behave correctly. Pushing the new commit...

[1] We load LOViewPage asynchronously, but the loading logic is placed in a different file.

321. By Stefano Verzegnassi

Fixed flickable

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/qml/common/ViewerPage.qml'
--- src/app/qml/common/ViewerPage.qml 2015-11-30 12:12:10 +0000
+++ src/app/qml/common/ViewerPage.qml 2016-03-30 11:10:56 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2015 Stefano Verzegnassi <verzegnassi.stefano@gmail.com>2 * Copyright (C) 2015, 2016 Stefano Verzegnassi <verzegnassi.stefano@gmail.com>
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
@@ -35,7 +35,21 @@
3535
36 Loader {36 Loader {
37 id: contentLoader37 id: contentLoader
38 anchors.fill: parent38 anchors {
39 left: parent.left
40 right: parent.right
41 bottom: parent.bottom
42
43 top: {
44 if (!viewerPage.header)
45 return parent.top
46
47 if (!viewerPage.header.flickable)
48 return viewerPage.header.bottom
49 else
50 return parent.top
51 }
52 }
3953
40 asynchronous: true54 asynchronous: true
41 sourceComponent: viewerPage.contents55 sourceComponent: viewerPage.contents
@@ -45,7 +59,22 @@
4559
46 Item {60 Item {
47 id: splashScreenItem61 id: splashScreenItem
48 anchors.fill: parent62
63 anchors {
64 left: parent.left
65 right: parent.right
66 bottom: parent.bottom
67
68 top: {
69 if (!viewerPage.header)
70 return parent.top
71
72 if (!viewerPage.header.flickable)
73 return viewerPage.header.bottom
74 else
75 return parent.top
76 }
77 }
4978
50 visible: contentLoader.status != Loader.Ready79 visible: contentLoader.status != Loader.Ready
51 enabled: visible80 enabled: visible
5281
=== modified file 'src/app/qml/loView/KeybHelper.js'
--- src/app/qml/loView/KeybHelper.js 2015-12-14 00:40:55 +0000
+++ src/app/qml/loView/KeybHelper.js 2016-03-30 11:10:56 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2015 Stefano Verzegnassi2 * Copyright (C) 2015, 2016 Stefano Verzegnassi
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
@@ -14,83 +14,59 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */15 */
16 16
17// Here we handle all the key events that are not
18// recognised by UITK ScrollView
19
17function parseEvent(event) {20function parseEvent(event) {
18 var pixelDiff = 5;
19
20 var view = loPage.contentItem.loView21 var view = loPage.contentItem.loView
21 var isPresentation = view.document.documentType === LibreOffice.Document.PresentationDocument22 var isPresentation = view.document.documentType === LibreOffice.Document.PresentationDocument
2223
23 if (event.key == Qt.Key_PageUp) {24 if (event.key == Qt.Key_PageUp) {
24 if (isPresentation)25 if (isPresentation) {
25 view.currentPart -= 126 view.currentPart -= 1
26 else27 event.accepted = true
27 view.moveView("vertical", -view.height)28 }
28
29 return;29 return;
30 }30 }
31 31
32 if (event.key == Qt.Key_PageDown) {32 if (event.key == Qt.Key_PageDown) {
33 if (isPresentation)33 if (isPresentation) {
34 view.currentPart += 134 view.currentPart += 1
35 else35 event.accepted = true
36 view.moveView("vertical", view.height)36 }
37
38 return;37 return;
39 }38 }
40 39
41 if (event.key == Qt.Key_Home) {40 if (event.key == Qt.Key_Home) {
42 if (event.modifiers & Qt.ControlModifier) {41 if (event.modifiers & Qt.ControlModifier)
43 view.contentX = 0
44 view.contentY = 0
45 view.currentPart = 042 view.currentPart = 0
46 } else {43
47 view.contentX = 044 event.accepted = false
48 view.contentY = 045 return
49 }
50 }46 }
5147
52 if (event.key == Qt.Key_End) {48 if (event.key == Qt.Key_End) {
53 if (event.modifiers & Qt.ControlModifier) {49 if (event.modifiers & Qt.ControlModifier)
54 view.contentX = view.contentWidth - view.width
55 view.contentY = view.contentHeight - view.height
56 console.log(view.currentPart, view.document.partsCount - 1)
57 view.currentPart = view.document.partsCount - 150 view.currentPart = view.document.partsCount - 1
58 } else {
59 view.contentX = view.contentWidth - view.width
60 view.contentY = view.contentHeight - view.height
61 }
62 }
6351
64 if (event.key == Qt.Key_Up) {52 event.accepted = false
65 view.moveView("vertical", -pixelDiff)53 return
66 return;
67 }
68
69 if (event.key == Qt.Key_Down) {
70 view.moveView("vertical", pixelDiff)
71 return;
72 }
73
74 if (event.key == Qt.Key_Left) {
75 view.moveView("horizontal", -pixelDiff)
76 return;
77 }
78
79 if (event.key == Qt.Key_Right) {
80 view.moveView("horizontal", pixelDiff)
81 return;
82 }54 }
8355
84 if (event.key == Qt.Key_Plus) {56 if (event.key == Qt.Key_Plus) {
85 if (event.modifiers & Qt.ControlModifier) {57 if (event.modifiers & Qt.ControlModifier) {
86 view.zoomFactor = Math.max(4.0, view.zoomFactor + 0.25)58 view.setZoom(Math.min(view.zoomSettings.maximumZoom, view.zoomSettings.zoomFactor + 0.25))
87 }59 }
60
61 return
88 }62 }
8963
90 if (event.key == Qt.Key_Minus) {64 if (event.key == Qt.Key_Minus) {
91 if (event.modifiers & Qt.ControlModifier) {65 if (event.modifiers & Qt.ControlModifier) {
92 view.zoomFactor = Math.min(0.5, view.zoomFactor - 0.25)66 view.setZoom(Math.max(view.zoomSettings.minimumZoom, view.zoomSettings.zoomFactor - 0.25))
93 }67 }
68
69 return
94 }70 }
9571
9672
9773
=== modified file 'src/app/qml/loView/LOViewDefaultHeader.qml'
--- src/app/qml/loView/LOViewDefaultHeader.qml 2015-11-30 12:12:10 +0000
+++ src/app/qml/loView/LOViewDefaultHeader.qml 2016-03-30 11:10:56 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2014-2015 Canonical, Ltd.2 * Copyright (C) 2014-2016 Canonical, Ltd.
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
@@ -16,68 +16,55 @@
1616
17import QtQuick 2.417import QtQuick 2.4
18import Ubuntu.Components 1.318import Ubuntu.Components 1.3
19import QtQuick.Layouts 1.1
20import Ubuntu.Components.Popups 1.319import Ubuntu.Components.Popups 1.3
21import DocumentViewer.LibreOffice 1.0 as LibreOffice20import DocumentViewer.LibreOffice 1.0 as LibreOffice
22import DocumentViewer 1.021import DocumentViewer 1.0
2322
24PageHeadState {23PageHeader {
25 id: rootItem24 id: defaultHeader
2625
27 property Page targetPage26 property var targetPage
28 head: targetPage.head27
2928 contents: ListItemLayout {
30 contents: RowLayout {29 anchors.centerIn: parent
31 anchors.fill: parent30
32 anchors.rightMargin: units.gu(2)31 title {
33 spacing: units.gu(1)32 elide: Text.ElideMiddle
3433 font.weight: Font.DemiBold
35 Column {34 text: defaultHeader.title
36 id: layout35 }
37 Layout.fillWidth: true36
3837 subtitle {
39 Label {38 textSize: Label.Small
40 anchors { left: parent.left; right: parent.right }39 text: {
41 elide: Text.ElideMiddle40 if (!targetPage.contentItem)
42 font.weight: Font.DemiBold41 return i18n.tr("Loading...")
43 text: targetPage.title42
44 }43 switch(targetPage.contentItem.loDocument.documentType) {
45 Label {44 case LibreOffice.Document.TextDocument:
46 anchors { left: parent.left; right: parent.right }45 return i18n.tr("LibreOffice text document")
47 elide: Text.ElideMiddle46 case LibreOffice.Document.SpreadsheetDocument:
48 textSize: Label.Small47 return i18n.tr("LibreOffice spread sheet")
49 text: {48 case LibreOffice.Document.PresentationDocument:
50 if (!targetPage.contentItem)49 return i18n.tr("LibreOffice presentation")
51 return i18n.tr("Loading...")50 case LibreOffice.Document.DrawingDocument:
5251 return i18n.tr("LibreOffice Draw document")
53 switch(targetPage.contentItem.loDocument.documentType) {52 case LibreOffice.Document.OtherDocument:
54 case 0:53 return i18n.tr("Unknown LibreOffice document")
55 return i18n.tr("LibreOffice text document")54 default:
56 case 1:55 return i18n.tr("Unknown type document")
57 return i18n.tr("LibreOffice spread sheet")
58 case 2:
59 return i18n.tr("LibreOffice presentation")
60 case 3:
61 return i18n.tr("LibreOffice Draw document")
62 case 4:
63 return i18n.tr("Unknown LibreOffice document")
64 default:
65 return i18n.tr("Unknown type document")
66 }
67 }56 }
68 }57 }
69 }58 }
7059
71 ZoomSelector {60 ZoomSelector {
72 Layout.preferredWidth: units.gu(12)61 SlotsLayout.position: SlotsLayout.Trailing
73 Layout.preferredHeight: units.gu(4)
74
75 view: targetPage.contentItem.loView62 view: targetPage.contentItem.loView
76 visible: targetPage.contentItem && (DocumentViewer.desktopMode || mainView.wideWindow)63 visible: targetPage.contentItem && (DocumentViewer.desktopMode || mainView.wideWindow)
77 }64 }
78 }65 }
7966
80 actions: [67 trailingActionBar.actions: [
81 Action {68 Action {
82 // FIXME: Autopilot test broken... seems not to detect we're now using an ActionBar since the switch to UITK 1.369 // FIXME: Autopilot test broken... seems not to detect we're now using an ActionBar since the switch to UITK 1.3
83 objectName: "gotopage"70 objectName: "gotopage"
@@ -86,12 +73,11 @@
86 visible: targetPage.contentItem.loDocument.documentType == LibreOffice.Document.TextDocument73 visible: targetPage.contentItem.loDocument.documentType == LibreOffice.Document.TextDocument
8774
88 onTriggered: {75 onTriggered: {
89 PopupUtils.open(76 var popupSettings = {
90 Qt.resolvedUrl("LOViewGotoDialog.qml"),77 view: targetPage.contentItem.loView
91 targetPage,78 }
92 {79
93 view: targetPage.contentItem.loView80 PopupUtils.open(Qt.resolvedUrl("LOViewGotoDialog.qml"), targetPage, popupSettings)
94 })
95 }81 }
96 },82 },
9783
9884
=== modified file 'src/app/qml/loView/LOViewPage.qml'
--- src/app/qml/loView/LOViewPage.qml 2016-02-03 21:35:53 +0000
+++ src/app/qml/loView/LOViewPage.qml 2016-03-30 11:10:56 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013-2015 Canonical, Ltd.2 * Copyright (C) 2013-2016 Canonical, Ltd.
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
@@ -32,9 +32,7 @@
32 property bool isTextDocument: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.TextDocument)32 property bool isTextDocument: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.TextDocument)
33 property bool isSpreadsheet: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.SpreadsheetDocument)33 property bool isSpreadsheet: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.SpreadsheetDocument)
3434
35 title: DocumentViewer.getFileBaseNameFromPath(file.path);35 header: defaultHeader
36 flickable: isTextDocument ? loPage.contentItem.loView : null
37
38 splashScreen: Splashscreen { }36 splashScreen: Splashscreen { }
3937
40 content: FocusScope {38 content: FocusScope {
@@ -137,96 +135,102 @@
137 color: "#f5f5f5"135 color: "#f5f5f5"
138 }136 }
139137
140 LibreOffice.Viewer {138 ScrollView {
141 id: loView
142 objectName: "loView"
143 anchors.fill: parent139 anchors.fill: parent
144140
145 documentPath: file.path141 // We need to set some custom event handler.
146142 // Forward the key events to the Viewer and
147 function updateContentSize(tgtScale) {143 // fallback to the ScrollView handlers if the
148 zoomSettings.zoomFactor = tgtScale144 // event hasn't been accepted.
149 }145 Keys.forwardTo: loView
150146 Keys.priority: Keys.AfterItem
151 // Keyboard events147
152 focus: true148 LibreOffice.Viewer {
153 Keys.onPressed: KeybHelper.parseEvent(event)149 id: loView
154150 objectName: "loView"
155 Component.onCompleted: {
156 // WORKAROUND: Fix for wrong grid unit size
157 flickDeceleration = 1500 * units.gridUnit / 8
158 maximumFlickVelocity = 2500 * units.gridUnit / 8
159 loPageContent.forceActiveFocus()
160 }
161
162 onErrorChanged: {
163 var errorString;
164
165 switch(error) {
166 case LibreOffice.Error.LibreOfficeNotFound:
167 errorString = i18n.tr("LibreOffice binaries not found.")
168 break;
169 case LibreOffice.Error.LibreOfficeNotInitialized:
170 errorString = i18n.tr("Error while loading LibreOffice.")
171 break;
172 case LibreOffice.Error.DocumentNotLoaded:
173 errorString = i18n.tr("Document not loaded.\nThe requested document may be corrupt or protected by a password.")
174 break;
175 }
176
177 if (errorString) {
178 loPage.pageStack.pop()
179
180 // We create the dialog in the MainView, so that it isn't
181 // initialized by 'loPage' and keep on working after the
182 // page is destroyed.
183 mainView.showErrorDialog(errorString);
184 }
185 }
186
187 ScalingMouseArea {
188 id: mouseArea
189 anchors.fill: parent151 anchors.fill: parent
190 targetFlickable: loView152
191 onTotalScaleChanged: targetFlickable.updateContentSize(totalScale)153 documentPath: file.path
192154
193 thresholdZoom: minimumZoom + (maximumZoom - minimumZoom) * 0.75155 Keys.onPressed: KeybHelper.parseEvent(event)
194 maximumZoom: {156
195 if (DocumentViewer.desktopMode || mainView.wideWindow)157 function updateContentSize(tgtScale) {
196 return 3.0158 zoomSettings.zoomFactor = tgtScale
197159 }
198 return minimumZoom * 3160
199 }161 Component.onCompleted: {
200 minimumZoom: {162 // WORKAROUND: Fix for wrong grid unit size
201 if (DocumentViewer.desktopMode || mainView.wideWindow)163 flickDeceleration = 1500 * units.gridUnit / 8
202 return loView.zoomSettings.minimumZoom164 maximumFlickVelocity = 2500 * units.gridUnit / 8
203165 loPageContent.forceActiveFocus()
204 switch(loView.document.documentType) {166 }
205 case LibreOffice.Document.TextDocument:167
206 return loView.zoomSettings.valueFitToWidthZoom168 onErrorChanged: {
207 case LibreOffice.Document.PresentationDocument:169 var errorString;
208 return loView.zoomSettings.valueAutomaticZoom170
209 default:171 switch(error) {
210 return loView.zoomSettings.minimumZoom172 case LibreOffice.Error.LibreOfficeNotFound:
211 }173 errorString = i18n.tr("LibreOffice binaries not found.")
212 }174 break;
213175 case LibreOffice.Error.LibreOfficeNotInitialized:
214 Binding {176 errorString = i18n.tr("Error while loading LibreOffice.")
215 target: mouseArea177 break;
216 property: "zoomValue"178 case LibreOffice.Error.DocumentNotLoaded:
217 value: loView.zoomSettings.zoomFactor179 errorString = i18n.tr("Document not loaded.\nThe requested document may be corrupt or protected by a password.")
218 }180 break;
219 }181 }
220182
221 Scrollbar { flickableItem: loView; parent: loView.parent }183 if (errorString) {
222 Scrollbar { flickableItem: loView; parent: loView.parent; align: Qt.AlignBottom }184 loPage.pageStack.pop()
223185
224 Label {186 // We create the dialog in the MainView, so that it isn't
225 anchors.centerIn: parent187 // initialized by 'loPage' and keep on working after the
226 parent: loPage188 // page is destroyed.
227 textSize: Label.Large189 mainView.showErrorDialog(errorString);
228 text: i18n.tr("This sheet has no content.")190 }
229 visible: loPage.isSpreadsheet && loView.contentWidth <= 0 && loView.contentHeight <= 0191 }
192
193 ScalingMouseArea {
194 id: mouseArea
195 anchors.fill: parent
196 targetFlickable: loView
197 onTotalScaleChanged: targetFlickable.updateContentSize(totalScale)
198
199 thresholdZoom: minimumZoom + (maximumZoom - minimumZoom) * 0.75
200 maximumZoom: {
201 if (DocumentViewer.desktopMode || mainView.wideWindow)
202 return 3.0
203
204 return minimumZoom * 3
205 }
206 minimumZoom: {
207 if (DocumentViewer.desktopMode || mainView.wideWindow)
208 return loView.zoomSettings.minimumZoom
209
210 switch(loView.document.documentType) {
211 case LibreOffice.Document.TextDocument:
212 return loView.zoomSettings.valueFitToWidthZoom
213 case LibreOffice.Document.PresentationDocument:
214 return loView.zoomSettings.valueAutomaticZoom
215 default:
216 return loView.zoomSettings.minimumZoom
217 }
218 }
219
220 Binding {
221 target: mouseArea
222 property: "zoomValue"
223 value: loView.zoomSettings.zoomFactor
224 }
225 }
226
227 Label {
228 anchors.centerIn: parent
229 parent: loPage
230 textSize: Label.Large
231 text: i18n.tr("This sheet has no content.")
232 visible: loPage.isSpreadsheet && loView.contentWidth <= 0 && loView.contentHeight <= 0
233 }
230 }234 }
231 }235 }
232 }236 }
@@ -265,12 +269,20 @@
265 }269 }
266 }270 }
267271
268 // *** HEADER ***272
269 state: "default"273 /*** Headers ***/
270 states: [274
271 LOViewDefaultHeader {275 LOViewDefaultHeader {
272 name: "default"276 id: defaultHeader
273 targetPage: loPage277 visible: loPage.loaded
274 }278 title: DocumentViewer.getFileBaseNameFromPath(file.path);
275 ]279 flickable: isTextDocument ? loPage.contentItem.loView : null
280 targetPage: loPage
281 }
282
283 PageHeader {
284 id: loadingHeader
285 visible: !loPage.loaded
286 // When we're still loading LibreOffice, show an empty header
287 }
276}288}

Subscribers

People subscribed via source and target branches