[Kst] extragear/graphics/kst/kst

Andrew Walker arwalker at sumusltd.com
Wed Aug 17 21:52:26 CEST 2005


SVN commit 450272 by arwalker:

Build for 3.1 Qt/KDE. Removed dependence on KStringHandler

 M  +35 -9     statuslabel.cpp  
 M  +2 -0      statuslabel.h  


--- trunk/extragear/graphics/kst/kst/statuslabel.cpp #450271:450272
@@ -20,7 +20,6 @@
 
 //include files for KDE
 #include <klocale.h>
-#include <kstringhandler.h>
 
 // application specific includes
 #include "statuslabel.h"
@@ -43,6 +42,37 @@
   setText(_fullText);
 }
 
+QString StatusLabel::squeeze(const QString& s, const QFontMetrics& fm, uint width) {
+  uint currentWidth = fm.width(s);
+  
+  if (s.isEmpty() || currentWidth <= width) {
+     return s;
+  }
+
+  QString str(s);
+  uint ellipsisWidth = fm.width("...");
+  
+  if (currentWidth > ellipsisWidth) {
+    const uint maxWidth = width - ellipsisWidth;
+    const uint emWidth  = fm.maxWidth( );
+    int truncate;
+  
+    while (currentWidth > maxWidth && !str.isEmpty()) {
+      truncate = (currentWidth-maxWidth)/emWidth;
+      if (truncate == 0) {
+        truncate = 1;
+      }
+      str.truncate(str.length()-truncate);  
+      currentWidth = fm.width(str); 
+    }
+    str += "...";
+  } else {
+    str = "...";
+  }
+    
+  return str;
+}
+
 void StatusLabel::setTextWidth(const QFontMetrics &metrics, int width) {
   QString str;
   
@@ -53,17 +83,13 @@
   }
   
   setMaximumWidth(width);
+
+  str = squeeze(_fullText, metrics, width);
   
-  str = KStringHandler::rPixelSqueeze(_fullText, metrics, width);
-  if (str.length() > _fullText.length()) {
-    //
-    // required because of a bug in KStringHandler that returns _fullText appended by ...
-    // 
+  if (str != _fullText) {
     QToolTip::add(this, _fullText);  
-    str = i18n("ellipsis","...");
-  } else if (str != _fullText) {
-    QToolTip::add(this, _fullText);  
   }
+
   setText(str);
 }
 
--- trunk/extragear/graphics/kst/kst/statuslabel.h #450271:450272
@@ -33,6 +33,8 @@
     const QString& fullText() const;
 
   private:
+    QString squeeze(const QString& s, const QFontMetrics& fm, uint width);
+  
     QString _fullText;
     int     _width;
 };


More information about the Kst mailing list