Merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/lok-zoom-object into lp:ubuntu-docviewer-app

Proposed by Stefano Verzegnassi
Status: Merged
Approved by: Stefano Verzegnassi
Approved revision: 261
Merged at revision: 278
Proposed branch: lp:~verzegnassi-stefano/ubuntu-docviewer-app/lok-zoom-object
Merge into: lp:ubuntu-docviewer-app
Diff against target: 1164 lines (+464/-319)
11 files modified
src/app/qml/loView/LOViewPage.qml (+1/-1)
src/app/qml/loView/ZoomSelector.qml (+13/-13)
src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt (+1/-0)
src/plugin/libreofficetoolkit-qml-plugin/loview.cpp (+72/-243)
src/plugin/libreofficetoolkit-qml-plugin/loview.h (+16/-36)
src/plugin/libreofficetoolkit-qml-plugin/lozoom.cpp (+240/-0)
src/plugin/libreofficetoolkit-qml-plugin/lozoom.h (+103/-0)
src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp (+2/-0)
src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml (+14/-19)
src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp (+1/-2)
src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h (+1/-5)
To merge this branch: bzr merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/lok-zoom-object
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Roman Shchekin Approve
Review via email: mp+283691@code.launchpad.net

Commit message

LibreOffice QML plugin:
* Provide zoom settings as grouped properties
* Added a minimum and a maximum value for the zoom factor
* Removed any reference to zoomFactor from SGTileItem
* Expose to QML the values for 'fitToWidth', 'fitToHeight' and 'Automatic' zoom

Description of the change

LibreOffice QML plugin:
*** Provide zoom settings as grouped properties
Well, with this branch the LibreOffice view has 8 properties about zoom settings.
I thought it's the case to gather those properties in a separate object, so that we're more comfortable when we have to deal with LOView.

*** Added a minimum and a maximum value for the zoom factor - 0.25 (min) and 4.0 (max).
On phones the default zoom factor was lower than the previous minimum value (0.5).
Values outside the interval [0.25, 4.0] are not longer accepted by the view.
We expose these values to QML so that we can set the ScalingPinchArea accordingly.
At the moment, they're only read-only. We could make them writable in future.

*** Removed any reference to zoomFactor from SGTileItem
I know Roman you wanted this. :)

*** Expose to QML the values for 'fitToWidth', 'fitToHeight' and 'Automatic' zoom
We may need them for setting the ScalingPinchArea when DocViewer is running on a phone.

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 :

LGTM, works well, no reasons to disapprove :)

review: Approve
261. By Stefano Verzegnassi

Reduce the size of that comment.

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
1=== modified file 'src/app/qml/loView/LOViewPage.qml'
2--- src/app/qml/loView/LOViewPage.qml 2015-12-27 07:30:41 +0000
3+++ src/app/qml/loView/LOViewPage.qml 2016-01-26 11:46:55 +0000
4@@ -107,7 +107,7 @@
5 documentPath: file.path
6
7 function updateContentSize(tgtScale) {
8- zoomFactor = tgtScale
9+ zoomSettings.zoomFactor = tgtScale
10 }
11
12 // Keyboard events
13
14=== modified file 'src/app/qml/loView/ZoomSelector.qml'
15--- src/app/qml/loView/ZoomSelector.qml 2015-12-27 17:41:17 +0000
16+++ src/app/qml/loView/ZoomSelector.qml 2016-01-26 11:46:55 +0000
17@@ -39,14 +39,14 @@
18
19 onHighlightedChanged: {
20 if (highlighted) {
21- text = parseInt(textField.view.zoomFactor * 100)
22+ text = parseInt(textField.view.zoomSettings.zoomFactor * 100)
23 } else text = ""
24 }
25
26 Label {
27 anchors.centerIn: parent
28 visible: !textField.highlighted
29- text: "%1%".arg(parseInt(textField.view.zoomFactor*100))
30+ text: "%1%".arg(parseInt(textField.view.zoomSettings.zoomFactor*100))
31 }
32
33 popover: TextFieldButtonPopover {
34@@ -66,7 +66,7 @@
35 Layout.fillHeight: true
36 Layout.fillWidth: true
37
38- onClicked: textField.view.setZoom(textField.view.zoomFactor + 0.1)
39+ onClicked: textField.view.setZoom(textField.view.zoomSettings.zoomFactor + 0.1)
40
41 Icon {
42 width: units.gu(2); height: width
43@@ -85,7 +85,7 @@
44 Layout.fillHeight: true
45 Layout.fillWidth: true
46
47- onClicked: textField.view.setZoom(textField.view.zoomFactor - 0.1)
48+ onClicked: textField.view.setZoom(textField.view.zoomSettings.zoomFactor - 0.1)
49
50 Icon {
51 width: units.gu(2); height: width
52@@ -105,30 +105,30 @@
53 id: zoomModesRepeater
54
55 function delegate_onClicked(mode) {
56- if (mode === LibreOffice.View.FitToWidth)
57+ if (mode === LibreOffice.Zoom.FitToWidth)
58 textField.view.adjustZoomToWidth()
59
60- if (mode === LibreOffice.View.FitToHeight)
61+ if (mode === LibreOffice.Zoom.FitToHeight)
62 textField.view.adjustZoomToHeight()
63
64- if (mode === LibreOffice.View.Automatic)
65+ if (mode === LibreOffice.Zoom.Automatic)
66 textField.view.adjustAutomaticZoom()
67 }
68
69 // Used for hiding the HorizontalDivider below.
70- visible: view.zoomModesAvailable > LibreOffice.View.Manual
71+ visible: view.zoomSettings.zoomModesAvailable > LibreOffice.Zoom.Manual
72
73 model: [
74- { text: i18n.tr("Fit width"), mode: LibreOffice.View.FitToWidth },
75- { text: i18n.tr("Fit height"), mode: LibreOffice.View.FitToHeight },
76- { text: i18n.tr("Automatic"), mode: LibreOffice.View.Automatic }
77+ { text: i18n.tr("Fit width"), mode: LibreOffice.Zoom.FitToWidth },
78+ { text: i18n.tr("Fit height"), mode: LibreOffice.Zoom.FitToHeight },
79+ { text: i18n.tr("Automatic"), mode: LibreOffice.Zoom.Automatic }
80 ]
81
82 ListItem {
83 height: units.gu(4)
84 divider.visible: false
85
86- visible: view.zoomModesAvailable & modelData.mode
87+ visible: view.zoomSettings.zoomModesAvailable & modelData.mode
88
89 onClicked: {
90 zoomSelectorDialogue.close()
91@@ -148,7 +148,7 @@
92 width: units.gu(2); height: width
93 name: "tick"
94 color: UbuntuColors.green
95- visible: textField.view.zoomMode == modelData.mode
96+ visible: textField.view.zoomSettings.zoomMode == modelData.mode
97 }
98 }
99 } // ListItem
100
101=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt'
102--- src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt 2016-01-18 00:02:05 +0000
103+++ src/plugin/libreofficetoolkit-qml-plugin/CMakeLists.txt 2016-01-26 11:46:55 +0000
104@@ -26,6 +26,7 @@
105 lopartsmodel.cpp
106 lorendertask.cpp
107 ucunits.cpp
108+ lozoom.cpp
109 ${QML_SRCS}
110 )
111
112
113=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.cpp'
114--- src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2016-01-17 22:57:05 +0000
115+++ src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2016-01-26 11:46:55 +0000
116@@ -16,6 +16,7 @@
117
118 #include "loview.h"
119 #include "lodocument.h"
120+#include "lozoom.h"
121 #include "sgtileitem.h"
122 #include "twips.h"
123 #include "config.h"
124@@ -24,42 +25,33 @@
125 #include <QTimer>
126 #include <QtCore/qmath.h>
127
128-static qreal zoomValueToFitWidth;
129-static qreal zoomValueToFitHeight;
130-
131-static qreal getZoomToFitWidth(const qreal &width, int documentWidth)
132-{
133- return qreal(width / Twips::convertTwipsToPixels(documentWidth, 1.0));
134-}
135-
136-static qreal getZoomToFitHeight(const qreal &height, int documentHeight)
137-{
138- return qreal(height / Twips::convertTwipsToPixels(documentHeight, 1.0));
139-}
140-
141 LOView::LOView(QQuickItem *parent)
142 : QQuickItem(parent)
143 , m_parentFlickable(nullptr)
144 , m_document(nullptr)
145+ , m_zoomSettings(new LOZoom(this))
146 , m_partsModel(nullptr)
147 , m_currentPart(0)
148- , m_zoomFactor(1.0)
149- , m_zoomModesAvailable(ZoomMode::Manual)
150 , m_cacheBuffer(TILE_SIZE * 3)
151 , m_visibleArea(0, 0, 0, 0)
152 , m_bufferArea(0, 0, 0, 0)
153 , m_error(LibreOfficeError::NoError)
154+ , m_zoomValueHasChanged(false)
155 {
156 Q_UNUSED(parent)
157
158- connect(this, SIGNAL(documentChanged()), this, SLOT(updateViewSize()));
159- connect(this, SIGNAL(zoomFactorChanged()), this, SLOT(updateViewSize()));
160- connect(this, SIGNAL(parentFlickableChanged()), this, SLOT(updateVisibleRect()));
161- connect(this, SIGNAL(cacheBufferChanged()), this, SLOT(updateVisibleRect()));
162- connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateVisibleRect()));
163+ connect(this, &LOView::documentChanged, this, &LOView::updateViewSize);
164+ connect(this, &LOView::parentFlickableChanged, this, &LOView::updateVisibleRect);
165+ connect(this, &LOView::cacheBufferChanged, this, &LOView::updateVisibleRect);
166+ connect(&m_updateTimer, &QTimer::timeout, this, &LOView::updateVisibleRect);
167
168 connect(RenderEngine::instance(), &RenderEngine::taskRenderFinished,
169 this, &LOView::slotTaskRenderFinished);
170+
171+ connect(m_zoomSettings, &LOZoom::zoomFactorChanged, [&]() {
172+ m_zoomValueHasChanged = true;
173+ updateViewSize();
174+ });
175 }
176
177 // Returns the parent QML Flickable
178@@ -127,21 +119,32 @@
179
180 Q_EMIT documentChanged();
181
182- // Set the proper zoom mode, according to the type of the loaded document.
183- setZoomModesAvailability();
184-
185- switch (m_document.data()->documentType()) {
186- case LODocument::DocumentType::SpreadsheetDocument:
187- setZoomMode(ZoomMode::Manual);
188- setZoomFactor(1.0);
189- break;
190- case LODocument::DocumentType::PresentationDocument:
191- setZoomMode(ZoomMode::Automatic);
192- break;
193- default:
194- setZoomMode(ZoomMode::FitToWidth);
195- break;
196- }
197+ // Init zoom settings
198+ m_zoomSettings->init();
199+}
200+
201+bool LOView::adjustZoomToWidth()
202+{
203+ if (!m_zoomSettings)
204+ return false;
205+
206+ return m_zoomSettings->adjustZoomToWidth();
207+}
208+
209+bool LOView::adjustZoomToHeight()
210+{
211+ if (!m_zoomSettings)
212+ return false;
213+
214+ return m_zoomSettings->adjustZoomToHeight();
215+}
216+
217+bool LOView::adjustAutomaticZoom()
218+{
219+ if (!m_zoomSettings)
220+ return false;
221+
222+ return m_zoomSettings->adjustAutomaticZoom();
223 }
224
225 // Return the LODocument rendered by this class
226@@ -155,6 +158,11 @@
227 return m_partsModel;
228 }
229
230+LOZoom *LOView::zoomSettings() const
231+{
232+ return m_zoomSettings;
233+}
234+
235 int LOView::currentPart() {
236 return m_currentPart;
237 }
238@@ -171,43 +179,6 @@
239 Q_EMIT currentPartChanged();
240 }
241
242-qreal LOView::zoomFactor() const
243-{
244- return m_zoomFactor;
245-}
246-
247-void LOView::setZoomFactor(const qreal zoom)
248-{
249- if (m_zoomFactor == zoom)
250- return;
251-
252- m_zoomFactor = zoom;
253-
254- if (m_zoomFactor != zoomValueToFitWidth && m_zoomFactor != zoomValueToFitHeight)
255- setZoomMode(LOView::Manual);
256-
257- Q_EMIT zoomFactorChanged();
258-}
259-
260-LOView::ZoomMode LOView::zoomMode() const
261-{
262- return m_zoomMode;
263-}
264-
265-LOView::ZoomModes LOView::zoomModesAvailable() const
266-{
267- return m_zoomModesAvailable;
268-}
269-
270-void LOView::setZoomMode(const ZoomMode zoomMode)
271-{
272- if (m_zoomMode == zoomMode)
273- return;
274-
275- m_zoomMode = zoomMode;
276- Q_EMIT zoomModeChanged();
277-}
278-
279 int LOView::cacheBuffer() const
280 {
281 return m_cacheBuffer;
282@@ -227,81 +198,16 @@
283 return m_error;
284 }
285
286-bool LOView::adjustZoomToWidth(bool changeMode)
287-{
288- if (!m_document)
289- return false;
290-
291- if (changeMode)
292- setZoomMode(LOView::FitToWidth);
293-
294- zoomValueToFitWidth = getZoomToFitWidth(m_parentFlickable->width(),
295- m_document->documentSize().width());
296-
297- if (m_zoomFactor != zoomValueToFitWidth) {
298- setZoomFactor(zoomValueToFitWidth);
299-
300- qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
301- return true;
302- }
303-
304- return false;
305-}
306-
307-bool LOView::adjustZoomToHeight(bool changeMode)
308-{
309- if (!m_document)
310- return false;
311-
312- if (changeMode)
313- setZoomMode(LOView::FitToHeight);
314-
315- zoomValueToFitHeight = getZoomToFitHeight(m_parentFlickable->height(),
316- m_document->documentSize().height());
317-
318- if (m_zoomFactor != zoomValueToFitHeight) {
319- setZoomFactor(zoomValueToFitHeight);
320-
321- qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
322- return true;
323- }
324-
325- return false;
326-}
327-
328-bool LOView::adjustAutomaticZoom(bool changeMode)
329-{
330- if (!m_document)
331- return false;
332-
333- if (changeMode)
334- setZoomMode(LOView::Automatic);
335-
336- zoomValueToFitWidth = getZoomToFitWidth(m_parentFlickable->width(),
337- m_document->documentSize().width());
338-
339- zoomValueToFitHeight = getZoomToFitHeight(m_parentFlickable->height(),
340- m_document->documentSize().height());
341-
342- if (m_zoomFactor != qMin(zoomValueToFitHeight, zoomValueToFitWidth)) {
343- setZoomFactor(qMin(zoomValueToFitHeight, zoomValueToFitWidth));
344-
345- qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
346- return true;
347- }
348-
349- return false;
350-}
351-
352 void LOView::updateViewSize()
353 {
354 if (!m_document)
355 return;
356
357 QSize docSize = m_document->documentSize();
358+ qreal zoomFactor = m_zoomSettings->zoomFactor();
359
360- this->setWidth(Twips::convertTwipsToPixels(docSize.width(), m_zoomFactor));
361- this->setHeight(Twips::convertTwipsToPixels(docSize.height(), m_zoomFactor));
362+ this->setWidth(Twips::convertTwipsToPixels(docSize.width(), zoomFactor));
363+ this->setHeight(Twips::convertTwipsToPixels(docSize.height(), zoomFactor));
364
365 updateVisibleRect();
366 }
367@@ -311,82 +217,33 @@
368 if (!m_parentFlickable || !m_document)
369 return;
370
371- /*
372- * Following code requires a bit of explanation:
373- *
374- * updateVisibleRect() is called when several events occures:
375- * - cacheBuffer value changes;
376- * - parentFlickable changes;
377- * - parentFlickable size changes;
378- * - parentFlickable is scrolled;
379- * - A new document is loaded (through LOView::updateViewSize())
380- * - The zoom value changes (through LOView::updateViewSize())
381- *
382- * We are interested to the last case.
383- * We have two different zoom behaviour: manual or automatic.
384- *
385- * When manual zoom is active, and a new zoom value is set, there is no
386- * other change/signal emission involved.
387- * The schema is:
388- * zoomFactorChanged -> updateViewSize() -> updateVisibleRect()
389- *
390- * When automatic zoom is active, things are a bit different.
391- * updateVisibleRect() could be triggered for two reasons:
392- * - User explicitely set the new zoom behaviour (e.g. through
393- * LOView::adjustZoomToWidth())
394- * - The parent flickable has been resized.
395- *
396- * For the former case, the schema is:
397- * adjustZoomToWidth() -> zoomFactorChanged -> updateViewSize() ->
398- * -> updateVisibleRect()
399- *
400- * For the latter, the code below is involved.
401- * At first we have:
402- * parentFlickableSizeChanged -> updateVisibleRect()
403- *
404- * When this function is called, we need to check if the zoom value is still
405- * valid. If not, we need to adjust the zoom (e.g. calling
406- * LOView::adjustZoomToWidth(false)).
407- *
408- * If the zoom value changes (i.e. required an adjustment), we have a
409- * zoomFactorChanged signal emission, which would call this function twice
410- * (see manual zoom, explained above).
411- * We want to avoid updateVisibleRect() to be called for nothing, so we stop
412- * the first execution of the function when this happens, and wait for the
413- * second one (via updateViewSize()).
414- *
415- * A full schema is:
416- * parentFlickableSizeChanged -> updateVisibleRect() ->
417- * -> adjustZoomToWidth(false) -> STOP THIS EXECUTION, returns
418- * L-> zoomFactorChanged() -> updateViewSize() -> updateVisibleRect()
419- */
420-
421- if (m_zoomMode == LOView::FitToWidth) {
422- if (adjustZoomToWidth(false))
423- return;
424- }
425-
426- else if (m_zoomMode == LOView::FitToHeight) {
427- if (adjustZoomToHeight(false))
428- return;
429- }
430-
431- else if (m_zoomMode == LOView::Automatic) {
432- if (adjustAutomaticZoom(false))
433+ // When we adjust the zoom value of an automatic zoom
434+ // mode, the view has to update the document size first.
435+ // updateVisibleRect() will be automatically triggered
436+ // later.
437+ if (m_zoomSettings->zoomMode() == LOZoom::FitToWidth) {
438+ if (m_zoomSettings->adjustZoomToWidth(false))
439+ return;
440+ }
441+
442+ else if (m_zoomSettings->zoomMode() == LOZoom::FitToHeight) {
443+ if (m_zoomSettings->adjustZoomToHeight(false))
444+ return;
445+ }
446+
447+ else if (m_zoomSettings->zoomMode() == LOZoom::Automatic) {
448+ if (m_zoomSettings->adjustAutomaticZoom(false))
449 return;
450 }
451
452 // Check if current tiles have a different zoom value
453- if (!m_tiles.isEmpty()) {
454- SGTileItem* tile = m_tiles.first();
455-
456- if (tile->zoomFactor() != m_zoomFactor) {
457- clearView();
458-
459+ if (m_zoomValueHasChanged && !m_tiles.isEmpty()) {
460+ m_zoomValueHasChanged = false;
461 #ifdef DEBUG_VERBOSE
462- qDebug() << "Zoom value of tiles is different than the current zoom value. Erasing cache...";
463+ qDebug() << "Zoom value of tiles is different than the current zoom value. Erasing cache...";
464 #endif
465- }
466+
467+ clearView();
468 }
469
470 // Just for convenience.
471@@ -502,7 +359,7 @@
472 qDebug() << "Creating tile indexed as" << index << "- Rect:" << rect;
473 #endif
474
475- auto tile = new SGTileItem(rect, m_zoomFactor, RenderEngine::getNextId(), this);
476+ auto tile = new SGTileItem(rect, RenderEngine::getNextId(), this);
477 m_tiles.insert(index, tile);
478 RenderEngine::instance()->enqueueTask(createTask(rect, tile->id()));
479 }
480@@ -522,8 +379,6 @@
481 m_updateTimer.start(20);
482 }
483
484-
485-
486 void LOView::clearView()
487 {
488 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)
489@@ -544,7 +399,7 @@
490 task->setPart(m_currentPart);
491 task->setDocument(m_document);
492 task->setArea(rect);
493- task->setZoom(m_zoomFactor);
494+ task->setZoom(m_zoomSettings->zoomFactor());
495 return task;
496 }
497
498@@ -577,41 +432,15 @@
499 Q_EMIT errorChanged();
500 }
501
502-void LOView::setZoomModesAvailability()
503-{
504- if (!m_document)
505- return;
506-
507- ZoomModes newZoomModesAvailable;
508- newZoomModesAvailable |= ZoomMode::Manual;
509-
510- switch (m_document.data()->documentType()) {
511- case LODocument::DocumentType::TextDocument:
512- newZoomModesAvailable |= ZoomMode::FitToWidth;
513- break;
514- case LODocument::DocumentType::SpreadsheetDocument:
515- break;
516- default:
517- newZoomModesAvailable |= ZoomMode::FitToWidth;
518- newZoomModesAvailable |= ZoomMode::FitToHeight;
519- newZoomModesAvailable |= ZoomMode::Automatic;
520- break;
521- }
522-
523- if (m_zoomModesAvailable != newZoomModesAvailable) {
524- m_zoomModesAvailable = newZoomModesAvailable;
525- Q_EMIT zoomModesAvailableChanged();
526- }
527-}
528-
529 LOView::~LOView()
530 {
531- delete m_partsModel;
532-
533 disconnect(RenderEngine::instance(), &RenderEngine::taskRenderFinished,
534 this, &LOView::slotTaskRenderFinished);
535
536 // Remove all tasks from rendering queue.
537 for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)
538 RenderEngine::instance()->dequeueTask(i.value()->id());
539+
540+ delete m_partsModel;
541+ delete m_zoomSettings;
542 }
543
544=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.h'
545--- src/plugin/libreofficetoolkit-qml-plugin/loview.h 2016-01-17 22:57:05 +0000
546+++ src/plugin/libreofficetoolkit-qml-plugin/loview.h 2016-01-26 11:46:55 +0000
547@@ -31,71 +31,53 @@
548
549 class LODocument;
550 class SGTileItem;
551+class LOZoom;
552
553 class LOView : public QQuickItem
554 {
555 Q_OBJECT
556- Q_ENUMS(ZoomMode)
557- Q_FLAGS(ZoomModes)
558 Q_PROPERTY(QQuickItem* parentFlickable READ parentFlickable WRITE setParentFlickable NOTIFY parentFlickableChanged)
559 Q_PROPERTY(LODocument* document READ document /*WRITE setDocument*/ NOTIFY documentChanged)
560 Q_PROPERTY(int currentPart READ currentPart WRITE setCurrentPart NOTIFY currentPartChanged)
561 Q_PROPERTY(LOPartsModel* partsModel READ partsModel NOTIFY partsModelChanged)
562- Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
563- Q_PROPERTY(ZoomMode zoomMode READ zoomMode NOTIFY zoomModeChanged)
564+ Q_PROPERTY(LOZoom* zoomSettings READ zoomSettings)
565 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
566 Q_PROPERTY(LibreOfficeError::Error error READ error NOTIFY errorChanged)
567- Q_PROPERTY(ZoomModes zoomModesAvailable READ zoomModesAvailable NOTIFY zoomModesAvailableChanged)
568
569 public:
570 LOView(QQuickItem *parent = 0);
571 ~LOView();
572
573- enum ZoomMode {
574- Manual = 0x0,
575- FitToWidth = 0x1,
576- FitToHeight = 0x2,
577- Automatic = 0x4
578- };
579- Q_DECLARE_FLAGS(ZoomModes, ZoomMode)
580-
581 QQuickItem* parentFlickable() const;
582- void setParentFlickable(QQuickItem* flickable);
583-
584- Q_INVOKABLE void initializeDocument(const QString& path);
585+ void setParentFlickable(QQuickItem* flickable);
586
587 LODocument* document() const;
588+
589 LOPartsModel* partsModel() const;
590
591+ LOZoom* zoomSettings() const;
592+
593 int currentPart();
594 void setCurrentPart(int index);
595
596- qreal zoomFactor() const;
597- void setZoomFactor(const qreal zoom);
598-
599- ZoomMode zoomMode() const;
600-
601- ZoomModes zoomModesAvailable() const;
602-
603- int cacheBuffer() const;
604- void setCacheBuffer(int cacheBuffer);
605+ int cacheBuffer() const;
606+ void setCacheBuffer(int cacheBuffer);
607
608 LibreOfficeError::Error error() const;
609
610- Q_INVOKABLE bool adjustZoomToWidth(bool changeMode = true);
611- Q_INVOKABLE bool adjustZoomToHeight(bool changeMode = true);
612- Q_INVOKABLE bool adjustAutomaticZoom(bool changeMode = true);
613+ Q_INVOKABLE void initializeDocument(const QString& path);
614+
615+ Q_INVOKABLE bool adjustZoomToWidth();
616+ Q_INVOKABLE bool adjustZoomToHeight();
617+ Q_INVOKABLE bool adjustAutomaticZoom();
618
619 Q_SIGNALS:
620 void parentFlickableChanged();
621 void documentChanged();
622 void partsModelChanged();
623 void currentPartChanged();
624- void zoomFactorChanged();
625- void zoomModeChanged();
626 void cacheBufferChanged();
627 void errorChanged();
628- void zoomModesAvailableChanged();
629
630 private Q_SLOTS:
631 void updateViewSize();
632@@ -108,13 +90,11 @@
633
634 QQuickItem* m_parentFlickable;
635 QSharedPointer<LODocument> m_document;
636+ LOZoom* m_zoomSettings;
637 LOPartsModel* m_partsModel; // TODO MB move to document.
638 LOPartsImageProvider* m_imageProvider; // The QQmlEngine takes ownership of provider.
639
640 int m_currentPart;
641- qreal m_zoomFactor;
642- ZoomMode m_zoomMode;
643- ZoomModes m_zoomModesAvailable;
644 int m_cacheBuffer;
645
646 QRect m_visibleArea;
647@@ -126,17 +106,17 @@
648
649 QMap<int, SGTileItem*> m_tiles;
650
651+ bool m_zoomValueHasChanged;
652+
653 private:
654 void generateTiles(int x1, int y1, int x2, int y2, int tilesPerWidth, int tilesPerHeight);
655 void createTile(int index, const QRect& rect);
656- void setZoomMode(const ZoomMode zoomMode);
657 void clearView();
658 TileRenderTask* createTask(const QRect& rect, int id) const;
659 void updateTileData(AbstractRenderTask* task, QImage img);
660 void updateThumbnailModel(AbstractRenderTask* task, QImage img);
661
662 void setError(const LibreOfficeError::Error &error);
663- void setZoomModesAvailability();
664 };
665
666 #endif // LOVIEW_H
667
668=== added file 'src/plugin/libreofficetoolkit-qml-plugin/lozoom.cpp'
669--- src/plugin/libreofficetoolkit-qml-plugin/lozoom.cpp 1970-01-01 00:00:00 +0000
670+++ src/plugin/libreofficetoolkit-qml-plugin/lozoom.cpp 2016-01-26 11:46:55 +0000
671@@ -0,0 +1,240 @@
672+/*
673+ * Copyright (C) 2016 Stefano Verzegnassi
674+ *
675+ * This program is free software; you can redistribute it and/or modify
676+ * it under the terms of the GNU General Public License as published by
677+ * the Free Software Foundation; version 3.
678+ *
679+ * This program is distributed in the hope that it will be useful,
680+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
681+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
682+ * GNU General Public License for more details.
683+ *
684+ * You should have received a copy of the GNU General Public License
685+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
686+ */
687+
688+#include "lozoom.h"
689+#include "loview.h"
690+#include "twips.h"
691+
692+static qreal getZoomToFitWidth(const qreal &width, int documentWidth)
693+{
694+ return qreal(width / Twips::convertTwipsToPixels(documentWidth, 1.0));
695+}
696+
697+static qreal getZoomToFitHeight(const qreal &height, int documentHeight)
698+{
699+ return qreal(height / Twips::convertTwipsToPixels(documentHeight, 1.0));
700+}
701+
702+LOZoom::LOZoom(LOView *view)
703+ : QObject(view)
704+ , m_view(view)
705+ , m_zoomMode(ZoomMode::Manual)
706+ , m_zoomModesAvailable(ZoomMode::Manual)
707+ , m_zoomFactor(1.0)
708+ , m_minimumZoom(0.25)
709+ , m_maximumZoom(4.0)
710+{ }
711+
712+LOZoom::~LOZoom()
713+{ }
714+
715+LOZoom::ZoomMode LOZoom::zoomMode() const
716+{
717+ return m_zoomMode;
718+}
719+
720+void LOZoom::setZoomMode(const LOZoom::ZoomMode zoomMode)
721+{
722+ if (m_zoomMode == zoomMode)
723+ return;
724+
725+ m_zoomMode = zoomMode;
726+ Q_EMIT zoomModeChanged();
727+}
728+
729+LOZoom::ZoomModes LOZoom::zoomModesAvailable() const
730+{
731+ return m_zoomModesAvailable;
732+}
733+
734+void LOZoom::setZoomModesAvailability()
735+{
736+ if (!m_view->document())
737+ return;
738+
739+ ZoomModes newZoomModesAvailable;
740+ newZoomModesAvailable |= ZoomMode::Manual;
741+
742+ switch (m_view->document()->documentType()) {
743+ case LODocument::DocumentType::TextDocument:
744+ newZoomModesAvailable |= ZoomMode::FitToWidth;
745+ break;
746+ case LODocument::DocumentType::SpreadsheetDocument:
747+ break;
748+ default:
749+ newZoomModesAvailable |= ZoomMode::FitToWidth;
750+ newZoomModesAvailable |= ZoomMode::FitToHeight;
751+ newZoomModesAvailable |= ZoomMode::Automatic;
752+ break;
753+ }
754+
755+ if (m_zoomModesAvailable != newZoomModesAvailable) {
756+ m_zoomModesAvailable = newZoomModesAvailable;
757+ Q_EMIT zoomModesAvailableChanged();
758+ }
759+}
760+
761+qreal LOZoom::zoomFactor() const
762+{
763+ return m_zoomFactor;
764+}
765+
766+void LOZoom::setZoomFactor(const qreal zoom)
767+{
768+ if (m_zoomFactor == zoom || zoom < m_minimumZoom || zoom > m_maximumZoom)
769+ return;
770+
771+ m_zoomFactor = zoom;
772+
773+ // m_valueAutomaticZoom is necessary equal to the fitToWidth or fitToHeight value.
774+ if (m_zoomFactor != m_valueFitToWidthZoom && m_zoomFactor != m_valueFitToHeightZoom)
775+ setZoomMode(LOZoom::Manual);
776+
777+ Q_EMIT zoomFactorChanged();
778+}
779+
780+qreal LOZoom::minimumZoom() const
781+{
782+ return m_minimumZoom;
783+}
784+
785+/*
786+void LOZoom::setMinimumZoom(const qreal newValue)
787+{
788+ if (m_minimumZoom == newValue)
789+ return;
790+
791+ m_minimumZoom = newValue;
792+ Q_EMIT minimumZoomChanged();
793+}
794+*/
795+
796+qreal LOZoom::maximumZoom() const
797+{
798+ return m_maximumZoom;
799+}
800+
801+/*
802+void LOZoom::setMaximumZoom(const qreal newValue)
803+{
804+ if (m_maximumZoom == newValue)
805+ return;
806+
807+ m_maximumZoom = newValue;
808+ Q_EMIT maximumZoomChanged();
809+}
810+*/
811+
812+qreal LOZoom::valueFitToWidthZoom() const
813+{
814+ return m_valueFitToWidthZoom;
815+}
816+
817+qreal LOZoom::valueFitToHeightZoom() const
818+{
819+ return m_valueFitToHeightZoom;
820+}
821+
822+qreal LOZoom::valueAutomaticZoom() const
823+{
824+ return m_valueAutomaticZoom;
825+}
826+
827+bool LOZoom::adjustZoomToWidth(bool changeMode)
828+{
829+ if (!m_view->document())
830+ return false;
831+
832+ if (changeMode)
833+ setZoomMode(LOZoom::FitToWidth);
834+
835+ m_valueFitToWidthZoom = getZoomToFitWidth(m_view->parentFlickable()->width(),
836+ m_view->document()->documentSize().width());
837+
838+ if (m_zoomFactor != m_valueFitToWidthZoom) {
839+ setZoomFactor(m_valueFitToWidthZoom);
840+
841+ qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
842+ return true;
843+ }
844+
845+ return false;
846+}
847+
848+bool LOZoom::adjustZoomToHeight(bool changeMode)
849+{
850+ if (!m_view->document())
851+ return false;
852+
853+ if (changeMode)
854+ setZoomMode(LOZoom::FitToHeight);
855+
856+ m_valueFitToHeightZoom = getZoomToFitHeight(m_view->parentFlickable()->height(),
857+ m_view->document()->documentSize().height());
858+
859+ if (m_zoomFactor != m_valueFitToHeightZoom) {
860+ setZoomFactor(m_valueFitToHeightZoom);
861+
862+ qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
863+ return true;
864+ }
865+
866+ return false;
867+}
868+
869+bool LOZoom::adjustAutomaticZoom(bool changeMode)
870+{
871+ if (!m_view->document())
872+ return false;
873+
874+ if (changeMode)
875+ setZoomMode(LOZoom::Automatic);
876+
877+ m_valueFitToWidthZoom = getZoomToFitWidth(m_view->parentFlickable()->width(),
878+ m_view->document()->documentSize().width());
879+
880+ m_valueFitToHeightZoom = getZoomToFitHeight(m_view->parentFlickable()->height(),
881+ m_view->document()->documentSize().height());
882+
883+ m_valueAutomaticZoom = qMin(m_valueFitToWidthZoom, m_valueFitToHeightZoom);
884+
885+ if (m_zoomFactor != m_valueAutomaticZoom) {
886+ setZoomFactor(m_valueAutomaticZoom);
887+
888+ qDebug() << Q_FUNC_INFO << "- value:" << m_zoomFactor << "- changeMode:" << changeMode;
889+ return true;
890+ }
891+
892+ return false;
893+}
894+
895+void LOZoom::init()
896+{
897+ setZoomModesAvailability();
898+
899+ switch (m_view->document()->documentType()) {
900+ case LODocument::DocumentType::SpreadsheetDocument:
901+ setZoomMode(ZoomMode::Manual);
902+ setZoomFactor(1.0);
903+ break;
904+ case LODocument::DocumentType::PresentationDocument:
905+ setZoomMode(ZoomMode::Automatic);
906+ break;
907+ default:
908+ setZoomMode(ZoomMode::FitToWidth);
909+ break;
910+ }
911+}
912
913=== added file 'src/plugin/libreofficetoolkit-qml-plugin/lozoom.h'
914--- src/plugin/libreofficetoolkit-qml-plugin/lozoom.h 1970-01-01 00:00:00 +0000
915+++ src/plugin/libreofficetoolkit-qml-plugin/lozoom.h 2016-01-26 11:46:55 +0000
916@@ -0,0 +1,103 @@
917+/*
918+ * Copyright (C) 2016 Stefano Verzegnassi
919+ *
920+ * This program is free software; you can redistribute it and/or modify
921+ * it under the terms of the GNU General Public License as published by
922+ * the Free Software Foundation; version 3.
923+ *
924+ * This program is distributed in the hope that it will be useful,
925+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
926+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
927+ * GNU General Public License for more details.
928+ *
929+ * You should have received a copy of the GNU General Public License
930+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
931+ */
932+
933+#ifndef LOZOOM_H
934+#define LOZOOM_H
935+
936+#include <QObject>
937+#include <QSharedPointer>
938+
939+class LOView;
940+
941+class LOZoom : public QObject
942+{
943+ Q_OBJECT
944+ Q_ENUMS(ZoomMode)
945+ Q_FLAGS(ZoomModes)
946+ Q_PROPERTY(ZoomMode zoomMode READ zoomMode NOTIFY zoomModeChanged)
947+ Q_PROPERTY(ZoomModes zoomModesAvailable READ zoomModesAvailable NOTIFY zoomModesAvailableChanged)
948+ Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
949+ Q_PROPERTY(qreal minimumZoom READ minimumZoom CONSTANT) //WRITE setMinimumZoom NOTIFY minimumZoomChanged)
950+ Q_PROPERTY(qreal maximumZoom READ maximumZoom CONSTANT) //WRITE setMaximumZoom NOTIFY maximumZoomChanged)
951+ Q_PROPERTY(qreal valueFitToWidthZoom READ valueFitToWidthZoom NOTIFY valueFitToWidthZoomChanged)
952+ Q_PROPERTY(qreal valueFitToHeightZoom READ valueFitToHeightZoom NOTIFY valueFitToHeightZoomChanged)
953+ Q_PROPERTY(qreal valueAutomaticZoom READ valueAutomaticZoom NOTIFY valueAutomaticZoomChanged)
954+
955+public:
956+ LOZoom(LOView *view);
957+ ~LOZoom();
958+
959+ enum ZoomMode {
960+ Manual = 0x0,
961+ FitToWidth = 0x1,
962+ FitToHeight = 0x2,
963+ Automatic = 0x4
964+ };
965+ Q_DECLARE_FLAGS(ZoomModes, ZoomMode)
966+
967+ ZoomMode zoomMode() const;
968+ ZoomModes zoomModesAvailable() const;
969+
970+ qreal zoomFactor() const;
971+ void setZoomFactor(const qreal zoom);
972+
973+ qreal minimumZoom() const;
974+// void setMinimumZoom(const qreal newValue);
975+
976+ qreal maximumZoom() const;
977+// void setMaximumZoom(const qreal newValue);
978+
979+ qreal valueFitToWidthZoom() const;
980+ qreal valueFitToHeightZoom() const;
981+ qreal valueAutomaticZoom() const;
982+
983+ bool adjustZoomToWidth(bool changeMode = true);
984+ bool adjustZoomToHeight(bool changeMode = true);
985+ bool adjustAutomaticZoom(bool changeMode = true);
986+
987+ void init();
988+
989+Q_SIGNALS:
990+ void zoomModeChanged();
991+ void zoomModesAvailableChanged();
992+ void zoomFactorChanged();
993+// void minimumZoomChanged();
994+// void maximumZoomChanged();
995+ void valueFitToWidthZoomChanged();
996+ void valueFitToHeightZoomChanged();
997+ void valueAutomaticZoomChanged();
998+
999+private:
1000+ LOView* m_view;
1001+
1002+ ZoomMode m_zoomMode;
1003+ ZoomModes m_zoomModesAvailable;
1004+
1005+ qreal m_zoomFactor;
1006+
1007+ qreal m_minimumZoom;
1008+ qreal m_maximumZoom;
1009+
1010+ qreal m_valueFitToWidthZoom;
1011+ qreal m_valueFitToHeightZoom;
1012+ qreal m_valueAutomaticZoom;
1013+
1014+private:
1015+ void setZoomMode(const ZoomMode zoomMode);
1016+ void setZoomModesAvailability();
1017+};
1018+
1019+#endif // LOZOOM_H
1020
1021=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp'
1022--- src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp 2015-11-22 13:35:56 +0000
1023+++ src/plugin/libreofficetoolkit-qml-plugin/plugin.cpp 2016-01-26 11:46:55 +0000
1024@@ -23,6 +23,7 @@
1025 #include "loview.h"
1026 #include "lopartsmodel.h"
1027 #include "loerror.h"
1028+#include "lozoom.h"
1029
1030 void LOPlugin::registerTypes(const char *uri)
1031 {
1032@@ -31,6 +32,7 @@
1033 //@uri DocumentViewer.LibreOffice
1034 qmlRegisterType<LODocument>(uri, 1, 0, "Document");
1035 qmlRegisterType<LOView>(uri, 1, 0, "View");
1036+ qmlRegisterUncreatableType<LOZoom>(uri, 1, 0, "Zoom", "Not creatable as an object, use only to retrieve error enums (e.g. LibreOffice.Zoom.Manual)");
1037 qmlRegisterUncreatableType<LOPartsModel>(uri, 1, 0, "PartsModel", "You shouldn't create LOPartsModel in QML");
1038 qmlRegisterUncreatableType<LibreOfficeError>(uri, 1, 0, "Error", "Not creatable as an object, use only to retrieve error enums (e.g. LibreOffice.Error.DocumentNotFound)");
1039 }
1040
1041=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml'
1042--- src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml 2016-01-17 22:57:05 +0000
1043+++ src/plugin/libreofficetoolkit-qml-plugin/qml/Viewer.qml 2016-01-26 11:46:55 +0000
1044@@ -20,52 +20,49 @@
1045 Flickable {
1046 id: rootFlickable
1047
1048- property alias document: view.document
1049- property alias zoomFactor: view.zoomFactor
1050- property alias cacheBuffer: view.cacheBuffer
1051- property alias partsModel: view.partsModel
1052- property alias zoomMode: view.zoomMode
1053- property alias error: view.error
1054- property alias currentPart: view.currentPart
1055-
1056- property alias zoomModesAvailable: view.zoomModesAvailable
1057+ property alias document: view.document
1058+ property alias zoomSettings: view.zoomSettings
1059+ property alias cacheBuffer: view.cacheBuffer
1060+ property alias partsModel: view.partsModel
1061+ property alias error: view.error
1062+ property alias currentPart: view.currentPart
1063
1064 property string documentPath: ""
1065
1066 function adjustZoomToWidth()
1067 {
1068- var oldZoom = view.zoomFactor
1069+ var oldZoom = view.zoomSettings.zoomFactor
1070 view.adjustZoomToWidth()
1071
1072- var zoomScale = view.zoomFactor / oldZoom
1073+ var zoomScale = view.zoomSettings.zoomFactor / oldZoom
1074 rootFlickable.contentX *= zoomScale
1075 rootFlickable.contentY *= zoomScale
1076 }
1077
1078 function adjustZoomToHeight()
1079 {
1080- var oldZoom = view.zoomFactor
1081+ var oldZoom = view.zoomSettings.zoomFactor
1082 view.adjustZoomToHeight()
1083
1084- var zoomScale = view.zoomFactor / oldZoom
1085+ var zoomScale = view.zoomSettings.zoomFactor / oldZoom
1086 rootFlickable.contentX *= zoomScale
1087 rootFlickable.contentY *= zoomScale
1088 }
1089
1090 function adjustAutomaticZoom()
1091 {
1092- var oldZoom = view.zoomFactor
1093+ var oldZoom = view.zoomSettings.zoomFactor
1094 view.adjustAutomaticZoom()
1095
1096- var zoomScale = view.zoomFactor / oldZoom
1097+ var zoomScale = view.zoomSettings.zoomFactor / oldZoom
1098 rootFlickable.contentX *= zoomScale
1099 rootFlickable.contentY *= zoomScale
1100 }
1101
1102 function setZoom(newValue)
1103 {
1104- var zoomScale = newValue / view.zoomFactor;
1105- view.zoomFactor = newValue;
1106+ var zoomScale = newValue / view.zoomSettings.zoomFactor;
1107+ view.zoomSettings.zoomFactor = newValue;
1108
1109 rootFlickable.contentX *= zoomScale;
1110 rootFlickable.contentY *= zoomScale;
1111@@ -114,8 +111,6 @@
1112
1113 boundsBehavior: Flickable.StopAtBounds
1114
1115- //Component.onCompleted: adjustZoomToWidth()
1116-
1117 LibreOffice.View {
1118 id: view
1119
1120
1121=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp'
1122--- src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp 2015-11-13 17:00:45 +0000
1123+++ src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.cpp 2016-01-26 11:46:55 +0000
1124@@ -9,10 +9,9 @@
1125 #include <QSGFlatColorMaterial>
1126 #endif
1127
1128-SGTileItem::SGTileItem(const QRect& area, qreal zoom, int id, QQuickItem *parent)
1129+SGTileItem::SGTileItem(const QRect& area, int id, QQuickItem *parent)
1130 : QQuickItem(parent)
1131 , m_area(area)
1132- , m_zoomFactor(zoom)
1133 , m_id (id)
1134 {
1135 setFlag(ItemHasContents, true);
1136
1137=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h'
1138--- src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h 2015-11-13 17:00:45 +0000
1139+++ src/plugin/libreofficetoolkit-qml-plugin/sgtileitem.h 2016-01-26 11:46:55 +0000
1140@@ -16,15 +16,12 @@
1141 {
1142 Q_OBJECT
1143 public:
1144- SGTileItem(const QRect& area, qreal zoom, int id, QQuickItem *parent = 0);
1145+ SGTileItem(const QRect& area, int id, QQuickItem *parent = 0);
1146 ~SGTileItem();
1147
1148 inline const QRect& area() { return m_area; }
1149 inline void setArea(const QRect& rect) { m_area = rect; }
1150
1151- inline const qreal& zoomFactor() const { return m_zoomFactor; }
1152- inline void setZoomFactor(const qreal &zoom) { m_zoomFactor = zoom; }
1153-
1154 inline int id() { return m_id; }
1155 inline void setId(int id) { m_id = id; }
1156
1157@@ -42,7 +39,6 @@
1158
1159 private:
1160 QRect m_area;
1161- qreal m_zoomFactor;
1162 QImage m_data;
1163 int m_id;
1164 };

Subscribers

People subscribed via source and target branches