Keep invite hit testing in the message presenter and show link cursor

This commit is contained in:
evgeny committed 2026-10-04 15:10:02 +02:00
1 parent 8574299ab3
commit c0ee38cb43
3 files changed
+10 -3

No files matched your search

+3 -3
View File
@@ -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<MessageDelegate*>(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());
+3
View File
@@ -7,6 +7,7 @@
#include <QPoint>
#include <QPushButton>
#include <QSet>
#include <functional>
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<QString(const QModelIndex&, const QPoint&)> 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<QString(const QModelIndex&, const QPoint&)> m_inviteHitTest;
QPushButton *m_scrollDownBtn = nullptr;
};
+4
View File
@@ -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);
});