From 5204cba58d02d66b7a90422aa75a4dac614d4f29 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 1 Jul 2016 16:25:46 +0300 Subject: [PATCH] compact contact list --- src/contact.py | 5 +++-- src/list_items.py | 16 +++++++++------- src/menu.py | 27 +++++++++++++++++++-------- src/profile.py | 8 ++++---- src/settings.py | 3 ++- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/contact.py b/src/contact.py index 3ee1b90..f4b3f9a 100644 --- a/src/contact.py +++ b/src/contact.py @@ -91,10 +91,11 @@ class Contact: if not os.path.isfile(avatar_path): # load default image avatar_path = 'avatar.png' os.chdir(curr_directory() + '/images/') - pixmap = QtGui.QPixmap(QtCore.QSize(64, 64)) + width = self._widget.avatar_label.width() + pixmap = QtGui.QPixmap(QtCore.QSize(width, width)) pixmap.load(avatar_path) self._widget.avatar_label.setScaledContents(False) - self._widget.avatar_label.setPixmap(pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio)) + self._widget.avatar_label.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio)) self._widget.avatar_label.repaint() def reset_avatar(self): diff --git a/src/list_items.py b/src/list_items.py index 0379ad2..c883df4 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -167,26 +167,28 @@ class ContactItem(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) - self.setBaseSize(QtCore.QSize(250, 70)) + mode = settings.Settings.get_instance()['compact_mode'] + self.setBaseSize(QtCore.QSize(250, 40 if mode else 70)) self.avatar_label = QtGui.QLabel(self) - self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64)) + size = 32 if mode else 64 + self.avatar_label.setGeometry(QtCore.QRect(3, 4, size, size)) self.avatar_label.setScaledContents(True) self.name = DataLabel(self) - self.name.setGeometry(QtCore.QRect(75, 10, 150, 25)) + self.name.setGeometry(QtCore.QRect(50 if mode else 75, 3 if mode else 10, 150, 15 if mode else 25)) font = QtGui.QFont() font.setFamily("Times New Roman") - font.setPointSize(12) + font.setPointSize(10 if mode else 12) font.setBold(True) self.name.setFont(font) self.status_message = DataLabel(self) - self.status_message.setGeometry(QtCore.QRect(75, 30, 170, 20)) + self.status_message.setGeometry(QtCore.QRect(50 if mode else 75, 20 if mode else 30, 170, 15 if mode else 20)) font.setPointSize(10) font.setBold(False) self.status_message.setFont(font) self.connection_status = StatusCircle(self) - self.connection_status.setGeometry(QtCore.QRect(230, 5, 32, 32)) + self.connection_status.setGeometry(QtCore.QRect(230, -2 if mode else 5, 32, 32)) self.messages = UnreadMessagesCount(self) - self.messages.setGeometry(QtCore.QRect(52, 50, 30, 20)) + self.messages.setGeometry(QtCore.QRect(20 if mode else 52, 20 if mode else 50, 30, 20)) class StatusCircle(QtGui.QWidget): diff --git a/src/menu.py b/src/menu.py index 8db9505..acf8c93 100644 --- a/src/menu.py +++ b/src/menu.py @@ -592,9 +592,13 @@ class InterfaceSettings(CenteredWidget): self.messages_font_size.setCurrentIndex(settings['message_font_size'] - 10) self.unread = QtGui.QPushButton(self) - self.unread.setGeometry(QtCore.QRect(30, 380, 340, 40)) + self.unread.setGeometry(QtCore.QRect(30, 380, 340, 30)) self.unread.clicked.connect(self.select_color) + self.compact_mode = QtGui.QCheckBox(self) + self.compact_mode.setGeometry(QtCore.QRect(30, 425, 370, 20)) + self.compact_mode.setChecked(settings['compact_mode']) + self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) @@ -607,6 +611,7 @@ class InterfaceSettings(CenteredWidget): self.mirror_mode.setText(QtGui.QApplication.translate("interfaceForm", "Mirror mode", None, QtGui.QApplication.UnicodeUTF8)) self.messages_font_size_label.setText(QtGui.QApplication.translate("interfaceForm", "Messages font size:", None, QtGui.QApplication.UnicodeUTF8)) self.unread.setText(QtGui.QApplication.translate("interfaceForm", "Select unread messages notification color", None, QtGui.QApplication.UnicodeUTF8)) + self.compact_mode.setText(QtGui.QApplication.translate("interfaceForm", "Compact contact list", None, QtGui.QApplication.UnicodeUTF8)) def select_color(self): col = QtGui.QColorDialog.getColor() @@ -621,15 +626,13 @@ class InterfaceSettings(CenteredWidget): settings = Settings.get_instance() settings['theme'] = str(self.themeSelect.currentText()) settings['smileys'] = self.smileys.isChecked() + restart = False if settings['mirror_mode'] != self.mirror_mode.isChecked(): settings['mirror_mode'] = self.mirror_mode.isChecked() - msgBox = QtGui.QMessageBox() - text = QtGui.QApplication.translate("interfaceForm", 'Restart app to apply settings', None, - QtGui.QApplication.UnicodeUTF8) - msgBox.setWindowTitle(QtGui.QApplication.translate("interfaceForm", 'Restart required', None, - QtGui.QApplication.UnicodeUTF8)) - msgBox.setText(text) - msgBox.exec_() + restart = True + if settings['compact_mode'] != self.compact_mode.isChecked(): + settings['compact_mode'] = self.compact_mode.isChecked() + restart = True settings['smiley_pack'] = self.smiley_pack.currentText() smileys.SmileyLoader.get_instance().load_pack() language = self.lang_choose.currentText() @@ -644,6 +647,14 @@ class InterfaceSettings(CenteredWidget): settings['message_font_size'] = self.messages_font_size.currentIndex() + 10 Profile.get_instance().update() settings.save() + if restart: + msgBox = QtGui.QMessageBox() + text = QtGui.QApplication.translate("interfaceForm", 'Restart app to apply settings', None, + QtGui.QApplication.UnicodeUTF8) + msgBox.setWindowTitle(QtGui.QApplication.translate("interfaceForm", 'Restart required', None, + QtGui.QApplication.UnicodeUTF8)) + msgBox.setText(text) + msgBox.exec_() class AudioSettings(CenteredWidget): diff --git a/src/profile.py b/src/profile.py index 4850f28..c8fe68e 100644 --- a/src/profile.py +++ b/src/profile.py @@ -62,7 +62,6 @@ class Profile(contact.Contact, Singleton): self._friends.append(friend) self.filtration(self._show_online) - # ----------------------------------------------------------------------------------------------------------------- # Edit current user's data # ----------------------------------------------------------------------------------------------------------------- @@ -116,15 +115,16 @@ class Profile(contact.Contact, Singleton): :param filter_str: show contacts which name contains this substring """ filter_str = filter_str.lower() + settings = Settings.get_instance() for index, friend in enumerate(self._friends): friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name.lower()) friend.visibility = friend.visibility or friend.messages or friend.actions if friend.visibility: - self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 70)) + self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, + 40 if settings['compact_mode'] else 70)) else: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0)) self._show_online, self._filter_string = show_online, filter_str - settings = Settings.get_instance() settings['show_online_friends'] = self._show_online settings.save() @@ -507,7 +507,7 @@ class Profile(contact.Contact, Singleton): """ item = ContactItem() elem = QtGui.QListWidgetItem(self._screen.friends_list) - elem.setSizeHint(QtCore.QSize(250, 70)) + elem.setSizeHint(QtCore.QSize(250, item.height())) self._screen.friends_list.addItem(elem) self._screen.friends_list.setItemWidget(elem, item) return item diff --git a/src/settings.py b/src/settings.py index e0c0aa9..e67d681 100644 --- a/src/settings.py +++ b/src/settings.py @@ -123,7 +123,8 @@ class Settings(dict, Singleton): 'y': 400, 'message_font_size': 14, 'unread_color': 'red', - 'save_unsent_only': False + 'save_unsent_only': False, + 'compact_mode': False } @staticmethod