Source

thg-qt-mq / elidelab.diff

Full commit
# HG changeset patch
# Parent d533e14e006b51188b723e2baef973cf5d568ba9

diff --git a/tortoisehg/hgqt/qtlib.py b/tortoisehg/hgqt/qtlib.py
--- a/tortoisehg/hgqt/qtlib.py
+++ b/tortoisehg/hgqt/qtlib.py
@@ -734,6 +734,25 @@ class LabeledSeparator(QWidget):
 
         self.setLayout(box)
 
+class ElidableLabel(QLabel):
+    def minimumSizeHint(self):
+        size = super(ElidableLabel, self).minimumSizeHint()
+        size.setWidth(0)  # XXX
+        return size
+
+    def paintEvent(self, event):
+        fm = self.fontMetrics()
+        if fm.width(self.text()) <= self.contentsRect().width():
+            return super(ElidableLabel, self).paintEvent(event)
+
+        s = fm.elidedText(self.text(), Qt.ElideRight,
+                          self.contentsRect().width(), Qt.TextShowMnemonic)
+        p = QPainter(self)
+        try:
+            p.drawText(0, fm.ascent(), s)
+        finally:
+            p.end()
+
 class InfoBar(QFrame):
     """Non-modal confirmation/alert (like web flash or Chrome's InfoBar)
 
@@ -794,8 +813,8 @@ class StatusInfoBar(InfoBar):
     """Show status message"""
     def __init__(self, message, parent=None):
         super(StatusInfoBar, self).__init__(parent)
-        self._msglabel = QLabel(message, self,
-                                textInteractionFlags=Qt.TextSelectableByMouse)
+        self._msglabel = ElidableLabel(message, self)
+        self._msglabel.setTextInteractionFlags(Qt.TextSelectableByMouse)
         self.addWidget(self._msglabel)
 
 class CommandErrorInfoBar(InfoBar):
@@ -805,8 +824,8 @@ class CommandErrorInfoBar(InfoBar):
     def __init__(self, message, parent=None):
         super(CommandErrorInfoBar, self).__init__(parent)
 
-        self._msglabel = QLabel(message, self,
-                                textInteractionFlags=Qt.TextSelectableByMouse)
+        self._msglabel = ElidableLabel(message, self)
+        self._msglabel.setTextInteractionFlags(Qt.TextSelectableByMouse)
         self.addWidget(self._msglabel)
 
         self._loglabel = QLabel('<a href="log:">%s</a>' % _('Show Log'))
@@ -822,8 +841,8 @@ class ConfirmInfoBar(InfoBar):
     def __init__(self, message, parent=None):
         super(ConfirmInfoBar, self).__init__(parent)
 
-        self._msglabel = QLabel(message, self,
-                                textInteractionFlags=Qt.TextSelectableByMouse)
+        self._msglabel = ElidableLabel(message, self)
+        self._msglabel.setTextInteractionFlags(Qt.TextSelectableByMouse)
         self.addWidget(self._msglabel)
 
         self._buttons = QDialogButtonBox(self)