Fixing the height-for-width bug, upping the max messages count to compensate
authorEd Page <eopage@byu.net>
Tue, 11 Jan 2011 00:19:32 +0000 (18:19 -0600)
committerEd Page <eopage@byu.net>
Tue, 11 Jan 2011 00:19:32 +0000 (18:19 -0600)
src/gv_views.py
src/util/qui_utils.py

index db25067..8cb1082 100644 (file)
@@ -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):
 
index 0249874..d49eb75 100644 (file)
@@ -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