Remove hardcoded font sizes on the top bars and text input

This commit is contained in:
Konstantinos Sideris 2017-07-01 15:52:46 +03:00
parent 22d0f50e36
commit 97ca8d0ed1
6 changed files with 42 additions and 17 deletions

View file

@ -63,4 +63,7 @@ private:
FlatButton *send_file_button_; FlatButton *send_file_button_;
FlatButton *send_message_button_; FlatButton *send_message_button_;
EmojiPickButton *emoji_button_; EmojiPickButton *emoji_button_;
const float TextFontRatio = 1.1;
const float EmojiFontRatio = 1.3;
}; };

View file

@ -68,6 +68,9 @@ private:
Avatar *avatar_; Avatar *avatar_;
int buttonSize_; int buttonSize_;
const float RoomNameFontRatio = 1.2;
const float RoomDescriptionFontRatio = 1;
}; };
inline void TopRoomBar::updateRoomAvatar(const QImage &avatar_image) 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) 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) 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);
} }

View file

@ -72,4 +72,7 @@ private:
LogoutDialog *logoutDialog_; LogoutDialog *logoutDialog_;
int logoutButtonSize_; int logoutButtonSize_;
const float DisplayNameFontRatio = 1.3;
const float UserIdFontRatio = 1.1;
}; };

View file

@ -57,10 +57,14 @@ TextInputWidget::TextInputWidget(QWidget *parent)
send_file_button_->setIcon(send_file_icon); send_file_button_->setIcon(send_file_icon);
send_file_button_->setIconSize(QSize(24, 24)); send_file_button_->setIconSize(QSize(24, 24));
QFont font;
font.setPointSize(this->font().pointSize() * TextFontRatio);
input_ = new FilteredTextEdit(this); input_ = new FilteredTextEdit(this);
input_->setFixedHeight(45); input_->setFixedHeight(45);
input_->setFont(font);
input_->setPlaceholderText(tr("Write a message...")); 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_ = new FlatButton(this);
send_message_button_->setForegroundColor(QColor("#acc7dc")); send_message_button_->setForegroundColor(QColor("#acc7dc"));
@ -95,10 +99,10 @@ void TextInputWidget::addSelectedEmoji(const QString &emoji)
QTextCursor cursor = input_->textCursor(); QTextCursor cursor = input_->textCursor();
QFont emoji_font("Emoji One"); QFont emoji_font("Emoji One");
emoji_font.setPixelSize(18); emoji_font.setPointSize(this->font().pointSize() * EmojiFontRatio);
QFont text_font("Open Sans"); QFont text_font("Open Sans");
text_font.setPixelSize(13); text_font.setPixelSize(this->font().pointSize() * TextFontRatio);
QTextCharFormat charfmt; QTextCharFormat charfmt;
charfmt.setFont(emoji_font); charfmt.setFont(emoji_font);

View file

@ -41,11 +41,18 @@ TopRoomBar::TopRoomBar(QWidget *parent)
text_layout_->setSpacing(0); text_layout_->setSpacing(0);
text_layout_->setContentsMargins(0, 0, 0, 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_ = 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_ = new QLabel(this);
topic_label_->setStyleSheet("font-size: 12px;"); topic_label_->setFont(font);
text_layout_->addWidget(name_label_); text_layout_->addWidget(name_label_);
text_layout_->addWidget(topic_label_); text_layout_->addWidget(topic_label_);

View file

@ -47,20 +47,21 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
userAvatar_->setBackgroundColor("#f9f9f9"); userAvatar_->setBackgroundColor("#f9f9f9");
userAvatar_->setTextColor("#333333"); userAvatar_->setTextColor("#333333");
QFont font;
font.setBold(true);
font.setPointSize(this->font().pointSize() * DisplayNameFontRatio);
displayNameLabel_ = new QLabel(this); displayNameLabel_ = new QLabel(this);
displayNameLabel_->setStyleSheet( displayNameLabel_->setFont(font);
"padding: 0 9px;" displayNameLabel_->setStyleSheet("padding: 0 9px; color: #171919; margin-bottom: -10px;");
"color: #171919;"
"font-size: 14px;"
"font-weight: 500;"
"margin-bottom: -10px;");
displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop); displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop);
font.setBold(false);
font.setPointSize(this->font().pointSize() * UserIdFontRatio);
userIdLabel_ = new QLabel(this); userIdLabel_ = new QLabel(this);
userIdLabel_->setStyleSheet( userIdLabel_->setFont(font);
"padding: 0 8px 8px 8px;" userIdLabel_->setStyleSheet("padding: 0 8px 8px 8px; color: #555459;");
"color: #555459;"
"font-size: 13px");
userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
avatarLayout_->addWidget(userAvatar_); avatarLayout_->addWidget(userAvatar_);