summaryrefslogtreecommitdiffstats
path: root/src/pdfwidgets/qpdfview_p.h
blob: d349cc2eee8b57db078081696d6ec0f5da968b0b (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
// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias König <tobias.koenig@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QPDFVIEW_P_H
#define QPDFVIEW_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qpdfview.h"
#include "qpdfdocument.h"
#include "qpdflinkmodel.h"

#include <QHash>
#include <QPointer>

QT_BEGIN_NAMESPACE

class QPdfPageRenderer;

class QPdfViewPrivate
{
    Q_DECLARE_PUBLIC(QPdfView)

public:
    QPdfViewPrivate(QPdfView *q);
    void init();

    void documentStatusChanged();
    void currentPageChanged(int currentPage);
    void calculateViewport();
    void setViewport(QRect viewport);
    void updateScrollBars();

    void pageRendered(int pageNumber, QSize imageSize, const QImage &image, quint64 requestId);
    void invalidateDocumentLayout();
    void invalidatePageCache();

    qreal yPositionForPage(int page) const;

    QTransform screenScaleTransform(int page) const; // points to pixels

    struct DocumentLayout
    {
        QSize documentSize;
        QHash<int, QPair<QRect, qreal>> pageGeometryAndScale;
    };

    DocumentLayout calculateDocumentLayout() const;
    void updateDocumentLayout();

    QPdfView *q_ptr;
    QPointer<QPdfDocument> m_document;
    QPointer<QPdfSearchModel> m_searchModel;
    QPdfPageNavigator* m_pageNavigator;
    QPdfPageRenderer *m_pageRenderer;
    QPdfLinkModel m_linkModel;

    QPdfView::PageMode m_pageMode;
    QPdfView::ZoomMode m_zoomMode;
    qreal m_zoomFactor;

    int m_currentSearchResultIndex = -1;

    int m_pageSpacing;
    QMargins m_documentMargins;

    bool m_blockPageScrolling;

    QMetaObject::Connection m_documentStatusChangedConnection;

    QRect m_viewport;

    QHash<int, QImage> m_pageCache;
    QList<int> m_cachedPagesLRU;
    int m_pageCacheLimit;

    DocumentLayout m_documentLayout;

    qreal m_screenResolution; // pixels per point
};

Q_DECLARE_TYPEINFO(QPdfViewPrivate::DocumentLayout, Q_RELOCATABLE_TYPE);

QT_END_NAMESPACE

#endif // QPDFVIEW_P_H