Skip to content

Commit

Permalink
Merge pull request #216 from geotribu/ui/vertically-optimized-widget
Browse files Browse the repository at this point in the history
ui(qchat): vertically optimize the QChat widget
  • Loading branch information
gounux authored Nov 14, 2024
2 parents eb21b4e + 27c5046 commit 4971448
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 148 deletions.
58 changes: 45 additions & 13 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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(
Expand Down Expand Up @@ -183,6 +185,18 @@ def __init__(
QIcon(QgsApplication.iconPath("mActionAddImage.svg"))
)

# 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 signal 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()
Expand All @@ -192,7 +206,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))
)
Expand Down Expand Up @@ -365,8 +381,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.lbl_status.setText("Connected")
self.grb_room.setTitle(self.tr("Room: {room}").format(room=room))
self.btn_list_users.setEnabled(True)
self.grb_user.setEnabled(True)
self.current_room = room
Expand Down Expand Up @@ -402,8 +416,6 @@ 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"))
self.grb_qchat.setTitle(self.tr("QChat"))
self.btn_list_users.setEnabled(False)
self.grb_user.setEnabled(False)
Expand Down Expand Up @@ -479,23 +491,22 @@ 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:
"""
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"),
)
Expand Down Expand Up @@ -552,8 +563,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 @@ -753,6 +763,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:
Expand All @@ -765,13 +779,31 @@ 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
"""
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
Loading

0 comments on commit 4971448

Please sign in to comment.