[1f4adec] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2013 Adam Reichold |
---|
| 4 | Copyright 2013 Alexander Volkov |
---|
| 5 | |
---|
| 6 | This file is part of qpdfview. |
---|
| 7 | |
---|
| 8 | The implementation is based on KDjVu by Pino Toscano. |
---|
| 9 | |
---|
| 10 | qpdfview is free software: you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation, either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | qpdfview is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License |
---|
| 21 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
| 22 | |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef DJVUMODEL_H |
---|
| 26 | #define DJVUMODEL_H |
---|
| 27 | |
---|
| 28 | #include <QHash> |
---|
| 29 | #include <QMutex> |
---|
| 30 | |
---|
| 31 | typedef struct ddjvu_context_s ddjvu_context_t; |
---|
| 32 | typedef struct ddjvu_format_s ddjvu_format_t; |
---|
| 33 | typedef struct ddjvu_document_s ddjvu_document_t; |
---|
| 34 | typedef struct ddjvu_pageinfo_s ddjvu_pageinfo_t; |
---|
| 35 | |
---|
| 36 | #include "model.h" |
---|
| 37 | |
---|
| 38 | namespace qpdfview |
---|
| 39 | { |
---|
| 40 | |
---|
| 41 | class DjVuPlugin; |
---|
| 42 | |
---|
| 43 | namespace Model |
---|
| 44 | { |
---|
| 45 | class DjVuPage : public Page |
---|
| 46 | { |
---|
| 47 | friend class DjVuDocument; |
---|
| 48 | |
---|
| 49 | public: |
---|
| 50 | ~DjVuPage(); |
---|
| 51 | |
---|
| 52 | QSizeF size() const; |
---|
| 53 | |
---|
| 54 | QImage render(qreal horizontalResolution, qreal verticalResolution, Rotation rotation, const QRect& boundingRect) const; |
---|
| 55 | |
---|
| 56 | QList< Link* > links() const; |
---|
| 57 | |
---|
| 58 | QString text(const QRectF& rect) const; |
---|
| 59 | |
---|
| 60 | QList< QRectF > search(const QString& text, bool matchCase, bool wholeWords) const; |
---|
| 61 | |
---|
| 62 | private: |
---|
| 63 | Q_DISABLE_COPY(DjVuPage) |
---|
| 64 | |
---|
| 65 | DjVuPage(const class DjVuDocument* parent, int index, const ddjvu_pageinfo_t& pageinfo); |
---|
| 66 | |
---|
| 67 | const class DjVuDocument* m_parent; |
---|
| 68 | |
---|
| 69 | int m_index; |
---|
| 70 | QSizeF m_size; |
---|
| 71 | int m_resolution; |
---|
| 72 | |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | class DjVuDocument : public Document |
---|
| 76 | { |
---|
| 77 | friend class DjVuPage; |
---|
| 78 | friend class qpdfview::DjVuPlugin; |
---|
| 79 | |
---|
| 80 | public: |
---|
| 81 | ~DjVuDocument(); |
---|
| 82 | |
---|
| 83 | int numberOfPages() const; |
---|
| 84 | |
---|
| 85 | Page* page(int index) const; |
---|
| 86 | |
---|
| 87 | QStringList saveFilter() const; |
---|
| 88 | |
---|
| 89 | bool canSave() const; |
---|
| 90 | bool save(const QString& filePath, bool withChanges) const; |
---|
| 91 | |
---|
| 92 | void loadOutline(QStandardItemModel* outlineModel) const; |
---|
| 93 | void loadProperties(QStandardItemModel* propertiesModel) const; |
---|
| 94 | |
---|
| 95 | private: |
---|
| 96 | Q_DISABLE_COPY(DjVuDocument) |
---|
| 97 | |
---|
| 98 | DjVuDocument(QMutex* globalMutex, ddjvu_context_t* context, ddjvu_document_t* document); |
---|
| 99 | |
---|
| 100 | mutable QMutex m_mutex; |
---|
| 101 | mutable QMutex* m_globalMutex; |
---|
| 102 | |
---|
| 103 | ddjvu_context_t* m_context; |
---|
| 104 | ddjvu_document_t* m_document; |
---|
| 105 | ddjvu_format_t* m_format; |
---|
| 106 | |
---|
| 107 | QHash< QString, int > m_indexByName; |
---|
| 108 | |
---|
| 109 | void prepareIndexByName(); |
---|
| 110 | |
---|
| 111 | }; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | class DjVuPlugin : public QObject, Plugin |
---|
| 115 | { |
---|
| 116 | Q_OBJECT |
---|
| 117 | Q_INTERFACES(qpdfview::Plugin) |
---|
| 118 | |
---|
| 119 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) |
---|
| 120 | |
---|
| 121 | Q_PLUGIN_METADATA(IID "local.qpdfview.Plugin") |
---|
| 122 | |
---|
| 123 | #endif // QT_VERSION |
---|
| 124 | |
---|
| 125 | public: |
---|
| 126 | DjVuPlugin(QObject* parent = 0); |
---|
| 127 | |
---|
| 128 | Model::Document* loadDocument(const QString& filePath) const; |
---|
| 129 | |
---|
| 130 | private: |
---|
| 131 | mutable QMutex m_globalMutex; |
---|
| 132 | |
---|
| 133 | }; |
---|
| 134 | |
---|
| 135 | } // qpdfview |
---|
| 136 | |
---|
| 137 | #endif // DJVUMODEL_H |
---|