summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorMax Sandholm <max@sandholm.org>2018-01-09 15:07:32 +0200
committermujx <mujx@users.noreply.github.com>2018-01-09 15:07:32 +0200
commit312df6f3bbcba0ad502864b13f9c51b4854ea2ce (patch)
treed43396836cb2ba21b13f218a6d25a7c82049338b /include
parentMake usernames in timeline less bold (diff)
downloadnheko-312df6f3bbcba0ad502864b13f9c51b4854ea2ce.tar.xz
Communities (#195)
Diffstat (limited to 'include')
-rw-r--r--include/ChatPage.h18
-rw-r--r--include/CommunitiesList.h42
-rw-r--r--include/CommunitiesListItem.h98
-rw-r--r--include/Community.h62
-rw-r--r--include/MatrixClient.h8
-rw-r--r--include/RoomInfoListItem.h13
-rw-r--r--include/RoomList.h6
-rw-r--r--include/ui/Theme.h5
8 files changed, 246 insertions, 6 deletions
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 <QTimer> #include <QWidget> +#include "CommunitiesList.h" +#include "Community.h" #include <mtx.hpp> 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<QString> &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<QString, QPixmap> room_avatars_; + QMap<QString, QPixmap> community_avatars_; UserInfoWidget *user_info_widget_; QMap<QString, RoomState> state_manager_; QMap<QString, QSharedPointer<RoomSettings>> settingsManager_; + QMap<QString, QSharedPointer<Community>> communityManager_; + // Keeps track of the users currently typing on each room. QMap<QString, QList<QString>> 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 <QScrollArea> +#include <QSharedPointer> +#include <QVBoxLayout> +#include <QWidget> + +#include "CommunitiesListItem.h" +#include "Community.h" +#include "MatrixClient.h" +#include "ui/Theme.h" + +class CommunitiesList : public QWidget +{ + Q_OBJECT + +public: + CommunitiesList(QSharedPointer<MatrixClient> client, QWidget *parent = nullptr); + ~CommunitiesList(); + + void setCommunities(const QMap<QString, QSharedPointer<Community>> &communities); + void clear(); + + void addCommunity(QSharedPointer<Community> 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<QString, QSharedPointer<CommunitiesListItem>> communities_; + + QSharedPointer<MatrixClient> 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 <QDebug> +#include <QMouseEvent> +#include <QPainter> +#include <QSharedPointer> +#include <QWidget> + +#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> community, + QString community_id, + QWidget *parent = nullptr); + + ~CommunitiesListItem(); + + void setCommunity(QSharedPointer<Community> 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> 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 <QJsonObject> +#include <QObject> +#include <QString> +#include <QUrl> + +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<QString> getRoomList() const; + +signals: + void roomsChanged(QList<QString> &rooms); + +private: + QUrl avatar_; + QString name_; + QString short_description_; + QString long_description_; + + QList<QString> 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<QString> +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<QString> &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<QString> room_ids); signals: void roomChanged(const QString &room_id); @@ -105,6 +107,10 @@ private: QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_; QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_; + QString selectedRoom_; + + bool filterRooms_ = false; + QList<QString> roomFilter_ = QList<QString>(); // which rooms to include in the room list QSharedPointer<MatrixClient> client_; QSharedPointer<Cache> 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;