Remove spacer & set sizePolicy on the timeline view & widgets

This was causing some flickering when many messages were added.
Mostly visible on macOS.
remotes/origin/HEAD
Konstantinos Sideris 6 years ago
parent 6b42e3b202
commit 6583686a7c
  1. 11
      src/timeline/TimelineItem.cpp
  2. 3
      src/timeline/TimelineItem.h
  3. 26
      src/timeline/TimelineView.cpp
  4. 2
      src/timeline/TimelineView.h

@ -184,7 +184,7 @@ TimelineItem::init()
topLayout_->setContentsMargins( topLayout_->setContentsMargins(
conf::timeline::msgLeftMargin, conf::timeline::msgTopMargin, 0, 0); conf::timeline::msgLeftMargin, conf::timeline::msgTopMargin, 0, 0);
topLayout_->setSpacing(0); topLayout_->setSpacing(0);
topLayout_->addLayout(mainLayout_, 1); topLayout_->addLayout(mainLayout_);
mainLayout_->setContentsMargins(conf::timeline::headerLeftMargin, 0, 0, 0); mainLayout_->setContentsMargins(conf::timeline::headerLeftMargin, 0, 0, 0);
mainLayout_->setSpacing(0); mainLayout_->setSpacing(0);
@ -196,6 +196,9 @@ TimelineItem::init()
statusIndicator_ = new StatusIndicator(this); statusIndicator_ = new StatusIndicator(this);
statusIndicator_->setFixedWidth(tsFm.height() - tsFm.leading()); statusIndicator_->setFixedWidth(tsFm.height() - tsFm.leading());
statusIndicator_->setFixedHeight(tsFm.height() - tsFm.leading()); statusIndicator_->setFixedHeight(tsFm.height() - tsFm.leading());
parentWidget()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
} }
/* /*
@ -586,7 +589,7 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam
userName_->setToolTip(user_id); userName_->setToolTip(user_id);
userName_->setToolTipDuration(1500); userName_->setToolTipDuration(1500);
userName_->setAttribute(Qt::WA_Hover); userName_->setAttribute(Qt::WA_Hover);
userName_->setAlignment(Qt::AlignLeft); userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text())); userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text()));
auto filter = new UserProfileFilter(user_id, userName_); auto filter = new UserProfileFilter(user_id, userName_);
@ -659,10 +662,10 @@ TimelineItem::setupAvatarLayout(const QString &userName)
userAvatar_->setLetter(QChar(userName[1]).toUpper()); userAvatar_->setLetter(QChar(userName[1]).toUpper());
topLayout_->insertWidget(0, userAvatar_); topLayout_->insertWidget(0, userAvatar_);
topLayout_->setAlignment(userAvatar_, Qt::AlignTop); topLayout_->setAlignment(userAvatar_, Qt::AlignTop | Qt::AlignLeft);
if (userName_) if (userName_)
mainLayout_->insertWidget(0, userName_); mainLayout_->insertWidget(0, userName_, Qt::AlignTop | Qt::AlignLeft);
} }
void void

@ -115,7 +115,8 @@ public:
&TextLabel::adjustHeight); &TextLabel::adjustHeight);
document()->setDocumentMargin(0); document()->setDocumentMargin(0);
setFixedHeight(20); setFixedHeight(QFontMetrics(QFont()).lineSpacing() + 4);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
} }
void wheelEvent(QWheelEvent *event) override { event->ignore(); } void wheelEvent(QWheelEvent *event) override { event->ignore(); }

@ -183,7 +183,7 @@ TimelineView::addBackwardsEvents(const mtx::responses::Messages &msgs)
// The RoomList message preview will be updated only if this // The RoomList message preview will be updated only if this
// is the first batch of messages received through /messages // is the first batch of messages received through /messages
// i.e there are no other messages currently present. // i.e there are no other messages currently present.
if (!topMessages_.empty() && scroll_layout_->count() == 1) if (!topMessages_.empty() && scroll_layout_->count() == 0)
notifyForLastEvent(findFirstViewableEvent(topMessages_)); notifyForLastEvent(findFirstViewableEvent(topMessages_));
if (isVisible()) { if (isVisible()) {
@ -513,7 +513,6 @@ TimelineView::init()
scroll_layout_ = new QVBoxLayout(scroll_widget_); scroll_layout_ = new QVBoxLayout(scroll_widget_);
scroll_layout_->setContentsMargins(4, 0, 15, 15); scroll_layout_->setContentsMargins(4, 0, 15, 15);
scroll_layout_->addStretch(1);
scroll_layout_->setSpacing(0); scroll_layout_->setSpacing(0);
scroll_layout_->setObjectName("timelinescrollarea"); scroll_layout_->setObjectName("timelinescrollarea");
@ -610,8 +609,13 @@ TimelineView::addTimelineItem(QWidget *item, TimelineDirection direction)
const auto newDate = getDate(item); const auto newDate = getDate(item);
if (direction == TimelineDirection::Bottom) { if (direction == TimelineDirection::Bottom) {
const auto lastItemPosition = scroll_layout_->count() - 1; QWidget *lastItem = nullptr;
const auto lastItem = scroll_layout_->itemAt(lastItemPosition)->widget(); int lastItemPosition = 0;
if (scroll_layout_->count() > 0) {
lastItemPosition = scroll_layout_->count() - 1;
lastItem = scroll_layout_->itemAt(lastItemPosition)->widget();
}
if (lastItem) { if (lastItem) {
const auto oldDate = getDate(lastItem); const auto oldDate = getDate(lastItem);
@ -626,10 +630,8 @@ TimelineView::addTimelineItem(QWidget *item, TimelineDirection direction)
pushTimelineItem(item); pushTimelineItem(item);
} else { } else {
// The first item (position 0) is a stretch widget that pushes if (scroll_layout_->count() > 0) {
// the widgets to the bottom of the page. const auto firstItem = scroll_layout_->itemAt(0)->widget();
if (scroll_layout_->count() > 1) {
const auto firstItem = scroll_layout_->itemAt(1)->widget();
if (firstItem) { if (firstItem) {
const auto oldDate = getDate(firstItem); const auto oldDate = getDate(firstItem);
@ -638,12 +640,12 @@ TimelineView::addTimelineItem(QWidget *item, TimelineDirection direction)
auto separator = new DateSeparator(oldDate); auto separator = new DateSeparator(oldDate);
if (separator) if (separator)
scroll_layout_->insertWidget(1, separator); scroll_layout_->insertWidget(0, separator);
} }
} }
} }
scroll_layout_->insertWidget(1, item); scroll_layout_->insertWidget(0, item);
} }
} }
@ -1010,8 +1012,6 @@ TimelineView::clearTimeline()
firstSender_.clear(); firstSender_.clear();
lastSender_.clear(); lastSender_.clear();
scroll_layout_->addStretch(1);
} }
void void
@ -1100,7 +1100,7 @@ TimelineView::relativeWidget(QWidget *item, int dt) const
pos = pos + dt; pos = pos + dt;
bool isOutOfBounds = (pos <= 0 || pos > scroll_layout_->count() - 1); bool isOutOfBounds = (pos < 0 || pos > scroll_layout_->count() - 1);
return isOutOfBounds ? nullptr : scroll_layout_->itemAt(pos)->widget(); return isOutOfBounds ? nullptr : scroll_layout_->itemAt(pos)->widget();
} }

@ -144,7 +144,7 @@ public slots:
void addBackwardsEvents(const mtx::responses::Messages &msgs); void addBackwardsEvents(const mtx::responses::Messages &msgs);
// Whether or not the initial batch has been loaded. // Whether or not the initial batch has been loaded.
bool hasLoaded() { return scroll_layout_->count() > 1 || isTimelineFinished; } bool hasLoaded() { return scroll_layout_->count() > 0 || isTimelineFinished; }
void handleFailedMessage(const std::string &txn_id); void handleFailedMessage(const std::string &txn_id);

Loading…
Cancel
Save