Browse Source

Keep return-to-latest action available in historical message windows

master
evgeny 4 days ago
parent
commit
7773a0c648
  1. 8
      tools/chatgui/src/chatview.cpp
  2. 3
      tools/chatgui/src/chatview.h

8
tools/chatgui/src/chatview.cpp

@ -49,6 +49,7 @@ ChatView::ChatView(QWidget *parent)
m_scrollDownBtn->setVisible(false);
connect(m_scrollDownBtn, &QPushButton::clicked, this, [this]() {
emit latestRequested();
scrollToBottom();
});
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &ChatView::updateScrollDownBtn);
@ -65,6 +66,11 @@ void ChatView::setBackgroundImage(const QString &path) {
viewport()->update();
}
void ChatView::setHistoricalWindow(bool enabled) {
m_historicalWindow = enabled;
updateScrollDownBtn();
}
void ChatView::resizeEvent(QResizeEvent *event) {
QListView::resizeEvent(event);
scheduleDelayedItemsLayout();
@ -241,7 +247,7 @@ void ChatView::copySelection() {
void ChatView::updateScrollDownBtn() {
QScrollBar* sb = verticalScrollBar();
bool atBottom = sb && (sb->value() >= sb->maximum());
m_scrollDownBtn->setVisible(!atBottom);
m_scrollDownBtn->setVisible(m_historicalWindow || !atBottom);
if (!atBottom) {
QRect vr = viewport()->geometry();
m_scrollDownBtn->move(vr.right() - 44, vr.bottom() - 44);

3
tools/chatgui/src/chatview.h

@ -24,6 +24,7 @@ public:
explicit ChatView(QWidget *parent = nullptr);
void setBackgroundImage(const QString &path);
void setHistoricalWindow(bool enabled);
bool hasSelection() const { return m_selStart.isValid(); }
QModelIndex selStart() const { return QModelIndex(m_selStart); }
@ -38,6 +39,7 @@ public:
signals:
void animationTriggered();
void linkActivated(const QString& link);
void latestRequested();
protected:
bool viewportEvent(QEvent *event) override;
@ -62,6 +64,7 @@ private:
QPersistentModelIndex m_pressIndex;
QPoint m_pressPos;
bool m_selecting = false;
bool m_historicalWindow = false;
std::function<QString(const QModelIndex&, const QPoint&)> m_linkHitTest;
QPushButton *m_scrollDownBtn = nullptr;
};

Loading…
Cancel
Save