blob: 7826c9a8f84ebe30101c8d9b76f77e45f46810fa (
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import QtQuick.Pdf
import Qt.labs.animation
ApplicationWindow {
id: root
width: 1280
height: 1024
color: "transparent"
flags: Qt.FramelessWindowHint
visibility: Window.FullScreen
property string source // for main.cpp
property real scaleStep: Math.sqrt(2)
Component {
id: pdfWindow
PdfPageView {
property alias source: document.source
Rectangle {
visible: parent.activeFocus
color: "transparent"
border.color: "cyan"
border.width: 3
anchors.fill: parent
anchors.margins: -border.width
anchors.topMargin: -toolbar.height - border.width
}
ToolBar {
id: toolbar
width: parent.width
y: -height
RowLayout {
anchors.fill: parent
anchors.rightMargin: 6
ToolButton {
action: Action {
shortcut: StandardKey.ZoomIn
enabled: pageView.sourceSize.width < 10000
icon.source: "../../../../examples/pdf/singlepage/resources/zoom-in.svg"
onTriggered: pageView.renderScale *= root.scaleStep
}
}
ToolButton {
action: Action {
shortcut: StandardKey.ZoomOut
enabled: pageView.sourceSize.width > 50
icon.source: "../../../../examples/pdf/singlepage/resources/zoom-out.svg"
onTriggered: pageView.renderScale /= root.scaleStep
}
}
ToolButton {
action: Action {
shortcut: "Ctrl+0"
icon.source: "../../../../examples/pdf/singlepage/resources/zoom-original.svg"
onTriggered: pageView.resetScale()
}
}
ToolButton {
action: Action {
icon.source: "../../../../examples/pdf/singlepage/resources/go-previous-view-page.svg"
enabled: pageView.backEnabled
onTriggered: pageView.back()
}
ToolTip.visible: enabled && hovered
ToolTip.delay: 2000
ToolTip.text: "go back"
}
SpinBox {
id: currentPageSB
from: 1
to: document.pageCount
editable: true
value: pageView.currentPage + 1
onValueModified: pageView.goToPage(value - 1)
Layout.maximumWidth: 60
}
ToolButton {
action: Action {
icon.source: "../../../../examples/pdf/singlepage/resources/go-next-view-page.svg"
enabled: pageView.forwardEnabled
onTriggered: pageView.forward()
}
ToolTip.visible: enabled && hovered
ToolTip.delay: 2000
ToolTip.text: "go forward"
}
Text {
text: document.title
elide: Text.ElideRight
Layout.fillWidth: true
}
DragHandler {
target: pageView
}
TapHandler {
onTapped: pageView.z++
}
ToolButton {
action: Action {
shortcut: StandardKey.Close
text: "☒"
onTriggered: pageView.destroy()
}
}
}
}
id: pageView
document: PdfDocument {
id: document
source: Qt.resolvedUrl(root.source)
onStatusChanged: (status) => { if (status === PdfDocument.Error) errorDialog.open() }
}
DragHandler {
acceptedButtons: Qt.MiddleButton
}
DragHandler {
acceptedDevices: PointerDevice.TouchScreen
}
HoverHandler {
onHoveredChanged: if (hovered) pageView.forceActiveFocus()
}
Dialog {
id: errorDialog
title: "Error loading " + document.source
standardButtons: Dialog.Ok
modal: true
closePolicy: Popup.CloseOnEscape
anchors.centerIn: parent
width: 300
Label {
id: errorField
text: document.error
}
}
}
}
Shortcut {
sequence: StandardKey.MoveToPreviousPage
onActivated: root.activeFocusItem.goToPage(root.activeFocusItem.currentPage - 1)
}
Shortcut {
sequence: StandardKey.MoveToNextPage
onActivated: root.activeFocusItem.goToPage(root.activeFocusItem.currentPage + 1)
}
Shortcut {
sequence: StandardKey.Open
onActivated: fileDialog.open()
}
Shortcut {
sequence: StandardKey.Quit
onActivated: Qt.quit()
}
function open(src) {
var win = pdfWindow.createObject(root, { source: src, y: 50 })
}
Component.onCompleted: {
if (Application.arguments.length > 2)
root.open(Application.arguments[Application.arguments.length - 1])
}
FileDialog {
id: fileDialog
title: "Open a PDF file"
nameFilters: [ "PDF files (*.pdf)" ]
onAccepted: root.open(selectedFile)
}
}
|