Add infinite scroll in member list

fixes #446
This commit is contained in:
Konstantinos Sideris 2018-09-25 15:43:48 +03:00
parent 39b4c83bb0
commit 7a288cc2cb
2 changed files with 5 additions and 30 deletions

View file

@ -1,6 +1,8 @@
#include <QAbstractSlider>
#include <QListWidgetItem>
#include <QPainter>
#include <QPushButton>
#include <QScrollBar>
#include <QShortcut>
#include <QStyleOption>
#include <QVBoxLayout>
@ -108,17 +110,10 @@ MemberList::MemberList(const QString &room_id, QWidget *parent)
list_->clear();
// Add button at the bottom.
moreBtn_ = new QPushButton(tr("Show more"), this);
moreBtn_->setFlat(true);
auto item = new QListWidgetItem;
item->setSizeHint(moreBtn_->minimumSizeHint());
item->setFlags(Qt::NoItemFlags);
item->setTextAlignment(Qt::AlignCenter);
list_->insertItem(0, item);
list_->setItemWidget(item, moreBtn_);
connect(list_->verticalScrollBar(), &QAbstractSlider::valueChanged, this, [this](int pos) {
if (pos != list_->verticalScrollBar()->maximum())
return;
connect(moreBtn_, &QPushButton::clicked, this, [this]() {
const size_t numMembers = list_->count() - 1;
if (numMembers > 0)
@ -136,26 +131,9 @@ MemberList::MemberList(const QString &room_id, QWidget *parent)
connect(okBtn, &QPushButton::clicked, this, &MemberList::close);
}
void
MemberList::moveButtonToBottom()
{
auto item = new QListWidgetItem(list_);
item->setSizeHint(moreBtn_->minimumSizeHint());
item->setFlags(Qt::NoItemFlags);
item->setTextAlignment(Qt::AlignCenter);
list_->setItemWidget(item, moreBtn_);
list_->addItem(item);
}
void
MemberList::addUsers(const std::vector<RoomMember> &members)
{
if (members.size() == 0) {
moreBtn_->hide();
} else {
moreBtn_->show();
}
for (const auto &member : members) {
auto user = new MemberItem(member, this);
auto item = new QListWidgetItem;

View file

@ -46,11 +46,8 @@ public slots:
void addUsers(const std::vector<RoomMember> &users);
private:
void moveButtonToBottom();
QString room_id_;
QLabel *topLabel_;
QListWidget *list_;
QPushButton *moreBtn_;
};
} // dialogs