13
13
* You should have received a copy of the GNU General Public License
14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
17
import Ubuntu.Components 1.1
19
import QtGraphicalEffects 1.0
22
property int index: model.index
23
property bool _previewFetched: false
25
property alias status: pageImg.status
23
27
width: parent.width
25
28
height: width * (model.height / model.width)
31
// Preview page rendering. Used as placeholder while zooming the page.
32
// We generate the low resolution preview from the texture of the PDF page,
33
// so that we can keep page rendering as fast as possible.
38
// We cannot change its opacity or visibility, otherwise the texture will be refreshed,
39
// even if live is false.
41
textureSize: Qt.size(256, 256 * (model.height / model.width))
39
sourceSize.width: parent.width - 2
40
fillMode: Image.PreserveAspectCrop
42
Component.onCompleted: source = "image://poppler/page/" + model.index
48
visible: imagePage.status === Image.Loading
51
anchors.centerIn: parent
52
running: parent.visible
48
source: "image://poppler" + (index % poppler.providersNumber) + "/page/" + index;
49
sourceSize.width: pdfPage.width
52
// This is supposed to run the first time PdfViewDelegate gets the page rendering.
53
if (!_previewFetched) {
54
if (status == Image.Ready) {
55
previewImg.sourceItem = pageImg
56
// Re-assign sourceItem property, so the texture is not updated when Image status changes.
57
previewImg.sourceItem = pdfPage
62
// Request a new page rendering. The order, which pages are requested with, depends on the distance from the currentPage
66
var diff = Math.abs(pdfView.currentPageIndex - model.index)
67
var prov = poppler.providersNumber * 0.5
72
return (diff - prov) * 10
76
pageImg.sourceSize.width = pdfPage.width;
81
// Page rendering depends on the width of PdfViewDelegate.
82
// Because of this, we have multiple callings to ImageProvider while zooming.
87
onPinchStarted: _zoomTimer.stop();
89
// This ensures that page image is not reloaded when the maximumScale or minimumScale has already been reached.
90
if ( !(_zoomHelper.scale >= 2.5 && pinch.scale > 1.0) && !(_zoomHelper.scale <= 1.0 && pinch.scale < 1.0) )
91
pageImg.sourceSize.width = 0;
93
onPinchFinished: _zoomTimer.restart();