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

Merge pull request #273 from apprb/master

autoscroll fix
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-09-10 20:32:27 +02:00
commit beb93c192e
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;