1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

autoscroll fix

This commit is contained in:
apprb 2014-09-11 01:28:05 +07:00
parent c3e55489b0
commit ff9e0bbf93
2 changed files with 20 additions and 1 deletions

View File

@ -34,6 +34,7 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
setAcceptRichText(false);
connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked);
connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
}
ChatAreaWidget::~ChatAreaWidget()
@ -84,6 +85,8 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
if (msgAction == nullptr)
return;
checkSlider();
moveCursor(QTextCursor::End);
moveCursor(QTextCursor::PreviousCell);
QTextCursor cur = textCursor();
@ -94,3 +97,16 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
messages.append(msgAction);
}
void ChatAreaWidget::onSliderRangeChanged()
{
QScrollBar* scroll = verticalScrollBar();
if (lockSliderToBottom)
scroll->setValue(scroll->maximum());
}
void ChatAreaWidget::checkSlider()
{
QScrollBar* scroll = verticalScrollBar();
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
}

View File

@ -36,10 +36,13 @@ signals:
protected:
void mouseReleaseEvent(QMouseEvent * event);
public slots:
private slots:
void onAnchorClicked(const QUrl& url);
void onSliderRangeChanged();
private:
void checkSlider();
QList<ChatAction*> messages;
bool lockSliderToBottom;
int sliderPosition;