[network/ruqola] src/widgets/room: Prepare to add new message indicator
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit ca78e6299f1ab30fb739e9c5b5635e0af31888a5 by Laurent Montel.
Committed on 29/07/2026 at 21:09.
Pushed by mlaurent into branch 'master'.
Prepare to add new message indicator
M +46 -0 src/widgets/room/messagelistview.cpp
M +5 -0 src/widgets/room/messagelistview.h
https://invent.kde.org/network/ruqola/-/commit/ca78e6299f1ab30fb739e9c5b5635e0af31888a5
diff --git a/src/widgets/room/messagelistview.cpp b/src/widgets/room/messagelistview.cpp
index 7fca584552..a98a57a462 100644
--- a/src/widgets/room/messagelistview.cpp
+++ b/src/widgets/room/messagelistview.cpp
@@ -56,6 +56,7 @@
#include <QPainter>
#include <QScrollBar>
+#include "newmessageindicator.h"
#include "ruqolaglobalconfig.h"
#include "config-ruqola.h"
@@ -81,6 +82,9 @@ MessageListView::MessageListView(RocketChatAccount *account, Mode mode, QWidget
}
connect(mActionButtonsGenerator, &ActionButtonsGenerator::uiInteractionRequested, this, &MessageListView::uiInteractionRequested);
+ mNewMessageIndicator = new NewMessageIndicator(viewport());
+ mNewMessageIndicator->hide();
+
mMessageListDelegate->setShowThreadContext(mMode != Mode::ThreadEditing);
mMessageListDelegate->setEnableEmojiMenu(mMode != Mode::Moderation);
setItemDelegate(mMessageListDelegate);
@@ -120,6 +124,12 @@ void MessageListView::wheelEvent(QWheelEvent *e)
MessageListViewBase::wheelEvent(e);
}
+void MessageListView::resizeEvent(QResizeEvent *e)
+{
+ MessageListViewBase::resizeEvent(e);
+ repositionNewMessageIndicator();
+}
+
void MessageListView::paintEvent(QPaintEvent *e)
{
if (mRoom && (mRoom->numberMessages() == 0)) {
@@ -166,12 +176,15 @@ void MessageListView::setRoom(Room *room)
{
if (mRoom) {
disconnect(mRoom, &Room::lastSeenChanged, this, &MessageListView::slotLastSeenChanged);
+ disconnect(mRoom, &Room::unreadChanged, this, &MessageListView::updateNewMessageIndicatorVisibility);
mMessageListDelegate->clearSelection();
}
mRoom = room;
if (mRoom) {
connect(mRoom, &Room::lastSeenChanged, this, &MessageListView::slotLastSeenChanged);
+ connect(mRoom, &Room::unreadChanged, this, &MessageListView::updateNewMessageIndicatorVisibility);
}
+ updateNewMessageIndicatorVisibility();
}
void MessageListView::slotVerticalScrollbarChanged(int value)
@@ -181,6 +194,39 @@ void MessageListView::slotVerticalScrollbarChanged(int value)
// Perhaps finding a better method.
verticalScrollBar()->setValue(1); // If we are at 0 we can't continue to load history
}
+ updateNewMessageIndicatorVisibility();
+}
+
+void MessageListView::updateNewMessageIndicatorVisibility()
+{
+ if (!mNewMessageIndicator) {
+ return;
+ }
+ const auto *vbar = verticalScrollBar();
+ const bool notAtBottom = vbar->value() < vbar->maximum();
+ const bool hasUnread = mRoom && (mRoom->unread() > 0);
+ const bool shouldShow = notAtBottom && hasUnread;
+ if (shouldShow && !mNewMessageIndicator->isVisible()) {
+ repositionNewMessageIndicator();
+ mNewMessageIndicator->showNewMessageIndicator(true);
+ mNewMessageIndicator->raise();
+ } else if (!shouldShow && mNewMessageIndicator->isVisible()) {
+ mNewMessageIndicator->showNewMessageIndicator(false);
+ }
+}
+
+void MessageListView::repositionNewMessageIndicator()
+{
+ if (!mNewMessageIndicator) {
+ return;
+ }
+ mNewMessageIndicator->adjustSize();
+ const QSize vSize = viewport()->size();
+ const QSize iSize = mNewMessageIndicator->sizeHint();
+ const int margin = 8;
+ const int x = (vSize.width() - iSize.width()) / 2;
+ const int y = vSize.height() - iSize.height() - margin;
+ mNewMessageIndicator->move(x, y);
}
void MessageListView::goToMessage(const QByteArray &messageId)
diff --git a/src/widgets/room/messagelistview.h b/src/widgets/room/messagelistview.h
index 28fe3b4198..22f625a1ba 100644
--- a/src/widgets/room/messagelistview.h
+++ b/src/widgets/room/messagelistview.h
@@ -14,6 +14,7 @@ class MessageListDelegate;
class RocketChatAccount;
class Room;
class ActionButtonsGenerator;
+class NewMessageIndicator;
namespace TextTranslator
{
class TranslatorMenu;
@@ -55,6 +56,7 @@ public:
protected:
void paintEvent(QPaintEvent *e) override;
+ void resizeEvent(QResizeEvent *e) override;
void contextMenuEvent(QContextMenuEvent *event) override;
bool mouseEvent(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index) override;
@@ -107,10 +109,13 @@ private:
LIBRUQOLAWIDGETS_NO_EXPORT void createEmojiWidgetAction(QMenu *menu, const QModelIndex &index);
LIBRUQOLAWIDGETS_NO_EXPORT void slotShowGeneratedMessage(const QModelIndex &index);
LIBRUQOLAWIDGETS_NO_EXPORT void slotReadReceiptsMessage(const QModelIndex &index);
+ LIBRUQOLAWIDGETS_NO_EXPORT void updateNewMessageIndicatorVisibility();
+ LIBRUQOLAWIDGETS_NO_EXPORT void repositionNewMessageIndicator();
QPointer<Room> mRoom;
const MessageListView::Mode mMode = MessageListView::Mode::Editing;
MessageListDelegate *const mMessageListDelegate;
TextTranslator::TranslatorMenu *mTranslatorMenu = nullptr;
QPointer<RocketChatAccount> mCurrentRocketChatAccount;
ActionButtonsGenerator *const mActionButtonsGenerator;
+ NewMessageIndicator *mNewMessageIndicator = nullptr;
};