Enable toggling tags

This commit is contained in:
Nicolas Werner 2021-06-11 14:51:29 +02:00
parent d8c0d4874b
commit 8d2d8dc267
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
8 changed files with 73 additions and 15 deletions

View file

@ -28,6 +28,7 @@ Rectangle {
Label { Label {
id: label id: label
anchors.fill: parent anchors.fill: parent
text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "") text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "")
textFormat: Text.RichText textFormat: Text.RichText

View file

@ -30,6 +30,7 @@ Rectangle {
CommunitiesList { CommunitiesList {
id: communitiesList id: communitiesList
collapsed: parent.collapsed collapsed: parent.collapsed
} }

View file

@ -10,7 +10,6 @@ import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import im.nheko 1.0 import im.nheko 1.0
Page { Page {
//leftPadding: Nheko.paddingSmall //leftPadding: Nheko.paddingSmall
//rightPadding: Nheko.paddingSmall //rightPadding: Nheko.paddingSmall
@ -97,8 +96,7 @@ Page {
TapHandler { TapHandler {
margin: -Nheko.paddingSmall margin: -Nheko.paddingSmall
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onSingleTapped: communityContextMenu.show(model.id); onSingleTapped: communityContextMenu.show(model.id)
gesturePolicy: TapHandler.ReleaseWithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds
} }
@ -127,15 +125,26 @@ Page {
height: avatarSize height: avatarSize
width: avatarSize width: avatarSize
url: { url: {
if (model.avatarUrl.startsWith("mxc://")) { if (model.avatarUrl.startsWith("mxc://"))
return model.avatarUrl.replace("mxc://", "image://MxcImage/") return model.avatarUrl.replace("mxc://", "image://MxcImage/");
} else { else
return "image://colorimage/"+model.avatarUrl+"?" + communityItem.unimportantText return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText;
}
} }
displayName: model.displayName displayName: model.displayName
color: communityItem.background color: communityItem.background
}
ElidedLabel {
visible: !collapsed
Layout.alignment: Qt.AlignVCenter
color: communityItem.importantText
elideWidth: parent.width - avatar.width - Nheko.paddingMedium
fullText: model.displayName
textFormat: Text.PlainText
}
Item {
Layout.fillWidth: true
} }
} }

View file

@ -118,6 +118,7 @@ CommunitiesModel::clear()
beginResetModel(); beginResetModel();
tags_.clear(); tags_.clear();
endResetModel(); endResetModel();
resetCurrentTagId();
emit tagsChanged(); emit tagsChanged();
} }
@ -148,12 +149,12 @@ CommunitiesModel::setCurrentTagId(QString tagId)
for (const auto &t : tags_) { for (const auto &t : tags_) {
if (t == tag) { if (t == tag) {
this->currentTagId_ = tagId; this->currentTagId_ = tagId;
emit currentTagIdChanged(); emit currentTagIdChanged(currentTagId_);
return; return;
} }
} }
} }
this->currentTagId_ = ""; this->currentTagId_ = "";
emit currentTagIdChanged(); emit currentTagIdChanged(currentTagId_);
} }

View file

@ -46,12 +46,12 @@ public slots:
void resetCurrentTagId() void resetCurrentTagId()
{ {
currentTagId_.clear(); currentTagId_.clear();
emit currentTagIdChanged(); emit currentTagIdChanged(currentTagId_);
} }
QStringList tags() const { return tags_; } QStringList tags() const { return tags_; }
signals: signals:
void currentTagIdChanged(); void currentTagIdChanged(QString tagId);
void tagsChanged(); void tagsChanged();
private: private:

View file

@ -324,6 +324,7 @@ RoomlistModel::initializeRooms()
models.clear(); models.clear();
roomids.clear(); roomids.clear();
invites.clear(); invites.clear();
currentRoom_ = nullptr;
invites = cache::client()->invites(); invites = cache::client()->invites();
for (const auto &id : invites.keys()) for (const auto &id : invites.keys())
@ -461,6 +462,22 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
return left.row() < right.row(); return left.row() < right.row();
} }
bool
FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const
{
if (filterType == FilterBy::Nothing)
return true;
else if (filterType == FilterBy::Tag) {
auto tags = sourceModel()
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
.toStringList();
return tags.contains(filterStr);
} else {
return true;
}
}
FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent) FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
, roomlistmodel(model) , roomlistmodel(model)

View file

@ -109,6 +109,7 @@ class FilteredRoomlistModel : public QSortFilterProxyModel
public: public:
FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr); FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr);
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &) const override;
public slots: public slots:
int roomidToIndex(QString roomid) int roomidToIndex(QString roomid)
@ -128,6 +129,19 @@ public slots:
void nextRoom(); void nextRoom();
void previousRoom(); void previousRoom();
void updateFilterTag(QString tagId)
{
if (tagId.startsWith("tag:")) {
filterType = FilterBy::Tag;
filterStr = tagId.mid(4);
} else {
filterType = FilterBy::Nothing;
filterStr.clear();
}
invalidateFilter();
}
signals: signals:
void currentRoomChanged(); void currentRoomChanged();
@ -135,4 +149,13 @@ private:
short int calculateImportance(const QModelIndex &idx) const; short int calculateImportance(const QModelIndex &idx) const;
RoomlistModel *roomlistmodel; RoomlistModel *roomlistmodel;
bool sortByImportance = true; bool sortByImportance = true;
enum class FilterBy
{
Tag,
Space,
Nothing,
};
QString filterStr = "";
FilterBy filterType = FilterBy::Nothing;
}; };

View file

@ -195,7 +195,13 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
}); });
qmlRegisterSingletonType<RoomlistModel>( qmlRegisterSingletonType<RoomlistModel>(
"im.nheko", 1, 0, "Rooms", [](QQmlEngine *, QJSEngine *) -> QObject * { "im.nheko", 1, 0, "Rooms", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new FilteredRoomlistModel(self->rooms_); auto ptr = new FilteredRoomlistModel(self->rooms_);
connect(self->communities_,
&CommunitiesModel::currentTagIdChanged,
ptr,
&FilteredRoomlistModel::updateFilterTag);
return ptr;
}); });
qmlRegisterSingletonType<RoomlistModel>( qmlRegisterSingletonType<RoomlistModel>(
"im.nheko", 1, 0, "Communities", [](QQmlEngine *, QJSEngine *) -> QObject * { "im.nheko", 1, 0, "Communities", [](QQmlEngine *, QJSEngine *) -> QObject * {