From 0247b47553f03ee21bf9040b76cb30029868029f Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 22 Jul 2018 15:41:06 +0300 Subject: [PATCH] Refactor the room settings menu to look like the user profile --- resources/icons/ui/edit.png | Bin 0 -> 592 bytes resources/icons/ui/edit.svg | 1 - resources/icons/ui/edit@2x.png | Bin 0 -> 858 bytes resources/icons/ui/world.png | Bin 0 -> 1484 bytes resources/icons/ui/world.svg | 1 - resources/icons/ui/world@2x.png | Bin 0 -> 2833 bytes resources/res.qrc | 8 +- src/CommunitiesListItem.cpp | 2 +- src/dialogs/RoomSettings.cpp | 242 +++++++++++--------------------- src/dialogs/RoomSettings.h | 36 +---- 10 files changed, 94 insertions(+), 196 deletions(-) create mode 100644 resources/icons/ui/edit.png delete mode 100644 resources/icons/ui/edit.svg create mode 100644 resources/icons/ui/edit@2x.png create mode 100644 resources/icons/ui/world.png delete mode 100644 resources/icons/ui/world.svg create mode 100644 resources/icons/ui/world@2x.png diff --git a/resources/icons/ui/edit.png b/resources/icons/ui/edit.png new file mode 100644 index 0000000000000000000000000000000000000000..762da80ebd04528a9a0c3c7b7111ae7be92bdacf GIT binary patch literal 592 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{-GzZ+Rj;xUkjGiz z5m^kh={g8AI%&+V01C2~c>21sKVlc-laM(5_$AOrMmbLx#}JR>ORxOZa&eS6{_%Zk z0q-Xvr;ZMlOKQ4`nw~-HlDF6HT(q}$FX#L2*lEe~|9x)HyKFZvz3*pw+_{=MORZexBOGMSk6B0@Tc8o_XB@Qdz;;V7W}l&o^R^@&5s^x?73U-R?NC3^7E%e zM%nYx%h^kAbUeJ-z;E{0LUNzz>3T-N#)yg;^B#brNVUW@q9i4;B-JXpC>2OC7#SE^ z=o*;o8X1KcnphcukhX!5m4U&jQ+D%EH00)|WTsW(*06hen-WliB*=!~{Irtt#G+J& k^73-M%)IR4 \ No newline at end of file diff --git a/resources/icons/ui/edit@2x.png b/resources/icons/ui/edit@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..31295e1bf08667edeb3fb4cd9c267cae9e4cd319 GIT binary patch literal 858 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I0wfs{c7_5;mUKs7M+SzC{oH>NS%G|oWRD45bDP46hOx7_4S6Fo+k-*%fF5lweBoc6VW5SkAGfyD zY->rpmh~g~50}MJBh{XuRS)~wKFt(5c60H={tw2lkD8e-?2O{Aw-A{>OJSDtAC8mN zo)#~ToEGLYcy~hG^U{Jx-)H|Y?#TP|`$yh`^Q(SH?UVdbeCFbZt7`jPkG@Ymb6|e> z$K5}(9_Sl{AAbL+yD>lbqqXlJ*CNvz(fPc8R7K-G4;|RPT5g-xkCX@2A%FPXc>kn6 z%l`3J?H?DnNsXmE@1Ic7_+uT7`;R&C?(gMi+ZTK^|LNYw_em4m^q+8QV*_J<F!-b|C5)mWH$Npa ztrE9}=AuRGff^)1HU#IVm6RtIr81P4m+NKbWfvzW7NqLs7p2dBXCnnv#Ng@b=d#Wz Gp$P!$k82%4(=4u%^T6U1T9fOQ9<(x5=8P}MJ$S{nfK5zVTa(6#%#d1%NdY03h-K zKp~vfJW;MEE{rA2F=4-c@)gP^nRGow33zB%jETmJV;x)|R-&Tdk+e!7 z;)?_lhon&z%(2H5`9EFh;jJA-=&EKb+O_Onh zQ_Zml%j<Y&3`BgZp4~GJ2et8 zBQ^33?J|;m66dNUf{V z?p6r;!Y=3)^UnhN%&~?D{&w5kdIz469(}viI$ita4RLebOdB-0uoAiz8lU#1(NcL- zU&3#neH1Adgge&pJ?%|!!Iab(c{$&@o{0*!=Vfe&zY7HOZuZe18y>Jn^QKZvc_zrybmC`oP`PS@v0dd)&zC*B}p zE{dfK>UbX7)@n0DDRphBW=REYn`sTY|1(*3tl>73@OI^Sh}K|QxCq61v^(Ru#X=d{ z($i3CfhC~VY3MZoN_(cRR?!)G-(@EoKAX;nAT{dv;#d&9E5E~I_FY@R#lbDnt-OUy zLQRBh9#BWF|waymXYn)(kAQMpD9E_Eh_1i#IO_9K`9VZmaA$-7zO8BTPo*zBv(a%+THOOKLzdCtfn zOG<@^d}^(9k0m^^m4fyvS+0#=P*%bxKzodYA7>YeNXUJctdx+u3KF@jyBB+dVBpL! z7?K+=arQ1&l)(5n@7jr{xEDvrbNuC~S!+d&xk1D(Zu7U4C$-WBu8mx3l2BP6Rpics zY{FH|OrZcoxV-LQa?JyM{F3eA2@jdxw&pbl4SoFeNBG#cGq5In?C@Ph_j&cjp@Ki^ zW+NtC2H+j&3)M}|QcD!09$X&2TsXtGHpF2AdDhWvQ)$+a-Q8`&-9aVhOsZ|D@tlt| zr;mk7ja5mc(06EIoRr`a-6@Kn_XkJ2$9vEa3M6rJEfhkZA(m7uNos|N8xNMtx4Da1% \ No newline at end of file diff --git a/resources/icons/ui/world@2x.png b/resources/icons/ui/world@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..f32cc24e45baf37fcdb5d54f3e3335a937bfca10 GIT binary patch literal 2833 zcmZ{mSv=J3`^Uf5u_Rey$i7oFX6zxm8KcpRr9xSc5qQzHf=$y%w# zQe@9INU|ntS)<7Eo9FO<@IScTpVxKWpU-`r+y{5cWt24^k2nti0DK6z1%|2k|B8#9 zNvtl-gemO4rk6|speB>|z=MO?%iM%xE&;$@C8jSC0QQ+9{1O1%h5*2dI{+Bu1Au5S z=?&VDdBEz4w6*|%igbA>v*QkiUkhVy8vCzU%v1{RFo&RU#3f7697yD(lqesky&uyy zjj%9vxbx*F8RzfXe!3%WsxnvHzeBTxJtv+pCXy(Th{*;!rpO!rViV*Nrx@~NY~6FR zq!<=hol;ZdNI4Hjt2IEgk}K}rKd+J@YzYs^5|=2$5+0~I@+x8ABazGnbD4NEz|BIzOesdsw0+N5cT3o1r z$Z=J_LangTD7x=6S{={6EqU2UVfkqS3Nt(cgcM*s_|E2w;d>z0!-Mlt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=A|fI*uz|R+ bn;ya58bP7Hg=>c5OcQ{xL|IgsxySzx-RmDr literal 0 HcmV?d00001 diff --git a/resources/res.qrc b/resources/res.qrc index 8484b299..d024a5d5 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -39,7 +39,6 @@ icons/ui/paper-clip-outline@2x.png icons/ui/angle-pointing-to-left.png icons/ui/angle-pointing-to-left@2x.png - icons/ui/world.svg icons/ui/angle-arrow-down.png icons/ui/angle-arrow-down@2x.png icons/ui/arrow-pointing-down.png @@ -50,7 +49,12 @@ icons/ui/pause-symbol@2x.png icons/ui/remove-symbol.png icons/ui/remove-symbol@2x.png - icons/ui/edit.svg + + icons/ui/world.png + icons/ui/world@2x.png + + icons/ui/edit.png + icons/ui/edit@2x.png icons/emoji-categories/people.png icons/emoji-categories/people@2x.png diff --git a/src/CommunitiesListItem.cpp b/src/CommunitiesListItem.cpp index 8afaebff..f2777e66 100644 --- a/src/CommunitiesListItem.cpp +++ b/src/CommunitiesListItem.cpp @@ -18,7 +18,7 @@ CommunitiesListItem::CommunitiesListItem(QString group_id, QWidget *parent) rippleOverlay_->setClipping(true); if (groupId_ == "world") - avatar_ = QPixmap(":/icons/icons/ui/world.svg"); + avatar_ = QPixmap(":/icons/icons/ui/world.png"); } void diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index cfb25997..2109c86a 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -26,40 +25,55 @@ using namespace dialogs; using namespace mtx::events; +constexpr int BUTTON_SIZE = 36; +constexpr int BUTTON_RADIUS = BUTTON_SIZE / 2; +constexpr int WIDGET_MARGIN = 20; +constexpr int TOP_WIDGET_MARGIN = 2 * WIDGET_MARGIN; +constexpr int WIDGET_SPACING = 15; +constexpr int TEXT_SPACING = 4; +constexpr int BUTTON_SPACING = 2 * TEXT_SPACING; + EditModal::EditModal(const QString &roomId, QWidget *parent) : QWidget(parent) , roomId_{roomId} { - setMinimumWidth(360); setAutoFillBackground(true); setAttribute(Qt::WA_DeleteOnClose, true); setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setWindowModality(Qt::WindowModal); + QFont doubleFont; + doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); + setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + auto layout = new QVBoxLayout(this); + QFont buttonFont; + buttonFont.setPointSizeF(buttonFont.pointSizeF() * 1.3); + applyBtn_ = new FlatButton(tr("APPLY"), this); - applyBtn_->setFontSize(conf::btn::fontSize); + applyBtn_->setFont(buttonFont); applyBtn_->setRippleStyle(ui::RippleStyle::NoRipple); + applyBtn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + cancelBtn_ = new FlatButton(tr("CANCEL"), this); - cancelBtn_->setFontSize(conf::btn::fontSize); + cancelBtn_->setFont(buttonFont); cancelBtn_->setRippleStyle(ui::RippleStyle::NoRipple); + cancelBtn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); auto btnLayout = new QHBoxLayout; - btnLayout->setContentsMargins(5, 20, 5, 5); + btnLayout->setMargin(5); + btnLayout->addStretch(1); btnLayout->addWidget(applyBtn_); btnLayout->addWidget(cancelBtn_); nameInput_ = new TextField(this); - nameInput_->setLabel(tr("Name")); + nameInput_->setLabel(tr("Name").toUpper()); topicInput_ = new TextField(this); - topicInput_->setLabel(tr("Topic")); - - QFont font; - font.setPixelSize(conf::modals::errorFont); + topicInput_->setLabel(tr("Topic").toUpper()); errorField_ = new QLabel(this); - errorField_->setFont(font); errorField_->setWordWrap(true); errorField_->hide(); @@ -154,79 +168,46 @@ EditModal::setFields(const QString &roomName, const QString &roomTopic) topicInput_->setText(roomTopic); } -TopSection::TopSection(const RoomInfo &info, const QImage &img, QWidget *parent) - : QWidget{parent} - , info_{std::move(info)} -{ - textColor_ = palette().color(QPalette::Text); - avatar_ = utils::scaleImageToPixmap(img, AvatarSize); - - QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum); - setSizePolicy(policy); -} - -void -TopSection::setRoomName(const QString &name) -{ - info_.name = name.toStdString(); - update(); -} - -QSize -TopSection::sizeHint() const -{ - QFont font; - font.setPixelSize(18); - return QSize(340, AvatarSize + QFontMetrics(font).ascent()); -} - RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) : QFrame(parent) , room_id_{std::move(room_id)} { - setMaximumWidth(420); retrieveRoomInfo(); - constexpr int SettingsMargin = 2; + QFont doubleFont; + doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + + setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); + setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); auto layout = new QVBoxLayout(this); - layout->setSpacing(15); - layout->setMargin(20); + layout->setSpacing(WIDGET_SPACING); + layout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN); - okBtn_ = new FlatButton(tr("OK"), this); - okBtn_->setFontSize(conf::btn::fontSize); - cancelBtn_ = new FlatButton(tr("CANCEL"), this); - cancelBtn_->setFontSize(conf::btn::fontSize); + QFont font; + font.setWeight(65); + font.setPointSizeF(font.pointSizeF() * 1.2); + auto settingsLabel = new QLabel(tr("Settings").toUpper(), this); + settingsLabel->setFont(font); - auto btnLayout = new QHBoxLayout(); - btnLayout->setSpacing(0); - btnLayout->setMargin(0); - btnLayout->addStretch(1); - btnLayout->addWidget(okBtn_); - btnLayout->addWidget(cancelBtn_); - - auto notifOptionLayout_ = new QHBoxLayout; - notifOptionLayout_->setMargin(SettingsMargin); auto notifLabel = new QLabel(tr("Notifications"), this); auto notifCombo = new QComboBox(this); notifCombo->setDisabled(true); notifCombo->addItem(tr("Muted")); notifCombo->addItem(tr("Mentions only")); notifCombo->addItem(tr("All messages")); - notifLabel->setStyleSheet("font-size: 15px;"); - notifOptionLayout_->addWidget(notifLabel); + auto notifOptionLayout_ = new QHBoxLayout; + notifOptionLayout_->setMargin(0); + notifOptionLayout_->addWidget(notifLabel, Qt::AlignBottom | Qt::AlignLeft); notifOptionLayout_->addWidget(notifCombo, 0, Qt::AlignBottom | Qt::AlignRight); - auto accessOptionLayout = new QHBoxLayout(); - accessOptionLayout->setMargin(SettingsMargin); auto accessLabel = new QLabel(tr("Room access"), this); accessCombo = new QComboBox(this); accessCombo->addItem(tr("Anyone and guests")); accessCombo->addItem(tr("Anyone")); accessCombo->addItem(tr("Invited users")); accessCombo->setDisabled(true); - accessLabel->setStyleSheet("font-size: 15px;"); if (info_.join_rule == JoinRule::Public) { if (info_.guest_access) { @@ -238,24 +219,19 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) accessCombo->setCurrentIndex(2); } - accessOptionLayout->addWidget(accessLabel); - accessOptionLayout->addWidget(accessCombo); + auto accessOptionLayout = new QHBoxLayout(); + accessOptionLayout->setMargin(0); + accessOptionLayout->addWidget(accessLabel, Qt::AlignBottom | Qt::AlignLeft); + accessOptionLayout->addWidget(accessCombo, 0, Qt::AlignBottom | Qt::AlignRight); - auto encryptionOptionLayout = new QHBoxLayout; - encryptionOptionLayout->setMargin(SettingsMargin); auto encryptionLabel = new QLabel(tr("Encryption"), this); - encryptionLabel->setStyleSheet("font-size: 15px;"); - encryptionToggle_ = new Toggle(this); + encryptionToggle_ = new Toggle(this); connect(encryptionToggle_, &Toggle::toggled, this, [this](bool isOn) { if (isOn) return; - QFont font; - font.setPixelSize(conf::fontSize); - QMessageBox msgBox; msgBox.setIcon(QMessageBox::Question); - msgBox.setFont(font); msgBox.setWindowTitle(tr("End-to-End Encryption")); msgBox.setText(tr( "Encryption is currently experimental and things might break unexpectedly.
" @@ -279,7 +255,9 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) } }); - encryptionOptionLayout->addWidget(encryptionLabel); + auto encryptionOptionLayout = new QHBoxLayout; + encryptionOptionLayout->setMargin(0); + encryptionOptionLayout->addWidget(encryptionLabel, Qt::AlignBottom | Qt::AlignLeft); encryptionOptionLayout->addWidget(encryptionToggle_, 0, Qt::AlignBottom | Qt::AlignRight); // Disable encryption button. @@ -296,30 +274,37 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) encryptionLabel->hide(); } - QFont font; - font.setPixelSize(18); - font.setWeight(70); + avatar_ = new Avatar(this); + avatar_->setSize(128); + if (avatarImg_.isNull()) + avatar_->setLetter(utils::firstChar(QString::fromStdString(info_.name))); + else + avatar_->setImage(avatarImg_); - auto menuLabel = new QLabel("Room Settings", this); - menuLabel->setFont(font); + auto roomNameLabel = new QLabel(QString::fromStdString(info_.name), this); + roomNameLabel->setFont(doubleFont); - topSection_ = new TopSection(info_, avatarImg_, this); + auto membersLabel = + new QLabel(QString::fromStdString("%1 members").arg(info_.member_count), this); - editLayout_ = new QHBoxLayout; - editLayout_->setMargin(0); - editLayout_->addWidget(topSection_); + auto textLayout = new QVBoxLayout; + textLayout->addWidget(roomNameLabel); + textLayout->addWidget(membersLabel); + textLayout->setAlignment(roomNameLabel, Qt::AlignCenter | Qt::AlignTop); + textLayout->setAlignment(membersLabel, Qt::AlignCenter | Qt::AlignTop); + textLayout->setSpacing(TEXT_SPACING); + textLayout->setMargin(0); setupEditButton(); - layout->addWidget(menuLabel); - layout->addLayout(editLayout_); + layout->addWidget(avatar_, Qt::AlignCenter | Qt::AlignTop); + layout->addLayout(textLayout); + layout->addLayout(btnLayout_); + layout->addWidget(settingsLabel, Qt::AlignLeft); layout->addLayout(notifOptionLayout_); layout->addLayout(accessOptionLayout); layout->addLayout(encryptionOptionLayout); - layout->addLayout(btnLayout); - - connect(cancelBtn_, &QPushButton::clicked, this, &RoomSettings::closing); - connect(okBtn_, &QPushButton::clicked, this, &RoomSettings::saveSettings); + layout->addStretch(1); connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) { encryptionToggle_->setState(true); @@ -332,9 +317,12 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) void RoomSettings::setupEditButton() { + btnLayout_ = new QHBoxLayout; + btnLayout_->setSpacing(BUTTON_SPACING); + btnLayout_->setMargin(0); + try { - QSettings settings; - auto userId = settings.value("auth/user_id").toString().toStdString(); + auto userId = utils::localUser().toStdString(); hasEditRights_ = cache::client()->hasEnoughPowerLevel( {EventType::RoomName, EventType::RoomTopic}, room_id_.toStdString(), userId); @@ -342,20 +330,17 @@ RoomSettings::setupEditButton() nhlog::db()->warn("lmdb error: {}", e.what()); } - constexpr int buttonSize = 36; - constexpr int iconSize = buttonSize / 2; - if (!hasEditRights_) return; QIcon editIcon; - editIcon.addFile(":/icons/icons/ui/edit.svg"); + editIcon.addFile(":/icons/icons/ui/edit.png"); editFieldsBtn_ = new FlatButton(this); - editFieldsBtn_->setFixedSize(buttonSize, buttonSize); - editFieldsBtn_->setCornerRadius(iconSize); + editFieldsBtn_->setFixedSize(BUTTON_SIZE, BUTTON_SIZE); + editFieldsBtn_->setCornerRadius(BUTTON_RADIUS); editFieldsBtn_->setIcon(editIcon); editFieldsBtn_->setIcon(editIcon); - editFieldsBtn_->setIconSize(QSize(iconSize, iconSize)); + editFieldsBtn_->setIconSize(QSize(BUTTON_RADIUS, BUTTON_RADIUS)); connect(editFieldsBtn_, &QPushButton::clicked, this, [this]() { retrieveRoomInfo(); @@ -364,12 +349,14 @@ RoomSettings::setupEditButton() modal->setFields(QString::fromStdString(info_.name), QString::fromStdString(info_.topic)); modal->show(); - connect(modal, &EditModal::nameChanged, this, [this](const QString &newName) { - topSection_->setRoomName(newName); + connect(modal, &EditModal::nameChanged, this, [](const QString &newName) { + Q_UNUSED(newName); }); }); - editLayout_->addWidget(editFieldsBtn_, 0, Qt::AlignRight | Qt::AlignTop); + btnLayout_->addStretch(1); + btnLayout_->addWidget(editFieldsBtn_); + btnLayout_->addStretch(1); } void @@ -439,64 +426,3 @@ RoomSettings::paintEvent(QPaintEvent *) QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } - -void -TopSection::paintEvent(QPaintEvent *) -{ - Painter p(this); - PainterHighQualityEnabler hq(p); - - constexpr int textStartX = AvatarSize + 5 * Padding; - const int availableTextWidth = width() - textStartX; - - constexpr int nameFont = 15; - constexpr int membersFont = 14; - - p.save(); - p.setPen(textColor()); - p.translate(textStartX, 2 * Padding); - - // Draw the name. - QFont font; - font.setPixelSize(membersFont); - const auto members = QString("%1 members").arg(info_.member_count); - - font.setPixelSize(nameFont); - const auto name = QFontMetrics(font).elidedText( - QString::fromStdString(info_.name), Qt::ElideRight, availableTextWidth - 4 * Padding); - - font.setWeight(60); - p.setFont(font); - p.drawTextLeft(0, 0, name); - - // Draw the number of members - p.translate(0, QFontMetrics(p.font()).ascent() + 2 * Padding); - - font.setPixelSize(membersFont); - font.setWeight(50); - p.setFont(font); - p.drawTextLeft(0, 0, members); - p.restore(); - - if (avatar_.isNull()) { - font.setPixelSize(AvatarSize / 2); - font.setWeight(60); - p.setFont(font); - - p.translate(Padding, Padding); - p.drawLetterAvatar(utils::firstChar(name), - QColor("white"), - QColor("black"), - AvatarSize + Padding, - AvatarSize + Padding, - AvatarSize); - } else { - QRect avatarRegion(Padding, Padding, AvatarSize, AvatarSize); - - QPainterPath pp; - pp.addEllipse(avatarRegion.center(), AvatarSize, AvatarSize); - - p.setClipPath(pp); - p.drawPixmap(avatarRegion, avatar_); - } -} diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettings.h index 6cab03b7..93e99c0a 100644 --- a/src/dialogs/RoomSettings.h +++ b/src/dialogs/RoomSettings.h @@ -49,32 +49,6 @@ private: FlatButton *cancelBtn_; }; -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); - QSize sizeHint() const override; - void setRoomName(const QString &name); - - 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 @@ -102,14 +76,12 @@ private: void retrieveRoomInfo(); void enableEncryption(); + Avatar *avatar_; + //! Whether the user would be able to change the name or the topic of the room. bool hasEditRights_ = true; bool usesEncryption_ = false; - QHBoxLayout *editLayout_; - - // Button section - FlatButton *okBtn_; - FlatButton *cancelBtn_; + QHBoxLayout *btnLayout_; FlatButton *editFieldsBtn_; @@ -117,8 +89,6 @@ private: QString room_id_; QImage avatarImg_; - TopSection *topSection_; - QComboBox *accessCombo; Toggle *encryptionToggle_; };