From 1f9dbd9dea77ffdd8efc7f733508e2b9aee37071 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 6 Oct 2026 20:01:38 +0200 Subject: [PATCH] Open desktop message avatars only after a completed click --- tools/chatgui/src/messagedelegate.cpp | 11 +++++++++-- tools/chatgui/src/messagedelegate.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/src/messagedelegate.cpp b/tools/chatgui/src/messagedelegate.cpp index ed2955a3..612ed0b5 100644 --- a/tools/chatgui/src/messagedelegate.cpp +++ b/tools/chatgui/src/messagedelegate.cpp @@ -131,14 +131,21 @@ static void ensureVoiceTimer() { bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { - if (event->type() != QEvent::MouseButtonRelease) return false; + if (event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease) return false; Layout L = calcLayout(option, index); const auto* mouse = static_cast(event); - if (mouse->button() == Qt::LeftButton && !L.narrow && L.avatarRect.contains(mouse->pos() - option.rect.topLeft())) { + const bool onAvatar=mouse->button()==Qt::LeftButton && !L.narrow && L.avatarRect.contains(mouse->pos()-option.rect.topLeft()); + if (event->type()==QEvent::MouseButtonPress) { + m_avatarPress=onAvatar ? index : QModelIndex(); m_avatarPressPosition=mouse->pos(); return onAvatar; + } + const bool activateAvatar=onAvatar && m_avatarPress==index && (mouse->pos()-m_avatarPressPosition).manhattanLength()<5; + m_avatarPress=QPersistentModelIndex(); + if (activateAvatar) { emit avatarRequested(index.data(MsgChannelIdRole).toString(), index.data(MsgAuthorNodeIdRole).toULongLong()); return true; } + if (onAvatar) return true; if (L.isVideo) { int dlState = index.data(MsgFileDownloadStateRole).toInt(); diff --git a/tools/chatgui/src/messagedelegate.h b/tools/chatgui/src/messagedelegate.h index 764f9108..93fab2af 100644 --- a/tools/chatgui/src/messagedelegate.h +++ b/tools/chatgui/src/messagedelegate.h @@ -4,6 +4,7 @@ #include #include +#include #include enum MessageDataRole { @@ -111,6 +112,8 @@ private: std::function m_videoOpenCb; std::function m_imageOpenCb; + QPersistentModelIndex m_avatarPress; + QPoint m_avatarPressPosition; std::function m_downloadCb; Layout calcLayout(const QStyleOptionViewItem &option,