From 0a833b6e9be809906ab5dc1ec6c2f602660aa13b Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Tue, 8 Jun 2021 17:20:09 -0400 Subject: Avoid unnecessary QColor -> QString conversions --- src/timeline/TimelineViewManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 628f3c31..0785e3e1 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -122,8 +122,7 @@ QColor TimelineViewManager::userColor(QString id, QColor background) { if (!userColors.contains(id)) - userColors.insert( - id, QColor(utils::generateContrastingHexColor(id, background.name()))); + userColors.insert(id, QColor(utils::generateContrastingHexColor(id, background))); return userColors.value(id); } -- cgit 1.5.1 From 8d2d8dc26727a5b46613d83522490f568aef7cad Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 11 Jun 2021 14:51:29 +0200 Subject: Enable toggling tags --- resources/qml/Avatar.qml | 1 + resources/qml/ChatPage.qml | 5 +++-- resources/qml/CommunitiesList.qml | 25 +++++++++++++++++-------- src/timeline/CommunitiesModel.cpp | 5 +++-- src/timeline/CommunitiesModel.h | 4 ++-- src/timeline/RoomlistModel.cpp | 17 +++++++++++++++++ src/timeline/RoomlistModel.h | 23 +++++++++++++++++++++++ src/timeline/TimelineViewManager.cpp | 8 +++++++- 8 files changed, 73 insertions(+), 15 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml index 9eb3380e..6c12952a 100644 --- a/resources/qml/Avatar.qml +++ b/resources/qml/Avatar.qml @@ -28,6 +28,7 @@ Rectangle { Label { id: label + anchors.fill: parent text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "") textFormat: Text.RichText diff --git a/resources/qml/ChatPage.qml b/resources/qml/ChatPage.qml index 5ccdd9f1..6cd48788 100644 --- a/resources/qml/ChatPage.qml +++ b/resources/qml/ChatPage.qml @@ -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 } diff --git a/resources/qml/CommunitiesList.qml b/resources/qml/CommunitiesList.qml index 6ca619c4..0ccd7e82 100644 --- a/resources/qml/CommunitiesList.qml +++ b/resources/qml/CommunitiesList.qml @@ -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 } } diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index c8ebaa96..9b758e97 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -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_); } diff --git a/src/timeline/CommunitiesModel.h b/src/timeline/CommunitiesModel.h index 3f6a2a4c..038c253b 100644 --- a/src/timeline/CommunitiesModel.h +++ b/src/timeline/CommunitiesModel.h @@ -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: diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 4dd44b30..c0fb74a4 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -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) diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h index 7ee0419f..b89c9a54 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h @@ -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; }; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index faf56b85..2ee79d4f 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -195,7 +195,13 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par }); qmlRegisterSingletonType( "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( "im.nheko", 1, 0, "Communities", [](QQmlEngine *, QJSEngine *) -> QObject * { -- cgit 1.5.1 From a5291605a9912a411100edf8ee88e59857d8b9aa Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 11 Jun 2021 17:54:05 +0200 Subject: Reenable tag hiding --- resources/qml/CommunitiesList.qml | 10 +++--- src/timeline/CommunitiesModel.cpp | 30 ++++++++++++++++- src/timeline/CommunitiesModel.h | 4 +++ src/timeline/RoomlistModel.cpp | 65 +++++++++++++++++++++++++++--------- src/timeline/RoomlistModel.h | 3 ++ src/timeline/TimelineViewManager.cpp | 4 +++ 6 files changed, 94 insertions(+), 22 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/resources/qml/CommunitiesList.qml b/resources/qml/CommunitiesList.qml index 0ccd7e82..6aab949c 100644 --- a/resources/qml/CommunitiesList.qml +++ b/resources/qml/CommunitiesList.qml @@ -33,16 +33,16 @@ Page { Platform.Menu { id: communityContextMenu - property string id + property string tagId function show(id_, tags_) { - id = id_; + tagId = id_; open(); } Platform.MenuItem { - text: qsTr("Leave room") - onTriggered: Rooms.leave(roomContextMenu.roomid) + text: qsTr("Hide rooms with this tag or from this space by default.") + onTriggered: Communities.toggleTagId(communityContextMenu.tagId) } } @@ -65,7 +65,7 @@ Page { states: [ State { name: "highlight" - when: hovered.hovered && !(Communities.currentTagId == model.id) + when: (hovered.hovered || model.hidden) && !(Communities.currentTagId == model.id) PropertyChanges { target: communityItem diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index 9b758e97..96a450ea 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -21,6 +21,7 @@ CommunitiesModel::roleNames() const {DisplayName, "displayName"}, {Tooltip, "tooltip"}, {ChildrenHidden, "childrenHidden"}, + {Hidden, "hidden"}, {Id, "id"}, }; } @@ -38,6 +39,8 @@ CommunitiesModel::data(const QModelIndex &index, int role) const return tr("Shows all rooms without filtering."); case CommunitiesModel::Roles::ChildrenHidden: return false; + case CommunitiesModel::Roles::Hidden: + return false; case CommunitiesModel::Roles::Id: return ""; } @@ -82,8 +85,10 @@ CommunitiesModel::data(const QModelIndex &index, int role) const } switch (role) { + case CommunitiesModel::Roles::Hidden: + return hiddentTagIds_.contains("tag:" + tag); case CommunitiesModel::Roles::ChildrenHidden: - return UserSettings::instance()->hiddenTags().contains("tag:" + tag); + return true; case CommunitiesModel::Roles::Id: return "tag:" + tag; } @@ -107,9 +112,12 @@ CommunitiesModel::initializeSidebar() tags_.clear(); for (const auto &t : ts) tags_.push_back(QString::fromStdString(t)); + + hiddentTagIds_ = UserSettings::instance()->hiddenTags(); endResetModel(); emit tagsChanged(); + emit hiddenTagsChanged(); } void @@ -158,3 +166,23 @@ CommunitiesModel::setCurrentTagId(QString tagId) this->currentTagId_ = ""; emit currentTagIdChanged(currentTagId_); } + +void +CommunitiesModel::toggleTagId(QString tagId) +{ + if (hiddentTagIds_.contains(tagId)) { + hiddentTagIds_.removeOne(tagId); + UserSettings::instance()->setHiddenTags(hiddentTagIds_); + } else { + hiddentTagIds_.push_back(tagId); + UserSettings::instance()->setHiddenTags(hiddentTagIds_); + } + + if (tagId.startsWith("tag:")) { + auto idx = tags_.indexOf(tagId.mid(4)); + if (idx != -1) + emit dataChanged(index(idx), index(idx), {Hidden}); + } + + emit hiddenTagsChanged(); +} diff --git a/src/timeline/CommunitiesModel.h b/src/timeline/CommunitiesModel.h index 038c253b..c98b5955 100644 --- a/src/timeline/CommunitiesModel.h +++ b/src/timeline/CommunitiesModel.h @@ -25,6 +25,7 @@ public: DisplayName, Tooltip, ChildrenHidden, + Hidden, Id, }; @@ -49,12 +50,15 @@ public slots: emit currentTagIdChanged(currentTagId_); } QStringList tags() const { return tags_; } + void toggleTagId(QString tagId); signals: void currentTagIdChanged(QString tagId); + void hiddenTagsChanged(); void tagsChanged(); private: QStringList tags_; QString currentTagId_; + QStringList hiddentTagIds_; }; diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index c0fb74a4..0f980c6c 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -462,22 +462,6 @@ 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) @@ -502,6 +486,55 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare sort(0); } +void +FilteredRoomlistModel::updateHiddenTagsAndSpaces() +{ + hiddenTags.clear(); + hiddenSpaces.clear(); + for (const auto &t : UserSettings::instance()->hiddenTags()) { + if (t.startsWith("tag:")) + hiddenTags.push_back(t.mid(4)); + else if (t.startsWith("space:")) + hiddenSpaces.push_back(t.mid(6)); + } + + invalidateFilter(); +} + +bool +FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const +{ + if (filterType == FilterBy::Nothing) { + if (!hiddenTags.empty()) { + auto tags = + sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) + .toStringList(); + + for (const auto &t : tags) + if (hiddenTags.contains(t)) + return false; + } + + return true; + } else if (filterType == FilterBy::Tag) { + auto tags = sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) + .toStringList(); + + if (!tags.contains(filterStr)) + return false; + else if (!hiddenTags.empty()) { + for (const auto &t : tags) + if (t != filterStr && hiddenTags.contains(t)) + return false; + } + return true; + } else { + return true; + } +} + void FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on) { diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h index b89c9a54..b0244886 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h @@ -142,6 +142,8 @@ public slots: invalidateFilter(); } + void updateHiddenTagsAndSpaces(); + signals: void currentRoomChanged(); @@ -158,4 +160,5 @@ private: }; QString filterStr = ""; FilterBy filterType = FilterBy::Nothing; + QStringList hiddenTags, hiddenSpaces; }; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 2ee79d4f..c109d38e 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -201,6 +201,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par &CommunitiesModel::currentTagIdChanged, ptr, &FilteredRoomlistModel::updateFilterTag); + connect(self->communities_, + &CommunitiesModel::hiddenTagsChanged, + ptr, + &FilteredRoomlistModel::updateHiddenTagsAndSpaces); return ptr; }); qmlRegisterSingletonType( -- cgit 1.5.1 From 1d80f5d0b4f353d135a5d7b348416db503197a16 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 11 Jun 2021 21:25:06 +0200 Subject: Remove useless capture --- src/timeline/TimelineViewManager.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index c109d38e..a6947f99 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -396,18 +396,17 @@ TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img) imgDialog->showFullScreen(); auto room = rooms_->currentRoom(); - connect( - imgDialog, &dialogs::ImageOverlay::saving, room, [this, eventId, imgDialog, room]() { - // hide the overlay while presenting the save dialog for better - // cross platform support. - imgDialog->hide(); - - if (!room->saveMedia(eventId)) { - imgDialog->show(); - } else { - imgDialog->close(); - } - }); + connect(imgDialog, &dialogs::ImageOverlay::saving, room, [eventId, imgDialog, room]() { + // hide the overlay while presenting the save dialog for better + // cross platform support. + imgDialog->hide(); + + if (!room->saveMedia(eventId)) { + imgDialog->show(); + } else { + imgDialog->close(); + } + }); } void -- cgit 1.5.1