forked from blue/squawk
double click word selection handle, sigint sermentation fault fix
This commit is contained in:
parent
3c48577eee
commit
1f065f23e6
6 changed files with 73 additions and 5 deletions
|
@ -482,6 +482,7 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
|||
void FeedView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QAbstractItemView::mousePressEvent(event);
|
||||
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
if (mousePressed) {
|
||||
dragStartPoint = event->localPos().toPoint();
|
||||
|
@ -499,6 +500,36 @@ void FeedView::mousePressEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
QAbstractItemView::mouseDoubleClickEvent(event);
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
if (mousePressed) {
|
||||
dragStartPoint = event->localPos().toPoint();
|
||||
if (specialDelegate && specialModel) {
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
QString lastSelectedId = del->clearSelection();
|
||||
selectedText = "";
|
||||
if (lastSelectedId.size()) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
QModelIndex index = feed->modelIndexById(lastSelectedId);
|
||||
if (index.isValid()) {
|
||||
setDirtyRegion(visualRect(index));
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex index = indexAt(dragStartPoint);
|
||||
QRect rect = visualRect(index);
|
||||
if (rect.contains(dragStartPoint)) {
|
||||
selectedText = del->leftDoubleClick(dragStartPoint, index, rect);
|
||||
if (selectedText.size() > 0) {
|
||||
setDirtyRegion(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QAbstractItemView::mouseReleaseEvent(event);
|
||||
|
|
|
@ -74,6 +74,7 @@ protected:
|
|||
void mouseMoveEvent(QMouseEvent * event) override;
|
||||
void mousePressEvent(QMouseEvent * event) override;
|
||||
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent * event) override;
|
||||
void keyPressEvent(QKeyEvent * event) override;
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
void endClearWidgets();
|
||||
void beginClearWidgets();
|
||||
void leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const;
|
||||
QString leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint);
|
||||
Shared::Hover hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const;
|
||||
QString mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint);
|
||||
QString clearSelection();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue