double click word selection handle, sigint sermentation fault fix

This commit is contained in:
Blue 2022-05-03 12:17:08 +03:00
parent 3c48577eee
commit 1f065f23e6
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 73 additions and 5 deletions

View file

@ -434,6 +434,39 @@ void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, c
}
}
QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint)
{
QVariant vi = index.data(Models::MessageFeed::Bulk);
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
if (data.text.size() > 0) {
QRect localHint = getHoveredMessageBodyRect(index, data, sizeHint);
if (localHint.contains(point)) {
QPoint translated = point - localHint.topLeft();
bodyRenderer->setHtml(Shared::processMessageBody(data.text));
bodyRenderer->setTextWidth(localHint.size().width());
QAbstractTextDocumentLayout* lay = bodyRenderer->documentLayout();
int position = lay->hitTest(translated, Qt::HitTestAccuracy::FuzzyHit);
QTextCursor cursor(bodyRenderer);
cursor.setPosition(position, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
selection.first = cursor.anchor();
selection.second = cursor.position();
currentId = data.id;
if (selection.first != selection.second) {
return cursor.selectedText();
}
}
}
return "";
}
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
{
QVariant vi = index.data(Models::MessageFeed::Bulk);
@ -454,10 +487,9 @@ Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex&
return Shared::Hover::anchor;
} else {
int position = lay->hitTest(translated, Qt::HitTestAccuracy::ExactHit);
if (position != -1) { //this is a bad way, it's false positive on the end of the last
return Shared::Hover::text; //line of a multiline block, so it's not better the checking the rect
if (position != -1) {
return Shared::Hover::text;
}
//return Shared::Hover::text;
}
}
}
@ -480,7 +512,6 @@ QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const
last.setY(std::max(last.y(), 0));
last.setY(std::min(last.y(), localHint.height()));
bodyRenderer->setHtml(Shared::processMessageBody(data.text));
bodyRenderer->setTextWidth(localHint.size().width());
selection.first = bodyRenderer->documentLayout()->hitTest(first, Qt::HitTestAccuracy::FuzzyHit);