Bug 41268 - scrolling behavior in diff view
Summary: scrolling behavior in diff view
Status: RESOLVED FIXED
Alias: None
Product: cervisia
Classification: Applications
Component: general (show other bugs)
Version: 1.5rich1
Platform: Mandrake RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Stephan Binner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-19 00:03 UTC by Richard Tango-Lowy
Modified: 2002-12-12 22:30 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Current proposed patch (11/29/02) (2.04 KB, patch)
2002-11-29 22:16 UTC, Christian Loose
Details
Current proposed patch (12/01/02) (2.24 KB, patch)
2002-12-08 12:58 UTC, Christian Loose
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Tango-Lowy 2002-04-18 23:54:36 UTC
(*** This bug was imported into bugs.kde.org ***)

Package:           cervisia
Version:           1.5rich1 (using KDE 3.0.0 )
Severity:          normal
Installed from:    Mandrake Linux 8.2 i586 - Cooker
Compiler:          gcc version 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)
OS:                Linux (i686) release 2.4.18-6mdk
OS/Compiler notes: 

When I view diffs in the diffs dialog tabs are expanded to 25 spaces or so. Deeply nested code scrolls off right side of the viewable diff display and can't be seen.

Ex:

<?PHP
class foo extends bar {
                          function next_line_begins_way_out_here() {
                                                                      this_line_is_waaaay_out_to_the_right;
                          }
}

I only have one actual tab in my source.

(Submitted via bugs.kde.org)
(Called from KBugReport dialog)
Comment 1 Richard Tango-Lowy 2002-04-19 17:55:12 UTC
--=-zQDlIxUgzqO7ETfJiQrl
Content-Type: multipart/alternative; boundary="=-omyd6FoqDlshJzF/asAv"

--=-omyd6FoqDlshJzF/asAv
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Dumb user error.

Today I noticed I can (1) change the tabwidth from 8 to 4 (2) switch to
a smaller (and fixed) font. I was using a proportional font before and
it seemed to screw up the tabs.

You do have a hard limit on how far to the right the user can
horizontally scroll in the diff windows though. It would be best if I
could scroll as far to the right as I have code to scroll to.

Rich Tango-Lowy
--=20
ars Cognita   The Art of Knowledge
              ---------------------
              Richard Tango-Lowy
      richtl@arscognita.com
      603 424-6555

--=-omyd6FoqDlshJzF/asAv
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
  <META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/1.0.1">
</HEAD>
<BODY>
Dumb user error.
<BR>

<BR>
Today I noticed I can (1) change the tabwidth from 8 to 4 (2) switch to a =
smaller (and fixed) font. I was using a proportional font before and it se=
emed to screw up the tabs.
<BR>

<BR>
You do have a hard limit on how far to the right the user can horizontally =
scroll in the diff windows though. It would be best if I could scroll as f=
ar to the right as I have code to scroll to.
<BR>

<BR>
Rich Tango-Lowy
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
<PRE>--=20
ars Cognita   The Art of Knowledge
              ---------------------
              Richard Tango-Lowy
      richtl@arscognita.com
      603 424-6555</PRE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

--=-omyd6FoqDlshJzF/asAv--

--=-zQDlIxUgzqO7ETfJiQrl
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA8wFoAD6UgN81JgeMRAibFAKCS75Cn35pHnSKh4vuxN6xx0/cClgCgwNUH
o/Fvo2m5+7KtOqduB1KaeRs=
=IWae
-----END PGP SIGNATURE-----

--=-zQDlIxUgzqO7ETfJiQrl--
Comment 2 Stephan Binner 2002-11-17 11:04:59 UTC
Subject: kdesdk/cervisia

CVS commit by binner: 

Changed handling of tabulators in to be diffed lines.
CCMAIL: 41268-done@bugs.kde.org


  M +11 -9     diffview.cpp   1.14

Comment 3 Stephan Binner 2002-11-25 17:39:55 UTC
Reopening because assumed fix was reverted. 
Comment 4 Christian Loose 2002-11-29 22:16:52 UTC
Created attachment 550 [details]
Current proposed patch (11/29/02)
Comment 5 Christian Loose 2002-12-08 12:58:38 UTC
Created attachment 585 [details]
Current proposed patch (12/01/02)
Comment 6 Christian Loose 2002-12-12 22:30:03 UTC
Subject: KDE_3_1_BRANCH: kdesdk/cervisia

CVS commit by cloose: 

backport from HEAD:
Fix the too small scroll area of diff view when
tabs in source code.

CCMAIL: 41268-done@bugs.kde.org


  M +5 -0      ChangeLog   1.22.2.3
  M +21 -6     diffview.cpp   1.15.2.1
  M +2 -0      diffview.h   1.4.2.1


--- kdesdk/cervisia/ChangeLog  #1.22.2.2:1.22.2.3
@@ -1,2 +1,7 @@
+2002-12-12  Christian Loose <christian.loose@hamburg.de>
+
+        * Fix the too small scroll area of diff view when
+          tabs in source code
+
 2002-12-05  Christian Loose <christian.loose@hamburg.de>
 

--- kdesdk/cervisia/diffview.cpp  #1.15:1.15.2.1
@@ -18,4 +18,5 @@
 #include <qscrollbar.h>
 #include <qpixmap.h>
+#include <qregexp.h>
 #include <qstyle.h>
 
@@ -70,4 +71,7 @@ DiffView::DiffView( bool withlinenos, bo
     textwidth = 0;
 
+    config->setGroup("General");
+    m_tabWidth = config->readUnsignedNumEntry("TabWidth", 8);
+
     items.setAutoDelete(true);
     linenos = withlinenos;
@@ -157,6 +161,20 @@ void DiffView::addLine(const QString &li
     QFont f(font());
     f.setBold(true);
-    QFontMetrics fm(f);
-    textwidth = QMAX(textwidth, fm.width(line));
+    QFontMetrics fmbold(f);
+    QFontMetrics fm(font());
+
+
+    // calculate textwidth based on 'line' where tabs are expanded
+    //
+    // *Please note*
+    // For some fonts, e.g. "Clean", is fm.maxWidth() greater than
+    // fmbold.maxWidth().
+    QString copy(line);
+    int numTabs = copy.contains('\t', false);
+    copy.replace( QRegExp("\t"), "");
+
+    uint tabSize   = m_tabWidth * QMAX(fm.maxWidth(), fmbold.maxWidth());
+    uint copyWidth = QMAX(fm.width(copy), fmbold.width(copy));
+    textwidth = QMAX(textwidth, copyWidth + numTabs * tabSize);
 
     DiffViewItem *item = new DiffViewItem;
@@ -282,9 +300,6 @@ QSize DiffView::sizeHint() const
 void DiffView::paintCell(QPainter *p, int row, int col)
 {
-    KConfig *config = CervisiaPart::config();
-    config->setGroup("General");
-    uint tabWidth = config->readUnsignedNumEntry("TabWidth", 8);
     QFontMetrics fm(font());
-    p->setTabStops(tabWidth * fm.maxWidth());
+    p->setTabStops(m_tabWidth * fm.maxWidth());
 
     DiffViewItem *item = items.at(row);

--- kdesdk/cervisia/diffview.h  #1.4:1.4.2.1
@@ -86,4 +86,6 @@ private:
     QColor diffInsertColor;
     QColor diffDeleteColor;
+
+    unsigned int    m_tabWidth;
 };