From 312df6f3bbcba0ad502864b13f9c51b4854ea2ce Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 9 Jan 2018 15:07:32 +0200 Subject: Communities (#195) --- include/ChatPage.h | 18 +++++++- include/CommunitiesList.h | 42 +++++++++++++++++++ include/CommunitiesListItem.h | 98 +++++++++++++++++++++++++++++++++++++++++++ include/Community.h | 62 +++++++++++++++++++++++++++ include/MatrixClient.h | 8 ++++ include/RoomInfoListItem.h | 13 ++++-- include/RoomList.h | 6 +++ include/ui/Theme.h | 5 ++- 8 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 include/CommunitiesList.h create mode 100644 include/CommunitiesListItem.h create mode 100644 include/Community.h (limited to 'include') diff --git a/include/ChatPage.h b/include/ChatPage.h index 584424c0..754ee0f4 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -24,6 +24,8 @@ #include #include +#include "CommunitiesList.h" +#include "Community.h" #include class Cache; @@ -80,6 +82,7 @@ private slots: void showUnreadMessageNotification(int count); void updateTopBarAvatar(const QString &roomid, const QPixmap &img); void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name); + void updateOwnCommunitiesInfo(const QList &own_communities); void setOwnAvatar(const QPixmap &img); void initialSyncCompleted(const mtx::responses::Sync &response); void syncCompleted(const mtx::responses::Sync &response); @@ -126,13 +129,21 @@ private: QHBoxLayout *topLayout_; Splitter *splitter; - QFrame *sideBar_; + QWidget *sideBar_; + QWidget *communitiesSideBar_; + QVBoxLayout *communitiesSideBarLayout_; QVBoxLayout *sideBarLayout_; + QVBoxLayout *sideBarTopLayout_; + QVBoxLayout *sideBarMainLayout_; + QWidget *sideBarTopWidget_; + QVBoxLayout *sideBarTopWidgetLayout_; QFrame *content_; QVBoxLayout *contentLayout_; + CommunitiesList *communitiesList_; RoomList *room_list_; + TimelineViewManager *view_manager_; SideBarActions *sidebarActions_; @@ -145,13 +156,18 @@ private: QTimer *consensusTimer_; QString current_room_; + QString current_community_; + QMap room_avatars_; + QMap community_avatars_; UserInfoWidget *user_info_widget_; QMap state_manager_; QMap> settingsManager_; + QMap> communityManager_; + // Keeps track of the users currently typing on each room. QMap> typingUsers_; QTimer *typingRefresher_; diff --git a/include/CommunitiesList.h b/include/CommunitiesList.h new file mode 100644 index 00000000..53715363 --- /dev/null +++ b/include/CommunitiesList.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include + +#include "CommunitiesListItem.h" +#include "Community.h" +#include "MatrixClient.h" +#include "ui/Theme.h" + +class CommunitiesList : public QWidget +{ + Q_OBJECT + +public: + CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); + ~CommunitiesList(); + + void setCommunities(const QMap> &communities); + void clear(); + + void addCommunity(QSharedPointer community, const QString &community_id); + void removeCommunity(const QString &community_id); +signals: + void communityChanged(const QString &community_id); + +public slots: + void updateCommunityAvatar(const QString &community_id, const QPixmap &img); + void highlightSelectedCommunity(const QString &community_id); + +private: + QVBoxLayout *topLayout_; + QVBoxLayout *contentsLayout_; + QWidget *scrollAreaContents_; + QScrollArea *scrollArea_; + + QMap> communities_; + + QSharedPointer client_; +}; diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h new file mode 100644 index 00000000..099b4fa2 --- /dev/null +++ b/include/CommunitiesListItem.h @@ -0,0 +1,98 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "Community.h" +#include "Menu.h" +#include "ui/Theme.h" + +class CommunitiesListItem : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QColor highlightedBackgroundColor READ highlightedBackgroundColor WRITE + setHighlightedBackgroundColor) + Q_PROPERTY( + QColor hoverBackgroundColor READ hoverBackgroundColor WRITE setHoverBackgroundColor) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) + +public: + CommunitiesListItem(QSharedPointer community, + QString community_id, + QWidget *parent = nullptr); + + ~CommunitiesListItem(); + + void setCommunity(QSharedPointer community); + + inline bool isPressed() const; + inline void setAvatar(const QImage &avatar_image); + + QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; } + QColor hoverBackgroundColor() const { return hoverBackgroundColor_; } + QColor backgroundColor() const { return backgroundColor_; } + + void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; } + void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; } + void setBackgroundColor(QColor &color) { backgroundColor_ = color; } + + QColor highlightedBackgroundColor_; + QColor hoverBackgroundColor_; + QColor backgroundColor_; + +signals: + void clicked(const QString &community_id); + +public slots: + void setPressedState(bool state); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; + +private: + const int IconSize = 55; + + QSharedPointer community_; + QString communityId_; + QString communityName_; + QString communityShortDescription; + + QPixmap communityAvatar_; + + Menu *menu_; + bool isPressed_ = false; +}; + +inline bool +CommunitiesListItem::isPressed() const +{ + return isPressed_; +} + +inline void +CommunitiesListItem::setAvatar(const QImage &avatar_image) +{ + communityAvatar_ = QPixmap::fromImage( + avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + update(); +} + +class WorldCommunityListItem : public CommunitiesListItem +{ + Q_OBJECT +public: + WorldCommunityListItem(QWidget *parent = nullptr); + ~WorldCommunityListItem(); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + +private: + const int IconSize = 55; +}; diff --git a/include/Community.h b/include/Community.h new file mode 100644 index 00000000..0d70dee1 --- /dev/null +++ b/include/Community.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include +#include +#include + +class Community : public QObject +{ + Q_OBJECT + +public: + void parseProfile(const QJsonObject &profile); + void parseRooms(const QJsonObject &rooms); + + inline QUrl getAvatar() const; + inline QString getName() const; + inline QString getShortDescription() const; + inline QString getLongDescription() const; + inline const QList getRoomList() const; + +signals: + void roomsChanged(QList &rooms); + +private: + QUrl avatar_; + QString name_; + QString short_description_; + QString long_description_; + + QList rooms_; +}; + +inline QUrl +Community::getAvatar() const +{ + return avatar_; +} + +inline QString +Community::getName() const +{ + return name_; +} + +inline QString +Community::getShortDescription() const +{ + return short_description_; +} + +inline QString +Community::getLongDescription() const +{ + return long_description_; +} + +inline const QList +Community::getRoomList() const +{ + return rooms_; +} diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 2627f578..8936003f 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -48,6 +48,9 @@ public: void versions() noexcept; void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url); void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl); + void fetchCommunityAvatar(const QString &communityId, const QUrl &avatarUrl); + void fetchCommunityProfile(const QString &communityId); + void fetchCommunityRooms(const QString &communityId); void fetchOwnAvatar(const QUrl &avatar_url); void downloadImage(const QString &event_id, const QUrl &url); void downloadFile(const QString &event_id, const QUrl &url); @@ -71,6 +74,7 @@ public: public slots: void getOwnProfile() noexcept; + void getOwnCommunities() noexcept; void logout() noexcept; void setServer(const QString &server) @@ -103,12 +107,16 @@ signals: const QString &url, const QByteArray &data); void userAvatarRetrieved(const QString &userId, const QImage &img); + void communityAvatarRetrieved(const QString &communityId, const QPixmap &img); + void communityProfileRetrieved(const QString &communityId, const QJsonObject &profile); + void communityRoomsRetrieved(const QString &communityId, const QJsonObject &rooms); void ownAvatarRetrieved(const QPixmap &img); void imageDownloaded(const QString &event_id, const QPixmap &img); void fileDownloaded(const QString &event_id, const QByteArray &data); // Returned profile data for the user's account. void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); + void getOwnCommunitiesResponse(const QList &own_communities); void initialSyncCompleted(const mtx::responses::Sync &response); void initialSyncFailed(const QString &msg); void syncCompleted(const mtx::responses::Sync &response); diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index 799e95bb..5cfea783 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -73,9 +73,10 @@ public: void clearUnreadMessageCount(); void setState(const RoomState &state); - bool isPressed() const { return isPressed_; } - RoomState state() const { return state_; } - int unreadMessageCount() const { return unreadMsgCount_; } + QString roomId(); + bool isPressed() const { return isPressed_; }; + RoomState state() const { return state_; }; + int unreadMessageCount() const { return unreadMsgCount_; }; void setAvatar(const QImage &avatar_image); void setDescriptionMessage(const DescInfo &info); @@ -182,3 +183,9 @@ private: QRectF acceptBtnRegion_; QRectF declineBtnRegion_; }; + +inline QString +RoomInfoListItem::roomId() +{ + return roomId_; +} diff --git a/include/RoomList.h b/include/RoomList.h index 6b2151a2..d10cf5db 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -64,6 +64,8 @@ public: const QString &room_id); void addInvitedRoom(const QString &room_id, const mtx::responses::InvitedRoom &room); void removeRoom(const QString &room_id, bool reset); + void setFilterRooms(bool filterRooms); + void setRoomFilter(QList room_ids); signals: void roomChanged(const QString &room_id); @@ -105,6 +107,10 @@ private: QSharedPointer leaveRoomDialog_; QMap> rooms_; + QString selectedRoom_; + + bool filterRooms_ = false; + QList roomFilter_ = QList(); // which rooms to include in the room list QSharedPointer client_; QSharedPointer cache_; diff --git a/include/ui/Theme.h b/include/ui/Theme.h index c6c39553..c2e4ab59 100644 --- a/include/ui/Theme.h +++ b/include/ui/Theme.h @@ -13,8 +13,9 @@ enum class AvatarType }; namespace sidebar { -static const int SmallSize = 60; -static const int NormalSize = 300; +static const int SmallSize = 60; +static const int NormalSize = 300; +static const int CommunitiesSidebarSize = 64; } // Default font size. const int FontSize = 16; -- cgit 1.5.1