From b5b5075588b35341f7169a6956dc8f7db624fcc5 Mon Sep 17 00:00:00 2001
From: smbaker <smbaker@fc8clean.lan>
Date: Wed, 31 Aug 2011 09:12:10 -0700
Subject: [PATCH] clip hostname/tag field at 48 characters

---
 sface/screens/mainscreen.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py
index b20ae51..e6e4fb4 100644
--- a/sface/screens/mainscreen.py
+++ b/sface/screens/mainscreen.py
@@ -31,6 +31,9 @@ NODE_STATUS_COLUMN = 1
 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"
@@ -144,15 +147,21 @@ class NodeNameDelegate(QStyledItemDelegate):
     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()
+        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)
 
-        data = index.data().toString()
         rect.setHeight(rect.height() - 2)
         rect.setWidth(fm.width(QString(data)) + 6)
         rect.setX(rect.x() + 5)
-- 
2.47.0