qint16 ChatItem::posToCursor(const QPointF &posInLine) const { QPointF pos = mapFromLine(posInLine); if (pos.y() > height()) return document()->characterCount()-1; if (pos.y() < 0) return 0; int found = document()->documentLayout()->hitTest(pos, Qt::FuzzyHit); if(found < 0) return 0; return found; }
qint16 ChatItem::posToCursor(const QPointF &posInLine) const { QPointF pos = mapFromLine(posInLine); if(pos.y() > height()) return data(MessageModel::DisplayRole).toString().length(); if(pos.y() < 0) return 0; for(int l = layout()->lineCount() - 1; l >= 0; l--) { QTextLine line = layout()->lineAt(l); if(pos.y() >= line.y()) { return line.xToCursor(pos.x(), QTextLine::CursorOnCharacter); } } return 0; }