Add next/prev room shortcuts
This commit is contained in:
parent
735086371d
commit
558fd10f7b
@ -18,6 +18,7 @@
|
||||
#include <QApplication>
|
||||
#include <QImageReader>
|
||||
#include <QSettings>
|
||||
#include <QShortcut>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "AvatarProvider.h"
|
||||
@ -148,6 +149,17 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||
trySync();
|
||||
});
|
||||
|
||||
connect(
|
||||
new QShortcut(QKeySequence("Ctrl+Down"), this), &QShortcut::activated, this, [this]() {
|
||||
if (isVisible())
|
||||
room_list_->nextRoom();
|
||||
});
|
||||
connect(
|
||||
new QShortcut(QKeySequence("Ctrl+Up"), this), &QShortcut::activated, this, [this]() {
|
||||
if (isVisible())
|
||||
room_list_->previousRoom();
|
||||
});
|
||||
|
||||
connect(top_bar_, &TopRoomBar::mentionsClicked, this, [this](const QPoint &mentionsPos) {
|
||||
if (user_mentions_popup_->isVisible()) {
|
||||
user_mentions_popup_->hide();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -72,6 +72,8 @@ public slots:
|
||||
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
||||
void closeJoinRoomDialog(bool isJoining, QString roomAlias);
|
||||
void updateReadStatus(const std::map<QString, bool> &status);
|
||||
void nextRoom();
|
||||
void previousRoom();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
Loading…
Reference in New Issue
Block a user