grepview enhanced patch

stephane ancelot sancelot at free.fr
Thu Mar 6 15:26:02 UTC 2003


Hi,

enclosed you will find a patch that enhances grepview display, it is
unuseful to display filename on each line.

Bye
steph

-------------- next part --------------
? toto
Index: ChangeLog
===================================================================
RCS file: /home/kde/kdevelop/ChangeLog,v
retrieving revision 1.966
diff -u -r1.966 ChangeLog
--- ChangeLog	5 Mar 2003 21:51:06 -0000	1.966
+++ ChangeLog	6 Mar 2003 14:22:54 -0000
@@ -1,3 +1,7 @@
+2003-03-06 Stephane ANCELOT <sancelot at free.fr>
+    * enhanced grepview , there is no need to display the filename in each lines, 
+     that takes the full width of the window when the pathfile is long.
+     filename is displayed only once 
 2003-03-05 Alexander Dymo <cloudtemple at mksat.net>
     * Documentation browser is now able to handle all Qt documentation including
       custom *.xml documentation. Configuration options are also available.
Index: parts/grepview/grepviewwidget.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/grepview/grepviewwidget.cpp,v
retrieving revision 1.13
diff -u -r1.13 grepviewwidget.cpp
--- parts/grepview/grepviewwidget.cpp	28 Feb 2003 23:48:10 -0000	1.13
+++ parts/grepview/grepviewwidget.cpp	6 Mar 2003 14:22:57 -0000
@@ -30,7 +30,7 @@
 class GrepListBoxItem : public ProcessListBoxItem
 {
 public:
-    GrepListBoxItem(const QString &s1, const QString &s2, const QString &s3);
+    GrepListBoxItem(const QString &s1, const QString &s2, const QString &s3,char show_filename_);
     QString filename()
         { return str1; }
     int linenumber()
@@ -40,17 +40,20 @@
 private:
     virtual void paint(QPainter *p);
     QString str1, str2, str3;
+    char show_filename;
 };
 
 
 GrepListBoxItem::GrepListBoxItem(const QString &s1,
                                  const QString &s2,
-                                 const QString &s3)
+                                 const QString &s3,
+                                 char _show_filename)
     : ProcessListBoxItem(s1+s2+s3, Normal)
 {
-    str1 = s1;
-    str2 = s2;
+    str1 = s1; // filename 
+    str2 = s2; 
     str3 = s3;
+    show_filename = _show_filename;
 }
 
 
@@ -63,24 +66,28 @@
 void GrepListBoxItem::paint(QPainter *p)
 {
     QFontMetrics fm = p->fontMetrics();
+    QString stx = str2.right(str2.length()-1);
     int y = fm.ascent()+fm.leading()/2;
     int x = 3; 
-
-    p->setPen(Qt::darkGreen);
-    p->drawText(x, y, str1);
-    x += fm.width(str1);
-    
+	if (show_filename)
+	{
+		p->setPen(Qt::darkGreen);
+		p->drawText(x, y, str1);
+		x += fm.width(str1);
+    }
+    else {
     p->setPen(Qt::black);
     QFont font1(p->font());
     QFont font2(font1); 
     font2.setBold(true);
     p->setFont(font2);
-    p->drawText(x, y, str2);
+    p->drawText(x, y, stx);
     p->setFont(font1);
-    x += fm.width(str2);
+    x += fm.width(stx);
     
     p->setPen(Qt::blue);
     p->drawText(x, y, str3);
+	}
 }
 
 
@@ -210,7 +217,7 @@
 {
     int pos;
     QString filename, linenumber, rest;
-
+    
     QString str = line;
     if ( (pos = str.find(':')) != -1)
         {
@@ -220,7 +227,17 @@
                 {
                     linenumber = str.left(pos);
                     str.remove(0, pos);
-                    insertItem(new GrepListBoxItem(filename, linenumber, str));
+                    // filename will be displayed only once
+                    // selecting filename will display line 1 of file, 
+                    // otherwise, line of requested search
+                    if (findItem(filename,BeginsWith|ExactMatch) == 0)
+							{
+							 insertItem(new GrepListBoxItem(filename, "1", str,1));
+							 insertItem(new GrepListBoxItem(filename, linenumber, str,0));
+
+							}
+						else insertItem(new GrepListBoxItem(filename, linenumber, str,0)); 
+
                 }
         }
 }


More information about the KDevelop-devel mailing list