From c7faeecb972a777d70c371755d3d9babe89ecea7 Mon Sep 17 00:00:00 2001 From: gounux Date: Fri, 1 Nov 2024 15:40:51 +0100 Subject: [PATCH 1/4] ui(qchat): vertically optimize the QChat widget --- qtribu/gui/dck_qchat.py | 39 ++++++++- qtribu/gui/dck_qchat.ui | 176 +++++++++++++++++++--------------------- 2 files changed, 120 insertions(+), 95 deletions(-) diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index 1b735e98..6416cd55 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -178,6 +178,18 @@ def __init__( QIcon(QgsApplication.iconPath("mActionAddImage.svg")) ) + # send extent message signa listener + self.btn_send_extent.pressed.connect(self.on_send_extent_button_clicked) + self.btn_send_extent.setIcon( + QIcon(QgsApplication.iconPath("mActionViewExtentInCanvas.svg")) + ) + + # send CRS message signa listener + self.btn_send_crs.pressed.connect(self.on_send_crs_button_clicked) + self.btn_send_crs.setIcon( + QIcon(QgsApplication.iconPath("mActionSetProjection.svg")) + ) + @property def settings(self) -> PlgSettingsStructure: return self.plg_settings.get_plg_settings() @@ -187,7 +199,9 @@ def load_settings(self) -> None: self.grb_instance.setTitle( self.tr("Instance: {uri}").format(uri=self.settings.qchat_instance_uri) ) - self.lbl_nickname.setText(self.settings.author_nickname) + self.grb_user.setTitle( + self.tr("User: {nickname}").format(nickname=self.settings.author_nickname) + ) self.btn_send.setIcon( QIcon(QgsApplication.iconPath(self.settings.author_avatar)) ) @@ -360,8 +374,7 @@ def on_ws_connected(self, room: str) -> None: Action called when websocket is connected to a room """ self.btn_connect.setText(self.tr("Disconnect")) - self.lbl_status.setText("Connected") - self.grb_room.setTitle(self.tr("Room: {room}").format(room=room)) + self.grb_room.setTitle(self.tr("Room ({room}) - connected").format(room=room)) self.btn_list_users.setEnabled(True) self.grb_user.setEnabled(True) self.current_room = room @@ -397,7 +410,7 @@ def disconnect_from_room(self, log: bool = True, close_ws: bool = True) -> None: ), ) self.btn_connect.setText(self.tr("Connect")) - self.lbl_status.setText("Disconnected") + self.grb_room.setTitle(self.tr("Room - disconnected")) self.grb_room.setTitle(self.tr("Room")) self.grb_qchat.setTitle(self.tr("QChat")) self.btn_list_users.setEnabled(False) @@ -747,6 +760,10 @@ def on_send_image_button_clicked(self) -> None: self.qchat_ws.send_message(message) def on_send_screenshot_button_clicked(self) -> None: + """ + Action called when the Send QGIS screenshot button is clicked + """ + sc_fp = os.path.join(tempfile.gettempdir(), "qgis_screenshot.png") self.iface.mapCanvas().saveAsImage(sc_fp) with open(sc_fp, "rb") as file: @@ -759,6 +776,20 @@ def on_send_screenshot_button_clicked(self) -> None: ) self.qchat_ws.send_message(message) + def on_send_extent_button_clicked(self) -> None: + """ + Action called when the Send extent button is clicked + """ + QMessageBox.critical( + self, self.tr("Send extent"), self.tr("Not implemented yet") + ) + + def on_send_crs_button_clicked(self) -> None: + """ + Action called when the Send CRS button is clicked + """ + QMessageBox.critical(self, self.tr("Send CRS"), self.tr("Not implemented yet")) + def add_admin_message(self, text: str) -> None: """ Adds an admin message to QTreeWidget chat diff --git a/qtribu/gui/dck_qchat.ui b/qtribu/gui/dck_qchat.ui index b22c39cc..27563c3c 100644 --- a/qtribu/gui/dck_qchat.ui +++ b/qtribu/gui/dck_qchat.ui @@ -6,7 +6,7 @@ 0 0 - 441 + 446 887 @@ -118,6 +118,25 @@ + + + + false + + + + 0 + 0 + + + + PointingHandCursor + + + List users + + + @@ -136,20 +155,6 @@ - - - - Status: - - - - - - - Not connected - - - @@ -222,19 +227,6 @@ - - - - false - - - PointingHandCursor - - - List users - - - @@ -276,70 +268,72 @@ User - - - - - Nickname: - - - - - - - Message: - - - - - - - PointingHandCursor - - - Send message - - - - - - - ForbiddenCursor - - - Nickname set in QTribu's plugin settings - - - Nickname - - - - - - - - - - - - - - PointingHandCursor - - - Send Image - - + + + + + + + Message: + + + + + + + + + + + + + + PointingHandCursor + + + Send + + + + - - - - PointingHandCursor - - - Send QGIS screenshot - - + + + + + + PointingHandCursor + + + Send Image + + + + + + + PointingHandCursor + + + Send QGIS screenshot + + + + + + + Send Extent + + + + + + + Send CRS + + + + From bfd8c30ae41715de9764ebe81057289727631f8f Mon Sep 17 00:00:00 2001 From: gounux Date: Sat, 2 Nov 2024 18:17:38 +0100 Subject: [PATCH 2/4] ui(qchat): refactor qchat widget --- qtribu/gui/dck_qchat.py | 12 ++--- qtribu/gui/dck_qchat.ui | 100 +++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index 6416cd55..f5d9bff9 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -135,6 +135,8 @@ def __init__( QIcon(QgsApplication.iconPath("processingResult.svg")) ) + self.ckb_autoscroll.setChecked(True) + # clear chat signal listener self.btn_clear_chat.pressed.connect(self.on_clear_chat_button_clicked) self.btn_clear_chat.setIcon( @@ -178,13 +180,13 @@ def __init__( QIcon(QgsApplication.iconPath("mActionAddImage.svg")) ) - # send extent message signa listener + # send extent message signal listener self.btn_send_extent.pressed.connect(self.on_send_extent_button_clicked) self.btn_send_extent.setIcon( QIcon(QgsApplication.iconPath("mActionViewExtentInCanvas.svg")) ) - # send CRS message signa listener + # send CRS message signal listener self.btn_send_crs.pressed.connect(self.on_send_crs_button_clicked) self.btn_send_crs.setIcon( QIcon(QgsApplication.iconPath("mActionSetProjection.svg")) @@ -374,7 +376,6 @@ def on_ws_connected(self, room: str) -> None: Action called when websocket is connected to a room """ self.btn_connect.setText(self.tr("Disconnect")) - self.grb_room.setTitle(self.tr("Room ({room}) - connected").format(room=room)) self.btn_list_users.setEnabled(True) self.grb_user.setEnabled(True) self.current_room = room @@ -410,8 +411,6 @@ def disconnect_from_room(self, log: bool = True, close_ws: bool = True) -> None: ), ) self.btn_connect.setText(self.tr("Connect")) - self.grb_room.setTitle(self.tr("Room - disconnected")) - self.grb_room.setTitle(self.tr("Room")) self.grb_qchat.setTitle(self.tr("QChat")) self.btn_list_users.setEnabled(False) self.grb_user.setEnabled(False) @@ -505,7 +504,8 @@ def on_nb_users_message_received(self, message: QChatNbUsersMessage) -> None: Launched when a nb_users message is received from the websocket """ self.grb_qchat.setTitle( - self.tr("QChat - {nb_users} {user_txt}").format( + self.tr("QChat - room: {room} - {nb_users} {user_txt}").format( + room=self.current_room, nb_users=message.nb_users, user_txt=self.tr("user") if message.nb_users <= 1 else self.tr("users"), ) diff --git a/qtribu/gui/dck_qchat.ui b/qtribu/gui/dck_qchat.ui index 27563c3c..e62cdeeb 100644 --- a/qtribu/gui/dck_qchat.ui +++ b/qtribu/gui/dck_qchat.ui @@ -51,7 +51,7 @@ - + 0 0 @@ -91,28 +91,58 @@ - + + + true + - + 0 0 + + + 0 + 1 + + + + + 0 + 1 + + - Room + QChat - - - - - Room: - - - - - + + false + + + + + + + + + 0 + 0 + + + + Room: + + + + + + 0 + 0 + + @@ -155,39 +185,6 @@ - - - - - - - true - - - - 0 - 0 - - - - - 0 - 1 - - - - - 0 - 1 - - - - QChat - - - false - - @@ -227,13 +224,20 @@ + + + + Autoscroll to last message + + + PointingHandCursor - Clear + Clear chat From 2bdd5ef14a578676fc86e19c96c5831be228a5af Mon Sep 17 00:00:00 2001 From: gounux Date: Sat, 2 Nov 2024 18:22:21 +0100 Subject: [PATCH 3/4] feature(qchat): autoscroll on last message if checkbox is checked --- qtribu/gui/dck_qchat.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index f5d9bff9..e373b5cf 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -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: """ @@ -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 @@ -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: """ From c3839685bff0d7c88a983688b051220d08cad857 Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 4 Nov 2024 11:31:23 +0100 Subject: [PATCH 4/4] fix(import): QChatApiClient module was renamed --- qtribu/gui/dlg_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtribu/gui/dlg_settings.py b/qtribu/gui/dlg_settings.py index 0732f58d..31f57832 100644 --- a/qtribu/gui/dlg_settings.py +++ b/qtribu/gui/dlg_settings.py @@ -24,7 +24,7 @@ __uri_tracker__, __version__, ) -from qtribu.logic.qchat_client import QChatApiClient +from qtribu.logic.qchat_api_client import QChatApiClient from qtribu.toolbelt import PlgLogger, PlgOptionsManager from qtribu.toolbelt.commons import open_url_in_browser, play_resource_sound from qtribu.toolbelt.preferences import PlgSettingsStructure