mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
beb93c192e
|
@ -34,6 +34,7 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
|
||||||
setAcceptRichText(false);
|
setAcceptRichText(false);
|
||||||
|
|
||||||
connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked);
|
connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked);
|
||||||
|
connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatAreaWidget::~ChatAreaWidget()
|
ChatAreaWidget::~ChatAreaWidget()
|
||||||
|
@ -84,6 +85,8 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
|
||||||
if (msgAction == nullptr)
|
if (msgAction == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
checkSlider();
|
||||||
|
|
||||||
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
||||||
moveCursor(QTextCursor::PreviousCell);
|
moveCursor(QTextCursor::PreviousCell);
|
||||||
QTextCursor cur = textCursor();
|
QTextCursor cur = textCursor();
|
||||||
|
@ -94,3 +97,16 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
|
||||||
|
|
||||||
messages.append(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:
|
protected:
|
||||||
void mouseReleaseEvent(QMouseEvent * event);
|
void mouseReleaseEvent(QMouseEvent * event);
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void onAnchorClicked(const QUrl& url);
|
void onAnchorClicked(const QUrl& url);
|
||||||
|
void onSliderRangeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void checkSlider();
|
||||||
|
|
||||||
QList<ChatAction*> messages;
|
QList<ChatAction*> messages;
|
||||||
bool lockSliderToBottom;
|
bool lockSliderToBottom;
|
||||||
int sliderPosition;
|
int sliderPosition;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user