forked from blue/squawk
selection message body now actually working
This commit is contained in:
parent
0340db7f2f
commit
3c48577eee
7 changed files with 138 additions and 40 deletions
|
@ -434,13 +434,37 @@ void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, c
|
|||
}
|
||||
}
|
||||
|
||||
bool MessageDelegate::isAnchorHovered(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
{
|
||||
QString anchor = getAnchor(point, index, sizeHint);
|
||||
return anchor.size() > 0;
|
||||
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();
|
||||
QString anchor = lay->anchorAt(translated);
|
||||
|
||||
if (anchor.size() > 0) {
|
||||
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
|
||||
}
|
||||
//return Shared::Hover::text;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Shared::Hover::nothing;
|
||||
}
|
||||
|
||||
bool MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint)
|
||||
QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint)
|
||||
{
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
|
@ -448,19 +472,31 @@ bool MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QM
|
|||
QRect localHint = getHoveredMessageBodyRect(index, data, sizeHint);
|
||||
|
||||
if (localHint.contains(start)) {
|
||||
QPoint translated = start - localHint.topLeft();
|
||||
QPoint tl = localHint.topLeft();
|
||||
QPoint first = start - tl;
|
||||
QPoint last = end - tl;
|
||||
last.setX(std::max(last.x(), 0));
|
||||
last.setX(std::min(last.x(), localHint.width() - 1));
|
||||
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(translated, Qt::HitTestAccuracy::FuzzyHit);
|
||||
selection.second = bodyRenderer->documentLayout()->hitTest(end - localHint.topLeft(), Qt::HitTestAccuracy::FuzzyHit);
|
||||
selection.first = bodyRenderer->documentLayout()->hitTest(first, Qt::HitTestAccuracy::FuzzyHit);
|
||||
selection.second = bodyRenderer->documentLayout()->hitTest(last, Qt::HitTestAccuracy::FuzzyHit);
|
||||
|
||||
currentId = data.id;
|
||||
|
||||
return true;
|
||||
if (selection.first != selection.second) {
|
||||
QTextCursor cursor(bodyRenderer);
|
||||
cursor.setPosition(selection.first, QTextCursor::MoveAnchor);
|
||||
cursor.setPosition(selection.second, QTextCursor::KeepAnchor);
|
||||
return cursor.selectedText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
|
||||
QString MessageDelegate::clearSelection()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue