From 1f065f23e65d3d85c994a9d3d342cac14a9bccc1 Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 3 May 2022 12:17:08 +0300 Subject: [PATCH] double click word selection handle, sigint sermentation fault fix --- CHANGELOG.md | 2 ++ main/application.cpp | 4 ++- ui/widgets/messageline/feedview.cpp | 31 +++++++++++++++++ ui/widgets/messageline/feedview.h | 1 + ui/widgets/messageline/messagedelegate.cpp | 39 +++++++++++++++++++--- ui/widgets/messageline/messagedelegate.h | 1 + 6 files changed, 73 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 241d61d..01fa4a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - now when you remove an account it actually gets removed - segfault on unitialized Availability in some rare occesions - fixed crash when you open a dialog with someone that has only error messages in archive +- message height is now calculated correctly on Chinese and Japanese paragraphs +- the app doesn't crash on SIGINT anymore ### Improvements - there is a way to disable an account and it wouldn't connect when you change availability diff --git a/main/application.cpp b/main/application.cpp index 410cd81..216e322 100644 --- a/main/application.cpp +++ b/main/application.cpp @@ -186,7 +186,9 @@ void Application::onSquawkClosing() { dialogueQueue.setParentWidnow(nullptr); - disconnect(core, &Core::Squawk::responseVCard, squawk, &Squawk::responseVCard); + if (!nowQuitting) { + disconnect(core, &Core::Squawk::responseVCard, squawk, &Squawk::responseVCard); + } destroyingSquawk = true; squawk->deleteLater(); diff --git a/ui/widgets/messageline/feedview.cpp b/ui/widgets/messageline/feedview.cpp index 353d851..69b5093 100644 --- a/ui/widgets/messageline/feedview.cpp +++ b/ui/widgets/messageline/feedview.cpp @@ -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(itemDelegate()); + QString lastSelectedId = del->clearSelection(); + selectedText = ""; + if (lastSelectedId.size()) { + Models::MessageFeed* feed = static_cast(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); diff --git a/ui/widgets/messageline/feedview.h b/ui/widgets/messageline/feedview.h index d0763a5..4194849 100644 --- a/ui/widgets/messageline/feedview.h +++ b/ui/widgets/messageline/feedview.h @@ -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; diff --git a/ui/widgets/messageline/messagedelegate.cpp b/ui/widgets/messageline/messagedelegate.cpp index 840ef5c..f935057 100644 --- a/ui/widgets/messageline/messagedelegate.cpp +++ b/ui/widgets/messageline/messagedelegate.cpp @@ -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(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); diff --git a/ui/widgets/messageline/messagedelegate.h b/ui/widgets/messageline/messagedelegate.h index dc0fb49..322fb76 100644 --- a/ui/widgets/messageline/messagedelegate.h +++ b/ui/widgets/messageline/messagedelegate.h @@ -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();