mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
autoscroll fix
This commit is contained in:
parent
c3e55489b0
commit
ff9e0bbf93
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user