Browse Source

Generalize Qt link gestures while preserving drag selection

master
evgeny 3 days ago
parent
commit
5b321c6304
  1. 8
      tools/chatgui/src/chatview.cpp
  2. 6
      tools/chatgui/src/chatview.h

8
tools/chatgui/src/chatview.cpp

@ -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;
}
}

6
tools/chatgui/src/chatview.h

@ -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;
};

Loading…
Cancel
Save