Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(qchat): use custom tree widget items #212

Merged
merged 16 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(qchat): edit click and dbl click actions
gounux committed Oct 26, 2024
commit 2b57e760d175905735be21d59466026a0fd1dbe0
33 changes: 10 additions & 23 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
@@ -15,13 +15,10 @@
from qgis.PyQt.QtGui import QCursor, QIcon
from qgis.PyQt.QtWidgets import (
QAction,
QDialog,
QFileDialog,
QLabel,
QMenu,
QMessageBox,
QTreeWidgetItem,
QVBoxLayout,
QWidget,
)

@@ -528,37 +525,27 @@ def on_message_clicked(self, item: QTreeWidgetItem, column: int) -> None:
"""
Action called when clicking on a chat message
"""
author = item.text(1)
widget = self.twg_chat.itemWidget(item, 2)
# if there is a widget (QLabel) usually,
# it means that there is an image
# -> display the image in a new window
if column == 2 and widget:
pixmap = widget.pixmap()
dialog = QDialog(self)
dialog.setWindowTitle(
self.tr("QChat image sent by {author}").format(author=author)
)
layout = QVBoxLayout()
label = QLabel()
label.setPixmap(pixmap)
layout.addWidget(label)
dialog.setLayout(layout)
dialog.setModal(True)
dialog.show()
item.on_click(column)
if type(item) is QChatImageTreeWidgetItem:
QMessageBox.warning(self, "lol", "biglol")

def on_message_double_clicked(self, item: QTreeWidgetItem, column: int) -> None:
"""
Action called when double clicking on a chat message
"""
author = item.text(1)
author = item.author
# do nothing if double click on admin message
if author == ADMIN_MESSAGES_NICKNAME:
if author == ADMIN_MESSAGES_NICKNAME or author == self.settings.author_nickname:
return
text = self.lne_message.text()
self.lne_message.setText(f"{text}@{author} ")
self.lne_message.setFocus()

def mention_user(self, user: str) -> None:
text = self.lne_message.text()
self.lne_message.setText(f"{text}@{user} ")
self.lne_message.setFocus()

def on_like_message(self, liked_author: str, msg: str) -> None:
"""
Action called when the "Like message" action is triggered
35 changes: 30 additions & 5 deletions qtribu/gui/qchat_tree_widget_items.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,13 @@
from qgis.core import QgsApplication
from qgis.PyQt.QtCore import QTime
from qgis.PyQt.QtGui import QBrush, QColor, QIcon, QPixmap
from qgis.PyQt.QtWidgets import QLabel, QTreeWidget, QTreeWidgetItem
from qgis.PyQt.QtWidgets import (
QDialog,
QLabel,
QTreeWidget,
QTreeWidgetItem,
QVBoxLayout,
)

from qtribu.constants import ADMIN_MESSAGES_AVATAR, ADMIN_MESSAGES_NICKNAME
from qtribu.logic.qchat_messages import QChatImageMessage, QChatTextMessage
@@ -48,6 +54,13 @@ def set_foreground_color(self, color: str) -> None:
self.setForeground(AUTHOR_COLUM, fg_color)
self.setForeground(MESSAGE_COLUMN, fg_color)

def on_click(self, column: int) -> None:
"""
Triggered when simple clicking on the item
Empty because this is the expected behaviour
"""
pass


class QChatAdminTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, text: str):
@@ -88,10 +101,22 @@ def __init__(self, parent: QTreeWidget, message: QChatImageMessage):
if message.author == self.settings.author_nickname:
self.set_foreground_color(self.settings.qchat_color_self)

pixmap = QPixmap()
self.pixmap = QPixmap()
data = base64.b64decode(message.image_data)
pixmap.loadFromData(data)
self.pixmap.loadFromData(data)
label = QLabel(self.parent())
label.setPixmap(pixmap)
label.setPixmap(self.pixmap)
self.treeWidget().setItemWidget(self, MESSAGE_COLUMN, label)
self.setSizeHint(MESSAGE_COLUMN, pixmap.size())
self.setSizeHint(MESSAGE_COLUMN, self.pixmap.size())

def on_click(self, column: int) -> None:
if column == MESSAGE_COLUMN:
dialog = QDialog(self.treeWidget())
dialog.setWindowTitle(f"QChat image {self.message.author}")
layout = QVBoxLayout()
label = QLabel()
label.setPixmap(self.pixmap)
layout.addWidget(label)
dialog.setLayout(layout)
dialog.setModal(True)
dialog.show()