From 3f9a35e1645cbbb38a6567eadd744227cb3ed442 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 13 Jul 2016 23:09:34 +0300 Subject: [PATCH] avatars in chat --- toxygen/friend.py | 6 +++--- toxygen/list_items.py | 8 ++++++++ toxygen/menu.py | 18 +++++++++++++----- toxygen/profile.py | 7 ++++++- toxygen/settings.py | 1 + 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/toxygen/friend.py b/toxygen/friend.py index 3dd5b0f..6d20a65 100644 --- a/toxygen/friend.py +++ b/toxygen/friend.py @@ -127,12 +127,12 @@ class Friend(contact.Contact): del self._message_getter # don't delete data about active file transfer if not save_unsent: - self._corr = list(filter(lambda x: x.get_type() in (2, 3) and + self._corr = list(filter(lambda x: x.get_type() == 2 and x.get_status() in ft.ACTIVE_FILE_TRANSFERS, self._corr)) self._unsaved_messages = 0 else: - self._corr = list(filter(lambda x: (x.get_type() in (2, 3) and x.get_status() in ft.ACTIVE_FILE_TRANSFERS) - or (x.get_type() <= 1 and x.get_owner() == MESSAGE_OWNER['NOT_SENT']), + self._corr = list(filter(lambda x: (x.get_type() == 2 and x.get_status() in ft.ACTIVE_FILE_TRANSFERS) + or (x.get_type() <= 1 and x.get_owner() == MESSAGE_OWNER['NOT_SENT']), self._corr)) self._unsaved_messages = len(self.get_unsent_messages()) diff --git a/toxygen/list_items.py b/toxygen/list_items.py index e445211..4932f96 100644 --- a/toxygen/list_items.py +++ b/toxygen/list_items.py @@ -159,6 +159,14 @@ class MessageItem(QtGui.QWidget): return True return False + def set_avatar(self, pixmap): + self.name.setAlignment(QtCore.Qt.AlignCenter) + self.message.setAlignment(QtCore.Qt.AlignVCenter) + self.setFixedHeight(max(self.height(), 36)) + self.name.setFixedHeight(self.height()) + self.message.setFixedHeight(self.height()) + self.name.setPixmap(pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio)) + class ContactItem(QtGui.QWidget): """ diff --git a/toxygen/menu.py b/toxygen/menu.py index 7f0f22b..74e785d 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -554,8 +554,8 @@ class InterfaceSettings(CenteredWidget): def initUI(self): self.setObjectName("interfaceForm") - self.setMinimumSize(QtCore.QSize(400, 550)) - self.setMaximumSize(QtCore.QSize(400, 550)) + self.setMinimumSize(QtCore.QSize(400, 580)) + self.setMaximumSize(QtCore.QSize(400, 580)) self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(30, 10, 370, 20)) font = QtGui.QFont() @@ -610,25 +610,30 @@ class InterfaceSettings(CenteredWidget): self.messages_font_size.setCurrentIndex(settings['message_font_size'] - 10) self.unread = QtGui.QPushButton(self) - self.unread.setGeometry(QtCore.QRect(30, 425, 340, 30)) + self.unread.setGeometry(QtCore.QRect(30, 465, 340, 30)) self.unread.clicked.connect(self.select_color) self.compact_mode = QtGui.QCheckBox(self) self.compact_mode.setGeometry(QtCore.QRect(30, 380, 370, 20)) self.compact_mode.setChecked(settings['compact_mode']) + self.show_avatars = QtGui.QCheckBox(self) + self.show_avatars.setGeometry(QtCore.QRect(30, 410, 370, 20)) + self.show_avatars.setChecked(settings['show_avatars']) + self.import_smileys = QtGui.QPushButton(self) - self.import_smileys.setGeometry(QtCore.QRect(30, 465, 340, 30)) + self.import_smileys.setGeometry(QtCore.QRect(30, 505, 340, 30)) self.import_smileys.clicked.connect(self.import_sm) self.import_stickers = QtGui.QPushButton(self) - self.import_stickers.setGeometry(QtCore.QRect(30, 505, 340, 30)) + self.import_stickers.setGeometry(QtCore.QRect(30, 545, 340, 30)) self.import_stickers.clicked.connect(self.import_st) self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): + self.show_avatars.setText(QtGui.QApplication.translate("interfaceForm", "Show avatars in chat", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8)) self.lang.setText(QtGui.QApplication.translate("interfaceForm", "Language:", None, QtGui.QApplication.UnicodeUTF8)) @@ -689,6 +694,9 @@ class InterfaceSettings(CenteredWidget): if settings['compact_mode'] != self.compact_mode.isChecked(): settings['compact_mode'] = self.compact_mode.isChecked() restart = True + if settings['show_avatars'] != self.show_avatars.isChecked(): + settings['show_avatars'] = self.show_avatars.isChecked() + restart = True settings['smiley_pack'] = self.smiley_pack.currentText() smileys.SmileyLoader.get_instance().load_pack() language = self.lang_choose.currentText() diff --git a/toxygen/profile.py b/toxygen/profile.py index 235db92..55f83c3 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -41,6 +41,8 @@ class Profile(contact.Contact, Singleton): self._load_history = True settings = Settings.get_instance() self._show_online = settings['show_online_friends'] + self._show_avatars = settings['show_avatars'] + self._friend_item_height = 40 if settings['compact_mode'] else 70 screen.online_contacts.setCurrentIndex(int(self._show_online)) aliases = settings['friends_aliases'] data = tox.self_get_friend_list() @@ -122,7 +124,7 @@ class Profile(contact.Contact, Singleton): friend.visibility = friend.visibility or friend.messages or friend.actions if friend.visibility: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, - 40 if settings['compact_mode'] else 70)) + self._friend_item_height)) else: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0)) self._show_online, self._filter_string = show_online, filter_str @@ -532,6 +534,9 @@ class Profile(contact.Contact, Singleton): else: name = self._name item = MessageItem(text, time, name, owner != MESSAGE_OWNER['NOT_SENT'], message_type, self._messages) + if self._show_avatars: + item.set_avatar(self._friends[self._active_friend].get_pixmap() if owner == MESSAGE_OWNER[ + 'FRIEND'] else self.get_pixmap()) elem = QtGui.QListWidgetItem() elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height())) if append: diff --git a/toxygen/settings.py b/toxygen/settings.py index f4c7746..48cb5bf 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -110,6 +110,7 @@ class Settings(dict, Singleton): 'show_online_friends': False, 'auto_accept_from_friends': [], 'friends_aliases': [], + 'show_avatars': False, 'typing_notifications': False, 'calls_sound': True, 'blocked': [],