ui update - long names and statuses, messages update - long data and last message
This commit is contained in:
parent
dd8f0e07e0
commit
c2aead6e06
4 changed files with 45 additions and 36 deletions
|
@ -30,7 +30,7 @@ class MessageItem(QtGui.QWidget):
|
|||
"""
|
||||
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.name = QtGui.QLabel(self)
|
||||
self.name = DataLabel(self)
|
||||
self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
|
||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||
font = QtGui.QFont()
|
||||
|
@ -39,7 +39,7 @@ class MessageItem(QtGui.QWidget):
|
|||
font.setBold(True)
|
||||
self.name.setFont(font)
|
||||
self.name.setObjectName("name")
|
||||
self.name.setText(user if len(user) <= 14 else user[:11] + '...')
|
||||
self.name.setText(user)
|
||||
|
||||
self.time = QtGui.QLabel(self)
|
||||
self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 25))
|
||||
|
@ -65,6 +65,15 @@ class MessageItem(QtGui.QWidget):
|
|||
self.message.setStyleSheet("QTextEdit { color: red; }")
|
||||
|
||||
|
||||
class DataLabel(QtGui.QLabel):
|
||||
|
||||
def paintEvent(self, event):
|
||||
painter = QtGui.QPainter(self)
|
||||
metrics = QtGui.QFontMetrics(self.font())
|
||||
text = metrics.elidedText(self.text(), QtCore.Qt.ElideRight, self.width())
|
||||
painter.drawText(self.rect(), self.alignment(), text)
|
||||
|
||||
|
||||
class ContactItem(QtGui.QWidget):
|
||||
"""
|
||||
Contact in friends list
|
||||
|
@ -75,7 +84,7 @@ class ContactItem(QtGui.QWidget):
|
|||
self.avatar_label = QtGui.QLabel(self)
|
||||
self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64))
|
||||
self.avatar_label.setScaledContents(True)
|
||||
self.name = QtGui.QLabel(self)
|
||||
self.name = DataLabel(self)
|
||||
self.name.setGeometry(QtCore.QRect(70, 10, 170, 25))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
|
@ -83,14 +92,14 @@ class ContactItem(QtGui.QWidget):
|
|||
font.setBold(True)
|
||||
self.name.setFont(font)
|
||||
self.name.setObjectName("name")
|
||||
self.status_message = QtGui.QLabel(self)
|
||||
self.status_message = DataLabel(self)
|
||||
self.status_message.setGeometry(QtCore.QRect(70, 30, 180, 20))
|
||||
font.setPointSize(10)
|
||||
font.setBold(False)
|
||||
self.status_message.setFont(font)
|
||||
self.status_message.setObjectName("status_message")
|
||||
self.connection_status = StatusCircle(self)
|
||||
self.connection_status.setGeometry(QtCore.QRect(218, 5, 32, 32))
|
||||
self.connection_status.setGeometry(QtCore.QRect(230, 5, 32, 32))
|
||||
self.connection_status.setObjectName("connection_status")
|
||||
|
||||
|
||||
|
@ -144,7 +153,7 @@ class FileTransferItem(QtGui.QListWidget):
|
|||
else:
|
||||
self.setStyleSheet('QWidget { background-color: #B40404; }')
|
||||
|
||||
self.name = QtGui.QLabel(self)
|
||||
self.name = DataLabel(self)
|
||||
self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
|
||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||
font = QtGui.QFont()
|
||||
|
@ -152,7 +161,7 @@ class FileTransferItem(QtGui.QListWidget):
|
|||
font.setPointSize(11)
|
||||
font.setBold(True)
|
||||
self.name.setFont(font)
|
||||
self.name.setText(user if len(user) <= 14 else user[:11] + '...')
|
||||
self.name.setText(user)
|
||||
self.name.setStyleSheet('QLabel { color: black; }')
|
||||
|
||||
self.time = QtGui.QLabel(self)
|
||||
|
@ -190,7 +199,7 @@ class FileTransferItem(QtGui.QListWidget):
|
|||
if state < 2:
|
||||
self.pb.setVisible(False)
|
||||
|
||||
self.file_name = QtGui.QLabel(self)
|
||||
self.file_name = DataLabel(self)
|
||||
self.file_name.setGeometry(QtCore.QRect(210, 2, 230, 46))
|
||||
font.setPointSize(12)
|
||||
self.file_name.setFont(font)
|
||||
|
@ -202,7 +211,7 @@ class FileTransferItem(QtGui.QListWidget):
|
|||
else:
|
||||
file_size = '{}KB'.format(file_size)
|
||||
file_data = u'{} {}'.format(file_size, file_name)
|
||||
self.file_name.setText(file_data if len(file_data) <= 27 else file_data[:24] + '...')
|
||||
self.file_name.setText(file_data)
|
||||
self.file_name.setStyleSheet('QLabel { color: black; }')
|
||||
self.saved_name = file_name
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ class MessageArea(QtGui.QPlainTextEdit):
|
|||
self.appendPlainText('')
|
||||
else:
|
||||
self.parent.send_message()
|
||||
elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText():
|
||||
self.appendPlainText(Profile.get_instance().get_last_message())
|
||||
else:
|
||||
super(self.__class__, self).keyPressEvent(event)
|
||||
|
||||
|
@ -148,7 +150,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||
self.avatar_label = Form.avatar_label = QtGui.QLabel(Form)
|
||||
self.avatar_label.setGeometry(QtCore.QRect(10, 20, 64, 64))
|
||||
self.avatar_label.setScaledContents(True)
|
||||
self.name = Form.name = QtGui.QLabel(Form)
|
||||
self.name = Form.name = DataLabel(Form)
|
||||
Form.name.setGeometry(QtCore.QRect(80, 30, 150, 25))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
|
@ -156,8 +158,8 @@ class MainWindow(QtGui.QMainWindow):
|
|||
font.setBold(True)
|
||||
Form.name.setFont(font)
|
||||
Form.name.setObjectName("name")
|
||||
self.status_message = Form.status_message = QtGui.QLabel(Form)
|
||||
Form.status_message.setGeometry(QtCore.QRect(80, 60, 190, 20))
|
||||
self.status_message = Form.status_message = DataLabel(Form)
|
||||
Form.status_message.setGeometry(QtCore.QRect(80, 60, 170, 20))
|
||||
font.setPointSize(12)
|
||||
font.setBold(False)
|
||||
Form.status_message.setFont(font)
|
||||
|
@ -179,7 +181,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||
self.account_avatar = QtGui.QLabel(Form)
|
||||
self.account_avatar.setGeometry(QtCore.QRect(10, 20, 64, 64))
|
||||
self.account_avatar.setScaledContents(True)
|
||||
self.account_name = QtGui.QLabel(Form)
|
||||
self.account_name = DataLabel(Form)
|
||||
self.account_name.setGeometry(QtCore.QRect(100, 30, 400, 25))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
|
@ -187,7 +189,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||
font.setBold(True)
|
||||
self.account_name.setFont(font)
|
||||
self.account_name.setObjectName("account_name")
|
||||
self.account_status = QtGui.QLabel(Form)
|
||||
self.account_status = DataLabel(Form)
|
||||
self.account_status.setGeometry(QtCore.QRect(100, 50, 400, 25))
|
||||
font.setPointSize(12)
|
||||
font.setBold(False)
|
||||
|
|
|
@ -26,6 +26,9 @@ class Message(object):
|
|||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_owner(self):
|
||||
return self._owner
|
||||
|
||||
|
||||
class TextMessage(Message):
|
||||
"""
|
||||
|
|
|
@ -86,15 +86,8 @@ class Contact(object):
|
|||
"""
|
||||
self._name, self._status_message = name, status_message
|
||||
self._status, self._widget = None, widget
|
||||
if type(self) is Profile:
|
||||
self._widget.name.setText(name if len(name) <= 12 else name[:9] + '...')
|
||||
else:
|
||||
self._widget.name.setText(name if len(name) <= 20 else name[:17] + '...')
|
||||
if type(self) is Profile:
|
||||
text = self._status_message if len(self._status_message) <= 20 else self._status_message[:17] + '...'
|
||||
else:
|
||||
text = self._status_message if len(self._status_message) <= 30 else self._status_message[:27] + '...'
|
||||
self._widget.status_message.setText(text)
|
||||
self._widget.name.setText(name)
|
||||
self._widget.status_message.setText(status_message)
|
||||
self._tox_id = tox_id
|
||||
self.load_avatar()
|
||||
|
||||
|
@ -107,10 +100,7 @@ class Contact(object):
|
|||
|
||||
def set_name(self, value):
|
||||
self._name = value.decode('utf-8')
|
||||
if type(self) is Profile:
|
||||
self._widget.name.setText(self._name if len(self._name) <= 12 else self._name[:9] + '...')
|
||||
else:
|
||||
self._widget.name.setText(self._name if len(self._name) <= 20 else self._name[:17] + '...')
|
||||
self._widget.name.setText(self._name)
|
||||
self._widget.name.repaint()
|
||||
|
||||
name = property(get_name, set_name)
|
||||
|
@ -124,11 +114,7 @@ class Contact(object):
|
|||
|
||||
def set_status_message(self, value):
|
||||
self._status_message = value.decode('utf-8')
|
||||
if type(self) is Profile:
|
||||
text = self._status_message if len(self._status_message) <= 20 else self._status_message[:17] + '...'
|
||||
else:
|
||||
text = self._status_message if len(self._status_message) <= 30 else self._status_message[:27] + '...'
|
||||
self._widget.status_message.setText(text)
|
||||
self._widget.status_message.setText(self._status_message)
|
||||
self._widget.status_message.repaint()
|
||||
|
||||
status_message = property(get_status_message, set_status_message)
|
||||
|
@ -254,6 +240,13 @@ class Friend(Contact):
|
|||
if message.get_type() <= 1:
|
||||
self._unsaved_messages += 1
|
||||
|
||||
def get_last_message(self):
|
||||
messages = filter(lambda x: x.get_type() <= 1 and not x.get_owner(), self._corr)
|
||||
if messages:
|
||||
return messages[-1].get_data()[0]
|
||||
else:
|
||||
return ''
|
||||
|
||||
def clear_corr(self):
|
||||
"""
|
||||
Clear messages list
|
||||
|
@ -466,10 +459,9 @@ class Profile(Contact, Singleton):
|
|||
self._messages.scrollToBottom()
|
||||
else:
|
||||
friend = self._friends[self._active_friend]
|
||||
name = friend.name if len(friend.name) < 50 else friend.name[:47] + '...'
|
||||
status_message = friend.status_message if len(friend.status_message) < 66 else friend.status_message[:63] + '...'
|
||||
self._screen.account_name.setText(name)
|
||||
self._screen.account_status.setText(status_message)
|
||||
|
||||
self._screen.account_name.setText(friend.name)
|
||||
self._screen.account_status.setText(friend.status_message)
|
||||
avatar_path = (Settings.get_default_path() + 'avatars/{}.png').format(friend.tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
|
||||
if not os.path.isfile(avatar_path): # load default image
|
||||
avatar_path = curr_directory() + '/images/avatar.png'
|
||||
|
@ -484,6 +476,9 @@ class Profile(Contact, Singleton):
|
|||
|
||||
active_friend = property(get_active, set_active)
|
||||
|
||||
def get_last_message(self):
|
||||
return self._friends[self._active_friend].get_last_message()
|
||||
|
||||
def get_active_number(self):
|
||||
return self._friends[self._active_friend].number if self._active_friend + 1 else -1
|
||||
|
||||
|
|
Loading…
Reference in a new issue