Derive widget sizing from the font size

This commit is contained in:
Konstantinos Sideris 2018-10-04 00:32:13 +03:00
parent be1478183e
commit 420937ab83
4 changed files with 41 additions and 25 deletions

View File

@ -32,22 +32,30 @@ TopRoomBar::TopRoomBar(QWidget *parent)
: QWidget(parent)
, buttonSize_{32}
{
setFixedHeight(56);
QFont f;
f.setPointSizeF(f.pointSizeF());
const int fontHeight = QFontMetrics(f).height();
const int widgetMargin = fontHeight / 3;
const int contentHeight = fontHeight * 3;
setFixedHeight(contentHeight + widgetMargin);
topLayout_ = new QHBoxLayout(this);
topLayout_->setSpacing(8);
topLayout_->setMargin(8);
topLayout_->setSpacing(widgetMargin);
topLayout_->setContentsMargins(
2 * widgetMargin, widgetMargin, 2 * widgetMargin, widgetMargin);
avatar_ = new Avatar(this);
avatar_->setLetter("");
avatar_->setSize(35);
avatar_->setSize(fontHeight * 2);
textLayout_ = new QVBoxLayout();
textLayout_->setSpacing(0);
textLayout_->setContentsMargins(0, 0, 0, 0);
textLayout_->setMargin(0);
QFont roomFont;
roomFont.setPointSizeF(roomFont.pointSizeF() * 1.2);
roomFont.setPointSizeF(roomFont.pointSizeF() * 1.1);
roomFont.setWeight(QFont::Medium);
nameLabel_ = new QLabel(this);

View File

@ -31,13 +31,16 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
, display_name_("User")
, user_id_("@user:homeserver.org")
{
const int fontHeight = QFontMetrics(font()).height();
QFont f;
f.setPointSizeF(f.pointSizeF());
const int fontHeight = QFontMetrics(f).height();
const int widgetMargin = fontHeight / 3;
const int contentHeight = fontHeight * 3;
logoutButtonSize_ = fontHeight + (fontHeight / 4);
logoutButtonSize_ = std::min(fontHeight, 20);
setFixedHeight(contentHeight + widgetMargin * 2);
setFixedHeight(contentHeight + widgetMargin);
topLayout_ = new QHBoxLayout(this);
topLayout_->setSpacing(0);
@ -45,9 +48,9 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
avatarLayout_ = new QHBoxLayout();
textLayout_ = new QVBoxLayout();
textLayout_->setSpacing(0);
textLayout_->setSpacing(widgetMargin);
textLayout_->setContentsMargins(
widgetMargin * 2, widgetMargin, widgetMargin * 2, widgetMargin);
widgetMargin * 1.5, widgetMargin, widgetMargin, widgetMargin);
userAvatar_ = new Avatar(this);
userAvatar_->setObjectName("userAvatar");
@ -55,6 +58,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
userAvatar_->setSize(fontHeight * 2.5);
QFont nameFont;
nameFont.setPointSizeF(nameFont.pointSizeF() * 1.1);
nameFont.setWeight(QFont::Medium);
displayNameLabel_ = new QLabel(this);
@ -63,12 +67,13 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop);
userIdLabel_ = new QLabel(this);
userIdLabel_->setFont(f);
userIdLabel_->setObjectName("userIdLabel");
userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
avatarLayout_->addWidget(userAvatar_);
textLayout_->addWidget(displayNameLabel_);
textLayout_->addWidget(userIdLabel_);
textLayout_->addWidget(displayNameLabel_, 0, Qt::AlignBottom);
textLayout_->addWidget(userIdLabel_, 0, Qt::AlignTop);
topLayout_->addLayout(avatarLayout_);
topLayout_->addLayout(textLayout_);

View File

@ -155,11 +155,6 @@ TimelineItem::init()
userName_ = nullptr;
body_ = nullptr;
usernameFont_ = font_;
usernameFont_.setWeight(QFont::Medium);
QFontMetrics fm(font_);
contextMenu_ = new QMenu(this);
showReadReceipts_ = new QAction("Read receipts", this);
markAsRead_ = new QAction("Mark as read", this);
@ -627,10 +622,14 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam
sender = displayname.split(":")[0].split("@")[1];
}
QFontMetrics fm(usernameFont_);
QFont usernameFont;
usernameFont.setPointSizeF(usernameFont.pointSizeF());
usernameFont.setWeight(QFont::Medium);
QFontMetrics fm(usernameFont);
userName_ = new QLabel(this);
userName_->setFont(usernameFont_);
userName_->setFont(usernameFont);
userName_->setText(fm.elidedText(sender, Qt::ElideRight, 500));
userName_->setToolTip(user_id);
userName_->setToolTipDuration(1500);
@ -693,9 +692,12 @@ TimelineItem::setupAvatarLayout(const QString &userName)
topLayout_->setContentsMargins(
conf::timeline::msgLeftMargin, conf::timeline::msgAvatarTopMargin, 0, 0);
QFont f;
f.setPointSizeF(f.pointSizeF());
userAvatar_ = new Avatar(this);
userAvatar_->setLetter(QChar(userName[0]).toUpper());
userAvatar_->setSize(conf::timeline::avatarSize);
userAvatar_->setSize(QFontMetrics(f).height() * 2);
// TODO: The provided user name should be a UserId class
if (userName[0] == '@' && userName.size() > 1)
@ -711,8 +713,11 @@ TimelineItem::setupAvatarLayout(const QString &userName)
void
TimelineItem::setupSimpleLayout()
{
topLayout_->setContentsMargins(conf::timeline::msgLeftMargin + conf::timeline::avatarSize +
2,
QFont f;
f.setPointSizeF(f.pointSizeF());
topLayout_->setContentsMargins(conf::timeline::msgLeftMargin +
QFontMetrics(f).height() * 2 + 2,
conf::timeline::msgTopMargin,
0,
0);

View File

@ -276,8 +276,6 @@ private:
Avatar *userAvatar_;
QFont font_;
QFont usernameFont_;
QFont timestampFont_;
StatusIndicator *statusIndicator_;