message edit rewritten. history bug fixed. ui improvements

This commit is contained in:
ingvar1995 2016-03-25 16:24:38 +03:00
parent 50825c238c
commit 1d5d9d6e47
5 changed files with 13 additions and 29 deletions

View file

@ -40,7 +40,7 @@ class History(object):
' id INTEGER PRIMARY KEY,'
' message TEXT,'
' owner INTEGER,'
' unix_time INTEGER,'
' unix_time REAL,'
' message_type INTEGER'
')')
db.commit()

View file

@ -5,33 +5,21 @@ from file_transfers import TOX_FILE_TRANSFER_STATE
from util import curr_directory
class MessageEdit(QtGui.QPlainTextEdit):
class MessageEdit(QtGui.QTextEdit):
def __init__(self, text, width, parent=None):
super(MessageEdit, self).__init__(parent)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
self.document().setTextWidth(width)
self.setPlainText(text)
self.document().setTextWidth(parent.width() - 100)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPixelSize(14)
font.setBold(False)
self.setFont(font)
lines = 0
fm = QtGui.QFontMetrics(font)
try:
for elem in xrange(self.document().blockCount()):
block = self.document().findBlockByLineNumber(elem)
line_width = fm.width(block.text())
print 'Width: ', line_width
lines += line_width / float(width) + 1
except:
print 'updateSize failed'
print 'lines ', lines
size = int(lines + 0.5) * 21
self.setFixedHeight(max(size, 25))
self.setFixedHeight(self.document().size().height())
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
@ -64,9 +52,7 @@ class MessageItem(QtGui.QWidget):
self.message = MessageEdit(text, parent.width() - 150, self)
self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
self.h = self.message.height()
print 'self.h ', self.h
self.setFixedHeight(self.getHeight())
self.setFixedHeight(self.message.height())
if message_type == TOX_MESSAGE_TYPE['ACTION']:
self.name.setStyleSheet("QLabel { color: #4169E1; }")
@ -77,9 +63,6 @@ class MessageItem(QtGui.QWidget):
if text[-1] == '<':
self.message.setStyleSheet("QPlainTextEdit { color: red; }")
def getHeight(self):
return max(self.h, 25)
class ContactItem(QtGui.QWidget):
"""
@ -205,7 +188,7 @@ class FileTransferItem(QtGui.QWidget):
self.file_name.setObjectName("time")
file_size = size / 1024
if not file_size:
file_size = '<1KB'
file_size = '<{}B'.format(size)
elif file_size >= 1024:
file_size = '{}MB'.format(file_size / 1024)
else:

View file

@ -211,6 +211,7 @@ class MainWindow(QtGui.QMainWindow):
def setup_right_center(self, widget):
self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 620, 250)
self.messages.setObjectName("messages")
def load(pos):
if not pos:

View file

@ -219,7 +219,6 @@ class Friend(Contact):
:param first_time: friend became active, load first part of messages
:return: list of loaded messages
"""
# TODO: fix bug with message order
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
return
data = self._message_getter.get(42)
@ -510,7 +509,7 @@ class Profile(Contact, Singleton):
self._messages.scrollToBottom()
self._friends[self._active_friend].append_message((message.decode('utf-8'),
MESSAGE_OWNER['FRIEND'],
int(time.time()),
time.time(),
message_type))
else:
friend = filter(lambda x: x.number == friend_num, self._friends)[0]
@ -538,7 +537,7 @@ class Profile(Contact, Singleton):
self._messages.scrollToBottom()
friend.append_message((text,
MESSAGE_OWNER['ME'],
int(time.time()),
time.time(),
message_type))
# -----------------------------------------------------------------------------------------------------------------
@ -580,6 +579,7 @@ class Profile(Contact, Singleton):
data = friend.load_corr(False)
if not data:
return
data.reverse()
for message in data:
self.create_message_item(message[0],
convert_time(message[2]),
@ -609,7 +609,7 @@ class Profile(Contact, Singleton):
def create_message_item(self, text, time, name, message_type, append=True):
item = MessageItem(text, time, name, message_type, self._messages)
elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(600, item.getHeight()))
elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append:
self._messages.addItem(elem)
else:

View file

@ -1252,9 +1252,9 @@ QPushButton:hover
background-color: #4A4949;
}
QListWidget QListWidgetItem:selected
#messages:item:selected
{
background-color: #4A4949;
background-color: transparent;
}
#friends_list:item:selected