File indexing completed on 2024-05-12 16:06:54
0001 /* 0002 SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef QPAGEITEM_H 0008 #define QPAGEITEM_H 0009 0010 #include <QImage> 0011 #include <QPointer> 0012 #include <QQuickItem> 0013 0014 #include <core/document.h> 0015 #include <core/view.h> 0016 0017 class QTimer; 0018 0019 class DocumentItem; 0020 0021 namespace Okular 0022 { 0023 class Document; 0024 class Page; 0025 } 0026 0027 class PageItem : public QQuickItem, public Okular::View 0028 { 0029 Q_OBJECT 0030 0031 /** 0032 * If this page is in a Flickable, assign it in this property, to make goToBookmark work 0033 */ 0034 Q_PROPERTY(QQuickItem *flickable READ flickable WRITE setFlickable NOTIFY flickableChanged) 0035 0036 /** 0037 * The document this page belongs to 0038 */ 0039 Q_PROPERTY(DocumentItem *document READ document WRITE setDocument NOTIFY documentChanged) 0040 0041 /** 0042 * The currently displayed page 0043 */ 0044 Q_PROPERTY(int pageNumber READ pageNumber WRITE setPageNumber NOTIFY pageNumberChanged) 0045 0046 /** 0047 * "Natural" width of the page 0048 */ 0049 Q_PROPERTY(int implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) 0050 0051 /** 0052 * "Natural" height of the page 0053 */ 0054 Q_PROPERTY(int implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) 0055 0056 /** 0057 * True if the page contains at least a bookmark. 0058 * Writing true to tis property idds a bookmark at the beginning of the page (if needed). 0059 * Writing false, all bookmarks for this page will be removed 0060 */ 0061 Q_PROPERTY(bool bookmarked READ isBookmarked WRITE setBookmarked NOTIFY bookmarkedChanged) 0062 0063 /** 0064 * list of bookmarks urls valid on this page 0065 */ 0066 Q_PROPERTY(QStringList bookmarks READ bookmarks NOTIFY bookmarksChanged) 0067 0068 public: 0069 explicit PageItem(QQuickItem *parent = nullptr); 0070 ~PageItem() override; 0071 0072 void setFlickable(QQuickItem *flickable); 0073 QQuickItem *flickable() const; 0074 0075 int implicitWidth() const; 0076 int implicitHeight() const; 0077 0078 DocumentItem *document() const; 0079 void setDocument(DocumentItem *doc); 0080 0081 int pageNumber() const; 0082 void setPageNumber(int number); 0083 0084 bool isBookmarked(); 0085 void setBookmarked(bool bookmarked); 0086 0087 QStringList bookmarks() const; 0088 void requestPixmap(); 0089 0090 /** 0091 * loads a page bookmark and tries to ensure the bookmarked position is visible 0092 * @param bookmark Url for the bookmark 0093 */ 0094 Q_INVOKABLE void goToBookmark(const QString &bookmark); 0095 0096 /** 0097 * Returns the position in the page for a bookmark 0098 * QPointF(-1,-1) if doesn't belong to this page 0099 * 0100 * @param bookmark Url for the bookmark 0101 */ 0102 Q_INVOKABLE QPointF bookmarkPosition(const QString &bookmark) const; 0103 0104 /** 0105 * Add a new bookmark ar a given position of the current page 0106 */ 0107 Q_INVOKABLE void setBookmarkAtPos(qreal x, qreal y); 0108 0109 /** 0110 * Remove a bookmark ar a given position of the current page (if present) 0111 */ 0112 Q_INVOKABLE void removeBookmarkAtPos(qreal x, qreal y); 0113 0114 /** 0115 * Remove a bookmark at a given position, if any 0116 */ 0117 Q_INVOKABLE void removeBookmark(const QString &bookmark); 0118 0119 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; 0120 0121 QSGNode *updatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *) override; 0122 0123 Q_SIGNALS: 0124 void flickableChanged(); 0125 void documentChanged(); 0126 void pageNumberChanged(); 0127 void bookmarkedChanged(); 0128 void bookmarksChanged(); 0129 0130 protected: 0131 void setIsThumbnail(bool thumbnail); 0132 0133 private Q_SLOTS: 0134 void pageHasChanged(int page, int flags); 0135 void checkBookmarksChanged(); 0136 void contentXChanged(); 0137 void contentYChanged(); 0138 0139 private: 0140 void paint(); 0141 void refreshPage(); 0142 0143 const Okular::Page *m_page; 0144 bool m_bookmarked; 0145 bool m_isThumbnail; 0146 QPointer<DocumentItem> m_documentItem; 0147 QTimer *m_redrawTimer; 0148 QPointer<QQuickItem> m_flickable; 0149 Okular::DocumentViewport m_viewPort; 0150 QImage m_buffer; 0151 }; 0152 0153 #endif