Skip to content

Commit

Permalink
feature(qchat): autoscroll on last message if checkbox is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Nov 2, 2024
1 parent bfd8c30 commit 2bdd5ef
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,14 @@ def on_text_message_received(self, message: QChatTextMessage) -> None:
self.settings.qchat_ring_tone, self.settings.qchat_sound_volume
)

self.twg_chat.addTopLevelItem(item)
self.twg_chat.scrollToItem(item)
self.add_tree_widget_item(item)

def on_image_message_received(self, message: QChatImageMessage) -> None:
"""
Launched when an image message is received from the websocket
"""
item = QChatImageTreeWidgetItem(self.twg_chat, message)
self.twg_chat.addTopLevelItem(item)
self.twg_chat.scrollToItem(item)
self.add_tree_widget_item(item)

def on_nb_users_message_received(self, message: QChatNbUsersMessage) -> None:
"""
Expand Down Expand Up @@ -562,8 +560,7 @@ def on_geojson_message_received(self, message: QChatGeojsonMessage) -> None:
Launched when a geojson message is received from the websocket
"""
item = QChatGeojsonTreeWidgetItem(self.twg_chat, message)
self.twg_chat.addTopLevelItem(item)
self.twg_chat.scrollToItem(item)
self.add_tree_widget_item(item)

# endregion

Expand Down Expand Up @@ -795,8 +792,12 @@ def add_admin_message(self, text: str) -> None:
Adds an admin message to QTreeWidget chat
"""
item = QChatAdminTreeWidgetItem(self.twg_chat, text)
self.add_tree_widget_item(item)

def add_tree_widget_item(self, item: QTreeWidgetItem) -> None:
self.twg_chat.addTopLevelItem(item)
self.twg_chat.scrollToItem(item)
if self.ckb_autoscroll.isChecked():
self.twg_chat.scrollToItem(item)

def on_widget_closed(self) -> None:
"""
Expand Down

0 comments on commit 2bdd5ef

Please sign in to comment.