bool Text::isOverSelection(QPointF scenePos) const { int cur = cursorFromPos(scenePos); if (getSelectionStart() < cur && getSelectionEnd() >= cur) return true; return false; }
void Text::selectionStarted(QPointF scenePos) { int cur = cursorFromPos(scenePos); if (cur >= 0) { selectionEnd = cur; selectionAnchor = cur; } }
void Text::selectionMouseMove(QPointF scenePos) { if (!doc) return; int cur = cursorFromPos(scenePos); if (cur >= 0) { selectionEnd = cur; selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd()); } update(); }
void Text::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { if (!doc) return; QString anchor = doc->documentLayout()->anchorAt(event->pos()); if (anchor.isEmpty()) setCursor(Qt::IBeamCursor); else setCursor(Qt::PointingHandCursor); // tooltip setToolTip(extractImgTooltip(cursorFromPos(event->scenePos(), false))); }
void Text::selectionDoubleClick(QPointF scenePos) { if (!doc) return; int cur = cursorFromPos(scenePos); if (cur >= 0) { QTextCursor cursor(doc); cursor.setPosition(cur); cursor.select(QTextCursor::WordUnderCursor); selectionAnchor = cursor.selectionStart(); selectionEnd = cursor.selectionEnd(); selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd()); } update(); }
void Text::selectionTripleClick(QPointF scenePos) { if (!doc) return; int cur = cursorFromPos(scenePos); if (cur >= 0) { QTextCursor cursor(doc); cursor.setPosition(cur); cursor.select(QTextCursor::BlockUnderCursor); selectionAnchor = cursor.selectionStart(); selectionEnd = cursor.selectionEnd(); if (cursor.block().isValid() && cursor.block().blockNumber() != 0) selectionAnchor++; selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd()); } update(); }
/** * @brief Extracts the target of a link from the text at a given coordinate * @param scenePos Position in scene coordinates * @return The link target URL, or an empty string if there is no link there */ QString Text::getLinkAt(QPointF scenePos) const { QTextCursor cursor(doc); cursor.setPosition(cursorFromPos(scenePos)); return cursor.charFormat().anchorHref(); }