Skip to content

Commit d946745

Browse files
committed
Corrections and optimizations for word wrap.
Signed-off-by: joachim99 <joachim.eibl@gmx.de>
1 parent 4d116d1 commit d946745

File tree

6 files changed

+79
-25
lines changed

6 files changed

+79
-25
lines changed

kdiff3/src-QT4/common.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ QFont ValueMap::readFontEntry(const QString& k, const QFont* defaultVal )
242242
f.setFamily( subSection( i->second, 0, ',' ) );
243243
f.setPointSize( subSection( i->second, 1, ',' ).toInt() );
244244
f.setBold( subSection( i->second, 2, ',' )=="bold" );
245-
//f.fromString(i->second);
246245
}
247-
246+
f.setKerning(false);
248247
return f;
249248
}
250249

kdiff3/src-QT4/difftextwindow.cpp

+43-12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ class DiffTextWindowData
9595
Diff3WrapLineVector m_diff3WrapLineVector;
9696
const ManualDiffHelpList* m_pManualDiffHelpList;
9797

98+
class WrapLineCacheData
99+
{
100+
public:
101+
WrapLineCacheData() : m_d3LineIdx(0), m_textStart(0), m_textLength(0) {}
102+
WrapLineCacheData( int d3LineIdx, int textStart, int textLength )
103+
: m_d3LineIdx(d3LineIdx), m_textStart(textStart), m_textLength(textLength) {}
104+
int m_d3LineIdx; int m_textStart; int m_textLength;
105+
};
106+
QVector<WrapLineCacheData> m_wrapLineCache;
107+
98108
Options* m_pOptions;
99109
QColor m_cThis;
100110
QColor m_cDiff1;
@@ -835,8 +845,8 @@ void DiffTextWindowData::prepareTextLayout( QTextLayout& textLayout, bool bFirst
835845
break;
836846

837847
height += leading;
838-
if ( !bFirstLine )
839-
indentation = m_pDiffTextWindow->fontMetrics().width(' ') * m_pOptions->m_tabSize;
848+
//if ( !bFirstLine )
849+
// indentation = m_pDiffTextWindow->fontMetrics().width(' ') * m_pOptions->m_tabSize;
840850
if ( visibleTextWidth>=0 )
841851
{
842852
line.setLineWidth( visibleTextWidth -indentation );
@@ -997,7 +1007,7 @@ void DiffTextWindowData::writeLine(
9971007
++outPos;
9981008
} // end for
9991009

1000-
QTextLayout textLayout( lineString.mid( wrapLineOffset, lineLength), m_pDiffTextWindow->font(), m_pDiffTextWindow );
1010+
QTextLayout textLayout( lineString.mid( wrapLineOffset, lineLength-wrapLineOffset), m_pDiffTextWindow->font(), m_pDiffTextWindow );
10011011
prepareTextLayout( textLayout, !m_bWordWrap || wrapLineOffset==0 );
10021012
textLayout.draw ( &p, QPoint(0, yOffset), frh.m_formatRanges /*, const QRectF & clip = QRectF() */);
10031013
}
@@ -1527,6 +1537,9 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
15271537

15281538
d->m_bWordWrap = bWordWrap;
15291539

1540+
if ( !bWordWrap || wrapLineVectorSize==0 )
1541+
d->m_wrapLineCache.clear();
1542+
15301543
if ( bWordWrap )
15311544
{
15321545
ProgressProxy pp;
@@ -1540,27 +1553,45 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
15401553
visibleTextWidth-= d->leftInfoWidth() * fontMetrics().width('0');
15411554
int i;
15421555
int wrapLineIdx = 0;
1556+
int wrapLineCacheIdx = 0;
15431557
int size = d->m_pDiff3LineVector->size();
15441558
pp.setMaxNofSteps(size);
15451559
for( i=0; i<size; ++i )
15461560
{
15471561
pp.setInformation( i18n("Word wrap"), double(i)/size, false );
15481562
if ( pp.wasCancelled() )
1549-
break;
1563+
return;
15501564

1551-
QString s = d->getString( i );
1552-
QTextLayout textLayout( s, font(), this);
1553-
d->prepareTextLayout( textLayout, true, visibleTextWidth );
1554-
int linesNeeded = textLayout.lineCount();
1555-
if ( wrapLineVectorSize > 0 )
1565+
int linesNeeded = 0;
1566+
if ( wrapLineVectorSize==0 )
15561567
{
1568+
QString s = d->getString( i );
1569+
QTextLayout textLayout( s, font(), this);
1570+
d->prepareTextLayout( textLayout, true, visibleTextWidth );
1571+
linesNeeded = textLayout.lineCount();
15571572
for( int l=0; l<linesNeeded; ++l )
15581573
{
1559-
Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
1574+
//Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
15601575
QTextLine line = textLayout.lineAt(l);
1561-
pDiff3WrapLine->wrapLineOffset = line.textStart();
1562-
pDiff3WrapLine->wrapLineLength = line.textLength();
1576+
d->m_wrapLineCache.push_back( DiffTextWindowData::WrapLineCacheData(i,line.textStart(),line.textLength()) );
1577+
}
1578+
}
1579+
else if ( wrapLineVectorSize > 0 )
1580+
{
1581+
while( wrapLineCacheIdx<d->m_wrapLineCache.count() &&
1582+
d->m_wrapLineCache[wrapLineCacheIdx].m_d3LineIdx<i )
1583+
++wrapLineCacheIdx;
1584+
int l=0;
1585+
while( wrapLineCacheIdx<d->m_wrapLineCache.count() &&
1586+
d->m_wrapLineCache[wrapLineCacheIdx].m_d3LineIdx==i )
1587+
{
1588+
Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
1589+
pDiff3WrapLine->wrapLineOffset = d->m_wrapLineCache[wrapLineCacheIdx].m_textStart;
1590+
pDiff3WrapLine->wrapLineLength = d->m_wrapLineCache[wrapLineCacheIdx].m_textLength;
1591+
++l;
1592+
++wrapLineCacheIdx;
15631593
}
1594+
linesNeeded = l;
15641595
}
15651596

15661597
Diff3Line& d3l = *(*d->m_pDiff3LineVector)[i];

kdiff3/src-QT4/kdiff3.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class KDiff3App : public QSplitter
325325
KParts::MainWindow* m_pKDiff3Shell;
326326
bool m_bAutoFlag;
327327
bool m_bAutoMode;
328-
void recalcWordWrap(int nofVisibleColumns=-1);
328+
bool recalcWordWrap(int nofVisibleColumns=-1);
329329
bool m_bRecalcWordWrapPosted;
330330
void setHScrollBarRange();
331331

kdiff3/src-QT4/kreplacements/ShellContextMenu.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "stable.h"
2323
#include <windows.h>
2424
#include <shlobj.h>
25+
#include <shlguid.h>
2526
#include <malloc.h>
2627
//#include <QString>
2728
//#include <QStringList>

kdiff3/src-QT4/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* (at your option) any later version. *
1515
* *
1616
***************************************************************************/
17-
17+
#include "stable.h"
1818
#include <kcmdlineargs.h>
1919
#include <kaboutdata.h>
2020
#include <klocale.h>
@@ -28,6 +28,7 @@
2828
#include <QLocale>
2929
#include <QFont>
3030
#include <QClipboard>
31+
#include <QMainWindow>
3132
#include <vector>
3233

3334
#ifdef KREPLACEMENTS_H

kdiff3/src-QT4/pdiff.cpp

+31-9
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,12 @@ void KDiff3App::slotAutoAdvanceToggled()
15371537
void KDiff3App::slotWordWrapToggled()
15381538
{
15391539
m_pOptions->m_bWordWrap = wordWrap->isChecked();
1540-
recalcWordWrap();
1540+
bool bSuccess = recalcWordWrap();
1541+
if ( ! bSuccess )
1542+
{
1543+
wordWrap->setChecked(false);
1544+
slotWordWrapToggled();
1545+
}
15411546
}
15421547

15431548
void KDiff3App::postRecalcWordWrap()
@@ -1551,11 +1556,17 @@ void KDiff3App::postRecalcWordWrap()
15511556

15521557
void KDiff3App::slotRecalcWordWrap()
15531558
{
1554-
recalcWordWrap();
1559+
bool bSuccess = recalcWordWrap();
15551560
m_bRecalcWordWrapPosted = false;
1561+
1562+
if ( ! bSuccess )
1563+
{
1564+
wordWrap->setChecked(false);
1565+
slotWordWrapToggled();
1566+
}
15561567
}
15571568

1558-
void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=0 only for printing, otherwise the really visible width is used
1569+
bool KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=0 only for printing, otherwise the really visible width is used
15591570
{
15601571
bool bPrinting = nofVisibleColumns>=0;
15611572
int firstD3LIdx = 0;
@@ -1584,22 +1595,28 @@ void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
15841595
}
15851596

15861597
ProgressProxy pp;
1587-
pp.setMaxNofSteps( (m_bTripleDiff ? 6 : 4 ) );
1588-
pp.setInformation("Word wrap",false);
1598+
pp.setMaxNofSteps( (m_bTripleDiff ? 4 : 3 ) );
1599+
pp.setInformation(i18n("Word wrap (Cancel disables word wrap)"),false);
15891600
// Let every window calc how many lines will be needed.
15901601
if ( m_pDiffTextWindow1 )
15911602
{
15921603
m_pDiffTextWindow1->recalcWordWrap(true,0,nofVisibleColumns);
1604+
if ( pp.wasCancelled() )
1605+
return false;
15931606
pp.step();
15941607
}
15951608
if ( m_pDiffTextWindow2 )
15961609
{
15971610
m_pDiffTextWindow2->recalcWordWrap(true,0,nofVisibleColumns);
1611+
if ( pp.wasCancelled() )
1612+
return false;
15981613
pp.step();
15991614
}
16001615
if ( m_pDiffTextWindow3 )
16011616
{
16021617
m_pDiffTextWindow3->recalcWordWrap(true,0,nofVisibleColumns);
1618+
if ( pp.wasCancelled() )
1619+
return false;
16031620
pp.step();
16041621
}
16051622

@@ -1615,18 +1632,22 @@ void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
16151632
if ( m_pDiffTextWindow1 )
16161633
{
16171634
m_pDiffTextWindow1->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
1618-
pp.step();
1635+
if ( pp.wasCancelled() )
1636+
return false;
16191637
}
16201638
if ( m_pDiffTextWindow2 )
16211639
{
16221640
m_pDiffTextWindow2->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
1623-
pp.step();
1641+
if ( pp.wasCancelled() )
1642+
return false;
16241643
}
16251644
if ( m_pDiffTextWindow3 )
16261645
{
16271646
m_pDiffTextWindow3->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
1628-
pp.step();
1647+
if ( pp.wasCancelled() )
1648+
return false;
16291649
}
1650+
pp.step();
16301651

16311652
m_neededLines = sumOfLines;
16321653
}
@@ -1641,7 +1662,7 @@ void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
16411662
m_pDiffTextWindow3->recalcWordWrap(false,0,0);
16421663
}
16431664
if (bPrinting)
1644-
return;
1665+
return true;
16451666

16461667
if (m_pOverview)
16471668
m_pOverview->slotRedraw();
@@ -1670,6 +1691,7 @@ void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
16701691
setHScrollBarRange();
16711692
m_pHScrollBar->setValue(0);
16721693
}
1694+
return true;
16731695
}
16741696

16751697
void KDiff3App::slotShowWhiteSpaceToggled()

0 commit comments

Comments
 (0)