Add next/prev room shortcuts

This commit is contained in:
Nicolas Werner 2020-01-31 01:39:51 +01:00
parent 735086371d
commit 558fd10f7b
3 changed files with 80 additions and 0 deletions

View file

@ -223,6 +223,72 @@ RoomList::highlightSelectedRoom(const QString &room_id)
selectedRoom_ = room_id;
}
void
RoomList::nextRoom()
{
for (int ii = 0; ii < contentsLayout_->count() - 1; ++ii) {
auto room = qobject_cast<RoomInfoListItem *>(contentsLayout_->itemAt(ii)->widget());
if (!room)
continue;
if (room->roomId() == selectedRoom_) {
auto nextRoom = qobject_cast<RoomInfoListItem *>(
contentsLayout_->itemAt(ii + 1)->widget());
// Not a room message.
if (!nextRoom || nextRoom->isInvite())
return;
emit roomChanged(nextRoom->roomId());
if (!roomExists(nextRoom->roomId())) {
nhlog::ui()->warn("roomlist: clicked unknown room_id");
return;
}
room->setPressedState(false);
nextRoom->setPressedState(true);
scrollArea_->ensureWidgetVisible(nextRoom);
selectedRoom_ = nextRoom->roomId();
return;
}
}
}
void
RoomList::previousRoom()
{
for (int ii = 1; ii < contentsLayout_->count(); ++ii) {
auto room = qobject_cast<RoomInfoListItem *>(contentsLayout_->itemAt(ii)->widget());
if (!room)
continue;
if (room->roomId() == selectedRoom_) {
auto nextRoom = qobject_cast<RoomInfoListItem *>(
contentsLayout_->itemAt(ii - 1)->widget());
// Not a room message.
if (!nextRoom || nextRoom->isInvite())
return;
emit roomChanged(nextRoom->roomId());
if (!roomExists(nextRoom->roomId())) {
nhlog::ui()->warn("roomlist: clicked unknown room_id");
return;
}
room->setPressedState(false);
nextRoom->setPressedState(true);
scrollArea_->ensureWidgetVisible(nextRoom);
selectedRoom_ = nextRoom->roomId();
return;
}
}
}
void
RoomList::updateRoomAvatar(const QString &roomid, const QString &img)
{