Commit bc8ed23e authored by Christian Loose's avatar Christian Loose
Browse files

Fix the too small scroll area of diff view when

tabs in source code.

svn path=/trunk/kdesdk/cervisia/; revision=193588
parent d32fc1d8
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-08 Christian Loose <christian.loose@hamburg.de>
* Make ChangeLog dialog more KDE standard conformant
......
......@@ -17,6 +17,7 @@
#include <qpainter.h>
#include <qscrollbar.h>
#include <qpixmap.h>
#include <qregexp.h>
#include <qstyle.h>
#include <kapplication.h>
......@@ -69,6 +70,9 @@ DiffView::DiffView( bool withlinenos, bool withmarker,
setCellWidth(0);
textwidth = 0;
config->setGroup("General");
m_tabWidth = config->readUnsignedNumEntry("TabWidth", 8);
items.setAutoDelete(true);
linenos = withlinenos;
marker = withmarker;
......@@ -156,8 +160,22 @@ void DiffView::addLine(const QString &line, DiffType type, int no)
{
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;
item->line = line;
......@@ -281,11 +299,8 @@ 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);
......
......@@ -85,6 +85,8 @@ private:
QColor diffChangeColor;
QColor diffInsertColor;
QColor diffDeleteColor;
unsigned int m_tabWidth;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment