summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-19 19:04:51 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-19 19:04:51 +0300
commit8299a74775bcdf917d58038fd35b2fdd208d4154 (patch)
treec437647cc7c5a4f7e13f6954e55d9d26a4b41ad8
parent8390ff253d3688c3f76e3149d43d3120f9549359 (diff)
Elide room topic
-rw-r--r--include/TopRoomBar.h13
-rw-r--r--src/TopRoomBar.cc16
2 files changed, 18 insertions, 11 deletions
diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h
index 2c7af218..87037574 100644
--- a/include/TopRoomBar.h
+++ b/include/TopRoomBar.h
@@ -83,6 +83,9 @@ private:
Avatar *avatar_;
int buttonSize_;
+
+ QString roomName_;
+ QString roomTopic_;
};
inline void
@@ -102,9 +105,7 @@ TopRoomBar::updateRoomAvatar(const QIcon &icon)
inline void
TopRoomBar::updateRoomName(const QString &name)
{
- QString elidedText =
- QFontMetrics(nameLabel_->font()).elidedText(name, Qt::ElideRight, width() * 0.8);
- nameLabel_->setText(elidedText);
+ roomName_ = name;
update();
}
@@ -112,10 +113,6 @@ inline void
TopRoomBar::updateRoomTopic(QString topic)
{
topic.replace(URL_REGEX, URL_HTML);
-
- QString elidedText =
- QFontMetrics(topicLabel_->font()).elidedText(topic, Qt::ElideRight, width() * 0.6);
-
- topicLabel_->setText(topic);
+ roomTopic_ = topic;
update();
}
diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc
index 5a1f2d25..8b2e338b 100644
--- a/src/TopRoomBar.cc
+++ b/src/TopRoomBar.cc
@@ -71,9 +71,8 @@ TopRoomBar::TopRoomBar(QWidget *parent)
settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
topLayout_->addWidget(avatar_);
- topLayout_->addLayout(textLayout_);
- topLayout_->addStretch(1);
- topLayout_->addWidget(settingsBtn_);
+ topLayout_->addLayout(textLayout_, 1);
+ topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight);
menu_ = new Menu(this);
@@ -149,6 +148,9 @@ TopRoomBar::reset()
nameLabel_->setText("");
topicLabel_->setText("");
avatar_->setLetter(QChar('?'));
+
+ roomName_.clear();
+ roomTopic_.clear();
}
void
@@ -161,6 +163,14 @@ TopRoomBar::paintEvent(QPaintEvent *event)
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
+
+ QString elidedText =
+ QFontMetrics(nameLabel_->font()).elidedText(roomName_, Qt::ElideRight, width());
+ nameLabel_->setText(elidedText);
+
+ elidedText =
+ QFontMetrics(topicLabel_->font()).elidedText(roomTopic_, Qt::ElideRight, width());
+ topicLabel_->setText(elidedText);
}
void