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 {
id: label
anchors.fill: parent
text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "")
textFormat: Text.RichText

View file

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

View file

@ -10,7 +10,6 @@ import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3
import im.nheko 1.0
Page {
//leftPadding: Nheko.paddingSmall
//rightPadding: Nheko.paddingSmall
@ -97,8 +96,7 @@ Page {
TapHandler {
margin: -Nheko.paddingSmall
acceptedButtons: Qt.RightButton
onSingleTapped: communityContextMenu.show(model.id);
onSingleTapped: communityContextMenu.show(model.id)
gesturePolicy: TapHandler.ReleaseWithinBounds
}
@ -127,15 +125,26 @@ Page {
height: avatarSize
width: avatarSize
url: {
if (model.avatarUrl.startsWith("mxc://")) {
return model.avatarUrl.replace("mxc://", "image://MxcImage/")
} else {
return "image://colorimage/"+model.avatarUrl+"?" + communityItem.unimportantText
}
if (model.avatarUrl.startsWith("mxc://"))
return model.avatarUrl.replace("mxc://", "image://MxcImage/");
else
return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText;
}
displayName: model.displayName
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();
tags_.clear();
endResetModel();
resetCurrentTagId();
emit tagsChanged();
}
@ -148,12 +149,12 @@ CommunitiesModel::setCurrentTagId(QString tagId)
for (const auto &t : tags_) {
if (t == tag) {
this->currentTagId_ = tagId;
emit currentTagIdChanged();
emit currentTagIdChanged(currentTagId_);
return;
}
}
}
this->currentTagId_ = "";
emit currentTagIdChanged();
emit currentTagIdChanged(currentTagId_);
}

View file

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

View file

@ -324,6 +324,7 @@ RoomlistModel::initializeRooms()
models.clear();
roomids.clear();
invites.clear();
currentRoom_ = nullptr;
invites = cache::client()->invites();
for (const auto &id : invites.keys())
@ -461,6 +462,22 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
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)
: QSortFilterProxyModel(parent)
, roomlistmodel(model)

View file

@ -109,6 +109,7 @@ class FilteredRoomlistModel : public QSortFilterProxyModel
public:
FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr);
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &) const override;
public slots:
int roomidToIndex(QString roomid)
@ -128,6 +129,19 @@ public slots:
void nextRoom();
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:
void currentRoomChanged();
@ -135,4 +149,13 @@ private:
short int calculateImportance(const QModelIndex &idx) const;
RoomlistModel *roomlistmodel;
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>(
"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>(
"im.nheko", 1, 0, "Communities", [](QQmlEngine *, QJSEngine *) -> QObject * {