1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2020 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtPDF module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL3$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or later as published by the Free 28 ** Software Foundation and appearing in the file LICENSE.GPL included in 29 ** the packaging of this file. Please review the following information to 30 ** ensure the GNU General Public License version 2.0 requirements will be 31 ** met: http://www.gnu.org/licenses/gpl-2.0.html. 32 ** 33 ** $QT_END_LICENSE$ 34 ** 35 ****************************************************************************/ 36 37 #ifndef QQUICKPDFSELECTION_P_H 38 #define QQUICKPDFSELECTION_P_H 39 40 // 41 // W A R N I N G 42 // ------------- 43 // 44 // This file is not part of the Qt API. It exists purely as an 45 // implementation detail. This header file may change from version to 46 // version without notice, or even be removed. 47 // 48 // We mean it. 49 // 50 51 #include <QPointF> 52 #include <QPolygonF> 53 #include <QVariant> 54 #include <QtQml/qqml.h> 55 #include <QtQuick/qquickitem.h> 56 57 QT_BEGIN_NAMESPACE 58 59 class QPdfSelection; 60 class QQuickPdfDocument; 61 62 class QQuickPdfSelection : public QQuickItem 63 { 64 Q_OBJECT 65 Q_PROPERTY(QQuickPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged) 66 Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged) 67 Q_PROPERTY(qreal renderScale READ renderScale WRITE setRenderScale NOTIFY renderScaleChanged) 68 Q_PROPERTY(QPointF fromPoint READ fromPoint WRITE setFromPoint NOTIFY fromPointChanged) 69 Q_PROPERTY(QPointF toPoint READ toPoint WRITE setToPoint NOTIFY toPointChanged) 70 Q_PROPERTY(bool hold READ hold WRITE setHold NOTIFY holdChanged) 71 72 Q_PROPERTY(QString text READ text NOTIFY textChanged) 73 Q_PROPERTY(QVector<QPolygonF> geometry READ geometry NOTIFY selectedAreaChanged) 74 75 public: 76 explicit QQuickPdfSelection(QQuickItem *parent = nullptr); 77 78 QQuickPdfDocument *document() const; 79 void setDocument(QQuickPdfDocument * document); 80 int page() const; 81 void setPage(int page); 82 qreal renderScale() const; 83 void setRenderScale(qreal scale); 84 QPointF fromPoint() const; 85 void setFromPoint(QPointF fromPoint); 86 QPointF toPoint() const; 87 void setToPoint(QPointF toPoint); 88 bool hold() const; 89 void setHold(bool hold); 90 91 QString text() const; 92 QVector<QPolygonF> geometry() const; 93 94 Q_INVOKABLE void clear(); 95 Q_INVOKABLE void selectAll(); 96 #if QT_CONFIG(clipboard) 97 Q_INVOKABLE void copyToClipboard() const; 98 #endif 99 100 signals: 101 void documentChanged(); 102 void pageChanged(); 103 void renderScaleChanged(); 104 void fromPointChanged(); 105 void toPointChanged(); 106 void holdChanged(); 107 void textChanged(); 108 void selectedAreaChanged(); 109 110 protected: 111 #if QT_CONFIG(im) 112 void keyReleaseEvent(QKeyEvent *ev) override; 113 void inputMethodEvent(QInputMethodEvent *event) override; 114 Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const; 115 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; 116 #endif 117 118 private: 119 void resetPoints(); 120 void updateResults(); 121 void update(const QPdfSelection &sel, bool textAndGeometryOnly = false); 122 const QString &pageText() const; 123 124 private: 125 QQuickPdfDocument *m_document = nullptr; 126 mutable QPointF m_hitPoint; 127 QPointF m_fromPoint; 128 mutable QPointF m_toPoint; 129 qreal m_renderScale = 1; 130 mutable qreal m_heightAtAnchor = 0; 131 mutable qreal m_heightAtCursor = 0; 132 QString m_text; // selected text 133 mutable QString m_pageText; // all text on the page 134 QVector<QPolygonF> m_geometry; 135 int m_page = 0; 136 int m_fromCharIndex = -1; // same as anchor position 137 mutable int m_toCharIndex = -1; // same as cursor position 138 bool m_hold = false; 139 mutable bool m_pageTextDirty = true; 140 141 Q_DISABLE_COPY(QQuickPdfSelection) 142 }; 143 144 QT_END_NAMESPACE 145 146 QML_DECLARE_TYPE(QQuickPdfSelection) 147 148 #endif // QQUICKPDFSELECTION_P_H 149