QPlainTextEditControl: reimplement anchorAt()

See comments in QPlainTextDocumentLayout::hitTest(). Since
QPlainTextEdit does not do hit testing on the document layout
level, allow QPlainTextEditControl to override anchorAt() so
that hit testing can be done on the widget level instead.

Change-Id: I70247eafae96897382a0c7db7d596128a03e7a6c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
J-P Nurmi 2015-01-10 12:45:15 +01:00
parent 7414c2c404
commit b26dc9bc05
3 changed files with 6 additions and 1 deletions

View File

@ -604,6 +604,10 @@ QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const {
return r;
}
QString QPlainTextEditControl::anchorAt(const QPointF &pos) const
{
return textEdit->anchorAt(pos.toPoint());
}
void QPlainTextEditPrivate::setTopLine(int visualTopLine, int dx)
{

View File

@ -77,6 +77,7 @@ public:
void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE;
int hitTest(const QPointF &point, Qt::HitTestAccuracy = Qt::FuzzyHit) const Q_DECL_OVERRIDE;
QRectF blockBoundingRect(const QTextBlock &block) const Q_DECL_OVERRIDE;
QString anchorAt(const QPointF &pos) const Q_DECL_OVERRIDE;
inline QRectF cursorRect(const QTextCursor &cursor) const {
QRectF r = QWidgetTextControl::cursorRect(cursor);
r.setLeft(qMax(r.left(), (qreal) 0.));

View File

@ -124,7 +124,7 @@ public:
QRectF selectionRect(const QTextCursor &cursor) const;
QRectF selectionRect() const;
QString anchorAt(const QPointF &pos) const;
virtual QString anchorAt(const QPointF &pos) const;
QPointF anchorPosition(const QString &name) const;
QString anchorAtCursor() const;