clip hostname/tag field at 48 characters
authorsmbaker <smbaker@fc8clean.lan>
Wed, 31 Aug 2011 16:12:10 +0000 (09:12 -0700)
committersmbaker <smbaker@fc8clean.lan>
Wed, 31 Aug 2011 16:12:10 +0000 (09:12 -0700)
sface/screens/mainscreen.py

index b20ae51..e6e4fb4 100644 (file)
@@ -31,6 +31,9 @@ NODE_STATUS_COLUMN = 1
 MEMBERSHIP_STATUS_COLUMN = 2
 KIND_COLUMN = 3
 
 MEMBERSHIP_STATUS_COLUMN = 2
 KIND_COLUMN = 3
 
+# maximum length of a name to display before clipping
+NAME_MAX_LEN = 48
+
 def itemType(index):
     if index.parent().parent().isValid():
         return "tag"
 def itemType(index):
     if index.parent().parent().isValid():
         return "tag"
@@ -144,15 +147,21 @@ class NodeNameDelegate(QStyledItemDelegate):
     def __init__(self, parent):
         QStyledItemDelegate.__init__(self, parent)
 
     def __init__(self, parent):
         QStyledItemDelegate.__init__(self, parent)
 
+    def displayText(self, value, locale):
+        data = str(QStyledItemDelegate.displayText(self, value, locale))
+        if (len(data)>NAME_MAX_LEN):
+            data = data[:(NAME_MAX_LEN-3)] + "..."
+        return QString(data)
+
     def paint(self, painter, option, index):
         model = index.model()
     def paint(self, painter, option, index):
         model = index.model()
+        data = str(self.displayText(index.data(), QLocale()))
         status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
         status_data = status_index.data().toString()
 
         fm = QFontMetrics(option.font)
         rect = QRect(option.rect)
 
         status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
         status_data = status_index.data().toString()
 
         fm = QFontMetrics(option.font)
         rect = QRect(option.rect)
 
-        data = index.data().toString()
         rect.setHeight(rect.height() - 2)
         rect.setWidth(fm.width(QString(data)) + 6)
         rect.setX(rect.x() + 5)
         rect.setHeight(rect.height() - 2)
         rect.setWidth(fm.width(QString(data)) + 6)
         rect.setX(rect.x() + 5)