Add scroll to bottom FAB.
This commit is contained in:
parent
6bd059ce63
commit
0b2ae33f29
|
@ -9,16 +9,23 @@ RoomListModel::RoomListModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
RoomListModel::~RoomListModel() {}
|
RoomListModel::~RoomListModel() {}
|
||||||
|
|
||||||
void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
|
void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
|
||||||
|
Q_ASSERT(connection);
|
||||||
|
|
||||||
|
using QMatrixClient::Connection;
|
||||||
|
using QMatrixClient::Room;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
m_rooms.clear();
|
connect(connection, &Connection::loggedOut, this,
|
||||||
connect(connection, &QMatrixClient::Connection::newRoom, this,
|
[=] { setConnection(connection); });
|
||||||
&RoomListModel::addRoom);
|
// connect(connection, &Connection::invitedRoom, this,
|
||||||
for (QMatrixClient::Room* room : connection->roomMap().values()) {
|
// &RoomListModel::updateRoom);
|
||||||
connect(room, &QMatrixClient::Room::namesChanged, this,
|
// connect(connection, &Connection::joinedRoom, this,
|
||||||
&RoomListModel::namesChanged);
|
// &RoomListModel::updateRoom);
|
||||||
m_rooms.append(room);
|
// connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom);
|
||||||
}
|
connect(connection, &Connection::aboutToDeleteRoom, this,
|
||||||
|
&RoomListModel::deleteRoom);
|
||||||
|
|
||||||
|
for (auto r : connection->roomMap()) addRoom(r);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +39,15 @@ void RoomListModel::addRoom(QMatrixClient::Room* room) {
|
||||||
endInsertRows();
|
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 {
|
int RoomListModel::rowCount(const QModelIndex& parent) const {
|
||||||
if (parent.isValid()) return 0;
|
if (parent.isValid()) return 0;
|
||||||
return m_rooms.count();
|
return m_rooms.count();
|
||||||
|
|
|
@ -30,6 +30,7 @@ class RoomListModel : public QAbstractListModel {
|
||||||
void namesChanged(QMatrixClient::Room* room);
|
void namesChanged(QMatrixClient::Room* room);
|
||||||
void unreadMessagesChanged(QMatrixClient::Room* room);
|
void unreadMessagesChanged(QMatrixClient::Room* room);
|
||||||
void addRoom(QMatrixClient::Room* room);
|
void addRoom(QMatrixClient::Room* room);
|
||||||
|
void deleteRoom(QMatrixClient::Room* room);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMatrixClient::Connection* m_connection = nullptr;
|
QMatrixClient::Connection* m_connection = nullptr;
|
||||||
|
|
|
@ -144,8 +144,37 @@ Item {
|
||||||
|
|
||||||
ScrollBar.vertical: ScrollBar { /*anchors.left: messageListView.right*/ }
|
ScrollBar.vertical: ScrollBar { /*anchors.left: messageListView.right*/ }
|
||||||
|
|
||||||
onAtYBeginningChanged: {
|
Behavior on contentY {
|
||||||
if(currentRoom && atYBeginning) currentRoom.getPreviousContent(50)
|
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 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue