mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
add rooms model, add room delegate for completer
This commit is contained in:
parent
734fb7e286
commit
19dbbb2c6c
6 changed files with 130 additions and 0 deletions
|
@ -326,6 +326,7 @@ set(SRC_FILES
|
|||
src/UserInfoWidget.cpp
|
||||
src/UserSettingsPage.cpp
|
||||
src/UsersModel.cpp
|
||||
src/RoomsModel.cpp
|
||||
src/Utils.cpp
|
||||
src/WebRTCSession.cpp
|
||||
src/WelcomePage.cpp
|
||||
|
@ -537,6 +538,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
|||
src/UserInfoWidget.h
|
||||
src/UserSettingsPage.h
|
||||
src/UsersModel.h
|
||||
src/RoomsModel.h
|
||||
src/WebRTCSession.h
|
||||
src/WelcomePage.h
|
||||
src/popups/PopupItem.h
|
||||
|
|
|
@ -154,6 +154,35 @@ Popup {
|
|||
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: "room"
|
||||
|
||||
RowLayout {
|
||||
id: del
|
||||
|
||||
anchors.centerIn: parent
|
||||
|
||||
Avatar {
|
||||
height: 24
|
||||
width: 24
|
||||
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
||||
}
|
||||
|
||||
Label {
|
||||
text: model.roomName
|
||||
color: model.index == popup.currentIndex ? colors.highlightedText : colors.text
|
||||
}
|
||||
|
||||
Label {
|
||||
text: "(" + model.roomAlias + ")"
|
||||
color: model.index == popup.currentIndex ? colors.highlightedText : colors.buttonText
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -183,6 +183,9 @@ Rectangle {
|
|||
} else if (event.key == Qt.Key_Colon) {
|
||||
messageInput.openCompleter(cursorPosition, "emoji");
|
||||
popup.open();
|
||||
} else if (event.key == Qt.Key_NumberSign) {
|
||||
messageInput.openCompleter(cursorPosition, "room");
|
||||
popup.open();
|
||||
} else if (event.key == Qt.Key_Escape && popup.opened) {
|
||||
completerTriggeredAt = -1;
|
||||
popup.completerName = "";
|
||||
|
|
57
src/RoomsModel.cpp
Normal file
57
src/RoomsModel.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "RoomsModel.h"
|
||||
|
||||
#include "Cache_p.h"
|
||||
#include "CompletionModelRoles.h"
|
||||
|
||||
RoomsModel::RoomsModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
rooms_ = cache::joinedRooms();
|
||||
roomInfos = cache::getRoomInfo(rooms_);
|
||||
|
||||
for (const auto &r : rooms_) {
|
||||
auto roomAliasesList = cache::client()->getRoomAliases(r);
|
||||
|
||||
if (roomAliasesList) {
|
||||
roomAliases.push_back(QString::fromStdString(roomAliasesList->alias));
|
||||
roomids.push_back(QString::fromStdString(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray>
|
||||
RoomsModel::roleNames() const
|
||||
{
|
||||
return {{CompletionModel::CompletionRole, "completionRole"},
|
||||
{CompletionModel::SearchRole, "searchRole"},
|
||||
{CompletionModel::SearchRole2, "searchRole2"},
|
||||
{Roles::RoomAlias, "roomAlias"},
|
||||
{Roles::AvatarUrl, "avatarUrl"},
|
||||
{Roles::RoomID, "roomid"},
|
||||
{Roles::RoomName, "roomName"}};
|
||||
}
|
||||
|
||||
QVariant
|
||||
RoomsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (hasIndex(index.row(), index.column(), index.parent())) {
|
||||
switch (role) {
|
||||
case CompletionModel::CompletionRole:
|
||||
return QString("%1").arg(roomAliases[index.row()]);
|
||||
case CompletionModel::SearchRole:
|
||||
case Qt::DisplayRole:
|
||||
case Roles::RoomAlias:
|
||||
return roomAliases[index.row()];
|
||||
case CompletionModel::SearchRole2:
|
||||
return roomAliases[index.row()];
|
||||
case Roles::AvatarUrl:
|
||||
return QString::fromStdString(
|
||||
roomInfos.at(roomids[index.row()]).avatar_url);
|
||||
case Roles::RoomID:
|
||||
return roomids[index.row()];
|
||||
case Roles::RoomName:
|
||||
return QString::fromStdString(roomInfos.at(roomids[index.row()]).name);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
33
src/RoomsModel.h
Normal file
33
src/RoomsModel.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "Cache.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QString>
|
||||
|
||||
class RoomsModel : public QAbstractListModel
|
||||
{
|
||||
public:
|
||||
enum Roles
|
||||
{
|
||||
AvatarUrl = Qt::UserRole,
|
||||
RoomAlias,
|
||||
RoomID,
|
||||
RoomName,
|
||||
};
|
||||
|
||||
RoomsModel(QObject *parent = nullptr);
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||||
{
|
||||
(void)parent;
|
||||
return (int)roomAliases.size();
|
||||
}
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
private:
|
||||
std::vector<std::string> rooms_;
|
||||
std::vector<QString> roomids;
|
||||
std::vector<QString> roomAliases;
|
||||
std::map<QString, RoomInfo> roomInfos;
|
||||
};
|
|
@ -23,6 +23,7 @@
|
|||
#include "TimelineViewManager.h"
|
||||
#include "UserSettingsPage.h"
|
||||
#include "UsersModel.h"
|
||||
#include "RoomsModel.h"
|
||||
#include "Utils.h"
|
||||
#include "dialogs/PreviewUploadOverlay.h"
|
||||
#include "emoji/EmojiModel.h"
|
||||
|
@ -186,6 +187,11 @@ InputBar::completerFor(QString completerName)
|
|||
auto proxy = new CompletionProxyModel(emojiModel);
|
||||
emojiModel->setParent(proxy);
|
||||
return proxy;
|
||||
} else if (completerName == "room") {
|
||||
auto roomModel = new RoomsModel();
|
||||
auto proxy = new CompletionProxyModel(roomModel);
|
||||
roomModel->setParent(proxy);
|
||||
return proxy;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue