~adamreichold/qpdfview/trunk

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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*

Copyright 2014 S. Razi Alavizadeh
Copyright 2013-2014 Adam Reichold

This file is part of qpdfview.

qpdfview is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

qpdfview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef DOCUMENTMODEL_H
#define DOCUMENTMODEL_H

#include <QList>
#include <QPainterPath>
#include <QtPlugin>
#include <QWidget>
#include <QVector>

class QAbstractItemModel;
class QColor;
class QImage;
class QPrinter;
class QSizeF;

#include "global.h"

namespace qpdfview
{

namespace Model
{
    struct Link
    {
        QPainterPath boundary;

        int page;
        qreal left;
        qreal top;

        QString urlOrFileName;

        Link() : boundary(), page(-1), left(qQNaN()), top(qQNaN()), urlOrFileName() {}

        Link(const QPainterPath& boundary, int page, qreal left = qQNaN(), qreal top = qQNaN()) : boundary(boundary), page(page), left(left), top(top), urlOrFileName() {}
        Link(const QRectF& boundingRect, int page, qreal left = qQNaN(), qreal top = qQNaN()) : boundary(), page(page), left(left), top(top), urlOrFileName() { boundary.addRect(boundingRect); }

        Link(const QPainterPath& boundary, const QString& url) : boundary(boundary), page(-1), left(qQNaN()), top(qQNaN()), urlOrFileName(url) {}
        Link(const QRectF& boundingRect, const QString& url) : boundary(), page(-1), left(qQNaN()), top(qQNaN()), urlOrFileName(url) { boundary.addRect(boundingRect); }

        Link(const QPainterPath& boundary, const QString& fileName, int page) : boundary(boundary), page(page), left(qQNaN()), top(qQNaN()), urlOrFileName(fileName) {}
        Link(const QRectF& boundingRect, const QString& fileName, int page) : boundary(), page(page), left(qQNaN()), top(qQNaN()), urlOrFileName(fileName) { boundary.addRect(boundingRect); }

    };

    struct Section;

    typedef QVector< Section > Outline;

    struct Section
    {
        QString title;
        Link link;

        Outline children;

    };

    typedef QVector< QPair< QString, QString > > Properties;

    class Annotation : public QObject
    {
        Q_OBJECT

    public:
        Annotation(QObject* parent = 0) : QObject(parent) {}
        virtual ~Annotation() {}

        virtual QRectF boundary() const = 0;
        virtual QString contents() const = 0;

        virtual QWidget* createWidget() = 0;

    signals:
        void wasModified();

    };

    class FormField : public QObject
    {
        Q_OBJECT

    public:
        FormField(QObject* parent = 0) : QObject(parent) {}
        virtual ~FormField() {}

        virtual QRectF boundary() const = 0;
        virtual QString name() const = 0;

        virtual QWidget* createWidget() = 0;

    signals:
        void wasModified();

    };

    class Page
    {
    public:
        virtual ~Page() {}

        virtual QSizeF size() const = 0;

        virtual QImage render(qreal horizontalResolution = 72.0, qreal verticalResolution = 72.0, Rotation rotation = RotateBy0, QRect boundingRect = QRect()) const = 0;

        virtual QString label() const { return QString(); }

        virtual QList< Link* > links() const { return QList< Link* >(); }

        virtual QString text(const QRectF& rect) const { Q_UNUSED(rect); return QString(); }
        virtual QString cachedText(const QRectF& rect) const { return text(rect); }

        virtual QList< QRectF > search(const QString& text, bool matchCase, bool wholeWords) const { Q_UNUSED(text); Q_UNUSED(matchCase); Q_UNUSED(wholeWords); return QList< QRectF >(); }

        virtual QList< Annotation* > annotations() const { return QList< Annotation* >(); }

        virtual bool canAddAndRemoveAnnotations() const { return false; }
        virtual Annotation* addTextAnnotation(const QRectF& boundary, const QColor& color) { Q_UNUSED(boundary); Q_UNUSED(color); return 0; }
        virtual Annotation* addHighlightAnnotation(const QRectF& boundary, const QColor& color) { Q_UNUSED(boundary); Q_UNUSED(color); return 0; }
        virtual void removeAnnotation(Annotation* annotation) { Q_UNUSED(annotation); }

        virtual QList< FormField* > formFields() const { return QList< FormField* >(); }

    };

    class Document
    {
    public:
        virtual ~Document() {}

        virtual int numberOfPages() const = 0;

        virtual Page* page(int index) const = 0;

        virtual bool isLocked() const { return false; }
        virtual bool unlock(const QString& password) { Q_UNUSED(password); return false; }

        virtual QStringList saveFilter() const { return QStringList(); }

        virtual bool canSave() const { return false; }
        virtual bool save(const QString& filePath, bool withChanges) const { Q_UNUSED(filePath); Q_UNUSED(withChanges); return false; }

        virtual bool canBePrintedUsingCUPS() const { return false; }

        virtual void setPaperColor(const QColor& paperColor) { Q_UNUSED(paperColor); }

        enum
        {
            PageRole = Qt::UserRole + 1,
            LeftRole,
            TopRole,
            FileNameRole,
            ExpansionRole
        };

        virtual Outline outline() const { return Outline(); }
        virtual Properties properties() const { return Properties(); }

        virtual QAbstractItemModel* fonts() const { return 0; }

        virtual bool wantsContinuousMode() const { return false; }
        virtual bool wantsSinglePageMode() const { return false; }
        virtual bool wantsTwoPagesMode() const { return false; }
        virtual bool wantsTwoPagesWithCoverPageMode() const { return false; }
        virtual bool wantsRightToLeftMode() const { return false; }

    };
}

class SettingsWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SettingsWidget(QWidget* parent = 0) : QWidget(parent) {}

    virtual void accept() = 0;
    virtual void reset() = 0;

};

class Plugin
{
public:
    virtual ~Plugin() {}

    virtual Model::Document* loadDocument(const QString& filePath) const = 0;

    virtual SettingsWidget* createSettingsWidget(QWidget* parent = 0) const { Q_UNUSED(parent); return 0; }

};

} // qpdfview

Q_DECLARE_INTERFACE(qpdfview::Plugin, "local.qpdfview.Plugin")

#endif // DOCUMENTMODEL_H