summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-10-04 00:32:13 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-10-04 00:32:13 +0300
commit420937ab8337f181105a571cdcb33d4d05091ed5 (patch)
treebb55527c22ed5de0fbcd3f2f2f5049f5f7740702 /src
parentRemove some unnecessary calls (diff)
downloadnheko-420937ab8337f181105a571cdcb33d4d05091ed5.tar.xz
Derive widget sizing from the font size
Diffstat (limited to 'src')
-rw-r--r--src/TopRoomBar.cpp20
-rw-r--r--src/UserInfoWidget.cpp19
-rw-r--r--src/timeline/TimelineItem.cpp25
-rw-r--r--src/timeline/TimelineItem.h2
4 files changed, 41 insertions, 25 deletions
diff --git a/src/TopRoomBar.cpp b/src/TopRoomBar.cpp
index f2afb9a1..5c817dc2 100644
--- a/src/TopRoomBar.cpp
+++ b/src/TopRoomBar.cpp
@@ -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);
diff --git a/src/UserInfoWidget.cpp b/src/UserInfoWidget.cpp
index 0c8a3114..f455b509 100644
--- a/src/UserInfoWidget.cpp
+++ b/src/UserInfoWidget.cpp
@@ -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_);
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp
index 74b1278d..fc7868de 100644
--- a/src/timeline/TimelineItem.cpp
+++ b/src/timeline/TimelineItem.cpp
@@ -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);
diff --git a/src/timeline/TimelineItem.h b/src/timeline/TimelineItem.h
index d24909d6..9b23a731 100644
--- a/src/timeline/TimelineItem.h
+++ b/src/timeline/TimelineItem.h
@@ -276,8 +276,6 @@ private:
 
         Avatar *userAvatar_;
 
-        QFont font_;
-        QFont usernameFont_;
         QFont timestampFont_;
 
         StatusIndicator *statusIndicator_;