Browse Source

Remove inline action hit targets from channel rows

master
evgeny 2 days ago
parent
commit
bfdd9cde15
  1. 69
      tools/chatgui/src/channellist.cpp
  2. 3
      tools/chatgui/src/channellist.h

69
tools/chatgui/src/channellist.cpp

@ -24,74 +24,18 @@ extern "C" {
#include "dm/dm_core.h"
}
/* QListView that prevents deselection, handles invite plus-button clicks */
/* Пустое место и заголовки секций не сбрасывают выбор канала. */
class ChannelListView : public QListView {
Q_OBJECT
public:
using QListView::QListView;
signals:
void inviteClicked(const QString& channelId);
void inviteByLinkClicked(const QString& channelId);
void settingsClicked(const QString& channelId);
protected:
void mousePressEvent(QMouseEvent* e) override {
QModelIndex idx = indexAt(e->pos());
if (!idx.isValid()) return;
if (idx.data(ChannelIsSectionRole).toBool()) return;
QRect gearRect = ChannelDelegate::settingsButtonRect(visualRect(idx));
if (gearRect.contains(e->pos())) {
emit settingsClicked(idx.data(ChannelChannelIdRole).toString());
return;
}
QRect invRect = ChannelDelegate::inviteByLinkButtonRect(visualRect(idx));
if (invRect.contains(e->pos())) {
emit inviteByLinkClicked(idx.data(ChannelChannelIdRole).toString());
return;
}
QRect plusRect = ChannelDelegate::inviteButtonRect(visualRect(idx));
if (plusRect.contains(e->pos())) {
emit inviteClicked(idx.data(ChannelChannelIdRole).toString());
return;
}
QListView::mousePressEvent(e);
}
void mouseMoveEvent(QMouseEvent* e) override {
int prevInv = m_hoveredInviteRow;
int prevInvBy = m_hoveredInviteByLinkRow;
int prevSettings = m_hoveredSettingsRow;
m_hoveredInviteRow = -1;
m_hoveredInviteByLinkRow = -1;
m_hoveredSettingsRow = -1;
QModelIndex idx = indexAt(e->pos());
if (idx.isValid() && !idx.data(ChannelIsSectionRole).toBool()) {
QRect gearRect = ChannelDelegate::settingsButtonRect(visualRect(idx));
QRect invRect = ChannelDelegate::inviteByLinkButtonRect(visualRect(idx));
QRect plusRect = ChannelDelegate::inviteButtonRect(visualRect(idx));
if (gearRect.contains(e->pos()))
m_hoveredSettingsRow = idx.row();
else if (invRect.contains(e->pos()))
m_hoveredInviteByLinkRow = idx.row();
else if (plusRect.contains(e->pos()))
m_hoveredInviteRow = idx.row();
}
if (m_hoveredInviteRow != prevInv)
model()->setData(model()->index(prevInv, 0), 0, ChannelInviteBtnHoveredRole);
if (m_hoveredInviteRow >= 0)
model()->setData(model()->index(m_hoveredInviteRow, 0), 1, ChannelInviteBtnHoveredRole);
if (m_hoveredInviteByLinkRow != prevInvBy)
model()->setData(model()->index(prevInvBy, 0), 0, ChannelInviteByLinkBtnHoveredRole);
if (m_hoveredInviteByLinkRow >= 0)
model()->setData(model()->index(m_hoveredInviteByLinkRow, 0), 1, ChannelInviteByLinkBtnHoveredRole);
if (m_hoveredSettingsRow != prevSettings)
model()->setData(model()->index(prevSettings, 0), 0, ChannelSettingsBtnHoveredRole);
if (m_hoveredSettingsRow >= 0)
model()->setData(model()->index(m_hoveredSettingsRow, 0), 1, ChannelSettingsBtnHoveredRole);
setCursor((m_hoveredInviteRow >= 0 || m_hoveredInviteByLinkRow >= 0 || m_hoveredSettingsRow >= 0)
? Qt::PointingHandCursor : Qt::ArrowCursor);
QListView::mouseMoveEvent(e);
}
QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex& idx, const QEvent* e) const override {
if (idx.isValid() && idx.data(ChannelIsSectionRole).toBool())
return QItemSelectionModel::NoUpdate;
@ -106,10 +50,6 @@ protected:
selectionModel()->select(currentIndex(), QItemSelectionModel::ClearAndSelect);
}
private:
int m_hoveredInviteRow = -1;
int m_hoveredInviteByLinkRow = -1;
int m_hoveredSettingsRow = -1;
};
static QIcon makeChannelIcon(const QColor &color, const QString &letter) {
@ -243,12 +183,6 @@ ChannelList::ChannelList(DbManager* db, QWidget *parent)
emit channelSelected(cid);
}
});
connect(static_cast<ChannelListView*>(m_listView), &ChannelListView::inviteClicked,
this, &ChannelList::inviteRequested);
connect(static_cast<ChannelListView*>(m_listView), &ChannelListView::inviteByLinkClicked,
this, &ChannelList::inviteByLinkRequested);
connect(static_cast<ChannelListView*>(m_listView), &ChannelListView::settingsClicked,
this, &ChannelList::channelSettingsRequested);
m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_listView, &QWidget::customContextMenuRequested, this, [this](const QPoint& point) {
auto index = m_listView->indexAt(point);
@ -478,4 +412,3 @@ int ChannelList::getChannelUnreadCount(const QString& channelId) const {
return 0;
}
#include "channellist.moc"

3
tools/chatgui/src/channellist.h

@ -30,9 +30,6 @@ public:
signals:
void channelSelected(const QString& channelId);
void inviteRequested(const QString& channelId);
void inviteByLinkRequested(const QString& channelId);
void channelSettingsRequested(const QString& channelId);
void filesRequested(const QString& channelId);
void ownFilesDropped(const QString& channelId, const QStringList& paths);
void joinRequested();

Loading…
Cancel
Save