Browse Source

Open desktop message avatars only after a completed click

master
evgeny 1 week ago
parent
commit
1f9dbd9dea
  1. 11
      tools/chatgui/src/messagedelegate.cpp
  2. 3
      tools/chatgui/src/messagedelegate.h

11
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<QMouseEvent*>(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();

3
tools/chatgui/src/messagedelegate.h

@ -4,6 +4,7 @@
#include <cstdint>
#include <QStyledItemDelegate>
#include <QPersistentModelIndex>
#include <functional>
enum MessageDataRole {
@ -111,6 +112,8 @@ private:
std::function<void(const QString&)> m_videoOpenCb;
std::function<void(const QString&)> m_imageOpenCb;
QPersistentModelIndex m_avatarPress;
QPoint m_avatarPressPosition;
std::function<bool(const QModelIndex&)> m_downloadCb;
Layout calcLayout(const QStyleOptionViewItem &option,

Loading…
Cancel
Save