[1f4adec] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2014 S. Razi Alavizadeh |
---|
| 4 | Copyright 2013-2014 Adam Reichold |
---|
| 5 | |
---|
| 6 | This file is part of qpdfview. |
---|
| 7 | |
---|
| 8 | qpdfview is free software: you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation, either version 2 of the License, or |
---|
| 11 | (at your option) any later version. |
---|
| 12 | |
---|
| 13 | qpdfview is distributed in the hope that it will be useful, |
---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | GNU General Public License for more details. |
---|
| 17 | |
---|
| 18 | You should have received a copy of the GNU General Public License |
---|
| 19 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
| 20 | |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #ifndef PDFMODEL_H |
---|
| 24 | #define PDFMODEL_H |
---|
| 25 | |
---|
| 26 | #include <QCoreApplication> |
---|
| 27 | #include <QMutex> |
---|
| 28 | #include <QScopedPointer> |
---|
| 29 | |
---|
| 30 | class QCheckBox; |
---|
| 31 | class QComboBox; |
---|
| 32 | class QFormLayout; |
---|
| 33 | class QSettings; |
---|
| 34 | |
---|
| 35 | namespace Poppler |
---|
| 36 | { |
---|
| 37 | class Annotation; |
---|
| 38 | class Document; |
---|
| 39 | class FormField; |
---|
| 40 | class Page; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | #include "model.h" |
---|
| 44 | |
---|
| 45 | namespace qpdfview |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | class PdfPlugin; |
---|
| 49 | |
---|
| 50 | namespace Model |
---|
| 51 | { |
---|
| 52 | class PdfAnnotation : public Annotation |
---|
| 53 | { |
---|
| 54 | Q_OBJECT |
---|
| 55 | |
---|
| 56 | friend class PdfPage; |
---|
| 57 | |
---|
| 58 | public: |
---|
| 59 | ~PdfAnnotation(); |
---|
| 60 | |
---|
| 61 | QRectF boundary() const; |
---|
| 62 | QString contents() const; |
---|
| 63 | |
---|
| 64 | QWidget* createWidget(); |
---|
| 65 | |
---|
| 66 | private: |
---|
| 67 | Q_DISABLE_COPY(PdfAnnotation) |
---|
| 68 | |
---|
| 69 | PdfAnnotation(QMutex* mutex, Poppler::Annotation* annotation); |
---|
| 70 | |
---|
| 71 | mutable QMutex* m_mutex; |
---|
| 72 | Poppler::Annotation* m_annotation; |
---|
| 73 | |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | class PdfFormField : public FormField |
---|
| 77 | { |
---|
| 78 | Q_OBJECT |
---|
| 79 | |
---|
| 80 | friend class PdfPage; |
---|
| 81 | |
---|
| 82 | public: |
---|
| 83 | ~PdfFormField(); |
---|
| 84 | |
---|
| 85 | QRectF boundary() const; |
---|
| 86 | QString name() const; |
---|
| 87 | |
---|
| 88 | QWidget* createWidget(); |
---|
| 89 | |
---|
| 90 | private: |
---|
| 91 | Q_DISABLE_COPY(PdfFormField) |
---|
| 92 | |
---|
| 93 | PdfFormField(QMutex* mutex, Poppler::FormField* formField); |
---|
| 94 | |
---|
| 95 | mutable QMutex* m_mutex; |
---|
| 96 | Poppler::FormField* m_formField; |
---|
| 97 | |
---|
| 98 | }; |
---|
| 99 | |
---|
| 100 | class PdfPage : public Page |
---|
| 101 | { |
---|
| 102 | Q_DECLARE_TR_FUNCTIONS(Model::PdfPage) |
---|
| 103 | |
---|
| 104 | friend class PdfDocument; |
---|
| 105 | |
---|
| 106 | public: |
---|
| 107 | ~PdfPage(); |
---|
| 108 | |
---|
| 109 | QSizeF size() const; |
---|
| 110 | |
---|
| 111 | QImage render(qreal horizontalResolution, qreal verticalResolution, Rotation rotation, const QRect& boundingRect) const; |
---|
| 112 | |
---|
| 113 | QString label() const; |
---|
| 114 | |
---|
| 115 | QList< Link* > links() const; |
---|
| 116 | |
---|
| 117 | QString text(const QRectF& rect) const; |
---|
| 118 | QString cachedText(const QRectF& rect) const; |
---|
| 119 | |
---|
| 120 | QList< QRectF > search(const QString& text, bool matchCase, bool wholeWords) const; |
---|
| 121 | |
---|
| 122 | QList< Annotation* > annotations() const; |
---|
| 123 | |
---|
| 124 | bool canAddAndRemoveAnnotations() const; |
---|
| 125 | Annotation* addTextAnnotation(const QRectF& boundary, const QColor& color); |
---|
| 126 | Annotation* addHighlightAnnotation(const QRectF& boundary, const QColor& color); |
---|
| 127 | void removeAnnotation(Annotation* annotation); |
---|
| 128 | |
---|
| 129 | QList< FormField* > formFields() const; |
---|
| 130 | |
---|
| 131 | private: |
---|
| 132 | Q_DISABLE_COPY(PdfPage) |
---|
| 133 | |
---|
| 134 | PdfPage(QMutex* mutex, Poppler::Page* page); |
---|
| 135 | |
---|
| 136 | mutable QMutex* m_mutex; |
---|
| 137 | Poppler::Page* m_page; |
---|
| 138 | |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | class PdfDocument : public Document |
---|
| 142 | { |
---|
| 143 | Q_DECLARE_TR_FUNCTIONS(Model::PdfDocument) |
---|
| 144 | |
---|
| 145 | friend class qpdfview::PdfPlugin; |
---|
| 146 | |
---|
| 147 | public: |
---|
| 148 | ~PdfDocument(); |
---|
| 149 | |
---|
| 150 | int numberOfPages() const; |
---|
| 151 | |
---|
| 152 | Page* page(int index) const; |
---|
| 153 | |
---|
| 154 | bool isLocked() const; |
---|
| 155 | bool unlock(const QString& password); |
---|
| 156 | |
---|
| 157 | QStringList saveFilter() const; |
---|
| 158 | |
---|
| 159 | bool canSave() const; |
---|
| 160 | bool save(const QString& filePath, bool withChanges) const; |
---|
| 161 | |
---|
| 162 | bool canBePrintedUsingCUPS() const; |
---|
| 163 | |
---|
| 164 | void setPaperColor(const QColor& paperColor); |
---|
| 165 | |
---|
| 166 | void loadOutline(QStandardItemModel* outlineModel) const; |
---|
| 167 | void loadProperties(QStandardItemModel* propertiesModel) const; |
---|
| 168 | |
---|
| 169 | void loadFonts(QStandardItemModel* fontsModel) const; |
---|
| 170 | |
---|
| 171 | bool wantsContinuousMode() const; |
---|
| 172 | bool wantsSinglePageMode() const; |
---|
| 173 | bool wantsTwoPagesMode() const; |
---|
| 174 | bool wantsTwoPagesWithCoverPageMode() const; |
---|
| 175 | bool wantsRightToLeftMode() const; |
---|
| 176 | |
---|
| 177 | private: |
---|
| 178 | Q_DISABLE_COPY(PdfDocument) |
---|
| 179 | |
---|
| 180 | PdfDocument(Poppler::Document* document); |
---|
| 181 | |
---|
| 182 | mutable QMutex m_mutex; |
---|
| 183 | Poppler::Document* m_document; |
---|
| 184 | |
---|
| 185 | }; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | class PdfSettingsWidget : public SettingsWidget |
---|
| 189 | { |
---|
| 190 | Q_OBJECT |
---|
| 191 | |
---|
| 192 | public: |
---|
| 193 | PdfSettingsWidget(QSettings* settings, QWidget* parent = 0); |
---|
| 194 | |
---|
| 195 | void accept(); |
---|
| 196 | void reset(); |
---|
| 197 | |
---|
| 198 | private: |
---|
| 199 | Q_DISABLE_COPY(PdfSettingsWidget) |
---|
| 200 | |
---|
| 201 | QSettings* m_settings; |
---|
| 202 | |
---|
| 203 | QFormLayout* m_layout; |
---|
| 204 | |
---|
| 205 | QCheckBox* m_antialiasingCheckBox; |
---|
| 206 | QCheckBox* m_textAntialiasingCheckBox; |
---|
| 207 | |
---|
| 208 | #ifdef HAS_POPPLER_18 |
---|
| 209 | |
---|
| 210 | QComboBox* m_textHintingComboBox; |
---|
| 211 | |
---|
| 212 | #else |
---|
| 213 | |
---|
| 214 | QCheckBox* m_textHintingCheckBox; |
---|
| 215 | |
---|
| 216 | #endif // HAS_POPPLER_18 |
---|
| 217 | |
---|
| 218 | #ifdef HAS_POPPLER_35 |
---|
| 219 | |
---|
| 220 | QCheckBox* m_ignorePaperColorCheckBox; |
---|
| 221 | |
---|
| 222 | #endif // HAS_POPPLER_35 |
---|
| 223 | |
---|
| 224 | #ifdef HAS_POPPLER_22 |
---|
| 225 | |
---|
| 226 | QCheckBox* m_overprintPreviewCheckBox; |
---|
| 227 | |
---|
| 228 | #endif // HAS_POPPLER_22 |
---|
| 229 | |
---|
| 230 | #ifdef HAS_POPPLER_24 |
---|
| 231 | |
---|
| 232 | QComboBox* m_thinLineModeComboBox; |
---|
| 233 | |
---|
| 234 | #endif // HAS_POPPLER_24 |
---|
| 235 | |
---|
| 236 | QComboBox* m_backendComboBox; |
---|
| 237 | |
---|
| 238 | }; |
---|
| 239 | |
---|
| 240 | class PdfPlugin : public QObject, Plugin |
---|
| 241 | { |
---|
| 242 | Q_OBJECT |
---|
| 243 | Q_INTERFACES(qpdfview::Plugin) |
---|
| 244 | |
---|
| 245 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) |
---|
| 246 | |
---|
| 247 | Q_PLUGIN_METADATA(IID "local.qpdfview.Plugin") |
---|
| 248 | |
---|
| 249 | #endif // QT_VERSION |
---|
| 250 | |
---|
| 251 | public: |
---|
| 252 | PdfPlugin(QObject* parent = 0); |
---|
| 253 | |
---|
| 254 | Model::Document* loadDocument(const QString& filePath) const; |
---|
| 255 | |
---|
| 256 | SettingsWidget* createSettingsWidget(QWidget* parent) const; |
---|
| 257 | |
---|
| 258 | private: |
---|
| 259 | Q_DISABLE_COPY(PdfPlugin) |
---|
| 260 | |
---|
| 261 | QSettings* m_settings; |
---|
| 262 | |
---|
| 263 | }; |
---|
| 264 | |
---|
| 265 | } // qpdfview |
---|
| 266 | |
---|
| 267 | #endif // PDFMODEL_H |
---|