~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to sources/pdfmodel.cpp

  • Committer: Adam Reichold
  • Date: 2021-04-18 17:24:01 UTC
  • Revision ID: adam.reichold@t-online.de-20210418172401-pr4a5lu8ya4p56z4
First stab at making the application compatible with Qt versions 4, 5 and 6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QMessageBox>
29
29
#include <QSettings>
30
30
 
31
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
31
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
 
32
 
 
33
#include <poppler-qt6.h>
 
34
 
 
35
#elif QT_VERSION >= QT_VERSION_CHECK(5,0,0)
32
36
 
33
37
#include <poppler-qt5.h>
34
38
 
65
69
using namespace qpdfview;
66
70
using namespace qpdfview::Model;
67
71
 
 
72
#ifdef HAS_POPPLER_74
 
73
 
 
74
Outline loadOutline(QVector< Poppler::OutlineItem > items, Poppler::Document* document)
 
75
{
 
76
    Outline outline;
 
77
 
 
78
    outline.reserve(items.size());
 
79
 
 
80
    for(QVector< Poppler::OutlineItem >::const_iterator item = items.constBegin(); item != items.constEnd(); ++item)
 
81
    {
 
82
        outline.push_back(Section());
 
83
        Section& section = outline.back();
 
84
 
 
85
        section.title = item->name();
 
86
 
 
87
        QSharedPointer< const Poppler::LinkDestination > destination = item->destination();
 
88
 
 
89
        if(destination)
 
90
        {
 
91
            int page = destination->pageNumber();
 
92
            qreal left = qQNaN();
 
93
            qreal top = qQNaN();
 
94
 
 
95
            page = page >= 1 ? page : 1;
 
96
            page = page <= document->numPages() ? page : document->numPages();
 
97
 
 
98
            if(destination->isChangeLeft())
 
99
            {
 
100
                left = destination->left();
 
101
 
 
102
                left = left >= 0.0 ? left : 0.0;
 
103
                left = left <= 1.0 ? left : 1.0;
 
104
            }
 
105
 
 
106
            if(destination->isChangeTop())
 
107
            {
 
108
                top = destination->top();
 
109
 
 
110
                top = top >= 0.0 ? top : 0.0;
 
111
                top = top <= 1.0 ? top : 1.0;
 
112
            }
 
113
 
 
114
            Link& link = section.link;
 
115
            link.page = page;
 
116
            link.left = left;
 
117
            link.top = top;
 
118
 
 
119
            const QString fileName = item->externalFileName();
 
120
 
 
121
            if(!fileName.isEmpty())
 
122
            {
 
123
                link.urlOrFileName = fileName;
 
124
            }
 
125
        }
 
126
 
 
127
        if(item->hasChildren())
 
128
        {
 
129
            section.children = loadOutline(item->children(), document);
 
130
        }
 
131
    }
 
132
 
 
133
    return outline;
 
134
}
 
135
 
 
136
#else
 
137
 
68
138
Outline loadOutline(const QDomNode& parent, Poppler::Document* document)
69
139
{
70
140
    Outline outline;
140
210
    return outline;
141
211
}
142
212
 
 
213
#endif // HAS_POPPLER_74
 
214
 
143
215
class FontsModel : public QAbstractTableModel
144
216
{
145
217
public:
972
1044
 
973
1045
Outline PdfDocument::outline() const
974
1046
{
 
1047
    LOCK_DOCUMENT
 
1048
 
 
1049
#ifdef HAS_POPPLER_74
 
1050
 
 
1051
    return loadOutline(m_document->outline(), m_document);
 
1052
 
 
1053
#else
 
1054
 
975
1055
    Outline outline;
976
1056
 
977
 
    LOCK_DOCUMENT
978
 
 
979
1057
    QScopedPointer< QDomDocument > toc(m_document->toc());
980
1058
 
981
1059
    if(toc)
984
1062
    }
985
1063
 
986
1064
    return outline;
 
1065
 
 
1066
#endif // HAS_POPPLER_74
987
1067
}
988
1068
 
989
1069
Properties PdfDocument::properties() const
1309
1389
            document->setRenderBackend(Poppler::Document::SplashBackend);
1310
1390
            break;
1311
1391
        case 1:
 
1392
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
 
1393
 
 
1394
            document->setRenderBackend(Poppler::Document::QPainterBackend);
 
1395
 
 
1396
#else
 
1397
 
1312
1398
            document->setRenderBackend(Poppler::Document::ArthurBackend);
 
1399
 
 
1400
#endif // QT_VERSION
1313
1401
            break;
1314
1402
        }
1315
1403