1 /* 2 SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef QPAGEITEM_H 8 #define QPAGEITEM_H 9 10 #include <QImage> 11 #include <QPointer> 12 #include <QQuickItem> 13 14 #include <core/document.h> 15 #include <core/view.h> 16 17 class QTimer; 18 19 class DocumentItem; 20 21 namespace Okular 22 { 23 class Document; 24 class Page; 25 } 26 27 class PageItem : public QQuickItem, public Okular::View 28 { 29 Q_OBJECT 30 31 /** 32 * If this page is in a Flickable, assign it in this property, to make goToBookmark work 33 */ 34 Q_PROPERTY(QQuickItem *flickable READ flickable WRITE setFlickable NOTIFY flickableChanged) 35 36 /** 37 * The document this page belongs to 38 */ 39 Q_PROPERTY(DocumentItem *document READ document WRITE setDocument NOTIFY documentChanged) 40 41 /** 42 * The currently displayed page 43 */ 44 Q_PROPERTY(int pageNumber READ pageNumber WRITE setPageNumber NOTIFY pageNumberChanged) 45 46 /** 47 * If true, the page will be rendered with antialias 48 */ 49 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) 50 51 /** 52 * "Natural" width of the page 53 */ 54 Q_PROPERTY(int implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) 55 56 /** 57 * "Natural" height of the page 58 */ 59 Q_PROPERTY(int implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) 60 61 /** 62 * True if the page contains at least a bookmark. 63 * Writing true to tis property idds a bookmark at the beginning of the page (if needed). 64 * Writing false, all bookmarks for this page will be removed 65 */ 66 Q_PROPERTY(bool bookmarked READ isBookmarked WRITE setBookmarked NOTIFY bookmarkedChanged) 67 68 /** 69 * list of bookmarks urls valid on this page 70 */ 71 Q_PROPERTY(QStringList bookmarks READ bookmarks NOTIFY bookmarksChanged) 72 73 public: 74 explicit PageItem(QQuickItem *parent = nullptr); 75 ~PageItem() override; 76 77 void setFlickable(QQuickItem *flickable); 78 QQuickItem *flickable() const; 79 80 int implicitWidth() const; 81 int implicitHeight() const; 82 83 DocumentItem *document() const; 84 void setDocument(DocumentItem *doc); 85 86 int pageNumber() const; 87 void setPageNumber(int number); 88 89 bool smooth() const; 90 void setSmooth(bool smooth); 91 92 bool isBookmarked(); 93 void setBookmarked(bool bookmarked); 94 95 QStringList bookmarks() const; 96 void requestPixmap(); 97 98 /** 99 * loads a page bookmark and tries to ensure the bookmarked position is visible 100 * @param bookmark Url for the bookmark 101 */ 102 Q_INVOKABLE void goToBookmark(const QString &bookmark); 103 104 /** 105 * Returns the position in the page for a bookmark 106 * QPointF(-1,-1) if doesn't belong to this page 107 * 108 * @param bookmark Url for the bookmark 109 */ 110 Q_INVOKABLE QPointF bookmarkPosition(const QString &bookmark) const; 111 112 /** 113 * Add a new bookmark ar a given position of the current page 114 */ 115 Q_INVOKABLE void setBookmarkAtPos(qreal x, qreal y); 116 117 /** 118 * Remove a bookmark ar a given position of the current page (if present) 119 */ 120 Q_INVOKABLE void removeBookmarkAtPos(qreal x, qreal y); 121 122 /** 123 * Remove a bookmark at a given position, if any 124 */ 125 Q_INVOKABLE void removeBookmark(const QString &bookmark); 126 127 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; 128 129 QSGNode *updatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *) override; 130 131 Q_SIGNALS: 132 void flickableChanged(); 133 void implicitWidthChanged(); 134 void implicitHeightChanged(); 135 void documentChanged(); 136 void pageNumberChanged(); 137 void bookmarkedChanged(); 138 void bookmarksChanged(); 139 140 protected: 141 void setIsThumbnail(bool thumbnail); 142 143 private Q_SLOTS: 144 void pageHasChanged(int page, int flags); 145 void checkBookmarksChanged(); 146 void contentXChanged(); 147 void contentYChanged(); 148 149 private: 150 void paint(); 151 void refreshPage(); 152 153 const Okular::Page *m_page; 154 bool m_smooth; 155 bool m_bookmarked; 156 bool m_isThumbnail; 157 QPointer<DocumentItem> m_documentItem; 158 QTimer *m_redrawTimer; 159 QPointer<QQuickItem> m_flickable; 160 Okular::DocumentViewport m_viewPort; 161 QImage m_buffer; 162 }; 163 164 #endif 165