diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-05-25 16:13:38 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-05-25 16:13:38 +0300 |
commit | bcba977f4cb5b5e1f6dfaaf21149a97f50f188d3 (patch) | |
tree | 53ded28758ac19679889b4e218551aec3527a301 /src | |
parent | Bump version to 0.4.2 (diff) | |
download | nheko-bcba977f4cb5b5e1f6dfaaf21149a97f50f188d3.tar.xz |
Fix resize slowness on the TopBar
Diffstat (limited to 'src')
-rw-r--r-- | src/TopRoomBar.cc | 71 | ||||
-rw-r--r-- | src/UserInfoWidget.cc | 4 |
2 files changed, 12 insertions, 63 deletions
diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index 7338cfb1..ae4c0926 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -21,7 +21,6 @@ #include "Avatar.h" #include "Config.h" #include "FlatButton.h" -#include "Label.h" #include "MainWindow.h" #include "Menu.h" #include "OverlayModal.h" @@ -32,12 +31,11 @@ TopRoomBar::TopRoomBar(QWidget *parent) : QWidget(parent) , buttonSize_{32} { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setFixedHeight(65); + setFixedHeight(60); - topLayout_ = new QHBoxLayout(); - topLayout_->setSpacing(10); - topLayout_->setMargin(10); + topLayout_ = new QHBoxLayout(this); + topLayout_->setSpacing(8); + topLayout_->setMargin(8); avatar_ = new Avatar(this); avatar_->setLetter(""); @@ -52,19 +50,16 @@ TopRoomBar::TopRoomBar(QWidget *parent) nameLabel_ = new QLabel(this); nameLabel_->setFont(roomFont); + nameLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); QFont descriptionFont("Open Sans"); descriptionFont.setPixelSize(conf::topRoomBar::fonts::roomDescription); - topicLabel_ = new Label(this); + topicLabel_ = new QLabel(this); topicLabel_->setFont(descriptionFont); - topicLabel_->setTextFormat(Qt::RichText); topicLabel_->setTextInteractionFlags(Qt::TextBrowserInteraction); topicLabel_->setOpenExternalLinks(true); - connect(topicLabel_, &Label::clicked, [this](QMouseEvent *e) { - if (e->button() == Qt::LeftButton && !topicLabel_->hasSelectedText()) - topicLabel_->setWordWrap(!topicLabel_->wordWrap()); - }); + topicLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); textLayout_->addWidget(nameLabel_); textLayout_->addWidget(topicLabel_); @@ -115,8 +110,6 @@ TopRoomBar::TopRoomBar(QWidget *parent) menu_->popup( QPoint(pos.x() + buttonSize_ - menu_->sizeHint().width(), pos.y() + buttonSize_)); }); - - setLayout(topLayout_); } void @@ -132,51 +125,6 @@ TopRoomBar::reset() nameLabel_->setText(""); topicLabel_->setText(""); avatar_->setLetter(""); - - roomName_.clear(); - roomTopic_.clear(); -} - -void -TopRoomBar::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - - QStyleOption option; - option.initFrom(this); - - QPainter painter(this); - style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this); - - painter.setPen(QPen(borderColor())); - painter.drawLine(QPointF(0, height()), QPointF(width(), height())); - - // Number of pixels that we can move sidebar splitter per frame. If label contains - // text which fills entire it's width then label starts blocking it's layout from - // shrinking. Making label little bit shorter leaves some space for it to shrink. - const auto perFrameResize = 20; - - QString elidedText = - QFontMetrics(nameLabel_->font()) - .elidedText(roomName_, Qt::ElideRight, nameLabel_->width() - perFrameResize); - nameLabel_->setText(elidedText); - - if (topicLabel_->wordWrap()) - elidedText = roomTopic_; - else - elidedText = - QFontMetrics(topicLabel_->font()) - .elidedText(roomTopic_, Qt::ElideRight, topicLabel_->width() - perFrameResize); - elidedText.replace(conf::strings::url_regex, conf::strings::url_html); - topicLabel_->setText(elidedText); -} - -void -TopRoomBar::mousePressEvent(QMouseEvent *event) -{ - if (childAt(event->pos()) == topicLabel_) { - event->accept(); - } } void @@ -196,13 +144,14 @@ TopRoomBar::updateRoomAvatar(const QIcon &icon) void TopRoomBar::updateRoomName(const QString &name) { - roomName_ = name; + nameLabel_->setText(name); update(); } void TopRoomBar::updateRoomTopic(QString topic) { - roomTopic_ = topic; + topic.replace(conf::strings::url_regex, conf::strings::url_html); + topicLabel_->setText(topic); update(); } diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index b7724257..092184f7 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -30,7 +30,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) , user_id_("@user:homeserver.org") , logoutButtonSize_{20} { - setFixedHeight(65); + setFixedHeight(60); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); @@ -42,7 +42,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) userAvatar_ = new Avatar(this); userAvatar_->setObjectName("userAvatar"); userAvatar_->setLetter(QChar('?')); - userAvatar_->setSize(55); + userAvatar_->setSize(45); QFont nameFont("Open Sans SemiBold"); nameFont.setPixelSize(conf::userInfoWidget::fonts::displayName); |