summaryrefslogtreecommitdiffstats
path: root/tests/manual/quick/pdf/pessimizedListView.qml
blob: 1b514668e62d47e8d9d567c0a85917b90321e6e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import QtQuick.Pdf

ApplicationWindow {
    width: 900
    height: 1000
    color: "lightgrey"
    title: doc.source + " scale " + imageScale.toFixed(2)
    visible: true
    property real imageScale: 1

    header: ToolBar {
        RowLayout {
            anchors.fill: parent
            anchors.rightMargin: 6
            ToolButton {
                action: Action {
                    text: "🗁"
                    shortcut: StandardKey.Open
                    onTriggered: fileDialog.open()
                }
            }
            ToolButton {
                action: Action {
                    text: "⊕"
                    shortcut: StandardKey.ZoomIn
                    onTriggered: imageScale *= Math.sqrt(2)
                }
            }
            ToolButton {
                action: Action {
                    text: "⊖"
                    shortcut: StandardKey.ZoomOut
                    onTriggered: imageScale /= Math.sqrt(2)
                }
            }
            ToolButton {
                action: Action {
                    text: "1x"
                    shortcut: "Ctrl+0"
                    onTriggered: imageScale = 1
                }
            }

            Label {
                text: "Pixels/point:"
            }
            SpinBox {
                id: oversamplingSB
                from: 1; to: 8; value: 4
            }

            Label {
                text: "cacheBuffer:"
            }
            SpinBox {
                id: cacheBufferSB
                from: 0; to: 1000; stepSize: 50; value: 100
            }

            CheckBox {
                id: asyncCB
                text: "async"
            }

            CheckBox {
                id: cacheCB
                text: "cache"
            }
        }
    }

    PdfDocument {
        id: doc
        source: "test.pdf"
    }

    FileDialog {
        id: fileDialog
        title: "Open a PDF file"
        nameFilters: [ "PDF files (*.pdf)" ]
        onAccepted: doc.source = selectedFile
    }

    ListView {
        id: listView
        anchors.fill: parent
        anchors.margins: 10
        model: doc.pageCount
        spacing: 6
        cacheBuffer: cacheBufferSB.value
        ScrollBar.vertical: ScrollBar { }
        delegate: Rectangle {
            id: paper
            width: Math.max(60, image.width) * imageScale
            height: 100 * imageScale
            BusyIndicator {
                anchors.centerIn: parent
                running: image.status === Image.Loading
            }
            PdfPageImage {
                id: image
                document: doc
                scale: imageScale
                anchors.centerIn: parent
                sourceSize.width: doc.pagePointSize(index).width * oversamplingSB.value
                height: 100
                fillMode: Image.PreserveAspectFit
                objectName: "PDF page " + index
                currentFrame: index
                asynchronous: asyncCB.checked
                cache: cacheCB.checked
            }
        }
    }

    Text {
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        text: "page " + Math.max(1, (listView.indexAt(0, listView.contentY) + 1)) + " of " + doc.pageCount
    }
}