Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpdfselection_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKPDFSELECTION_P_H
5#define QQUICKPDFSELECTION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
19#include <QtPdfQuick/private/qquickpdfdocument_p.h>
20
21#include <QtCore/QPointF>
22#include <QtCore/QVariant>
23#include <QtGui/QPolygonF>
24#include <QtQml/QQmlEngine>
25#include <QtQuick/QQuickItem>
26
27QT_BEGIN_NAMESPACE
28class QPdfSelection;
29
30class Q_PDFQUICK_EXPORT QQuickPdfSelection : public QQuickItem
31{
32 Q_OBJECT
33 Q_PROPERTY(QQuickPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged)
34 Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged)
35 Q_PROPERTY(qreal renderScale READ renderScale WRITE setRenderScale NOTIFY renderScaleChanged)
36 Q_PROPERTY(QPointF from READ from WRITE setFrom NOTIFY fromChanged)
37 Q_PROPERTY(QPointF to READ to WRITE setTo NOTIFY toChanged)
38 Q_PROPERTY(bool hold READ hold WRITE setHold NOTIFY holdChanged)
39
40 Q_PROPERTY(QString text READ text NOTIFY textChanged)
41 Q_PROPERTY(QList<QPolygonF> geometry READ geometry NOTIFY selectedAreaChanged)
42 QML_NAMED_ELEMENT(PdfSelection)
43 QML_ADDED_IN_VERSION(5, 15)
44
45public:
46 explicit QQuickPdfSelection(QQuickItem *parent = nullptr);
47 ~QQuickPdfSelection() override;
48
49 QQuickPdfDocument *document() const;
50 void setDocument(QQuickPdfDocument * document);
51 int page() const;
52 void setPage(int page);
53 qreal renderScale() const;
54 void setRenderScale(qreal scale);
55 QPointF from() const;
56 void setFrom(QPointF from);
57 QPointF to() const;
58 void setTo(QPointF to);
59 bool hold() const;
60 void setHold(bool hold);
61
62 QString text() const;
63 QList<QPolygonF> geometry() const;
64
65 Q_INVOKABLE void clear();
66 Q_INVOKABLE void selectAll();
67#if QT_CONFIG(clipboard)
68 Q_INVOKABLE void copyToClipboard() const;
69#endif
70
71signals:
72 void documentChanged();
73 void pageChanged();
74 void renderScaleChanged();
75 void fromChanged();
76 void toChanged();
77 void holdChanged();
78 void textChanged();
79 void selectedAreaChanged();
80
81protected:
82#if QT_CONFIG(im)
83 void keyReleaseEvent(QKeyEvent *ev) override;
84 void inputMethodEvent(QInputMethodEvent *event) override;
85 Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
86 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
87#endif
88
89private:
90 void resetPoints();
91 void updateResults();
92 void update(const QPdfSelection &sel, bool textAndGeometryOnly = false);
93 const QString &pageText() const;
94
95private:
96 QQuickPdfDocument *m_document = nullptr;
97 mutable QPointF m_hitPoint;
98 QPointF m_from;
99 mutable QPointF m_to;
100 qreal m_renderScale = 1;
101 mutable qreal m_heightAtAnchor = 0;
102 mutable qreal m_heightAtCursor = 0;
103 QString m_text; // selected text
104 mutable QString m_pageText; // all text on the page
105 QList<QPolygonF> m_geometry;
106 int m_page = 0;
107 int m_fromCharIndex = -1; // same as anchor position
108 mutable int m_toCharIndex = -1; // same as cursor position
109 bool m_hold = false;
110 mutable bool m_pageTextDirty = true;
111
112 Q_DISABLE_COPY(QQuickPdfSelection)
113};
114
115QT_END_NAMESPACE
116
117QML_DECLARE_TYPE(QQuickPdfSelection)
118
119#endif // QQUICKPDFSELECTION_P_H