7#include <QGuiApplication>
8#include <QLoggingCategory>
11#include <QRegularExpression>
12#include <QStandardPaths>
13#include <QtPdf/private/qpdfdocument_p.h>
48 setFlags(ItemIsFocusScope | ItemAcceptsInputMethod);
74 this, &QQuickPdfSelection::resetPoints);
80 this, &QQuickPdfSelection::resetPoints);
132 m_heightAtAnchor = 0;
133 m_heightAtCursor = 0;
134 m_fromCharIndex = -1;
155 if (sel.text() != m_text) {
162 if (sel.bounds() != m_geometry) {
163 m_geometry = sel.bounds();
167 m_fromCharIndex = sel.startIndex();
168 m_toCharIndex = sel.endIndex();
169 if (sel.bounds().isEmpty()) {
173 m_from = sel.bounds().first().boundingRect().topLeft() * m_renderScale;
174 m_to = sel.bounds().last().boundingRect().bottomRight() * m_renderScale -
QPointF(0, m_heightAtCursor);
184 qCDebug(qLcIm) <<
"release" << ev;
185 const auto &allText = pageText();
191 int i = allText.lastIndexOf(
WordDelimiter, m_fromCharIndex - allText.size());
215 for (
auto attr :
event->attributes()) {
218 qCDebug(qLcIm) <<
"QInputMethodEvent::Cursor: moved to" << attr.start <<
"len" << attr.length;
225 qCDebug(qLcIm) <<
"QInputMethodEvent::Selection: from" << attr.start <<
"len" << attr.length
226 <<
"result:" << m_fromCharIndex <<
"->" << m_toCharIndex << sel.boundingRectangle();
247 if (m_hitPoint ==
argument.toPointF())
248 return inputMethodQuery(
query);
250 auto tp = m_document->document()->d->
hitTest(m_page, m_hitPoint / m_renderScale);
251 qCDebug(qLcIm) <<
"ImCursorPosition hit testing in px" << m_hitPoint <<
"pt" << (m_hitPoint / m_renderScale)
252 <<
"got char index" << tp.charIndex <<
"@" << tp.position <<
"pt," << tp.position * m_renderScale <<
"px";
253 if (tp.charIndex >= 0) {
254 m_toCharIndex = tp.charIndex;
255 m_to = tp.position * m_renderScale -
QPointF(0, m_heightAtCursor);
256 m_heightAtCursor = tp.height * m_renderScale;
258 m_heightAtAnchor = m_heightAtCursor;
262 return inputMethodQuery(
query);
279 ret = m_fromCharIndex;
324 qWarning() <<
"unexpected composite query";
332const QString &QQuickPdfSelection::pageText()
const
334 if (m_pageTextDirty) {
338 m_pageTextDirty =
false;
343void QQuickPdfSelection::resetPoints()
345 bool wasHolding = m_hold;
370 m_pageTextDirty =
true;
385 return m_renderScale;
391 qWarning() <<
"PdfSelection.renderScale cannot be set to 0.";
398 m_renderScale =
scale;
419 if (m_hold || m_from ==
from)
442 if (m_hold || m_to ==
to)
482#if QT_CONFIG(clipboard)
488void QQuickPdfSelection::copyToClipboard()
const
494void QQuickPdfSelection::updateResults()
499 m_from / m_renderScale, m_to / m_renderScale);
505 if (sel.text() != m_text) {
512 if (sel.bounds() != m_geometry) {
513 m_geometry = sel.bounds();
517 if (textAndGeometryOnly)
520 m_fromCharIndex = sel.startIndex();
521 m_toCharIndex = sel.endIndex();
522 if (sel.bounds().isEmpty()) {
523 m_from = sel.boundingRectangle().topLeft() * m_renderScale;
526 Qt::InputMethodQueries toUpdate = {};
527 QRectF firstLineBounds = sel.bounds().first().boundingRect();
528 m_from = firstLineBounds.topLeft() * m_renderScale;
529 if (!
qFuzzyCompare(m_heightAtAnchor, firstLineBounds.height())) {
530 m_heightAtAnchor = firstLineBounds.height() * m_renderScale;
533 QRectF lastLineBounds = sel.bounds().last().boundingRect();
534 if (!
qFuzzyCompare(m_heightAtCursor, lastLineBounds.height())) {
535 m_heightAtCursor = lastLineBounds.height() * m_renderScale;
538 m_to = lastLineBounds.topRight() * m_renderScale;
546#include "moc_qquickpdfselection_p.cpp"
void setPointSizeF(qreal)
Sets the point size to pointSize.
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
static QFont font()
Returns the default application font.
static QInputMethod * inputMethod()
returns the input method.
The QKeyEvent class describes a key event.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
TextPosition hitTest(int page, QPointF position)
Q_INVOKABLE QPdfSelection getAllText(int page)
Returns all the text and its bounds on the given page.
Q_INVOKABLE QPdfSelection getSelectionAtIndex(int page, int startIndex, int maxLength)
Returns information about the text on the given page that can be found beginning at the given startIn...
Q_INVOKABLE QPdfSelection getSelection(int page, QPointF start, QPointF end)
Returns information about the text on the given page that can be found between the given start and en...
The QPdfSelection class defines a range of text that has been selected on one page in a PDF document,...
QString text
This property holds the selected text.
\inmodule QtCore\reentrant
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
qreal scale
\qmlproperty real QtQuick::Item::scale This property holds the scale factor for this item.
void update()
Schedules a call to updatePaintNode() for this item.
void setFrom(QPointF from)
void setDocument(QQuickPdfDocument *document)
Q_INVOKABLE void clear()
\qmlmethod void PdfSelection::clear()
Q_INVOKABLE void selectAll()
\qmlmethod void PdfSelection::selectAll()
void renderScaleChanged()
QList< QPolygonF > geometry
QQuickPdfDocument * document
~QQuickPdfSelection() override
void setRenderScale(qreal scale)
void selectedAreaChanged()
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const noexcept
Returns the number of characters in this string.
Combined button and popup list for selecting options.
@ ImInputItemClipRectangle
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLenum GLenum GLenum GLenum scale
static QT_BEGIN_NAMESPACE const QRegularExpression WordDelimiter(QStringLiteral("\\s"))
#define QStringLiteral(str)
myObject disconnect()
[26]