move INV button from footer into channel delegate rows (second button left of plus)

This commit is contained in:
evgeny committed 2026-08-04 22:57:36 +03:00
1 parent 24316e8cf8
commit 44c99f603d
3 files changed
+58 -21

No files matched your search

+25 -21
View File
@@ -19,13 +19,19 @@ class ChannelListView : public QListView {
public:
using QListView::QListView;
signals:
signals:
void inviteClicked(const QString& channelId);
void inviteByLinkClicked(const QString& channelId);
protected:
void mousePressEvent(QMouseEvent* e) override {
QModelIndex idx = indexAt(e->pos());
if (!idx.isValid()) 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());
@@ -34,19 +40,28 @@ protected:
QListView::mousePressEvent(e);
}
void mouseMoveEvent(QMouseEvent* e) override {
int prevRow = m_hoveredInviteRow;
int prevInv = m_hoveredInviteRow;
int prevInvBy = m_hoveredInviteByLinkRow;
m_hoveredInviteRow = -1;
m_hoveredInviteByLinkRow = -1;
QModelIndex idx = indexAt(e->pos());
if (idx.isValid()) {
QRect invRect = ChannelDelegate::inviteByLinkButtonRect(visualRect(idx));
QRect plusRect = ChannelDelegate::inviteButtonRect(visualRect(idx));
if (plusRect.contains(e->pos()))
if (invRect.contains(e->pos()))
m_hoveredInviteByLinkRow = idx.row();
else if (plusRect.contains(e->pos()))
m_hoveredInviteRow = idx.row();
}
if (m_hoveredInviteRow != prevRow) {
model()->setData(model()->index(prevRow, 0), 0, ChannelInviteBtnHoveredRole);
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);
}
setCursor(m_hoveredInviteRow >= 0 ? Qt::PointingHandCursor : Qt::ArrowCursor);
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);
setCursor((m_hoveredInviteRow >= 0 || m_hoveredInviteByLinkRow >= 0) ? Qt::PointingHandCursor : Qt::ArrowCursor);
QListView::mouseMoveEvent(e);
}
QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex& idx, const QEvent* e) const override {
@@ -63,6 +78,7 @@ protected:
private:
int m_hoveredInviteRow = -1;
int m_hoveredInviteByLinkRow = -1;
};
static QIcon makeChannelIcon(const QColor &color, const QString &letter) {
@@ -134,20 +150,6 @@ ChannelList::ChannelList(DbManager* db, QWidget *parent)
connect(createBtn, &QPushButton::clicked, this, [this] { emit createGroupRequested(); });
fl->addWidget(createBtn);
auto *inviteBtn = new QPushButton("INV", footer);
inviteBtn->setFixedSize(36, 28);
inviteBtn->setToolTip(QString::fromUtf8("Пригласить в канал по ссылке"));
inviteBtn->setStyleSheet(
"QPushButton { border: 1.5px solid #E67E22; border-radius: 6px;"
" font-size: 11px; font-weight: bold; color: #E67E22; background: transparent; }"
"QPushButton:hover { background: #E67E22; color: white; }");
connect(inviteBtn, &QPushButton::clicked, this, [this] {
QModelIndex cur = m_listView->currentIndex();
if (cur.isValid())
emit inviteByLinkRequested(cur.data(ChannelChannelIdRole).toString());
});
fl->addWidget(inviteBtn);
auto *plusBtn = new QPushButton("+", footer);
plusBtn->setFixedSize(28, 28);
plusBtn->setToolTip(QString::fromUtf8("Присоединиться"));
@@ -169,6 +171,8 @@ ChannelList::ChannelList(DbManager* db, QWidget *parent)
});
connect(static_cast<ChannelListView*>(m_listView), &ChannelListView::inviteClicked,
this, &ChannelList::inviteRequested);
connect(static_cast<ChannelListView*>(m_listView), &ChannelListView::inviteByLinkClicked,
this, &ChannelList::inviteByLinkRequested);
}
void ChannelList::loadChannels() {