Generalize Qt link gestures while preserving drag selection

This commit is contained in:
evgeny committed 2026-10-04 19:04:11 +02:00
1 parent 3482e4a327
commit 5b321c6304
2 files changed
+7 -7

No files matched your search

+4 -4
View File
@@ -154,7 +154,7 @@ 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();
const bool link = m_linkHitTest && !m_linkHitTest(idx, event->pos()).isEmpty();
viewport()->setCursor(link ? Qt::PointingHandCursor : Qt::ArrowCursor);
if (idx != QModelIndex(m_lastHovered)) {
m_lastHovered = idx;
@@ -185,11 +185,11 @@ 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) {
const QString link = m_inviteHitTest ? m_inviteHitTest(pressed, event->pos()) : QString();
const QString link = m_linkHitTest ? m_linkHitTest(pressed, event->pos()) : QString();
if (!link.isEmpty()) {
m_pressIndex = QPersistentModelIndex();
GUI_INFO("invite link: activated row=%d bytes=%d", pressed.row(), link.size());
emit inviteLinkActivated(link);
GUI_INFO("message link: activated row=%d bytes=%d", pressed.row(), link.size());
emit linkActivated(link);
event->accept(); return;
}
}
+3 -3
View File
@@ -33,11 +33,11 @@ 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); }
void setLinkHitTest(std::function<QString(const QModelIndex&, const QPoint&)> fn) { m_linkHitTest = std::move(fn); }
signals:
void animationTriggered();
void inviteLinkActivated(const QString& link);
void linkActivated(const QString& link);
protected:
bool viewportEvent(QEvent *event) override;
@@ -62,6 +62,6 @@ private:
QPersistentModelIndex m_pressIndex;
QPoint m_pressPos;
bool m_selecting = false;
std::function<QString(const QModelIndex&, const QPoint&)> m_inviteHitTest;
std::function<QString(const QModelIndex&, const QPoint&)> m_linkHitTest;
QPushButton *m_scrollDownBtn = nullptr;
};