Don't move scrollbar to the bottom when it's active

fixes #55
This commit is contained in:
Konstantinos Sideris 2017-09-30 22:26:33 +03:00
parent 96562c078d
commit 775d2e88f5
2 changed files with 11 additions and 11 deletions

View file

@ -134,6 +134,8 @@ private:
QString local_user_; QString local_user_;
bool isPaginationInProgress_ = false; bool isPaginationInProgress_ = false;
// Keeps track whether or not the user has visited the view.
bool isInitialized = false; bool isInitialized = false;
bool isTimelineFinished = false; bool isTimelineFinished = false;
bool isInitialSync = true; bool isInitialSync = true;

View file

@ -55,9 +55,6 @@ TimelineView::TimelineView(const Timeline &timeline,
, room_id_{ room_id } , room_id_{ room_id }
, client_{ client } , client_{ client }
{ {
QSettings settings;
local_user_ = settings.value("auth/user_id").toString();
init(); init();
addEvents(timeline); addEvents(timeline);
} }
@ -69,9 +66,6 @@ TimelineView::TimelineView(QSharedPointer<MatrixClient> client,
, room_id_{ room_id } , room_id_{ room_id }
, client_{ client } , client_{ client }
{ {
QSettings settings;
local_user_ = settings.value("auth/user_id").toString();
init(); init();
client_->messages(room_id_, ""); client_->messages(room_id_, "");
} }
@ -86,6 +80,8 @@ TimelineView::sliderRangeChanged(int min, int max)
return; return;
} }
// If the scrollbar is close to the bottom and a new message
// is added we move the scrollbar.
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP) if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP)
scroll_area_->verticalScrollBar()->setValue(max); scroll_area_->verticalScrollBar()->setValue(max);
@ -96,9 +92,8 @@ TimelineView::sliderRangeChanged(int min, int max)
int diff = currentHeight - oldHeight_; int diff = currentHeight - oldHeight_;
int newPosition = oldPosition_ + diff; int newPosition = oldPosition_ + diff;
// Keep the scroll bar to the bottom if we are coming from // Keep the scroll bar to the bottom if it hasn't been activated yet.
// an scrollbar without height i.e scrollbar->value() == 0 if (oldPosition_ == 0 && !scroll_area_->verticalScrollBar()->isVisible())
if (oldPosition_ == 0)
newPosition = max; newPosition = max;
scroll_area_->verticalScrollBar()->setValue(newPosition); scroll_area_->verticalScrollBar()->setValue(newPosition);
@ -108,7 +103,7 @@ TimelineView::sliderRangeChanged(int min, int max)
void void
TimelineView::fetchHistory() TimelineView::fetchHistory()
{ {
bool hasEnoughMessages = scroll_area_->verticalScrollBar()->value() != 0; bool hasEnoughMessages = scroll_area_->verticalScrollBar()->isVisible();
if (!hasEnoughMessages && !isTimelineFinished) { if (!hasEnoughMessages && !isTimelineFinished) {
isPaginationInProgress_ = true; isPaginationInProgress_ = true;
@ -371,6 +366,9 @@ TimelineView::addEvents(const Timeline &timeline)
void void
TimelineView::init() TimelineView::init()
{ {
QSettings settings;
local_user_ = settings.value("auth/user_id").toString();
top_layout_ = new QVBoxLayout(this); top_layout_ = new QVBoxLayout(this);
top_layout_->setSpacing(0); top_layout_->setSpacing(0);
top_layout_->setMargin(0); top_layout_->setMargin(0);