From: Ed Page Date: Tue, 11 Jan 2011 00:19:32 +0000 (-0600) Subject: Fixing the height-for-width bug, upping the max messages count to compensate X-Git-Url: http://git.maemo.org/git/?p=gc-dialer;a=commitdiff_plain;h=51eacb82a6525f34cdb6b7e822792e8f50f44688 Fixing the height-for-width bug, upping the max messages count to compensate --- diff --git a/src/gv_views.py b/src/gv_views.py index db25067..8cb1082 100644 --- a/src/gv_views.py +++ b/src/gv_views.py @@ -450,7 +450,7 @@ class Messages(object): ALL_STATUS = "Any" MESSAGE_STATUSES = [UNREAD_STATUS, UNARCHIVED_STATUS, ALL_STATUS] - _MIN_MESSAGES_SHOWN = 1 + _MIN_MESSAGES_SHOWN = 4 def __init__(self, app, session, errorLog): self._selectedTypeFilter = self.ALL_TYPES @@ -506,6 +506,7 @@ class Messages(object): self._itemView.setItemsExpandable(False) self._itemView.setItemDelegate(self._htmlDelegate) self._itemView.activated.connect(self._on_row_activated) + self._itemView.header().sectionResized.connect(self._on_column_resized) self._layout = QtGui.QVBoxLayout() self._layout.addLayout(self._selectionLayout) @@ -668,6 +669,11 @@ class Messages(object): numbersWithDescriptions = [(number, "")] self._session.draft.add_contact(contactId, title, description, numbersWithDescriptions) + @QtCore.pyqtSlot(QtCore.QModelIndex) + @misc_utils.log_exception(_moduleLogger) + def _on_column_resized(self, index, oldSize, newSize): + self._htmlDelegate.setWidth(newSize) + class Contacts(object): diff --git a/src/util/qui_utils.py b/src/util/qui_utils.py index 0249874..d49eb75 100644 --- a/src/util/qui_utils.py +++ b/src/util/qui_utils.py @@ -187,7 +187,11 @@ class ErrorDisplay(object): class QHtmlDelegate(QtGui.QStyledItemDelegate): - # @bug Not showing all of a message + UNDEFINED_SIZE = -1 + + def __init__(self, *args, **kwd): + QtGui.QStyledItemDelegate.__init__(*((self, ) + args), **kwd) + self._width = self.UNDEFINED_SIZE def paint(self, painter, option, index): newOption = QtGui.QStyleOptionViewItemV4(option) @@ -229,13 +233,21 @@ class QHtmlDelegate(QtGui.QStyledItemDelegate): doc.documentLayout().draw(painter, ctx) painter.restore() + def setWidth(self, width): + # @bug we need to be emitting sizeHintChanged but it requires an index + self._width = width + def sizeHint(self, option, index): newOption = QtGui.QStyleOptionViewItemV4(option) self.initStyleOption(newOption, index) doc = QtGui.QTextDocument() doc.setHtml(newOption.text) - doc.setTextWidth(newOption.rect.width()) + if self._width != self.UNDEFINED_SIZE: + width = self._width + else: + width = newOption.rect.width() + doc.setTextWidth(width) size = QtCore.QSize(doc.idealWidth(), doc.size().height()) return size