Elide room topic

This commit is contained in:
Konstantinos Sideris 2017-10-19 19:04:51 +03:00
parent 8390ff253d
commit 8299a74775
2 changed files with 18 additions and 11 deletions

View file

@ -83,6 +83,9 @@ private:
Avatar *avatar_; Avatar *avatar_;
int buttonSize_; int buttonSize_;
QString roomName_;
QString roomTopic_;
}; };
inline void inline void
@ -102,9 +105,7 @@ TopRoomBar::updateRoomAvatar(const QIcon &icon)
inline void inline void
TopRoomBar::updateRoomName(const QString &name) TopRoomBar::updateRoomName(const QString &name)
{ {
QString elidedText = roomName_ = name;
QFontMetrics(nameLabel_->font()).elidedText(name, Qt::ElideRight, width() * 0.8);
nameLabel_->setText(elidedText);
update(); update();
} }
@ -112,10 +113,6 @@ inline void
TopRoomBar::updateRoomTopic(QString topic) TopRoomBar::updateRoomTopic(QString topic)
{ {
topic.replace(URL_REGEX, URL_HTML); topic.replace(URL_REGEX, URL_HTML);
roomTopic_ = topic;
QString elidedText =
QFontMetrics(topicLabel_->font()).elidedText(topic, Qt::ElideRight, width() * 0.6);
topicLabel_->setText(topic);
update(); update();
} }

View file

@ -71,9 +71,8 @@ TopRoomBar::TopRoomBar(QWidget *parent)
settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2)); settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
topLayout_->addWidget(avatar_); topLayout_->addWidget(avatar_);
topLayout_->addLayout(textLayout_); topLayout_->addLayout(textLayout_, 1);
topLayout_->addStretch(1); topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight);
topLayout_->addWidget(settingsBtn_);
menu_ = new Menu(this); menu_ = new Menu(this);
@ -149,6 +148,9 @@ TopRoomBar::reset()
nameLabel_->setText(""); nameLabel_->setText("");
topicLabel_->setText(""); topicLabel_->setText("");
avatar_->setLetter(QChar('?')); avatar_->setLetter(QChar('?'));
roomName_.clear();
roomTopic_.clear();
} }
void void
@ -161,6 +163,14 @@ TopRoomBar::paintEvent(QPaintEvent *event)
QPainter painter(this); QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &option, &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 void