2016-03-01 22:17:22 +01:00
|
|
|
from toxcore_enums_and_consts import *
|
|
|
|
from PySide import QtGui, QtCore
|
2016-03-04 18:52:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MessageEdit(QtGui.QPlainTextEdit):
|
2016-03-05 13:44:52 +01:00
|
|
|
def __init__(self, text, width, parent=None):
|
2016-03-04 18:52:52 +01:00
|
|
|
super(MessageEdit, self).__init__(parent)
|
2016-03-15 18:05:19 +01:00
|
|
|
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
|
|
|
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
2016-03-04 18:52:52 +01:00
|
|
|
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
|
|
|
self.setPlainText(text)
|
|
|
|
self.document().setTextWidth(parent.width() - 100)
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
2016-03-11 12:37:45 +01:00
|
|
|
font.setPixelSize(14)
|
2016-03-04 18:52:52 +01:00
|
|
|
font.setBold(False)
|
|
|
|
self.setFont(font)
|
2016-03-05 13:44:52 +01:00
|
|
|
lines = 0
|
|
|
|
fm = QtGui.QFontMetrics(font)
|
2016-03-04 18:52:52 +01:00
|
|
|
try:
|
|
|
|
for elem in xrange(self.document().blockCount()):
|
2016-03-05 13:44:52 +01:00
|
|
|
block = self.document().findBlockByLineNumber(elem)
|
|
|
|
line_width = fm.width(block.text())
|
|
|
|
print 'Width: ', line_width
|
|
|
|
print 'Parent width', parent.width()
|
|
|
|
lines += line_width // width + 1
|
2016-03-04 18:52:52 +01:00
|
|
|
except:
|
|
|
|
print 'updateSize failed'
|
|
|
|
print 'lines ', lines
|
2016-03-05 13:44:52 +01:00
|
|
|
if self.document().blockCount() == 1:
|
|
|
|
lines += 1
|
2016-03-11 12:37:45 +01:00
|
|
|
size = lines * 21
|
2016-03-08 19:53:11 +01:00
|
|
|
self.setFixedHeight(max(size, 30))
|
2016-03-04 18:52:52 +01:00
|
|
|
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
2016-03-01 22:17:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MessageItem(QtGui.QListWidget):
|
|
|
|
"""
|
|
|
|
Message in messages list
|
|
|
|
"""
|
|
|
|
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
|
|
|
QtGui.QListWidget.__init__(self, parent)
|
|
|
|
self.name = QtGui.QLabel(self)
|
2016-03-15 21:54:01 +01:00
|
|
|
self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
|
2016-03-01 22:17:22 +01:00
|
|
|
self.name.setTextFormat(QtCore.Qt.PlainText)
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
2016-03-15 21:35:15 +01:00
|
|
|
font.setPointSize(11)
|
2016-03-01 22:17:22 +01:00
|
|
|
font.setBold(True)
|
|
|
|
self.name.setFont(font)
|
|
|
|
self.name.setObjectName("name")
|
|
|
|
self.name.setText(user)
|
|
|
|
|
|
|
|
self.time = QtGui.QLabel(self)
|
2016-03-08 19:53:11 +01:00
|
|
|
self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 25))
|
2016-03-01 22:17:22 +01:00
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
|
|
|
font.setPointSize(10)
|
|
|
|
font.setBold(False)
|
|
|
|
self.time.setFont(font)
|
|
|
|
self.time.setObjectName("time")
|
|
|
|
self.time.setText(time)
|
|
|
|
|
2016-03-08 19:53:11 +01:00
|
|
|
self.message = MessageEdit(text, parent.width() - 150, self)
|
|
|
|
self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
|
2016-03-04 18:52:52 +01:00
|
|
|
self.h = self.message.height()
|
2016-03-08 19:53:11 +01:00
|
|
|
print 'self.h ', self.h
|
2016-03-04 20:03:20 +01:00
|
|
|
self.setFixedHeight(self.getHeight())
|
|
|
|
|
2016-03-04 18:52:52 +01:00
|
|
|
self.message.setFrameShape(QtGui.QFrame.NoFrame)
|
|
|
|
self.time.setFrameShape(QtGui.QFrame.NoFrame)
|
|
|
|
self.name.setFrameShape(QtGui.QFrame.NoFrame)
|
|
|
|
self.setFrameShape(QtGui.QFrame.NoFrame)
|
2016-03-01 22:17:22 +01:00
|
|
|
|
|
|
|
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
|
|
|
self.name.setStyleSheet("QLabel { color: blue; }")
|
|
|
|
self.message.setStyleSheet("QPlainTextEdit { color: blue; }")
|
2016-03-04 18:52:52 +01:00
|
|
|
else:
|
|
|
|
if text[0] == '>':
|
|
|
|
self.message.setStyleSheet("QPlainTextEdit { color: green; }")
|
|
|
|
if text[-1] == '<':
|
|
|
|
self.message.setStyleSheet("QPlainTextEdit { color: red; }")
|
|
|
|
|
|
|
|
def getHeight(self):
|
|
|
|
return max(self.h, 30)
|
|
|
|
|
2016-03-01 22:17:22 +01:00
|
|
|
|
|
|
|
class ContactItem(QtGui.QListWidget):
|
|
|
|
"""
|
|
|
|
Contact in friends list
|
|
|
|
"""
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QtGui.QListWidget.__init__(self, parent)
|
2016-03-08 19:53:11 +01:00
|
|
|
self.setBaseSize(QtCore.QSize(250, 70))
|
|
|
|
self.avatar_label = QtGui.QLabel(self)
|
|
|
|
self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64))
|
|
|
|
self.avatar_label.setScaledContents(True)
|
2016-03-01 22:17:22 +01:00
|
|
|
self.name = QtGui.QLabel(self)
|
2016-03-08 19:53:11 +01:00
|
|
|
self.name.setGeometry(QtCore.QRect(70, 10, 170, 25))
|
2016-03-01 22:17:22 +01:00
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
|
|
|
font.setPointSize(12)
|
|
|
|
font.setBold(True)
|
|
|
|
self.name.setFont(font)
|
|
|
|
self.name.setObjectName("name")
|
|
|
|
self.status_message = QtGui.QLabel(self)
|
2016-03-08 19:53:11 +01:00
|
|
|
self.status_message.setGeometry(QtCore.QRect(70, 30, 180, 20))
|
2016-03-01 22:17:22 +01:00
|
|
|
font.setPointSize(10)
|
|
|
|
font.setBold(False)
|
|
|
|
self.status_message.setFont(font)
|
|
|
|
self.status_message.setObjectName("status_message")
|
|
|
|
self.connection_status = StatusCircle(self)
|
2016-03-08 19:53:11 +01:00
|
|
|
self.connection_status.setGeometry(QtCore.QRect(218, 5, 32, 32))
|
|
|
|
# self.connection_status.setMinimumSize(QtCore.QSize(32, 32))
|
|
|
|
# self.connection_status.setMaximumSize(QtCore.QSize(32, 32))
|
|
|
|
# self.connection_status.setBaseSize(QtCore.QSize(32, 32))
|
2016-03-01 22:17:22 +01:00
|
|
|
self.connection_status.setObjectName("connection_status")
|
|
|
|
|
|
|
|
|
|
|
|
class StatusCircle(QtGui.QWidget):
|
|
|
|
"""
|
|
|
|
Connection status
|
|
|
|
"""
|
|
|
|
def __init__(self, parent):
|
|
|
|
QtGui.QWidget.__init__(self, parent)
|
|
|
|
self.setGeometry(0, 0, 32, 32)
|
|
|
|
self.data = None
|
2016-03-05 17:44:44 +01:00
|
|
|
self.messages = False
|
2016-03-01 22:17:22 +01:00
|
|
|
|
|
|
|
def paintEvent(self, event):
|
|
|
|
paint = QtGui.QPainter()
|
|
|
|
paint.begin(self)
|
|
|
|
paint.setRenderHint(QtGui.QPainter.Antialiasing)
|
|
|
|
k = 16
|
|
|
|
rad_x = rad_y = 5
|
|
|
|
if self.data is None:
|
|
|
|
color = QtCore.Qt.transparent
|
|
|
|
else:
|
|
|
|
if self.data == TOX_USER_STATUS['NONE']:
|
2016-03-08 19:53:11 +01:00
|
|
|
color = QtGui.QColor(50, 205, 50)
|
2016-03-01 22:17:22 +01:00
|
|
|
elif self.data == TOX_USER_STATUS['AWAY']:
|
2016-03-08 19:53:11 +01:00
|
|
|
color = QtGui.QColor(255, 200, 50)
|
2016-03-01 22:17:22 +01:00
|
|
|
else: # self.data == TOX_USER_STATUS['BUSY']:
|
2016-03-08 19:53:11 +01:00
|
|
|
color = QtGui.QColor(255, 50, 0)
|
2016-03-01 22:17:22 +01:00
|
|
|
|
|
|
|
paint.setPen(color)
|
|
|
|
center = QtCore.QPoint(k, k)
|
|
|
|
paint.setBrush(color)
|
|
|
|
paint.drawEllipse(center, rad_x, rad_y)
|
2016-03-05 17:44:44 +01:00
|
|
|
if self.messages:
|
|
|
|
if color == QtCore.Qt.transparent:
|
|
|
|
color = QtCore.Qt.darkRed
|
|
|
|
paint.setBrush(QtCore.Qt.transparent)
|
|
|
|
paint.setPen(color)
|
2016-03-08 19:53:11 +01:00
|
|
|
paint.drawEllipse(center, rad_x + 3, rad_y + 3)
|
2016-03-04 20:03:20 +01:00
|
|
|
paint.end()
|
2016-03-18 22:28:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
class FileTransferItem(QtGui.QListWidget):
|
|
|
|
def __init__(self, file_name, time, user, friend_number, file_number, parent=None):
|
|
|
|
QtGui.QListWidget.__init__(self, parent)
|
|
|
|
self.name = QtGui.QLabel(self)
|
|
|
|
self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
|
|
|
|
self.name.setTextFormat(QtCore.Qt.PlainText)
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
|
|
|
font.setPointSize(11)
|
|
|
|
font.setBold(True)
|
|
|
|
self.name.setFont(font)
|
|
|
|
self.name.setObjectName("name")
|
|
|
|
self.name.setText(file_name)
|
|
|
|
|
|
|
|
self.time = QtGui.QLabel(self)
|
|
|
|
self.time.setGeometry(QtCore.QRect(500, 0, 50, 25))
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setFamily("Times New Roman")
|
|
|
|
font.setPointSize(10)
|
|
|
|
font.setBold(False)
|
|
|
|
self.time.setFont(font)
|
|
|
|
self.time.setObjectName("time")
|
|
|
|
self.time.setText(time)
|
|
|
|
|
|
|
|
self.cancel = QtGui.QPushButton(self)
|
|
|
|
self.cancel.setGeometry(QtCore.QRect(100, 2, 200, 20))
|
|
|
|
self.cancel.setText("Cancel")
|
|
|
|
self.cancel.clicked.connect(lambda: self.click(friend_number, file_number))
|
|
|
|
|
|
|
|
def click(self, friend_number, file_number):
|
|
|
|
from profile import Profile
|
|
|
|
profile = Profile.get_instance()
|
|
|
|
profile.cancel_transfer(friend_number, file_number)
|
|
|
|
self.name.setText('Cancelled')
|