diff --git a/resources/icons/ui/edit.png b/resources/icons/ui/edit.png
new file mode 100644
index 0000000..762da80
Binary files /dev/null and b/resources/icons/ui/edit.png differ
diff --git a/resources/icons/ui/edit.svg b/resources/icons/ui/edit.svg
deleted file mode 100644
index 2313feb..0000000
--- a/resources/icons/ui/edit.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ 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 0000000..31295e1
Binary files /dev/null and b/resources/icons/ui/edit@2x.png differ
diff --git a/resources/icons/ui/world.png b/resources/icons/ui/world.png
new file mode 100644
index 0000000..9887686
Binary files /dev/null and b/resources/icons/ui/world.png differ
diff --git a/resources/icons/ui/world.svg b/resources/icons/ui/world.svg
deleted file mode 100644
index 93b6178..0000000
--- a/resources/icons/ui/world.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ 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 0000000..f32cc24
Binary files /dev/null and b/resources/icons/ui/world@2x.png differ
diff --git a/resources/res.qrc b/resources/res.qrc
index 8484b29..d024a5d 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 8afaebf..f2777e6 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 cfb2599..2109c86 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);
- auto layout = new QVBoxLayout(this);
- layout->setSpacing(15);
- layout->setMargin(20);
+ setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN);
+ setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
- okBtn_ = new FlatButton(tr("OK"), this);
- okBtn_->setFontSize(conf::btn::fontSize);
- cancelBtn_ = new FlatButton(tr("CANCEL"), this);
- cancelBtn_->setFontSize(conf::btn::fontSize);
+ auto layout = new QVBoxLayout(this);
+ layout->setSpacing(WIDGET_SPACING);
+ layout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN);
- auto btnLayout = new QHBoxLayout();
- btnLayout->setSpacing(0);
- btnLayout->setMargin(0);
- btnLayout->addStretch(1);
- btnLayout->addWidget(okBtn_);
- btnLayout->addWidget(cancelBtn_);
+ QFont font;
+ font.setWeight(65);
+ font.setPointSizeF(font.pointSizeF() * 1.2);
+ auto settingsLabel = new QLabel(tr("Settings").toUpper(), this);
+ settingsLabel->setFont(font);
- 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 6cab03b..93e99c0 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_;
};