chatgui: add scroll-to-bottom floating button, incremental message refresh via getMessagesSince
This commit is contained in:
1 parent
b6d44bd947
commit
ce9e58a925
6 files changed
+114
-16
No files matched your search
@@ -6,11 +6,38 @@
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
ChatView::ChatView(QWidget *parent)
|
||||
: QListView(parent)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
|
||||
m_scrollDownBtn = new QPushButton(QStringLiteral("\u25BC"), this);
|
||||
m_scrollDownBtn->setFixedSize(36, 36);
|
||||
m_scrollDownBtn->setCursor(Qt::PointingHandCursor);
|
||||
m_scrollDownBtn->setStyleSheet(
|
||||
"QPushButton {"
|
||||
" background: rgba(60,60,60,180);"
|
||||
" color: #ffffff;"
|
||||
" border: none;"
|
||||
" border-radius: 18px;"
|
||||
" font-size: 16px;"
|
||||
"}"
|
||||
"QPushButton:hover {"
|
||||
" background: rgba(90,90,90,220);"
|
||||
"}"
|
||||
);
|
||||
m_scrollDownBtn->setToolTip(tr("Scroll to bottom"));
|
||||
m_scrollDownBtn->setVisible(false);
|
||||
|
||||
connect(m_scrollDownBtn, &QPushButton::clicked, this, [this]() {
|
||||
scrollToBottom();
|
||||
});
|
||||
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &ChatView::updateScrollDownBtn);
|
||||
connect(verticalScrollBar(), &QScrollBar::rangeChanged, this, &ChatView::updateScrollDownBtn);
|
||||
|
||||
m_scrollDownBtn->raise();
|
||||
}
|
||||
|
||||
void ChatView::setBackgroundImage(const QString &path) {
|
||||
@@ -24,6 +51,7 @@ void ChatView::setBackgroundImage(const QString &path) {
|
||||
void ChatView::resizeEvent(QResizeEvent *event) {
|
||||
QListView::resizeEvent(event);
|
||||
scheduleDelayedItemsLayout();
|
||||
updateScrollDownBtn();
|
||||
}
|
||||
|
||||
void ChatView::scrollContentsBy(int dx, int dy) {
|
||||
@@ -150,3 +178,14 @@ void ChatView::copySelection() {
|
||||
QApplication::clipboard()->setText(r);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatView::updateScrollDownBtn() {
|
||||
QScrollBar* sb = verticalScrollBar();
|
||||
bool atBottom = sb && (sb->value() >= sb->maximum());
|
||||
m_scrollDownBtn->setVisible(!atBottom);
|
||||
if (!atBottom) {
|
||||
QRect vr = viewport()->geometry();
|
||||
m_scrollDownBtn->move(vr.right() - 44, vr.bottom() - 44);
|
||||
m_scrollDownBtn->raise();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user