Skip to content
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
33 changes: 20 additions & 13 deletions qchat/gui/qchat_tree_widget_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
QgsVectorLayer,
)
from qgis.gui import QgsMapCanvas
from qgis.PyQt.QtCore import QDateTime, QTime
from qgis.PyQt.QtCore import QDateTime
from qgis.PyQt.QtGui import QBrush, QColor, QIcon, QPixmap
from qgis.PyQt.QtWidgets import (
QDialog,
Expand Down Expand Up @@ -52,11 +52,15 @@ class QChatTreeWidgetItem(QTreeWidgetItem):
"""

def __init__(
self, parent: QTreeWidget, time: QTime, author: str, avatar: Optional[str]
self,
parent: QTreeWidget,
datetime: QDateTime,
author: str,
avatar: Optional[str],
):
super().__init__(parent)
self.plg_settings = PlgOptionsManager()
self.time = time
self.datetime = datetime
self.author = author
self.avatar = avatar

Expand All @@ -65,7 +69,8 @@ def settings(self) -> PlgSettingsStructure:
return self.plg_settings.get_plg_settings()

def init_time_and_author(self) -> None:
self.setText(TIME_COLUMN, self.time.toString())
self.setText(TIME_COLUMN, self.datetime.toLocalTime().time().toString())
self.setToolTip(TIME_COLUMN, self.datetime.date().toString())
self.setText(AUTHOR_COLUM, self.author)
if self.settings.show_avatars and self.avatar:
self.setIcon(AUTHOR_COLUM, QIcon(QgsApplication.iconPath(self.avatar)))
Expand Down Expand Up @@ -123,10 +128,12 @@ def copy_to_clipboard(self) -> None:
class QChatAdminTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, text: str, timestamp: Optional[int] = None):
if timestamp is None:
time = QTime.currentTime()
datetime = QDateTime.currentDateTime()
else:
time = QDateTime.fromSecsSinceEpoch(timestamp).toLocalTime().time()
super().__init__(parent, time, ADMIN_MESSAGES_NICKNAME, ADMIN_MESSAGES_AVATAR)
datetime = QDateTime.fromSecsSinceEpoch(timestamp)
super().__init__(
parent, datetime, ADMIN_MESSAGES_NICKNAME, ADMIN_MESSAGES_AVATAR
)
self.text = text
self.init_time_and_author()
self.setText(MESSAGE_COLUMN, text)
Expand All @@ -146,7 +153,7 @@ class QChatTextTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, message: QChatTextMessage):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp),
message.author,
message.avatar,
)
Expand Down Expand Up @@ -179,7 +186,7 @@ class QChatImageTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, message: QChatImageMessage):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp),
message.author,
message.avatar,
)
Expand Down Expand Up @@ -226,7 +233,7 @@ class QChatGeojsonTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, message: QChatGeojsonMessage):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp),
message.author,
message.avatar,
)
Expand Down Expand Up @@ -284,7 +291,7 @@ class QChatCrsTreeWidgetItem(QChatTreeWidgetItem):
def __init__(self, parent: QTreeWidget, message: QChatCrsMessage):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp),
message.author,
message.avatar,
)
Expand Down Expand Up @@ -321,7 +328,7 @@ def __init__(
):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime(),
message.author,
message.avatar,
)
Expand Down Expand Up @@ -371,7 +378,7 @@ def __init__(
):
super().__init__(
parent,
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime().time(),
QDateTime.fromSecsSinceEpoch(message.timestamp).toLocalTime(),
message.author,
message.avatar,
)
Expand Down
Loading