diff --git a/tools/chatgui/src/chatview.cpp b/tools/chatgui/src/chatview.cpp index d98a3196..7b5b256d 100644 --- a/tools/chatgui/src/chatview.cpp +++ b/tools/chatgui/src/chatview.cpp @@ -154,6 +154,8 @@ void ChatView::mouseMoveEvent(QMouseEvent *event) { } if (!m_selecting) { QModelIndex idx = indexAt(viewport()->mapFrom(this, event->pos())); + const bool link = m_inviteHitTest && !m_inviteHitTest(idx, event->pos()).isEmpty(); + viewport()->setCursor(link ? Qt::PointingHandCursor : Qt::ArrowCursor); if (idx != QModelIndex(m_lastHovered)) { m_lastHovered = idx; const auto paths = animatedEmojiPaths(idx); @@ -183,9 +185,7 @@ void ChatView::mouseReleaseEvent(QMouseEvent *event) { const QModelIndex pressed(m_pressIndex); if (event->button() == Qt::LeftButton && !m_selecting && pressed.isValid() && (event->pos() - m_pressPos).manhattanLength() < 5 && indexAt(event->pos()) == pressed) { - auto* delegate = qobject_cast(itemDelegate(pressed)); - QStyleOptionViewItem option; option.initFrom(this); option.widget = this; option.rect = visualRect(pressed); - const QString link = delegate ? delegate->inviteLinkAt(option, pressed, event->pos()) : QString(); + const QString link = m_inviteHitTest ? m_inviteHitTest(pressed, event->pos()) : QString(); if (!link.isEmpty()) { m_pressIndex = QPersistentModelIndex(); GUI_INFO("invite link: activated row=%d bytes=%d", pressed.row(), link.size()); diff --git a/tools/chatgui/src/chatview.h b/tools/chatgui/src/chatview.h index 7abda76d..e0c75c12 100644 --- a/tools/chatgui/src/chatview.h +++ b/tools/chatgui/src/chatview.h @@ -7,6 +7,7 @@ #include #include #include +#include struct ChatTextSelection { QPersistentModelIndex index; @@ -32,6 +33,7 @@ public: bool isRowSelected(const QModelIndex &idx) const; void setTextSelChars(int start, int end) { m_textSel.startChar = start; m_textSel.endChar = end; } + void setInviteHitTest(std::function fn) { m_inviteHitTest = std::move(fn); } signals: void animationTriggered(); @@ -60,5 +62,6 @@ private: QPersistentModelIndex m_pressIndex; QPoint m_pressPos; bool m_selecting = false; + std::function m_inviteHitTest; QPushButton *m_scrollDownBtn = nullptr; }; diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index f02df1c5..9e9d8e4c 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -421,6 +421,10 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent m_view->setModel(m_model); auto* msgDelegate = new MessageDelegate(this); + m_view->setInviteHitTest([this, msgDelegate](const QModelIndex& index, const QPoint& point) { + QStyleOptionViewItem option; option.initFrom(m_view); option.widget = m_view; option.rect = m_view->visualRect(index); + return msgDelegate->inviteLinkAt(option, index, point); + }); msgDelegate->setVideoOpenCallback([this](const QString& path) { emit openVideoRequested(path); });