From 3097037c3dc882be2efe64dce6aefeea43d5f040 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 30 Apr 2018 21:41:47 +0300 Subject: Add prototype room settings menu --- include/Cache.h | 8 ++++ include/ChatPage.h | 1 + include/MainWindow.h | 6 +++ include/TopRoomBar.h | 4 +- include/dialogs/RoomSettings.hpp | 88 ++++++++++++++++++++++++++++++++++++++++ include/ui/Painter.h | 2 +- 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 include/dialogs/RoomSettings.hpp (limited to 'include') diff --git a/include/Cache.h b/include/Cache.h index a92f6bc5..db5dba00 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -64,6 +64,8 @@ struct RoomInfo std::string avatar_url; //! Whether or not the room is an invite. bool is_invite = false; + //! Total number of members in the room. + int16_t member_count = 0; }; inline void @@ -73,6 +75,9 @@ to_json(json &j, const RoomInfo &info) j["topic"] = info.topic; j["avatar_url"] = info.avatar_url; j["is_invite"] = info.is_invite; + + if (info.member_count != 0) + j["member_count"] = info.member_count; } inline void @@ -82,6 +87,9 @@ from_json(const json &j, RoomInfo &info) info.topic = j.at("topic"); info.avatar_url = j.at("avatar_url"); info.is_invite = j.at("is_invite"); + + if (j.count("member_count")) + info.member_count = j.at("member_count"); } //! Basic information per member; diff --git a/include/ChatPage.h b/include/ChatPage.h index 831f3933..1582db06 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -80,6 +80,7 @@ public: } QSharedPointer userSettings() { return userSettings_; } + QSharedPointer cache() { return cache_; } signals: void contentLoaded(); diff --git a/include/MainWindow.h b/include/MainWindow.h index d747f9b4..08d7e53e 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -50,6 +50,7 @@ class JoinRoom; class LeaveRoom; class Logout; class ReCaptcha; +class RoomSettings; } class MainWindow : public QMainWindow @@ -68,6 +69,7 @@ public: std::function callback); void openJoinRoomDialog(std::function callback); void openLogoutDialog(std::function callback); + void openRoomSettings(const QString &room_id = ""); protected: void closeEvent(QCloseEvent *event); @@ -147,4 +149,8 @@ private: QSharedPointer logoutModal_; //! Logout dialog. QSharedPointer logoutDialog_; + //! Room settings modal. + QSharedPointer roomSettingsModal_; + //! Room settings dialog. + QSharedPointer roomSettingsDialog_; }; diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 12fd0645..37a0b61b 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -66,8 +65,9 @@ private: QLabel *nameLabel_; Label *topicLabel_; - QMenu *menu_; + Menu *menu_; QAction *leaveRoom_; + QAction *roomSettings_; QAction *inviteUsers_; FlatButton *settingsBtn_; diff --git a/include/dialogs/RoomSettings.hpp b/include/dialogs/RoomSettings.hpp new file mode 100644 index 00000000..fbbc2e02 --- /dev/null +++ b/include/dialogs/RoomSettings.hpp @@ -0,0 +1,88 @@ +#pragma once + +#include +#include + +#include "Cache.h" + +class FlatButton; +class TextField; +class Avatar; +class QPixmap; +class QLayout; +class QLabel; + +template +class QSharedPointer; + +class TopSection : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + +public: + TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr) + : QWidget{parent} + , info_{std::move(info)} + { + textColor_ = palette().color(QPalette::Text); + avatar_ = QPixmap::fromImage(img.scaled( + AvatarSize, AvatarSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } + + QSize sizeHint() const override + { + QFont font; + font.setPixelSize(18); + return QSize(200, AvatarSize + QFontMetrics(font).ascent() + 6 * Padding); + } + + QColor textColor() const { return textColor_; } + void setTextColor(QColor &color) { textColor_ = color; } + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + static constexpr int AvatarSize = 72; + static constexpr int Padding = 5; + + RoomInfo info_; + QPixmap avatar_; + QColor textColor_; +}; + +namespace dialogs { + +class RoomSettings : public QFrame +{ + Q_OBJECT +public: + RoomSettings(const QString &room_id, + QSharedPointer cache, + QWidget *parent = nullptr); + +signals: + void closing(); + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + static constexpr int AvatarSize = 64; + + void setAvatar(const QImage &img) { avatarImg_ = img; } + + QSharedPointer cache_; + + // Button section + FlatButton *saveBtn_; + FlatButton *cancelBtn_; + + RoomInfo info_; + QString room_id_; + QImage avatarImg_; +}; + +} // dialogs diff --git a/include/ui/Painter.h b/include/ui/Painter.h index 9558b004..8de39651 100644 --- a/include/ui/Painter.h +++ b/include/ui/Painter.h @@ -103,7 +103,7 @@ public: drawPixmap(region, pix); } - void drawLetterAvatar(const QChar &c, + void drawLetterAvatar(const QString &c, const QColor &penColor, const QColor &brushColor, int w, -- cgit 1.5.1