ui update - messages #3
This commit is contained in:
parent
374f474b14
commit
7622ecbda7
@ -4,7 +4,7 @@ from PySide import QtGui, QtCore
|
||||
|
||||
|
||||
class MessageEdit(QtGui.QPlainTextEdit):
|
||||
def __init__(self, text='', parent=None):
|
||||
def __init__(self, text, width, parent=None):
|
||||
super(MessageEdit, self).__init__(parent)
|
||||
|
||||
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
||||
@ -12,22 +12,25 @@ class MessageEdit(QtGui.QPlainTextEdit):
|
||||
self.document().setTextWidth(parent.width() - 100)
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
font.setPointSize(10)
|
||||
font.setPixelSize(12)
|
||||
font.setBold(False)
|
||||
|
||||
self.setFont(font)
|
||||
lines = prev = 0
|
||||
lines = 0
|
||||
fm = QtGui.QFontMetrics(font)
|
||||
try:
|
||||
for elem in xrange(self.document().blockCount()):
|
||||
pos = self.document().findBlockByLineNumber(elem).position()
|
||||
lines += (pos - prev) // 55 + 1
|
||||
prev = pos
|
||||
block = self.document().findBlockByLineNumber(elem)
|
||||
l = block.length()
|
||||
line_width = fm.width(block.text())
|
||||
print 'Width: ', line_width
|
||||
print 'Parent width', parent.width()
|
||||
lines += line_width // width + 1
|
||||
except:
|
||||
print 'updateSize failed'
|
||||
print 'lines ', lines
|
||||
self.setFixedHeight(max(lines * 18, 30))
|
||||
self.setMinimumHeight(max(lines * 18, 30))
|
||||
self.setMaximumHeight(max(lines * 18, 30))
|
||||
if self.document().blockCount() == 1:
|
||||
lines += 1
|
||||
self.setFixedHeight(max(lines * 15, 30))
|
||||
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
||||
|
||||
|
||||
@ -49,7 +52,7 @@ class MessageItem(QtGui.QListWidget):
|
||||
self.name.setText(user)
|
||||
|
||||
self.time = QtGui.QLabel(self)
|
||||
self.time.setGeometry(QtCore.QRect(450, 0, 50, 50))
|
||||
self.time.setGeometry(QtCore.QRect(450, 0, 50, 25))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
font.setPointSize(10)
|
||||
@ -58,7 +61,7 @@ class MessageItem(QtGui.QListWidget):
|
||||
self.time.setObjectName("time")
|
||||
self.time.setText(time)
|
||||
|
||||
self.message = MessageEdit(text, self)
|
||||
self.message = MessageEdit(text, parent.width() - 100, self)
|
||||
self.message.setGeometry(QtCore.QRect(50, 0, parent.width() - 100, self.message.height()))
|
||||
self.h = self.message.height()
|
||||
self.setFixedHeight(self.getHeight())
|
||||
|
@ -5,6 +5,19 @@ from profile import *
|
||||
from list_items import *
|
||||
|
||||
|
||||
class MessageArea(QtGui.QPlainTextEdit):
|
||||
|
||||
def __init__(self, parent, form):
|
||||
super(MessageArea, self).__init__(parent)
|
||||
self.parent = form
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() == QtCore.Qt.Key_Return:
|
||||
self.parent.send_message()
|
||||
else:
|
||||
super(self.__class__, self).keyPressEvent(event)
|
||||
|
||||
|
||||
class MainWindow(QtGui.QMainWindow):
|
||||
|
||||
def __init__(self, tox):
|
||||
@ -77,7 +90,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
Form.setObjectName("right_bottom")
|
||||
Form.resize(500, 150)
|
||||
Form.setMinimumSize(QtCore.QSize(100, 50))
|
||||
self.messageEdit = QtGui.QTextEdit(Form)
|
||||
self.messageEdit = MessageArea(Form, self)
|
||||
self.messageEdit.setGeometry(QtCore.QRect(20, 20, 311, 111))
|
||||
self.messageEdit.setObjectName("messageEdit")
|
||||
self.screenshotButton = QtGui.QPushButton(Form)
|
||||
@ -96,7 +109,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
QtCore.QMetaObject.connectSlotsByName(Form)
|
||||
|
||||
def setup_left_bottom(self, Form):
|
||||
Form.setObjectName("left_center")
|
||||
Form.setObjectName("left_bottom")
|
||||
Form.resize(500, 80)
|
||||
self.online_contacts = QtGui.QCheckBox(Form)
|
||||
self.online_contacts.setGeometry(QtCore.QRect(0, 20, 141, 22))
|
||||
@ -286,3 +299,5 @@ class MainWindow(QtGui.QMainWindow):
|
||||
|
||||
def filtering(self):
|
||||
self.profile.filtration(self.online_contacts.isChecked(), self.contact_name.text())
|
||||
|
||||
|
||||
|
@ -264,7 +264,7 @@ class Profile(Contact):
|
||||
elem.setSizeHint(QtCore.QSize(500, item.getHeight()))
|
||||
self._messages.addItem(elem)
|
||||
self._messages.setItemWidget(elem, item)
|
||||
self._messages.scrollToBottom()
|
||||
#self._messages.scrollToBottom()
|
||||
self._messages.repaint()
|
||||
else:
|
||||
friend = filter(lambda x: x.number == id, self._friends)[0]
|
||||
|
Loading…
Reference in New Issue
Block a user