Add scroll to bottom FAB.

This commit is contained in:
Black Hat
2018-07-09 13:36:28 +08:00
parent 6bd059ce63
commit 0b2ae33f29
3 changed files with 56 additions and 10 deletions

View File

@@ -9,16 +9,23 @@ RoomListModel::RoomListModel(QObject* parent) : QAbstractListModel(parent) {}
RoomListModel::~RoomListModel() {}
void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
Q_ASSERT(connection);
using QMatrixClient::Connection;
using QMatrixClient::Room;
beginResetModel();
m_connection = connection;
m_rooms.clear();
connect(connection, &QMatrixClient::Connection::newRoom, this,
&RoomListModel::addRoom);
for (QMatrixClient::Room* room : connection->roomMap().values()) {
connect(room, &QMatrixClient::Room::namesChanged, this,
&RoomListModel::namesChanged);
m_rooms.append(room);
}
connect(connection, &Connection::loggedOut, this,
[=] { setConnection(connection); });
// connect(connection, &Connection::invitedRoom, this,
// &RoomListModel::updateRoom);
// connect(connection, &Connection::joinedRoom, this,
// &RoomListModel::updateRoom);
// connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom);
connect(connection, &Connection::aboutToDeleteRoom, this,
&RoomListModel::deleteRoom);
for (auto r : connection->roomMap()) addRoom(r);
endResetModel();
}
@@ -32,6 +39,15 @@ void RoomListModel::addRoom(QMatrixClient::Room* room) {
endInsertRows();
}
void RoomListModel::deleteRoom(QMatrixClient::Room* room) {
const auto it = std::find(m_rooms.begin(), m_rooms.end(), room);
if (it == m_rooms.end()) return; // Already deleted, nothing to do
const int row = it - m_rooms.begin();
beginRemoveRows(QModelIndex(), row, row);
m_rooms.erase(it);
endRemoveRows();
}
int RoomListModel::rowCount(const QModelIndex& parent) const {
if (parent.isValid()) return 0;
return m_rooms.count();