mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Fix resize slowness on the TopBar
This commit is contained in:
parent
f533d9d7ea
commit
bcba977f4c
4 changed files with 42 additions and 79 deletions
|
@ -75,8 +75,8 @@ constexpr int communityBubble = bubble - 4;
|
|||
|
||||
namespace userInfoWidget {
|
||||
namespace fonts {
|
||||
constexpr int displayName = 16;
|
||||
constexpr int userid = 14;
|
||||
constexpr int displayName = 15;
|
||||
constexpr int userid = 13;
|
||||
} // namespace fonts
|
||||
} // namespace userInfoWidget
|
||||
|
||||
|
|
|
@ -22,12 +22,15 @@
|
|||
#include <QImage>
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QSharedPointer>
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class Avatar;
|
||||
class FlatButton;
|
||||
class Label;
|
||||
class Menu;
|
||||
class OverlayModal;
|
||||
|
||||
|
@ -55,21 +58,35 @@ signals:
|
|||
void inviteUsers(QStringList users);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *) override
|
||||
{
|
||||
if (roomSettings_ != nullptr)
|
||||
roomSettings_->trigger();
|
||||
}
|
||||
|
||||
void paintEvent(QPaintEvent *) override
|
||||
{
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
|
||||
p.setPen(QPen(borderColor()));
|
||||
p.drawLine(QPointF(0, height()), QPointF(width(), height()));
|
||||
}
|
||||
|
||||
private:
|
||||
QHBoxLayout *topLayout_;
|
||||
QVBoxLayout *textLayout_;
|
||||
QHBoxLayout *topLayout_ = nullptr;
|
||||
QVBoxLayout *textLayout_ = nullptr;
|
||||
|
||||
QLabel *nameLabel_;
|
||||
Label *topicLabel_;
|
||||
QLabel *nameLabel_ = nullptr;
|
||||
QLabel *topicLabel_ = nullptr;
|
||||
|
||||
Menu *menu_;
|
||||
QAction *leaveRoom_;
|
||||
QAction *roomMembers_;
|
||||
QAction *roomSettings_;
|
||||
QAction *inviteUsers_;
|
||||
QAction *leaveRoom_ = nullptr;
|
||||
QAction *roomMembers_ = nullptr;
|
||||
QAction *roomSettings_ = nullptr;
|
||||
QAction *inviteUsers_ = nullptr;
|
||||
|
||||
FlatButton *settingsBtn_;
|
||||
|
||||
|
@ -77,8 +94,5 @@ private:
|
|||
|
||||
int buttonSize_;
|
||||
|
||||
QString roomName_;
|
||||
QString roomTopic_;
|
||||
|
||||
QColor borderColor_;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue