Add scroll to bottom FAB.

square-messages
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();

View File

@ -30,6 +30,7 @@ class RoomListModel : public QAbstractListModel {
void namesChanged(QMatrixClient::Room* room);
void unreadMessagesChanged(QMatrixClient::Room* room);
void addRoom(QMatrixClient::Room* room);
void deleteRoom(QMatrixClient::Room* room);
private:
QMatrixClient::Connection* m_connection = nullptr;

View File

@ -144,8 +144,37 @@ Item {
ScrollBar.vertical: ScrollBar { /*anchors.left: messageListView.right*/ }
onAtYBeginningChanged: {
if(currentRoom && atYBeginning) currentRoom.getPreviousContent(50)
Behavior on contentY {
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
}
RoundButton {
id: goTopFab
width: height
height: !parent.atYEnd ? 64 : 0
anchors.verticalCenter: parent.bottom
anchors.verticalCenterOffset: -48
anchors.horizontalCenter: parent.right
anchors.horizontalCenterOffset: -48
contentItem: MaterialIcon {
anchors.fill: parent
icon: "\ue313"
color: "white"
}
opacity: hovered ? 1 : 0.5
Material.background: Qt.lighter(Material.accent)
onClicked: parent.positionViewAtBeginning()
Behavior on height {
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
}
Behavior on opacity {
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
}
}
}