Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickpdfpageimage.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include <private/qpdffile_p.h>
7#include <QtQuick/private/qquickimage_p_p.h>
8
10
11Q_LOGGING_CATEGORY(qLcImg, "qt.pdf.image")
12
13
16
32
37
42{
44 // cancel any async rendering job that is running on my behalf
45 d->pix.clear();
46}
47
54{
56 if (d->doc == document)
57 return;
58
59 if (d->doc)
61 d->doc = document;
62 if (document) {
64 if (document->document()->status() == QPdfDocument::Status::Ready)
65 setSource(document->resolvedSource()); // calls load()
66 }
68}
69
71{
72 Q_D(const QQuickPdfPageImage);
73 return d->doc;
74}
75
77{
79 QUrl url = source();
80 if (!d->doc || !d->doc->carrierFile()) {
81 if (!url.isEmpty()) {
82 qmlWarning(this) << "document property not set: falling back to inefficient loading of " << url;
84 }
85 return;
86 }
87 if (url != d->doc->resolvedSource()) {
88 url = d->doc->resolvedSource();
89 qmlWarning(this) << "document and source properties in conflict: preferring document source " << url;
90 }
91 auto carrierFile = d->doc->carrierFile();
92 static int thisRequestProgress = -1;
93 static int thisRequestFinished = -1;
94 if (thisRequestProgress == -1) {
95 thisRequestProgress =
96 QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
97 thisRequestFinished =
98 QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()");
99 }
100
101 d->pix.loadImageFromDevice(qmlEngine(this), carrierFile, url,
102 d->sourceClipRect.toRect(), d->sourcesize * d->devicePixelRatio,
103 QQuickImageProviderOptions(), d->currentFrame, d->frameCount);
104
105 qCDebug(qLcImg) << "loading page" << d->currentFrame << "of" << d->frameCount
106 << "from" << carrierFile->fileName() << "status" << d->pix.status();
107
108 switch (d->pix.status()) {
110 pixmapChange();
111 break;
113 d->pix.connectFinished(this, thisRequestFinished);
114 d->pix.connectDownloadProgress(this, thisRequestProgress);
115 if (d->progress != 0.0) {
116 d->progress = 0.0;
117 emit progressChanged(d->progress);
118 }
119 if (d->status != Loading) {
120 d->status = Loading;
121 emit statusChanged(d->status);
122 }
123 break;
124 default:
125 qCDebug(qLcImg) << "unexpected status" << d->pix.status();
126 break;
127 }
128}
129
131{
133 const auto status = d->doc->document()->status();
134 qCDebug(qLcImg) << "document status" << status;
136 setSource(d->doc->resolvedSource()); // calls load()
137}
138
140
141#include "moc_qquickpdfpageimage_p.cpp"
Status status
This property holds the current status of the document.
void statusChanged(QPdfDocument::Status status)
virtual void load()
void statusChanged(QQuickImageBase::Status)
void progressChanged(qreal progress)
virtual void setSource(const QUrl &url)
The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image reques...
void pixmapChange() override
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QUrl resolvedSource() const
Displays one page from a PDF document.
QQuickPdfDocument * document
void setDocument(QQuickPdfDocument *document)
\qmlproperty PdfDocument PdfPageImage::document
QQuickPdfPageImage(QQuickItem *parent=nullptr)
\inmodule QtCore
Definition qurl.h:94
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition qurl.cpp:1896
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define emit
QUrl url("example.com")
[constructor-url-reference]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]