summaryrefslogtreecommitdiffstats
path: root/src/pdfquick/qquickpdfselection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdfquick/qquickpdfselection.cpp')
-rw-r--r--src/pdfquick/qquickpdfselection.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/pdfquick/qquickpdfselection.cpp b/src/pdfquick/qquickpdfselection.cpp
index c414e7ecf..4776cb8b4 100644
--- a/src/pdfquick/qquickpdfselection.cpp
+++ b/src/pdfquick/qquickpdfselection.cpp
@@ -46,8 +46,6 @@ QQuickPdfSelection::QQuickPdfSelection(QQuickItem *parent)
{
#if QT_CONFIG(im)
setFlags(ItemIsFocusScope | ItemAcceptsInputMethod);
- // workaround to get Copy instead of Paste on the popover menu (QTBUG-83811)
- setProperty("qt_im_readonly", QVariant(true));
#endif
}
@@ -151,6 +149,8 @@ void QQuickPdfSelection::clear()
*/
void QQuickPdfSelection::selectAll()
{
+ if (!m_document)
+ return;
QPdfSelection sel = m_document->document()->getAllText(m_page);
if (sel.text() != m_text) {
m_text = sel.text();
@@ -184,21 +184,25 @@ void QQuickPdfSelection::keyReleaseEvent(QKeyEvent *ev)
qCDebug(qLcIm) << "release" << ev;
const auto &allText = pageText();
if (ev == QKeySequence::MoveToPreviousWord) {
+ if (!m_document)
+ return;
// iOS sends MoveToPreviousWord first to get to the beginning of the word,
// and then SelectNextWord to select the whole word.
- int i = allText.lastIndexOf(WordDelimiter, m_fromCharIndex - allText.length());
+ int i = allText.lastIndexOf(WordDelimiter, m_fromCharIndex - allText.size());
if (i < 0)
i = 0;
else
i += 1; // don't select the space before the word
- auto sel = m_document->document()->getSelectionAtIndex(m_page, i, m_text.length() + m_fromCharIndex - i);
+ auto sel = m_document->document()->getSelectionAtIndex(m_page, i, m_text.size() + m_fromCharIndex - i);
update(sel);
QGuiApplication::inputMethod()->update(Qt::ImAnchorRectangle);
} else if (ev == QKeySequence::SelectNextWord) {
+ if (!m_document)
+ return;
int i = allText.indexOf(WordDelimiter, m_toCharIndex);
if (i < 0)
- i = allText.length(); // go to the end of m_textAfter
- auto sel = m_document->document()->getSelectionAtIndex(m_page, m_fromCharIndex, m_text.length() + i - m_toCharIndex);
+ i = allText.size(); // go to the end of m_textAfter
+ auto sel = m_document->document()->getSelectionAtIndex(m_page, m_fromCharIndex, m_text.size() + i - m_toCharIndex);
update(sel);
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
} else if (ev == QKeySequence::Copy) {
@@ -214,6 +218,8 @@ void QQuickPdfSelection::inputMethodEvent(QInputMethodEvent *event)
qCDebug(qLcIm) << "QInputMethodEvent::Cursor: moved to" << attr.start << "len" << attr.length;
break;
case QInputMethodEvent::Selection: {
+ if (!m_document)
+ return;
auto sel = m_document->document()->getSelectionAtIndex(m_page, attr.start, attr.length);
update(sel);
qCDebug(qLcIm) << "QInputMethodEvent::Selection: from" << attr.start << "len" << attr.length
@@ -235,6 +241,8 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query, const
if (!argument.isNull()) {
qCDebug(qLcIm) << "IM query" << query << "with arg" << argument;
if (query == Qt::ImCursorPosition) {
+ if (!m_document)
+ return {};
// If it didn't move since last time, return the same result.
if (m_hitPoint == argument.toPointF())
return inputMethodQuery(query);
@@ -309,6 +317,7 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
case Qt::ImPlatformData:
break;
case Qt::ImReadOnly:
+ ret = true;
break;
case Qt::ImQueryInput:
case Qt::ImQueryAll:
@@ -323,6 +332,8 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
const QString &QQuickPdfSelection::pageText() const
{
if (m_pageTextDirty) {
+ if (!m_document)
+ return m_pageText;
m_pageText = m_document->document()->getAllText(m_page).text();
m_pageTextDirty = false;
}