Merge lp:~mrqtros/ubuntu-docviewer-app/reboot-qsg-impress-support into lp:ubuntu-docviewer-app

Proposed by Stefano Verzegnassi
Status: Merged
Approved by: Stefano Verzegnassi
Approved revision: 187
Merged at revision: 186
Proposed branch: lp:~mrqtros/ubuntu-docviewer-app/reboot-qsg-impress-support
Merge into: lp:ubuntu-docviewer-app
Prerequisite: lp:~verzegnassi-stefano/ubuntu-docviewer-app/reboot-qsg-impress-support
Diff against target: 1256 lines (+329/-245)
19 files modified
po/com.ubuntu.docviewer.pot (+17/-17)
src/app/qml/loView/LOViewDefaultHeader.qml (+36/-46)
src/app/qml/loView/LOViewPage.qml (+3/-3)
src/app/qml/loView/PartsView.qml (+8/-9)
src/app/qml/ubuntu-docviewer-app.qml (+1/-1)
src/plugin/libreofficetoolkit-qml-plugin/lodocument.cpp (+12/-24)
src/plugin/libreofficetoolkit-qml-plugin/lodocument.h (+9/-4)
src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp (+20/-16)
src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h (+7/-2)
src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.cpp (+45/-44)
src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h (+21/-10)
src/plugin/libreofficetoolkit-qml-plugin/loview.cpp (+47/-19)
src/plugin/libreofficetoolkit-qml-plugin/loview.h (+17/-7)
src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp (+1/-1)
src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml (+2/-1)
src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp (+39/-11)
src/plugin/libreofficetoolkit-qml-plugin/renderengine.h (+38/-18)
src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp (+5/-5)
src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h (+1/-7)
To merge this branch: bzr merge lp:~mrqtros/ubuntu-docviewer-app/reboot-qsg-impress-support
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Stefano Verzegnassi Approve
Review via email: mp+273984@code.launchpad.net

This proposal supersedes a proposal from 2015-10-08.

Commit message

RenderEngine - impress support.

Description of the change

RenderEngine - impress support.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

I've added lp:~verzegnassi-stefano/ubuntu-docviewer-app/reboot-qsg-impress-support as prerequisite branch, so that the diff is a bit shorter :)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Overall it looks good to me! Excellent work! :)

Anyway there are a few things that require a fix (mostly some bad-looking piece of code I wrote, or deprecated stuff imported from PDF code).
Since I've already fixed six times the 'go to position' dialog in LibreOffice viewer (bzr conflicts), I'd prefer to push those fixes in this branch, and do the work just once.

It would be really appreciated if you could include the following changes in your branch:
https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/reboot-impress-support-mp-review/+merge/274068

187. By Roman Shchekin

UPD

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

LGTM

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'po/com.ubuntu.docviewer.pot'
--- po/com.ubuntu.docviewer.pot 2015-10-10 12:32:48 +0000
+++ po/com.ubuntu.docviewer.pot 2015-10-11 19:35:30 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: \n"9"Project-Id-Version: \n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2015-10-10 14:32+0200\n"11"POT-Creation-Date: 2015-10-11 13:31+0200\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -24,7 +24,7 @@
24msgstr ""24msgstr ""
2525
26#: ../src/app/qml/common/DetailsPage.qml:2726#: ../src/app/qml/common/DetailsPage.qml:27
27#: ../src/app/qml/loView/LOViewDefaultHeader.qml:11627#: ../src/app/qml/loView/LOViewDefaultHeader.qml:114
28#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:9728#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:97
29#: ../src/app/qml/textView/TextViewDefaultHeader.qml:8329#: ../src/app/qml/textView/TextViewDefaultHeader.qml:83
30msgid "Details"30msgid "Details"
@@ -63,7 +63,7 @@
63#: ../src/app/qml/common/RejectedImportDialog.qml:3863#: ../src/app/qml/common/RejectedImportDialog.qml:38
64#: ../src/app/qml/documentPage/DocumentPageSelectionModeHeader.qml:3264#: ../src/app/qml/documentPage/DocumentPageSelectionModeHeader.qml:32
65#: ../src/app/qml/documentPage/SortSettingsDialog.qml:5365#: ../src/app/qml/documentPage/SortSettingsDialog.qml:53
66#: ../src/app/qml/loView/LOViewDefaultHeader.qml:8066#: ../src/app/qml/loView/LOViewDefaultHeader.qml:78
67#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:6167#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:61
68#: ../src/app/qml/textView/TextViewDefaultHeader.qml:6168#: ../src/app/qml/textView/TextViewDefaultHeader.qml:61
69msgid "Close"69msgid "Close"
@@ -254,7 +254,7 @@
254msgstr ""254msgstr ""
255255
256#: ../src/app/qml/documentPage/DocumentPageSearchHeader.qml:27256#: ../src/app/qml/documentPage/DocumentPageSearchHeader.qml:27
257#: ../src/app/qml/loView/LOViewDefaultHeader.qml:80257#: ../src/app/qml/loView/LOViewDefaultHeader.qml:78
258#: ../src/app/qml/loView/LOViewPage.qml:191258#: ../src/app/qml/loView/LOViewPage.qml:191
259#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:61259#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:61
260#: ../src/app/qml/textView/TextViewDefaultHeader.qml:61260#: ../src/app/qml/textView/TextViewDefaultHeader.qml:61
@@ -306,50 +306,50 @@
306msgid "Reverse order"306msgid "Reverse order"
307msgstr ""307msgstr ""
308308
309#: ../src/app/qml/loView/LOViewDefaultHeader.qml:57309#: ../src/app/qml/loView/LOViewDefaultHeader.qml:55
310#: ../src/app/qml/textView/TextView.qml:42310#: ../src/app/qml/textView/TextView.qml:42
311msgid "Loading..."311msgid "Loading..."
312msgstr ""312msgstr ""
313313
314#: ../src/app/qml/loView/LOViewDefaultHeader.qml:59
315msgid "LibreOffice text document"
316msgstr ""
317
314#: ../src/app/qml/loView/LOViewDefaultHeader.qml:61318#: ../src/app/qml/loView/LOViewDefaultHeader.qml:61
315msgid "LibreOffice text document"319msgid "LibreOffice spread sheet"
316msgstr ""320msgstr ""
317321
318#: ../src/app/qml/loView/LOViewDefaultHeader.qml:63322#: ../src/app/qml/loView/LOViewDefaultHeader.qml:63
319msgid "LibreOffice spread sheet"323msgid "LibreOffice presentation"
320msgstr ""324msgstr ""
321325
322#: ../src/app/qml/loView/LOViewDefaultHeader.qml:65326#: ../src/app/qml/loView/LOViewDefaultHeader.qml:65
323msgid "LibreOffice presentation"327msgid "LibreOffice Draw document"
324msgstr ""328msgstr ""
325329
326#: ../src/app/qml/loView/LOViewDefaultHeader.qml:67330#: ../src/app/qml/loView/LOViewDefaultHeader.qml:67
327msgid "LibreOffice Draw document"331msgid "Unknown LibreOffice document"
328msgstr ""332msgstr ""
329333
330#: ../src/app/qml/loView/LOViewDefaultHeader.qml:69334#: ../src/app/qml/loView/LOViewDefaultHeader.qml:69
331msgid "Unknown LibreOffice document"
332msgstr ""
333
334#: ../src/app/qml/loView/LOViewDefaultHeader.qml:71
335msgid "Unknown type document"335msgid "Unknown type document"
336msgstr ""336msgstr ""
337337
338#: ../src/app/qml/loView/LOViewDefaultHeader.qml:96338#: ../src/app/qml/loView/LOViewDefaultHeader.qml:94
339msgid "Show zoom controls"339msgid "Show zoom controls"
340msgstr ""340msgstr ""
341341
342#: ../src/app/qml/loView/LOViewDefaultHeader.qml:103342#: ../src/app/qml/loView/LOViewDefaultHeader.qml:101
343msgid "Go to position..."343msgid "Go to position..."
344msgstr ""344msgstr ""
345345
346#: ../src/app/qml/loView/LOViewDefaultHeader.qml:110346#: ../src/app/qml/loView/LOViewDefaultHeader.qml:108
347#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:91347#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:91
348#: ../src/app/qml/textView/TextViewDefaultHeader.qml:77348#: ../src/app/qml/textView/TextViewDefaultHeader.qml:77
349msgid "Disable night mode"349msgid "Disable night mode"
350msgstr ""350msgstr ""
351351
352#: ../src/app/qml/loView/LOViewDefaultHeader.qml:110352#: ../src/app/qml/loView/LOViewDefaultHeader.qml:108
353#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:91353#: ../src/app/qml/pdfView/PdfViewDefaultHeader.qml:91
354#: ../src/app/qml/textView/TextViewDefaultHeader.qml:77354#: ../src/app/qml/textView/TextViewDefaultHeader.qml:77
355msgid "Enable night mode"355msgid "Enable night mode"
356356
=== modified file 'src/app/qml/loView/LOViewDefaultHeader.qml'
--- src/app/qml/loView/LOViewDefaultHeader.qml 2015-10-10 12:13:40 +0000
+++ src/app/qml/loView/LOViewDefaultHeader.qml 2015-10-11 19:35:30 +0000
@@ -16,7 +16,6 @@
1616
17import QtQuick 2.317import QtQuick 2.3
18import Ubuntu.Components 1.118import Ubuntu.Components 1.1
19import QtQuick.Layouts 1.1
20import Ubuntu.Components.Popups 1.019import Ubuntu.Components.Popups 1.0
21import DocumentViewer.LibreOffice 1.0 as LibreOffice20import DocumentViewer.LibreOffice 1.0 as LibreOffice
2221
@@ -24,57 +23,48 @@
24 id: rootItem23 id: rootItem
2524
26 property Page targetPage25 property Page targetPage
27 property alias activityRunning: activity.running
28
29 head: targetPage.head26 head: targetPage.head
3027
31 contents: RowLayout {28 contents: Column {
32 anchors.fill: parent29 anchors {
33 spacing: units.gu(1)30 left: parent.left
3431 right: parent.right
35 ActivityIndicator { id: activity }32 verticalCenter: parent.verticalCenter
3633 }
37 Column {34
38 id: layout35 Label {
39 Layout.fillWidth: true36 anchors { left: parent.left; right: parent.right }
4037 elide: Text.ElideMiddle
41 Label {38 font.weight: Font.DemiBold
42 width: parent.width39 text: targetPage.title
43 //horizontalAlignment: Text.AlignHCenter40 }
44 elide: Text.ElideMiddle41 Label {
4542 anchors { left: parent.left; right: parent.right }
46 font.weight: Font.DemiBold43 elide: Text.ElideMiddle
47 text: targetPage.title44 fontSize: "small"
48 }45 text: {
49 Label {46 if (!loPageContentLoader.item)
50 width: parent.width47 return i18n.tr("Loading...")
51 //horizontalAlignment: Text.AlignHCenter48
52 elide: Text.ElideMiddle49 switch(loPageContentLoader.item.loDocument.documentType) {
5350 case 0:
54 fontSize: "small"51 return i18n.tr("LibreOffice text document")
55 text: {52 case 1:
56 if (!loPageContentLoader.item)53 return i18n.tr("LibreOffice spread sheet")
57 return i18n.tr("Loading...")54 case 2:
5855 return i18n.tr("LibreOffice presentation")
59 switch(loPageContentLoader.item.loDocument.documentType) {56 case 3:
60 case 0:57 return i18n.tr("LibreOffice Draw document")
61 return i18n.tr("LibreOffice text document")58 case 4:
62 case 1:59 return i18n.tr("Unknown LibreOffice document")
63 return i18n.tr("LibreOffice spread sheet")60 default:
64 case 2:61 return i18n.tr("Unknown type document")
65 return i18n.tr("LibreOffice presentation")
66 case 3:
67 return i18n.tr("LibreOffice Draw document")
68 case 4:
69 return i18n.tr("Unknown LibreOffice document")
70 default:
71 return i18n.tr("Unknown type document")
72 }
73 }62 }
74 }63 }
75 }64 }
76 }65 }
7766
67
78 backAction: Action {68 backAction: Action {
79 iconName: "back"69 iconName: "back"
80 text: (pageStack.depth > 1) ? i18n.tr("Back") : i18n.tr("Close")70 text: (pageStack.depth > 1) ? i18n.tr("Back") : i18n.tr("Close")
@@ -102,7 +92,7 @@
102 iconName: "browser-tabs"92 iconName: "browser-tabs"
103 text: i18n.tr("Go to position...")93 text: i18n.tr("Go to position...")
104 onTriggered: PopupUtils.open(Qt.resolvedUrl("LOViewGotoDialog.qml"), targetPage)94 onTriggered: PopupUtils.open(Qt.resolvedUrl("LOViewGotoDialog.qml"), targetPage)
105 visible: loDocument.documentType == LibreOffice.Document.TextDocument95 visible: loPageContentLoader.item.loDocument.documentType == LibreOffice.Document.TextDocument
106 },96 },
10797
108 Action {98 Action {
10999
=== modified file 'src/app/qml/loView/LOViewPage.qml'
--- src/app/qml/loView/LOViewPage.qml 2015-09-23 16:48:39 +0000
+++ src/app/qml/loView/LOViewPage.qml 2015-10-11 19:35:30 +0000
@@ -99,8 +99,8 @@
99 left: parent.left99 left: parent.left
100 }100 }
101101
102 model: LO.PartsModel { document: loPageContent.loDocument }102 model: loView.partsModel
103 visible: model && loDocument.documentType == LO.Document.PresentationDocument103 visible: loDocument.documentType == LO.Document.PresentationDocument
104 width: visible ? units.gu(40) : 0104 width: visible ? units.gu(40) : 0
105 }105 }
106106
@@ -198,7 +198,7 @@
198 PartsView {198 PartsView {
199 property bool belongsToNestedPage: true199 property bool belongsToNestedPage: true
200 anchors.fill: parent200 anchors.fill: parent
201 model: LO.PartsModel { document: loPageContent.loDocument }201 model: loView.partsModel
202 }202 }
203 }203 }
204 }204 }
205205
=== modified file 'src/app/qml/loView/PartsView.qml'
--- src/app/qml/loView/PartsView.qml 2015-09-23 16:48:39 +0000
+++ src/app/qml/loView/PartsView.qml 2015-10-11 19:35:30 +0000
@@ -28,7 +28,7 @@
2828
29 property bool expanded: true29 property bool expanded: true
3030
31 currentIndex: view.model ? view.model.document.currentPart : -131 currentIndex: view.model ? loView.document.currentPart : -1
32 highlightMoveDuration: UbuntuAnimation.SnapDuration32 highlightMoveDuration: UbuntuAnimation.SnapDuration
3333
34 delegate: ListItemWithActions {34 delegate: ListItemWithActions {
@@ -37,15 +37,15 @@
37 width: parent.width37 width: parent.width
38 height: units.gu(16)38 height: units.gu(16)
3939
40 color: (view.model.document.currentPart === model.index) ? Theme.palette.selected.background40 color: (loView.document.currentPart === model.index) ? Theme.palette.selected.background
41 : "transparent"41 : "transparent"
4242
43 AbstractButton {43 AbstractButton {
44 objectName: "abstractbutton"44 objectName: "abstractbutton"
45 anchors.fill: parent45 anchors.fill: parent
4646
47 onClicked: {47 onClicked: {
48 view.model.document.currentPart = model.index48 loView.document.currentPart = model.index
4949
50 // Check if the view has been included in a nested page (e.g.50 // Check if the view has been included in a nested page (e.g.
51 // bottomEdge). If so, close that page and return to the51 // bottomEdge). If so, close that page and return to the
@@ -65,22 +65,21 @@
65 fillMode: Image.PreserveAspectFit65 fillMode: Image.PreserveAspectFit
66 // Do not store a cache of the thumbnail, so that we don't show66 // Do not store a cache of the thumbnail, so that we don't show
67 // thumbnails of a previously loaded document.67 // thumbnails of a previously loaded document.
68 cache: false68 cache: true // TODO PLAY WITH IT
6969 source: model.thumbnail
70 source: "image://lok/part/" + model.index
71 }70 }
7271
73 Label {72 Label {
74 Layout.fillWidth: true73 Layout.fillWidth: true
75 wrapMode: Text.WordWrap74 wrapMode: Text.WordWrap
76 text: model.name75 text: model.name
77 color: (view.model.document.currentPart === model.index) ? UbuntuColors.orange76 color: (loView.document.currentPart === model.index) ? UbuntuColors.orange
78 : Theme.palette.selected.backgroundText77 : Theme.palette.selected.backgroundText
79 }78 }
8079
81 Label {80 Label {
82 text: model.index + 181 text: model.index + 1
83 color: (view.model.document.currentPart === model.index) ? UbuntuColors.orange82 color: (loView.document.currentPart === model.index) ? UbuntuColors.orange
84 : Theme.palette.selected.backgroundText83 : Theme.palette.selected.backgroundText
85 }84 }
86 }85 }
8786
=== modified file 'src/app/qml/ubuntu-docviewer-app.qml'
--- src/app/qml/ubuntu-docviewer-app.qml 2015-09-11 14:48:57 +0000
+++ src/app/qml/ubuntu-docviewer-app.qml 2015-10-11 19:35:30 +0000
@@ -37,7 +37,7 @@
37 useDeprecatedToolbar: false 37 useDeprecatedToolbar: false
38 automaticOrientation: true38 automaticOrientation: true
3939
40 width: units.gu(50)40 width: units.gu(150)
41 height: units.gu(75)41 height: units.gu(75)
4242
43 function openDocument(path) {43 function openDocument(path) {
4444
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lodocument.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/lodocument.cpp 2015-10-04 12:38:48 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lodocument.cpp 2015-10-11 19:35:30 +0000
@@ -110,6 +110,17 @@
110 return m_docType;110 return m_docType;
111}111}
112112
113int LODocument::documentPart() const
114{
115 return m_document->getPart();
116}
117
118void LODocument::setDocumentPart(int p)
119{
120 if (documentPart() != p)
121 m_document->setPart(p);
122}
123
113// Return the size of the document, in TWIPs124// Return the size of the document, in TWIPs
114QSize LODocument::documentSize() const125QSize LODocument::documentSize() const
115{126{
@@ -123,16 +134,11 @@
123 return QSize(pWidth, pHeight);134 return QSize(pWidth, pHeight);
124}135}
125136
126// Paint a tile, with size=canvasSize, of the part of the document defined by
127// the rect tileSize.
128QImage LODocument::paintTile(const QSize& canvasSize, const QRect& tileSize, const qreal &zoom)137QImage LODocument::paintTile(const QSize& canvasSize, const QRect& tileSize, const qreal &zoom)
129{138{
130 if (!m_document)139 if (!m_document)
131 return QImage();140 return QImage();
132141
133 if (m_currentPart != m_document->getPart())
134 m_document->setPart(m_currentPart);
135
136 QImage result = QImage(canvasSize.width(), canvasSize.height(), QImage::Format_RGB32);142 QImage result = QImage(canvasSize.width(), canvasSize.height(), QImage::Format_RGB32);
137143
138#ifdef DEBUG_TILE_BENCHMARK144#ifdef DEBUG_TILE_BENCHMARK
@@ -154,7 +160,7 @@
154 return result.rgbSwapped();160 return result.rgbSwapped();
155}161}
156162
157QImage LODocument::paintThumbnail(int part, qreal size)163QImage LODocument::paintThumbnail(qreal size)
158{164{
159 if (!m_document)165 if (!m_document)
160 return QImage();166 return QImage();
@@ -164,14 +170,6 @@
164 renderTimer.start();170 renderTimer.start();
165#endif171#endif
166172
167 // This is used by LOPartsImageProvider to temporarily change the current part,
168 // in order to generate thumbnails.
169
170 // FIXME: Sometimes docviewer crashes at m_document->getPart() when a
171 // document is being loaded.
172 if (m_document->getPart() != part)
173 m_document->setPart(part);
174
175 qreal tWidth = this->documentSize().width();173 qreal tWidth = this->documentSize().width();
176 qreal tHeight = this->documentSize().height();174 qreal tHeight = this->documentSize().height();
177175
@@ -189,10 +187,6 @@
189 m_document->paintTile(result.bits(), resultSize.width(), resultSize.height(),187 m_document->paintTile(result.bits(), resultSize.width(), resultSize.height(),
190 0, 0, tWidth, tHeight);188 0, 0, tWidth, tHeight);
191189
192 // Restore the active part used for tile rendering.
193 if (m_currentPart != part)
194 m_document->setPart(m_currentPart);
195
196#ifdef DEBUG_TILE_BENCHMARK190#ifdef DEBUG_TILE_BENCHMARK
197 qDebug() << "Time to render the thumbnail:" << renderTimer.elapsed() << "ms";191 qDebug() << "Time to render the thumbnail:" << renderTimer.elapsed() << "ms";
198#endif192#endif
@@ -216,12 +210,6 @@
216 return QString::fromUtf8(m_document->getPartName(index));210 return QString::fromUtf8(m_document->getPartName(index));
217}211}
218 212
219/* Export the file in a given format:
220 * - url is a mandatory argument.
221 * - format is optional. If not specified, lok will try to get it from the file
222 * extension given at the 'url' argument.
223 * - filerOptions is also optional.
224 */
225// TODO: Is there some documentation on safe formats or filterOptions that can213// TODO: Is there some documentation on safe formats or filterOptions that can
226// be used?214// be used?
227bool LODocument::saveAs(QString url, QString format = QString(), QString filterOptions = QString())215bool LODocument::saveAs(QString url, QString format = QString(), QString filterOptions = QString())
228216
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lodocument.h'
--- src/plugin/libreofficetoolkit-qml-plugin/lodocument.h 2015-09-23 16:48:39 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lodocument.h 2015-10-11 19:35:30 +0000
@@ -30,11 +30,12 @@
30 Q_OBJECT30 Q_OBJECT
31 Q_DISABLE_COPY(LODocument)31 Q_DISABLE_COPY(LODocument)
3232
33 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)33 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
34 Q_PROPERTY(int currentPart READ currentPart WRITE setCurrentPart NOTIFY currentPartChanged)34 Q_PROPERTY(int currentPart READ currentPart WRITE setCurrentPart NOTIFY currentPartChanged)
35 // Declare partsCount as constant at the moment, since LOK-plugin is just a viewer for now.35 // Declare partsCount as constant at the moment, since LOK-plugin is just a viewer for now.
36 Q_PROPERTY(int partsCount READ partsCount CONSTANT)36 Q_PROPERTY(int partsCount READ partsCount CONSTANT)
37 Q_PROPERTY(DocumentType documentType READ documentType NOTIFY documentTypeChanged)37 Q_PROPERTY(int documentPart READ documentPart WRITE setDocumentPart NOTIFY documentPartChanged)
38 Q_PROPERTY(DocumentType documentType READ documentType NOTIFY documentTypeChanged)
38 Q_ENUMS(DocumentType)39 Q_ENUMS(DocumentType)
3940
40public:41public:
@@ -57,10 +58,13 @@
5758
58 DocumentType documentType() const;59 DocumentType documentType() const;
5960
61 int documentPart() const;
62 void setDocumentPart(int p);
63
60 QSize documentSize() const;64 QSize documentSize() const;
6165
62 QImage paintTile(const QSize& canvasSize, const QRect& tileSize, const qreal& zoom = 1.0);66 QImage paintTile(const QSize& canvasSize, const QRect& tileSize, const qreal& zoom = 1.0);
63 QImage paintThumbnail(int part, qreal size);67 QImage paintThumbnail(qreal size);
6468
65 int partsCount();69 int partsCount();
66 QString getPartName(int index) const;70 QString getPartName(int index) const;
@@ -72,6 +76,7 @@
72 void pathChanged();76 void pathChanged();
73 void currentPartChanged();77 void currentPartChanged();
74 void documentTypeChanged();78 void documentTypeChanged();
79 void documentPartChanged();
7580
76private:81private:
77 QString m_path;82 QString m_path;
7883
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp 2015-09-23 16:48:39 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.cpp 2015-10-11 19:35:30 +0000
@@ -18,9 +18,9 @@
18#include "lodocument.h"18#include "lodocument.h"
19#include "renderengine.h"19#include "renderengine.h"
2020
21LOPartsImageProvider::LOPartsImageProvider(LODocument *document)21LOPartsImageProvider::LOPartsImageProvider(const QSharedPointer<LODocument>& d)
22 : QQuickImageProvider(QQuickImageProvider::Image, QQuickImageProvider::ForceAsynchronousImageLoading)22 : QQuickImageProvider(QQuickImageProvider::Image),
23 , m_document(document)23 m_document(d)
24{ }24{ }
2525
26QImage LOPartsImageProvider::requestImage(const QString & id, QSize * size, const QSize & requestedSize)26QImage LOPartsImageProvider::requestImage(const QString & id, QSize * size, const QSize & requestedSize)
@@ -33,18 +33,22 @@
33 m_document->documentType() != LODocument::PresentationDocument)33 m_document->documentType() != LODocument::PresentationDocument)
34 return QImage();34 return QImage();
3535
36 // Wait for any in-progress rendering to be completed36 // Get info from "id".
37 while (RenderEngine::instance()->activeTaskCount() != 0) { }
38
39 // Lock the render engine
40 RenderEngine::instance()->setEnabled(false);
41
42 // Render the part to QImage
43 int partNumber = id.section("/", 1, 1).toInt();37 int partNumber = id.section("/", 1, 1).toInt();
44 QImage result = m_document->paintThumbnail(partNumber, 256.0);38 int itemId = id.section("/", 2, 2).toInt();
4539
46 // Unlock the render engine40 // Once rendered images can be found in hash.
47 RenderEngine::instance()->setEnabled(true);41 if (m_images.contains(itemId))
4842 return m_images[itemId];
49 return result;43
44 const int defaultSize = 256;
45
46 RenderEngine::instance()->enqueueTask(m_document, partNumber, defaultSize, itemId);
47
48 // Return default image (empty).
49 static QImage defaultImage;
50 if (defaultImage.isNull())
51 defaultImage = QImage(defaultSize, defaultSize, QImage::Format_ARGB32);
52
53 return defaultImage;
50}54}
5155
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h'
--- src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h 2015-09-15 18:20:00 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lopartsimageprovider.h 2015-10-11 19:35:30 +0000
@@ -19,17 +19,22 @@
19#define LOPARTSIMAGEPROVIDER_H19#define LOPARTSIMAGEPROVIDER_H
2020
21#include <QQuickImageProvider>21#include <QQuickImageProvider>
22#include <QSharedPointer>
23#include <QHash>
24#include <QDebug>
2225
23class LODocument;26class LODocument;
2427
25class LOPartsImageProvider : public QQuickImageProvider28class LOPartsImageProvider : public QQuickImageProvider
26{29{
27public:30public:
28 LOPartsImageProvider(LODocument *document);31 LOPartsImageProvider(const QSharedPointer<LODocument>& d);
29 QImage requestImage(const QString & id, QSize * size, const QSize & requestedSize);32 QImage requestImage(const QString & id, QSize * size, const QSize & requestedSize);
3033
34 QHash<int, QImage> m_images;
35
31private:36private:
32 LODocument *m_document;37 QSharedPointer<LODocument> m_document;
33};38};
3439
35#endif // LOPARTSIMAGEPROVIDER_H40#endif // LOPARTSIMAGEPROVIDER_H
3641
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.cpp 2015-10-04 14:01:25 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.cpp 2015-10-11 19:35:30 +0000
@@ -19,32 +19,13 @@
19#include "lodocument.h"19#include "lodocument.h"
20#include "lopartsimageprovider.h"20#include "lopartsimageprovider.h"
2121
22#include <QQmlContext>
23#include <QQmlEngine>
24#include <QDebug>22#include <QDebug>
2523
26LOPartsModel::LOPartsModel(QAbstractListModel *parent):24LOPartsModel::LOPartsModel(const QSharedPointer<LODocument>& document, QAbstractListModel *parent):
27 QAbstractListModel(parent)25 QAbstractListModel(parent)
28{ 26{
29 connect(this, SIGNAL(documentChanged()), this, SLOT(fillModel()));
30}
31
32void LOPartsModel::setDocument(LODocument *document)
33{
34 if (m_document == document)
35 return;
36
37 m_document = document;27 m_document = document;
38 Q_EMIT documentChanged();28 fillModel();
39
40 QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
41 QString imageProviderName = "lok";
42
43 if (engine->imageProvider(imageProviderName))
44 engine->removeImageProvider(imageProviderName);
45
46 engine->addImageProvider(imageProviderName, new LOPartsImageProvider(m_document));
47
48}29}
4930
50QHash<int, QByteArray> LOPartsModel::roleNames() const31QHash<int, QByteArray> LOPartsModel::roleNames() const
@@ -52,6 +33,8 @@
52 QHash<int, QByteArray> roles;33 QHash<int, QByteArray> roles;
53 roles[IndexRole] = "index";34 roles[IndexRole] = "index";
54 roles[NameRole] = "name";35 roles[NameRole] = "name";
36 roles[IdRole] = "id";
37 roles[ThumbnailRole] = "thumbnail";
5538
56 return roles;39 return roles;
57}40}
@@ -74,6 +57,10 @@
74 return part.index;57 return part.index;
75 case NameRole:58 case NameRole:
76 return part.name;59 return part.name;
60 case IdRole:
61 return part.id;
62 case ThumbnailRole:
63 return part.thumbnail;
7764
78 default:65 default:
79 return 0;66 return 0;
@@ -92,34 +79,48 @@
92 QVariantMap map;79 QVariantMap map;
93 map["name"] = part.name;80 map["name"] = part.name;
94 map["index"] = part.index;81 map["index"] = part.index;
82 map["id"] = part.id;
83 map["thumbnail"] = part.thumbnail;
9584
96 return map;85 return map;
97}86}
9887
88void LOPartsModel::notifyAboutChanges(int id)
89{
90 for (int i = 0; i < m_entries.size(); i++)
91 if (m_entries[i].id == id) {
92 m_entries[i].thumbnail += "/cached";
93 Q_EMIT dataChanged(createIndex(i, 0), createIndex(i + 1, 0));
94 break;
95 }
96}
97
99void LOPartsModel::fillModel() {98void LOPartsModel::fillModel() {
100 if (m_document) {99 if (!m_document)
101 if (!m_entries.isEmpty()) {100 return;
102 beginRemoveRows(QModelIndex(), 0, rowCount());101
103 m_entries.clear();102 if (!m_entries.isEmpty()) {
104 endRemoveRows();103 beginRemoveRows(QModelIndex(), 0, rowCount());
105 }104 m_entries.clear();
106105 endRemoveRows();
107 int partsCount = m_document->partsCount();106 }
108107
109 for (int i = 0; i < partsCount; i++) {108 int partsCount = m_document->partsCount();
110 LOPartEntry part;109 beginInsertColumns(QModelIndex(), 0, qMax(partsCount - 1, 0));
111 part.index = i;110 for (int i = 0; i < partsCount; i++) {
112 part.name = m_document->getPartName(i);111 LOPartEntry part;
113112
114 beginInsertRows(QModelIndex(), rowCount(), rowCount());113 part.index = i;
115 m_entries.append(part);114 part.name = m_document->getPartName(i);
116 endInsertRows();115 part.id = RenderEngine::getNextId();
117 }116 part.thumbnail = QString("image://lok/part/%1/%2").arg(QString::number(part.index)).arg(QString::number(part.id));
118117
119 Q_EMIT countChanged();118 m_entries.append(part);
120 } 119 }
120 endInsertColumns();
121
122 Q_EMIT countChanged();
121}123}
122124
123LOPartsModel::~LOPartsModel()125LOPartsModel::~LOPartsModel()
124{126{ }
125}
126127
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h'
--- src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h 2015-09-15 18:20:00 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/lopartsmodel.h 2015-10-11 19:35:30 +0000
@@ -19,35 +19,45 @@
19#define LOPARTSMODEL_H19#define LOPARTSMODEL_H
2020
21#include <QAbstractListModel>21#include <QAbstractListModel>
22#include <QHash>
23#include <QSharedPointer>
24
25#include "renderengine.h"
2226
23class LODocument;27class LODocument;
2428
25class LOPartEntry29class LOPartEntry
26{30{
27public:31public:
32 LOPartEntry():
33 index(0)
34 {
35 id = RenderEngine::getNextId();
36 }
37
38 int id;
28 QString name;39 QString name;
29 int index = 0;40 int index;
41 QString thumbnail;
30};42};
3143
32class LOPartsModel : public QAbstractListModel44class LOPartsModel : public QAbstractListModel
33{45{
34 Q_OBJECT46 Q_OBJECT
35 Q_DISABLE_COPY(LOPartsModel)47 Q_DISABLE_COPY(LOPartsModel)
36 Q_PROPERTY(LODocument* document READ document WRITE setDocument NOTIFY documentChanged)
37 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)48 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
3849
39public:50public:
40 enum Roles {51 enum Roles {
41 NameRole,52 NameRole = Qt::UserRole + 1,
42 IndexRole53 IndexRole,
54 IdRole,
55 ThumbnailRole
43 };56 };
4457
45 explicit LOPartsModel(QAbstractListModel *parent = 0);58 explicit LOPartsModel(const QSharedPointer<LODocument>& document, QAbstractListModel *parent = 0);
46 ~LOPartsModel();59 ~LOPartsModel();
4760
48 LODocument* document() { return m_document; }
49 void setDocument(LODocument* document);
50
51 QHash<int, QByteArray> roleNames() const;61 QHash<int, QByteArray> roleNames() const;
5262
53 int rowCount(const QModelIndex & parent = QModelIndex()) const;63 int rowCount(const QModelIndex & parent = QModelIndex()) const;
@@ -55,15 +65,16 @@
5565
56 Q_INVOKABLE QVariantMap get(int index) const;66 Q_INVOKABLE QVariantMap get(int index) const;
5767
68 void notifyAboutChanges(int id);
69
58Q_SIGNALS:70Q_SIGNALS:
59 void documentChanged();
60 void countChanged();71 void countChanged();
6172
62private slots:73private slots:
63 void fillModel();74 void fillModel();
6475
65private:76private:
66 LODocument* m_document;77 QSharedPointer<LODocument> m_document;
67 QList<LOPartEntry> m_entries;78 QList<LOPartEntry> m_entries;
68};79};
6980
7081
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2015-09-22 19:02:46 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2015-10-11 19:35:30 +0000
@@ -20,7 +20,6 @@
20#include "twips.h"20#include "twips.h"
21#include "config.h"21#include "config.h"
2222
23#include <QPainter>
24#include <QImage>23#include <QImage>
25#include <QTimer>24#include <QTimer>
26#include <QtCore/qmath.h>25#include <QtCore/qmath.h>
@@ -36,6 +35,7 @@
36 : QQuickItem(parent)35 : QQuickItem(parent)
37 , m_parentFlickable(nullptr)36 , m_parentFlickable(nullptr)
38 , m_document(nullptr)37 , m_document(nullptr)
38 , m_partsModel(nullptr)
39 , m_zoomFactor(1.0)39 , m_zoomFactor(1.0)
40 , m_cacheBuffer(TILE_SIZE * 3)40 , m_cacheBuffer(TILE_SIZE * 3)
41 , m_visibleArea(0, 0, 0, 0)41 , m_visibleArea(0, 0, 0, 0)
@@ -48,7 +48,11 @@
48 connect(this, SIGNAL(parentFlickableChanged()), this, SLOT(updateVisibleRect()));48 connect(this, SIGNAL(parentFlickableChanged()), this, SLOT(updateVisibleRect()));
49 connect(this, SIGNAL(cacheBufferChanged()), this, SLOT(updateVisibleRect()));49 connect(this, SIGNAL(cacheBufferChanged()), this, SLOT(updateVisibleRect()));
50 connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateVisibleRect()));50 connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateVisibleRect()));
51 connect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)), this, SLOT(renderResultReceived(int,QImage)));51
52 connect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)),
53 this, SLOT(slotTileRenderFinished(int,QImage)));
54 connect(RenderEngine::instance(), SIGNAL(thumbnailRenderFinished(int,QImage)),
55 this, SLOT(slotThumbnailRenderFinished(int,QImage)));
52}56}
5357
54// Returns the parent QML Flickable58// Returns the parent QML Flickable
@@ -79,12 +83,25 @@
7983
80void LOView::initializeDocument(const QString &path)84void LOView::initializeDocument(const QString &path)
81{85{
82 if (m_document.data())86 if (m_document)
83 m_document.data()->disconnect(this);87 m_document->disconnect(this);
8488
85 m_document = QSharedPointer<LODocument>(new LODocument());89 m_document = QSharedPointer<LODocument>(new LODocument());
86 m_document->setPath(path);90 m_document->setPath(path);
8791
92 // TODO MOVE
93 m_partsModel = new LOPartsModel(m_document);
94 Q_EMIT partsModelChanged();
95
96 // --------------------------------------------------
97 QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
98 if (engine->imageProvider("lok"))
99 engine->removeImageProvider("lok");
100
101 m_imageProvider = new LOPartsImageProvider(m_document);
102 engine->addImageProvider("lok", m_imageProvider);
103 // --------------------------------------------------
104
88 connect(m_document.data(), SIGNAL(currentPartChanged()), this, SLOT(invalidateAllTiles()));105 connect(m_document.data(), SIGNAL(currentPartChanged()), this, SLOT(invalidateAllTiles()));
89106
90 Q_EMIT documentChanged();107 Q_EMIT documentChanged();
@@ -96,6 +113,11 @@
96 return m_document.data();113 return m_document.data();
97}114}
98115
116LOPartsModel *LOView::partsModel() const
117{
118 return m_partsModel;
119}
120
99qreal LOView::zoomFactor() const121qreal LOView::zoomFactor() const
100{122{
101 return m_zoomFactor;123 return m_zoomFactor;
@@ -173,7 +195,6 @@
173 return false;195 return false;
174}196}
175197
176// Update the size of LOView, according to the size of the loaded document.
177void LOView::updateViewSize()198void LOView::updateViewSize()
178{199{
179 if (!m_document)200 if (!m_document)
@@ -184,13 +205,9 @@
184 this->setWidth(Twips::convertTwipsToPixels(docSize.width(), m_zoomFactor));205 this->setWidth(Twips::convertTwipsToPixels(docSize.width(), m_zoomFactor));
185 this->setHeight(Twips::convertTwipsToPixels(docSize.height(), m_zoomFactor));206 this->setHeight(Twips::convertTwipsToPixels(docSize.height(), m_zoomFactor));
186207
187 // TODO: Consider to use connections to widthChanged and heightChanged208 updateVisibleRect();
188 this->updateVisibleRect();
189}209}
190210
191// Update the informations of the currently visible area of the parent
192// Flickable, then generate/delete all the required tiles, according to these
193// informations.
194void LOView::updateVisibleRect()211void LOView::updateVisibleRect()
195{212{
196 if (!m_parentFlickable)213 if (!m_parentFlickable)
@@ -228,10 +245,10 @@
228 m_parentFlickable->height());245 m_parentFlickable->height());
229246
230 // Update information about the buffer area247 // Update information about the buffer area
231 m_bufferArea.setRect(qMax(0, m_visibleArea.x() - this->cacheBuffer()),248 m_bufferArea.setRect(qMax(0, m_visibleArea.x() - m_cacheBuffer),
232 qMax(0, m_visibleArea.y() - this->cacheBuffer()),249 qMax(0, m_visibleArea.y() - m_cacheBuffer),
233 qMin(int(this->width() - m_bufferArea.x()), m_visibleArea.width() + (this->cacheBuffer() * 2)),250 qMin(int(this->width() - m_bufferArea.x()), m_visibleArea.width() + (m_cacheBuffer * 2)),
234 qMin(int(this->height() - m_bufferArea.y()), m_visibleArea.height() + (this->cacheBuffer() * 2)));251 qMin(int(this->height() - m_bufferArea.y()), m_visibleArea.height() + (m_cacheBuffer * 2)));
235252
236 // Delete tiles that are outside the loading area253 // Delete tiles that are outside the loading area
237 if (!m_tiles.isEmpty()) {254 if (!m_tiles.isEmpty()) {
@@ -300,7 +317,6 @@
300 }317 }
301}318}
302319
303// FIXME: Just for the moment. In zoom branch we have all we need :)
304void LOView::invalidateAllTiles()320void LOView::invalidateAllTiles()
305{321{
306 clearView();322 clearView();
@@ -314,9 +330,9 @@
314 qDebug() << "Creating tile indexed as" << index;330 qDebug() << "Creating tile indexed as" << index;
315#endif331#endif
316332
317 auto tile = new SGTileItem(rect, m_zoomFactor, this);333 auto tile = new SGTileItem(rect, m_zoomFactor, RenderEngine::getNextId(), this);
318 m_tiles.insert(index, tile);334 m_tiles.insert(index, tile);
319 RenderEngine::instance()->enqueueTask(m_document, rect, m_zoomFactor, tile->id());335 RenderEngine::instance()->enqueueTask(m_document, m_document->currentPart(), rect, m_zoomFactor, tile->id());
320 }336 }
321#ifdef DEBUG_VERBOSE337#ifdef DEBUG_VERBOSE
322 else {338 else {
@@ -331,7 +347,7 @@
331 m_updateTimer.start(20);347 m_updateTimer.start(20);
332}348}
333349
334void LOView::renderResultReceived(int id, QImage img)350void LOView::slotTileRenderFinished(int id, QImage img)
335{351{
336 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i) {352 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i) {
337 SGTileItem* sgtile = i.value();353 SGTileItem* sgtile = i.value();
@@ -342,6 +358,13 @@
342 }358 }
343}359}
344360
361void LOView::slotThumbnailRenderFinished(int id, QImage img)
362{
363 if (!m_imageProvider->m_images.contains(id))
364 m_imageProvider->m_images.insert(id, img);
365 m_partsModel->notifyAboutChanges(id);
366}
367
345void LOView::clearView()368void LOView::clearView()
346{369{
347 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)370 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)
@@ -352,7 +375,12 @@
352375
353LOView::~LOView()376LOView::~LOView()
354{377{
355 disconnect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)), this, SLOT(renderResultReceived(int,QImage)));378 delete m_partsModel;
379
380 disconnect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)),
381 this, SLOT(slotTileRenderFinished(int,QImage)));
382 disconnect(RenderEngine::instance(), SIGNAL(thumbnailRenderFinished(int,QImage)),
383 this, SLOT(slotThumbnailRenderFinished(int,QImage)));
356384
357 // Remove all tasks from rendering queue.385 // Remove all tasks from rendering queue.
358 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)386 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)
359387
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.h'
--- src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-09-22 19:02:46 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-10-11 19:35:30 +0000
@@ -17,12 +17,15 @@
17#ifndef LOVIEW_H17#ifndef LOVIEW_H
18#define LOVIEW_H18#define LOVIEW_H
1919
20#include <QQuickPaintedItem>
21#include <QQuickItem>20#include <QQuickItem>
22#include <QTimer>21#include <QTimer>
23#include <QSharedPointer>22#include <QSharedPointer>
23#include <QQmlContext>
24#include <QQmlEngine>
2425
25#include "renderengine.h"26#include "renderengine.h"
27#include "lopartsmodel.h"
28#include "lopartsimageprovider.h"
2629
27class LODocument;30class LODocument;
28class SGTileItem;31class SGTileItem;
@@ -31,11 +34,12 @@
31{34{
32 Q_OBJECT35 Q_OBJECT
33 Q_ENUMS(ZoomMode)36 Q_ENUMS(ZoomMode)
34 Q_PROPERTY(QQuickItem* parentFlickable READ parentFlickable WRITE setParentFlickable NOTIFY parentFlickableChanged)37 Q_PROPERTY(QQuickItem* parentFlickable READ parentFlickable WRITE setParentFlickable NOTIFY parentFlickableChanged)
35 Q_PROPERTY(LODocument* document READ document /*WRITE setDocument*/ NOTIFY documentChanged)38 Q_PROPERTY(LODocument* document READ document /*WRITE setDocument*/ NOTIFY documentChanged)
36 Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)39 Q_PROPERTY(LOPartsModel* partsModel READ partsModel NOTIFY partsModelChanged)
37 Q_PROPERTY(ZoomMode zoomMode READ zoomMode NOTIFY zoomModeChanged)40 Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
38 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)41 Q_PROPERTY(ZoomMode zoomMode READ zoomMode NOTIFY zoomModeChanged)
42 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
3943
40public:44public:
41 LOView(QQuickItem *parent = 0);45 LOView(QQuickItem *parent = 0);
@@ -52,6 +56,7 @@
52 Q_INVOKABLE void initializeDocument(const QString& path);56 Q_INVOKABLE void initializeDocument(const QString& path);
5357
54 LODocument* document() const;58 LODocument* document() const;
59 LOPartsModel* partsModel() const;
5560
56 qreal zoomFactor() const;61 qreal zoomFactor() const;
57 void setZoomFactor(const qreal zoom);62 void setZoomFactor(const qreal zoom);
@@ -66,6 +71,7 @@
66Q_SIGNALS:71Q_SIGNALS:
67 void parentFlickableChanged();72 void parentFlickableChanged();
68 void documentChanged();73 void documentChanged();
74 void partsModelChanged();
69 void zoomFactorChanged();75 void zoomFactorChanged();
70 void zoomModeChanged();76 void zoomModeChanged();
71 void cacheBufferChanged();77 void cacheBufferChanged();
@@ -75,12 +81,16 @@
75 void updateVisibleRect();81 void updateVisibleRect();
76 void scheduleVisibleRectUpdate();82 void scheduleVisibleRectUpdate();
77 void invalidateAllTiles();83 void invalidateAllTiles();
78 void renderResultReceived(int id, QImage img);84
85 void slotTileRenderFinished(int id, QImage img);
86 void slotThumbnailRenderFinished(int id, QImage img);
7987
80private:88private:
8189
82 QQuickItem* m_parentFlickable;90 QQuickItem* m_parentFlickable;
83 QSharedPointer<LODocument> m_document;91 QSharedPointer<LODocument> m_document;
92 LOPartsModel* m_partsModel; // TODO MB move to document.
93 LOPartsImageProvider* m_imageProvider; // The QQmlEngine takes ownership of provider.
8494
85 qreal m_zoomFactor;95 qreal m_zoomFactor;
86 ZoomMode m_zoomMode;96 ZoomMode m_zoomMode;
8797
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp 2015-09-15 18:20:00 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp 2015-10-11 19:35:30 +0000
@@ -30,7 +30,7 @@
30 //@uri DocumentViewer.LibreOffice30 //@uri DocumentViewer.LibreOffice
31 qmlRegisterType<LODocument>(uri, 1, 0, "Document");31 qmlRegisterType<LODocument>(uri, 1, 0, "Document");
32 qmlRegisterType<LOView>(uri, 1, 0, "View");32 qmlRegisterType<LOView>(uri, 1, 0, "View");
33 qmlRegisterType<LOPartsModel>(uri, 1, 0, "PartsModel");33 qmlRegisterUncreatableType<LOPartsModel>(uri, 1, 0, "PartsModel", "You shouldn't create LOPartsModel in QML");
34}34}
3535
36void LOPlugin::initializeEngine(QQmlEngine *engine, const char *uri)36void LOPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
3737
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml'
--- src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml 2015-09-26 13:46:07 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml 2015-10-11 19:35:30 +0000
@@ -23,8 +23,9 @@
23 property alias document: view.document23 property alias document: view.document
24 property alias zoomFactor: view.zoomFactor24 property alias zoomFactor: view.zoomFactor
25 property alias cacheBuffer: view.cacheBuffer25 property alias cacheBuffer: view.cacheBuffer
2626 property alias partsModel: view.partsModel
27 property alias zoomMode: view.zoomMode27 property alias zoomMode: view.zoomMode
28
28 property string documentPath: ""29 property string documentPath: ""
2930
30 function adjustZoomToWidth()31 function adjustZoomToWidth()
3132
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp 2015-09-23 16:51:17 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/renderengine.cpp 2015-10-11 19:35:30 +0000
@@ -7,7 +7,8 @@
7RenderEngine::RenderEngine():7RenderEngine::RenderEngine():
8 QObject(nullptr),8 QObject(nullptr),
9 m_activeTaskCount(0),9 m_activeTaskCount(0),
10 m_enabled(true)10 m_enabled(true),
11 m_lastPart(-1)
11{12{
12 int itc = QThread::idealThreadCount();13 int itc = QThread::idealThreadCount();
13 m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc;14 m_idealThreadCount = itc == -1 ? DefaultIdealThreadCount : itc;
@@ -15,11 +16,20 @@
15 connect(this, SIGNAL(enabledChanged()), this, SLOT(doNextTask()));16 connect(this, SIGNAL(enabledChanged()), this, SLOT(doNextTask()));
16}17}
1718
18void RenderEngine::enqueueTask(const QSharedPointer<LODocument>& doc, const QRect& area, const qreal &zoom, int id)19void RenderEngine::enqueueTask(const QSharedPointer<LODocument>& doc, int part, const QRect& area, const qreal &zoom, int id)
19{20{
20 Q_ASSERT(doc != nullptr);21 Q_ASSERT(doc != nullptr);
2122
22 m_queue.enqueue(EngineTask(doc, area, zoom, id));23 m_queue.enqueue(EngineTask(doc, part, area, zoom, id));
24
25 doNextTask();
26}
27
28void RenderEngine::enqueueTask(const QSharedPointer<LODocument> &doc, int part, qreal size, int id)
29{
30 Q_ASSERT(doc != nullptr);
31
32 m_queue.enqueue(EngineTask(doc, part, size, id));
2333
24 doNextTask();34 doNextTask();
25}35}
@@ -33,10 +43,12 @@
33 }43 }
34}44}
3545
36void RenderEngine::internalRenderCallback(int id, QImage img)46void RenderEngine::internalRenderCallback(int id, QImage img, bool isThumbnail)
37{47{
38 m_activeTaskCount--;48 m_activeTaskCount--;
39 Q_EMIT renderFinished(id, img);49 if (isThumbnail)
50 Q_EMIT thumbnailRenderFinished(id, img);
51 else Q_EMIT renderFinished(id, img);
40 doNextTask();52 doNextTask();
41}53}
4254
@@ -46,14 +58,30 @@
46 qDebug() << " ---- doNextTask" << m_activeTaskCount << m_queue.count();58 qDebug() << " ---- doNextTask" << m_activeTaskCount << m_queue.count();
47#endif59#endif
4860
61 // Check for too much threads or empty queue.
49 if (m_activeTaskCount >= m_idealThreadCount || !m_queue.count() || !m_enabled)62 if (m_activeTaskCount >= m_idealThreadCount || !m_queue.count() || !m_enabled)
50 return;63 return;
5164
65 // We should avoid different part rendering in the same time.
66 if (m_activeTaskCount && m_queue.head().part != m_lastPart)
67 return;
68
52 m_activeTaskCount++;69 m_activeTaskCount++;
53 auto task = m_queue.dequeue();70 EngineTask task = m_queue.dequeue();
71
72 // Set correct part.
73 m_lastPart = task.part;
74 task.document->setDocumentPart(m_lastPart);
5475
55 QtConcurrent::run( [=] {76 QtConcurrent::run( [=] {
56 QImage img = task.document->paintTile(task.area.size(), task.area, task.zoom);77 if (task.isThumbnail) {
57 QMetaObject::invokeMethod(this, "internalRenderCallback", Q_ARG(int, task.id), Q_ARG(QImage, img));78 QImage img = task.document->paintThumbnail(task.size);
79 QMetaObject::invokeMethod(this, "internalRenderCallback",
80 Q_ARG(int, task.id), Q_ARG(QImage, img), Q_ARG(bool, task.isThumbnail));
81 } else {
82 QImage img = task.document->paintTile(task.area.size(), task.area, task.zoom);
83 QMetaObject::invokeMethod(this, "internalRenderCallback",
84 Q_ARG(int, task.id), Q_ARG(QImage, img), Q_ARG(bool, task.isThumbnail));
85 }
58 });86 });
59}87}
6088
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/renderengine.h'
--- src/plugin/libreofficetoolkit-qml-plugin/renderengine.h 2015-09-23 16:48:39 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/renderengine.h 2015-10-11 19:35:30 +0000
@@ -10,19 +10,42 @@
1010
11#include "lodocument.h"11#include "lodocument.h"
1212
13// TODO replace with class.
14
15
16// TODO Need more OOP here.
13struct EngineTask17struct EngineTask
14{18{
15 int id;19 int id;
20 int part;
21 QSharedPointer<LODocument> document;
22 // Used in thumbnail rendering.
23 qreal size;
24 // Used in tile rendering.
16 QRect area;25 QRect area;
17 qreal zoom;26 qreal zoom;
18 QSharedPointer<LODocument> document;27 // Internal.
1928 bool isThumbnail;
20public:29public:
21 EngineTask(const QSharedPointer<LODocument>& d, const QRect& a, const qreal& z, int i):30
22 id(i),31 EngineTask(const QSharedPointer<LODocument>& d, int p, const QRect& a, const qreal& z, int i):
23 area(a),32 id(i),
24 zoom(z),33 part(p),
25 document(d)34 document(d),
35 size(0),
36 area(a),
37 zoom(z),
38 isThumbnail(false)
39 { }
40
41 EngineTask(const QSharedPointer<LODocument>& d, int p, qreal s, int i):
42 id(i),
43 part(p),
44 document(d),
45 size(s),
46 area(),
47 zoom(0),
48 isThumbnail(true)
26 { }49 { }
27};50};
2851
@@ -37,7 +60,8 @@
37 const int DefaultIdealThreadCount = 2;60 const int DefaultIdealThreadCount = 2;
3861
39public:62public:
40 void enqueueTask(const QSharedPointer<LODocument>& doc, const QRect& area, const qreal& zoom, int id);63 void enqueueTask(const QSharedPointer<LODocument>& doc, int part, const QRect& area, const qreal& zoom, int id);
64 void enqueueTask(const QSharedPointer<LODocument>& doc, int part, qreal size, int id);
41 void dequeueTask(int id);65 void dequeueTask(int id);
4266
43 static RenderEngine* instance() {67 static RenderEngine* instance() {
@@ -46,23 +70,18 @@
46 return s_instance;70 return s_instance;
47 }71 }
4872
49 int activeTaskCount() { return m_activeTaskCount; }73 static int getNextId() {
5074 static int idCounter = 0xDEAD0000;
51 bool enabled() { return m_enabled.loadAcquire(); }75 return idCounter++;
52 void setEnabled(bool enabled) {
53 if (m_enabled.loadAcquire() == enabled)
54 return;
55
56 m_enabled.storeRelease(enabled);
57 Q_EMIT enabledChanged();
58 }76 }
5977
60Q_SIGNALS:78Q_SIGNALS:
61 void renderFinished(int id, QImage img);79 void renderFinished(int id, QImage img);
80 void thumbnailRenderFinished(int id, QImage img);
62 void enabledChanged();81 void enabledChanged();
6382
64private:83private:
65 Q_INVOKABLE void internalRenderCallback(int id, QImage img);84 Q_INVOKABLE void internalRenderCallback(int id, QImage img, bool isThumbnail);
6685
67private slots:86private slots:
68 void doNextTask();87 void doNextTask();
@@ -71,6 +90,7 @@
71 QQueue<EngineTask> m_queue;90 QQueue<EngineTask> m_queue;
72 int m_activeTaskCount;91 int m_activeTaskCount;
73 int m_idealThreadCount;92 int m_idealThreadCount;
93 int m_lastPart;
7494
75 QAtomicInt m_enabled;95 QAtomicInt m_enabled;
76};96};
7797
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp'
--- src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp 2015-09-22 00:01:22 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp 2015-10-11 19:35:30 +0000
@@ -1,20 +1,20 @@
1#include "sgtileitem.h"1#include "sgtileitem.h"
2
3#include "lodocument.h"2#include "lodocument.h"
4#include "config.h"3#include "config.h"
54
5#include <QQuickWindow>
6#include <QSGSimpleTextureNode>
7
6#ifdef DEBUG_SHOW_TILE_BORDER8#ifdef DEBUG_SHOW_TILE_BORDER
7#include <QSGGeometryNode>9#include <QSGGeometryNode>
8#include <QSGFlatColorMaterial>10#include <QSGFlatColorMaterial>
9#endif11#endif
1012
11int SGTileItem::s_idCounter = 0xDEAD0000;13SGTileItem::SGTileItem(const QRect& area, qreal zoom, int id, QQuickItem *parent)
12
13SGTileItem::SGTileItem(const QRect& area, const qreal &zoom, QQuickItem *parent)
14 : QQuickItem(parent)14 : QQuickItem(parent)
15 , m_area(area)15 , m_area(area)
16 , m_zoomFactor(zoom)16 , m_zoomFactor(zoom)
17 , m_id (s_idCounter++)17 , m_id (id)
18{18{
19 setFlag(ItemHasContents, true);19 setFlag(ItemHasContents, true);
20}20}
2121
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h'
--- src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h 2015-09-22 00:01:22 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h 2015-10-11 19:35:30 +0000
@@ -2,11 +2,7 @@
2#define SGTILEITEM_H2#define SGTILEITEM_H
33
4#include <QQuickItem>4#include <QQuickItem>
5#include <QQuickWindow>
6#include <QSGSimpleTextureNode>
7#include <QImage>5#include <QImage>
8#include <QtConcurrent/QtConcurrent>
9#include <QAtomicInteger>
106
11class LODocument;7class LODocument;
128
@@ -14,7 +10,7 @@
14{10{
15 Q_OBJECT11 Q_OBJECT
16public:12public:
17 SGTileItem(const QRect& area, const qreal &zoom = 1.0, QQuickItem *parent = 0);13 SGTileItem(const QRect& area, qreal zoom, int id, QQuickItem *parent = 0);
18 ~SGTileItem();14 ~SGTileItem();
1915
20 inline const QRect& area() { return m_area; }16 inline const QRect& area() { return m_area; }
@@ -43,8 +39,6 @@
43 qreal m_zoomFactor;39 qreal m_zoomFactor;
44 QImage m_data;40 QImage m_data;
45 int m_id;41 int m_id;
46
47 static int s_idCounter;
48};42};
4943
50#endif // SGTILEITEM_H44#endif // SGTILEITEM_H

Subscribers

People subscribed via source and target branches