mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Enable toggling tags
This commit is contained in:
parent
d8c0d4874b
commit
8d2d8dc267
8 changed files with 73 additions and 15 deletions
|
@ -28,6 +28,7 @@ Rectangle {
|
|||
|
||||
Label {
|
||||
id: label
|
||||
|
||||
anchors.fill: parent
|
||||
text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "")
|
||||
textFormat: Text.RichText
|
||||
|
|
|
@ -24,12 +24,13 @@ Rectangle {
|
|||
id: communityListC
|
||||
|
||||
minimumWidth: communitiesList.avatarSize * 4 + Nheko.paddingMedium * 2
|
||||
collapsedWidth: communitiesList.avatarSize + 2* Nheko.paddingMedium
|
||||
collapsedWidth: communitiesList.avatarSize + 2 * Nheko.paddingMedium
|
||||
preferredWidth: collapsedWidth
|
||||
maximumWidth: communitiesList.avatarSize * 10 + 2* Nheko.paddingMedium
|
||||
maximumWidth: communitiesList.avatarSize * 10 + 2 * Nheko.paddingMedium
|
||||
|
||||
CommunitiesList {
|
||||
id: communitiesList
|
||||
|
||||
collapsed: parent.collapsed
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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_);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 * {
|
||||
|
|
Loading…
Reference in a new issue