diff view/Pane.cpp @ 294:919740b20cc9

* Better abbreviation modes for layer names in pane (and input model combo of plugin parameter dialog) * Avoid crash when loading SV file containing model derived from nonexistent model (shouldn't happen of course, but see bug #1771769) * Remember last-used input model in plugin parameter dialog * Don't override a layer colour loaded from a session file with the generated default colour when attaching it to a view
author Chris Cannam
date Fri, 10 Aug 2007 16:36:50 +0000
parents 3101c68a00c1
children 5c59c433b358
line wrap: on
line diff
--- a/view/Pane.cpp	Thu Aug 09 14:40:03 2007 +0000
+++ b/view/Pane.cpp	Fri Aug 10 16:36:50 2007 +0000
@@ -21,6 +21,7 @@
 #include "base/Profiler.h"
 #include "ViewManager.h"
 #include "base/CommandHistory.h"
+#include "base/TextAbbrev.h"
 #include "layer/WaveformLayer.h"
 
 #include <QPaintEvent>
@@ -714,31 +715,14 @@
         return;
     }
 
-    std::vector<QString> texts;
-    int maxTextWidth = 0;
+    QStringList texts;
+    for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
+        texts.push_back((*i)->getLayerPresentationName());
+    }
 
-    for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
-        
-        QString text = (*i)->getLayerPresentationName();
-        int tw = paint.fontMetrics().width(text);
-        bool reduced = false;
-        while (tw > width() / 3 && text.length() > 4) {
-            if (!reduced && text.length() > 8) {
-                text = text.left(text.length() - 4);
-            } else {
-                text = text.left(text.length() - 2);
-            }
-            reduced = true;
-            tw = paint.fontMetrics().width(text + "...");
-        }
-        if (reduced) {
-            texts.push_back(text + "...");
-        } else {
-            texts.push_back(text);
-        }
-        if (tw > maxTextWidth) maxTextWidth = tw;
-    }
-    
+    int maxTextWidth = width() / 3;
+    texts = TextAbbrev::abbreviate(texts, paint.fontMetrics(), maxTextWidth);
+
     int lly = height() - 6;
     int llx = width() - maxTextWidth - 5;