Skip to content

Commit

Permalink
feat: mention user when double clicking on chat button
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jul 25, 2024
1 parent 8af8751 commit 22925d7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from qgis.core import Qgis, QgsApplication
from qgis.gui import QgisInterface, QgsDockWidget
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QTime, QUrl
from qgis.PyQt.QtCore import QPoint, Qt, QTime, QUrl
from qgis.PyQt.QtGui import QBrush, QColor, QCursor, QIcon
from qgis.PyQt.QtWidgets import QAction, QMenu, QMessageBox, QTreeWidgetItem, QWidget

Expand Down Expand Up @@ -90,6 +90,7 @@ def __init__(self, iface: QgisInterface, parent: QWidget = None):
self.tr("Message"),
]
)
self.twg_chat.itemDoubleClicked.connect(self.on_message_double_clicked)
self.twg_chat.setContextMenuPolicy(Qt.CustomContextMenu)
self.twg_chat.customContextMenuRequested.connect(
self.on_custom_context_menu_requested
Expand Down Expand Up @@ -379,9 +380,18 @@ def handle_internal_message(self, message: dict[str, Any]) -> None:
)
)

def on_custom_context_menu_requested(self, point) -> None:
# def on_message_double_clicked(self, point: QModelIndex) -> None:
def on_message_double_clicked(self, item: QTreeWidgetItem, column: int) -> None:
"""
Action called on right click on a chat message
Action called when double clicking on a chat message
"""
text = self.lne_message.text()
author = item.text(2)
self.lne_message.setText(f"{text}@{author} ")

def on_custom_context_menu_requested(self, point: QPoint) -> None:
"""
Action called when right clicking on a chat message
"""
item = self.twg_chat.itemAt(point)
message = item.text(3)
Expand Down Expand Up @@ -466,7 +476,7 @@ def on_send_button_clicked(self) -> None:
return

# send message to websocket
message = {"message": message_text, "author": nickname}
message = {"message": message_text.strip(), "author": nickname}
self.ws_client.sendTextMessage(json.dumps(message))
self.lne_message.setText("")

Expand Down

0 comments on commit 22925d7

Please sign in to comment.