// Return the offset of the character at the given screen coordinates. int QsciAccessibleScintillaBase::offsetAtPoint(const QPoint &point) const { QsciScintillaBase *sb = sciWidget(); QPoint p = sb->viewport()->mapFromGlobal(point); int position = sb->SendScintilla(QsciScintillaBase::SCI_POSITIONFROMPOINT, p.x(), p.y()); return (position >= 0) ? positionAsOffset(sb, position) : -1; }
QRect QsciAccessibleScintillaBase::characterRect(int offset) const { QsciScintillaBase *sb = sciWidget(); int position = offsetAsPosition(sb, offset); int x_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTXFROMPOSITION, position); int y_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTYFROMPOSITION, position); const QString ch = text(offset, offset + 1); // Get the character's font metrics. int style = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT, position); QFontMetrics metrics(fontForStyle(style)); QRect rect(x_vport, y_vport, metrics.width(ch), metrics.height()); rect.moveTo(sb->viewport()->mapToGlobal(rect.topLeft())); return rect; }