Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[office] Adjust content position when device is rotated and zoom level changes. #25

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions plugin/PDFView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,45 @@ SilicaFlickable {
property alias itemHeight: pdfCanvas.height;
property alias document: pdfCanvas.document;

property bool scaled: false;
property bool scaled: pdfCanvas.width != width;

signal clicked();
signal updateSize(real newWidth, real newHeight);

function zoom(amount, center) {
var oldWidth = pdfCanvas.width;

pdfCanvas.width *= amount;

if(pdfCanvas.width < d.minWidth) {
pdfCanvas.width = d.minWidth;
function clamp(value) {
if (value < width) {
return width;
}

if(pdfCanvas.width > d.maxWidth) {
pdfCanvas.width = d.maxWidth;
if (value > width * 2.5) {
return width * 2.5;
}

if(pdfCanvas.width == d.minWidth) {
base.scaled = false;
} else {
base.scaled = true;
}
return value;
}

function zoom(amount, center) {
var oldWidth = pdfCanvas.width;

pdfCanvas.width = clamp(pdfCanvas.width * amount);

var realZoom = pdfCanvas.width / oldWidth;
contentX += (center.x * realZoom) - center.x;
contentY += (center.y * realZoom) - center.y;
}

// Ensure proper zooming level when device is rotated.
onWidthChanged: pdfCanvas.width = scaled ? clamp(pdfCanvas.width) : width

PDF.Canvas {
id: pdfCanvas;

width: base.width;
// When not zoomed, device rotation will change width and height,
// so, we shift content position with changing ratio.
onHeightChanged: if (!base.scaled) base.contentY *= height / base.contentHeight
onWidthChanged: if (!base.scaled) base.contentX *= width / base.contentWidth

spacing: Theme.paddingLarge;
flickable: base;
linkColor: Theme.highlightColor;
Expand Down Expand Up @@ -90,13 +96,6 @@ SilicaFlickable {
VerticalScrollDecorator { color: Theme.highlightDimmerColor; }
]

QtObject {
id: d;

property real minWidth: base.width;
property real maxWidth: base.width * 2.5;
}

function goToPage(pageNumber) {
base.contentY = pdfCanvas.pagePosition( pageNumber );
}
Expand Down