summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-30 21:41:47 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-30 21:41:47 +0300
commit3097037c3dc882be2efe64dce6aefeea43d5f040 (patch)
tree1e3375fbd423c3bd18513e6d2a502b7fa1e4cfb8 /include
parentShow room tooltips when the sidebar is collapsed (diff)
downloadnheko-3097037c3dc882be2efe64dce6aefeea43d5f040.tar.xz
Add prototype room settings menu
Diffstat (limited to 'include')
-rw-r--r--include/Cache.h8
-rw-r--r--include/ChatPage.h1
-rw-r--r--include/MainWindow.h6
-rw-r--r--include/TopRoomBar.h4
-rw-r--r--include/dialogs/RoomSettings.hpp88
-rw-r--r--include/ui/Painter.h2
6 files changed, 106 insertions, 3 deletions
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> userSettings() { return userSettings_; } + QSharedPointer<Cache> 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<void(const mtx::requests::CreateRoom &request)> callback); void openJoinRoomDialog(std::function<void(const QString &room_id)> callback); void openLogoutDialog(std::function<void()> callback); + void openRoomSettings(const QString &room_id = ""); protected: void closeEvent(QCloseEvent *event); @@ -147,4 +149,8 @@ private: QSharedPointer<OverlayModal> logoutModal_; //! Logout dialog. QSharedPointer<dialogs::Logout> logoutDialog_; + //! Room settings modal. + QSharedPointer<OverlayModal> roomSettingsModal_; + //! Room settings dialog. + QSharedPointer<dialogs::RoomSettings> 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 <QIcon> #include <QImage> #include <QLabel> -#include <QMenu> #include <QPaintEvent> #include <QSharedPointer> #include <QVBoxLayout> @@ -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 <QFrame> +#include <QImage> + +#include "Cache.h" + +class FlatButton; +class TextField; +class Avatar; +class QPixmap; +class QLayout; +class QLabel; + +template<class T> +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> 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> 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,