toxygen/toxygen/ui/items_factories.py

91 lines
3.6 KiB
Python
Raw Normal View History

2018-05-15 21:51:42 +02:00
from ui.contact_items import *
from ui.messages_widgets import *
2016-10-22 20:55:34 +02:00
2018-05-03 23:17:48 +02:00
class FriendItemsFactory:
2016-10-22 20:55:34 +02:00
def __init__(self, settings, main_screen):
self._settings = settings
self._friends_list = main_screen.friends_list
2018-05-03 23:17:48 +02:00
def create_friend_item(self):
2018-04-30 21:28:33 +02:00
item = ContactItem(self._settings)
elem = QtWidgets.QListWidgetItem(self._friends_list)
2016-10-22 20:55:34 +02:00
elem.setSizeHint(QtCore.QSize(250, item.height()))
self._friends_list.addItem(elem)
self._friends_list.setItemWidget(elem, item)
2016-10-22 20:55:34 +02:00
return item
class MessagesItemsFactory:
2018-05-15 21:51:42 +02:00
def __init__(self, settings, plugin_loader, smiley_loader, main_screen, delete_action):
self._file_transfers_handler = None
self._settings, self._plugin_loader = settings, plugin_loader
2018-05-15 21:51:42 +02:00
self._smiley_loader, self._delete_action = smiley_loader, delete_action
self._messages = main_screen.messages
self._message_edit = main_screen.messageEdit
def set_file_transfers_handler(self, file_transfers_handler):
self._file_transfers_handler = file_transfers_handler
def create_message_item(self, message, append=True, pixmap=None):
item = message.get_widget(self._settings, self._create_message_browser,
2018-05-15 21:51:42 +02:00
self._delete_action, self._messages)
2016-10-22 20:55:34 +02:00
if pixmap is not None:
item.set_avatar(pixmap)
elem = QtWidgets.QListWidgetItem()
2016-10-22 20:55:34 +02:00
elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append:
self._messages.addItem(elem)
else:
self._messages.insertItem(0, elem)
self._messages.setItemWidget(elem, item)
2016-10-22 20:55:34 +02:00
return item
2018-05-16 23:02:22 +02:00
def create_inline_item(self, data, append=True, position=0):
elem = QtWidgets.QListWidgetItem()
2018-05-18 11:26:02 +02:00
item = InlineImageItem(data, self._messages.width(), elem, self._messages)
2016-10-22 20:55:34 +02:00
elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append:
self._messages.addItem(elem)
else:
self._messages.insertItem(position, elem)
2016-10-22 20:55:34 +02:00
self._messages.setItemWidget(elem, item)
2016-10-22 20:55:34 +02:00
return item
def create_unsent_file_item(self, message, append=True):
item = message.get_widget(self._file_transfers_handler, self._settings, self._messages.width(), self._messages)
elem = QtWidgets.QListWidgetItem()
2016-10-22 20:55:34 +02:00
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
if append:
self._messages.addItem(elem)
else:
self._messages.insertItem(0, elem)
self._messages.setItemWidget(elem, item)
2016-10-22 20:55:34 +02:00
return item
def create_file_transfer_item(self, message, append=True):
item = message.get_widget(self._file_transfers_handler, self._settings, self._messages.width(), self._messages)
elem = QtWidgets.QListWidgetItem()
2016-10-22 20:55:34 +02:00
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
if append:
self._messages.addItem(elem)
else:
self._messages.insertItem(0, elem)
self._messages.setItemWidget(elem, item)
2016-10-22 20:55:34 +02:00
return item
2018-05-04 23:09:33 +02:00
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
2018-05-04 23:09:33 +02:00
def _create_message_browser(self, text, width, message_type, parent=None):
return MessageBrowser(self._settings, self._message_edit, self._smiley_loader, self._plugin_loader,
text, width, message_type, parent)