From 97ca8d0ed109dc2be80e459e4b2a4dbafa1aced8 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 1 Jul 2017 15:52:46 +0300 Subject: [PATCH] Remove hardcoded font sizes on the top bars and text input --- include/TextInputWidget.h | 3 +++ include/TopRoomBar.h | 11 +++++++++-- include/UserInfoWidget.h | 3 +++ src/TextInputWidget.cc | 10 +++++++--- src/TopRoomBar.cc | 11 +++++++++-- src/UserInfoWidget.cc | 21 +++++++++++---------- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index 225750f2..e176d48c 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -63,4 +63,7 @@ private: FlatButton *send_file_button_; FlatButton *send_message_button_; EmojiPickButton *emoji_button_; + + const float TextFontRatio = 1.1; + const float EmojiFontRatio = 1.3; }; diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 6e4bfe7a..ad246090 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -68,6 +68,9 @@ private: Avatar *avatar_; int buttonSize_; + + const float RoomNameFontRatio = 1.2; + const float RoomDescriptionFontRatio = 1; }; inline void TopRoomBar::updateRoomAvatar(const QImage &avatar_image) @@ -82,10 +85,14 @@ inline void TopRoomBar::updateRoomAvatar(const QIcon &icon) inline void TopRoomBar::updateRoomName(const QString &name) { - name_label_->setText(name); + QString elidedText = QFontMetrics(name_label_->font()) + .elidedText(name, Qt::ElideRight, width() * 0.8); + name_label_->setText(elidedText); } inline void TopRoomBar::updateRoomTopic(const QString &topic) { - topic_label_->setText(topic); + QString elidedText = QFontMetrics(topic_label_->font()) + .elidedText(topic, Qt::ElideRight, width() * 0.8); + topic_label_->setText(elidedText); } diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 10c770d8..35f7a6f5 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -72,4 +72,7 @@ private: LogoutDialog *logoutDialog_; int logoutButtonSize_; + + const float DisplayNameFontRatio = 1.3; + const float UserIdFontRatio = 1.1; }; diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index 82cc8b4e..f09608a0 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -57,10 +57,14 @@ TextInputWidget::TextInputWidget(QWidget *parent) send_file_button_->setIcon(send_file_icon); send_file_button_->setIconSize(QSize(24, 24)); + QFont font; + font.setPointSize(this->font().pointSize() * TextFontRatio); + input_ = new FilteredTextEdit(this); input_->setFixedHeight(45); + input_->setFont(font); input_->setPlaceholderText(tr("Write a message...")); - input_->setStyleSheet("color: #333333; font-size: 13px; border-radius: 0; padding-top: 10px;"); + input_->setStyleSheet("color: #333333; border-radius: 0; padding-top: 10px;"); send_message_button_ = new FlatButton(this); send_message_button_->setForegroundColor(QColor("#acc7dc")); @@ -95,10 +99,10 @@ void TextInputWidget::addSelectedEmoji(const QString &emoji) QTextCursor cursor = input_->textCursor(); QFont emoji_font("Emoji One"); - emoji_font.setPixelSize(18); + emoji_font.setPointSize(this->font().pointSize() * EmojiFontRatio); QFont text_font("Open Sans"); - text_font.setPixelSize(13); + text_font.setPixelSize(this->font().pointSize() * TextFontRatio); QTextCharFormat charfmt; charfmt.setFont(emoji_font); diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index 4b4c8aa5..74e255a0 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -41,11 +41,18 @@ TopRoomBar::TopRoomBar(QWidget *parent) text_layout_->setSpacing(0); text_layout_->setContentsMargins(0, 0, 0, 0); + QFont font; + font.setPointSize(this->font().pointSize() * RoomNameFontRatio); + font.setBold(true); + name_label_ = new QLabel(this); - name_label_->setStyleSheet("font-size: 14px; font-weight: 600;"); + name_label_->setFont(font); + + font.setBold(false); + font.setPointSize(this->font().pointSize() * RoomDescriptionFontRatio); topic_label_ = new QLabel(this); - topic_label_->setStyleSheet("font-size: 12px;"); + topic_label_->setFont(font); text_layout_->addWidget(name_label_); text_layout_->addWidget(topic_label_); diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index 361689ef..a8fddcd0 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -47,20 +47,21 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) userAvatar_->setBackgroundColor("#f9f9f9"); userAvatar_->setTextColor("#333333"); + QFont font; + font.setBold(true); + font.setPointSize(this->font().pointSize() * DisplayNameFontRatio); + displayNameLabel_ = new QLabel(this); - displayNameLabel_->setStyleSheet( - "padding: 0 9px;" - "color: #171919;" - "font-size: 14px;" - "font-weight: 500;" - "margin-bottom: -10px;"); + displayNameLabel_->setFont(font); + displayNameLabel_->setStyleSheet("padding: 0 9px; color: #171919; margin-bottom: -10px;"); displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop); + font.setBold(false); + font.setPointSize(this->font().pointSize() * UserIdFontRatio); + userIdLabel_ = new QLabel(this); - userIdLabel_->setStyleSheet( - "padding: 0 8px 8px 8px;" - "color: #555459;" - "font-size: 13px"); + userIdLabel_->setFont(font); + userIdLabel_->setStyleSheet("padding: 0 8px 8px 8px; color: #555459;"); userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); avatarLayout_->addWidget(userAvatar_);