Commit 88ed3eb5 authored by Joachim Eibl's avatar Joachim Eibl Committed by Michael Reeves

- Word wrap multithreaded. - Preserve carriage return reintroduced.

Signed-off-by: default avatarjoachim99 <joachim.eibl@gmx.de>
parent d8d48199
......@@ -121,7 +121,7 @@ static bool isLineOrBufEnd( const QChar* p, int i, int size )
{
return
i>=size // End of file
|| p[i]=='\n' // Normal end of line
|| isEndOfLine(p[i]) // Normal end of line
// No support for Mac-end of line yet, because incompatible with GNU-diff-routines.
// || ( p[i]=='\r' && (i>=size-1 || p[i+1]!='\n')
......@@ -836,34 +836,44 @@ void SourceData::FileData::preprocess( bool bPreserveCR, QTextCodec* pEncoding )
qint64 i;
// detect line end style
QVector<e_LineEndStyle> vOrigDataLineEndStyle;
m_eLineEndStyle = eLineEndStyleUndefined;
for( i=0; i<m_size; ++i )
{
if ( m_pBuf[i]=='\n' )
if ( m_pBuf[i]=='\r' )
{
if ( (i>0 && m_pBuf[i-1]=='\r') || // normal file
(i>3 && m_pBuf[i-1]=='\0' && m_pBuf[i-2]=='\r' && m_pBuf[i-3]=='\0')) // 16-bit unicode: TODO only little endian covered here
m_eLineEndStyle = eLineEndStyleDos;
else
m_eLineEndStyle = eLineEndStyleUnix;
break; // Only analyze first line
if ( i+1<m_size && m_pBuf[i+1]=='\n' ) // not 16-bit unicode
{
vOrigDataLineEndStyle.push_back( eLineEndStyleDos );
++i;
}
else if( i>0 && i+2<m_size && m_pBuf[i-1]=='\0' && m_pBuf[i+1]=='\0' && m_pBuf[i+2]=='\n' ) // 16-bit unicode
{
vOrigDataLineEndStyle.push_back( eLineEndStyleDos );
i+=2;
}
else // old mac line end style ?
{
vOrigDataLineEndStyle.push_back( eLineEndStyleUndefined );
const_cast<char*>(m_pBuf)[i]='\n'; // fix it in original data
}
}
else if ( m_pBuf[i]=='\n' )
{
vOrigDataLineEndStyle.push_back( eLineEndStyleUnix );
}
}
if ( ! vOrigDataLineEndStyle.isEmpty() )
m_eLineEndStyle = vOrigDataLineEndStyle[0];
qint64 skipBytes = 0;
QTextCodec* pCodec = ::detectEncoding( m_pBuf, m_size, skipBytes );
if ( pCodec != pEncoding )
skipBytes=0;
QByteArray ba = QByteArray::fromRawData( m_pBuf+skipBytes, m_size-skipBytes );
if ( m_eLineEndStyle == eLineEndStyleUndefined ) // normally only for one liners except when old mac line end style is used
{
for( int j=0; j<ba.size(); ++j ) // int because QByteArray does not support operator[](qint64)
{
if ( ba[j]=='\r' )
ba[j]='\n'; // We only fix the old mac line end style, but leave it as "undefined"
}
}
QTextStream ts( ba, QIODevice::ReadOnly );
QTextStream ts( ba, QIODevice::ReadOnly | QIODevice::Text );
ts.setCodec( pEncoding);
ts.setAutoDetectUnicode( false );
m_unicodeBuf = ts.readAll();
......@@ -877,7 +887,7 @@ void SourceData::FileData::preprocess( bool bPreserveCR, QTextCodec* pEncoding )
m_bIncompleteConversion = false;
for( i=0; i<ucSize; ++i )
{
if ( isLineOrBufEnd(p,i,ucSize) )
if ( i>=ucSize || p[i]=='\n' )
{
++lines;
}
......@@ -898,15 +908,25 @@ void SourceData::FileData::preprocess( bool bPreserveCR, QTextCodec* pEncoding )
int whiteLength = 0;
for( i=0; i<=ucSize; ++i )
{
if ( isLineOrBufEnd( p, i, ucSize ) )
if ( i>=ucSize || p[i]=='\n' )
{
m_v[lineIdx].pLine = &p[ i-lineLength ];
while ( !bPreserveCR && lineLength>0 && m_v[lineIdx].pLine[lineLength-1]=='\r' )
while ( /*!bPreserveCR &&*/ lineLength>0 && m_v[lineIdx].pLine[lineLength-1]=='\r' )
{
--lineLength;
}
m_v[lineIdx].pFirstNonWhiteChar = m_v[lineIdx].pLine + min2(whiteLength,lineLength);
m_v[lineIdx].size = lineLength;
if ( lineIdx < vOrigDataLineEndStyle.count() && bPreserveCR && i<ucSize)
{
++m_v[lineIdx].size;
switch ( vOrigDataLineEndStyle[lineIdx] )
{
case eLineEndStyleUnix: const_cast<QChar*>(m_v[lineIdx].pLine)[lineLength] = '\n'; break;
case eLineEndStyleDos: const_cast<QChar*>(m_v[lineIdx].pLine)[lineLength] = '\r'; break;
case eLineEndStyleUndefined: const_cast<QChar*>(m_v[lineIdx].pLine)[lineLength] = '\x0b'; break;
}
}
lineLength = 0;
bNonWhiteFound = false;
whiteLength = 0;
......@@ -1130,6 +1150,10 @@ void calcDiff3LineListUsingAB(
--d.diff2;
++lineB;
}
else if ( d.nofEquals < 0 )
{
assert(false);
}
d3ll.push_back( d3l );
}
......@@ -2232,6 +2256,7 @@ bool fineDiff(
int k2=0;
bool bTextsTotalEqual = true;
int listSize = diff3LineList.size();
pp.setMaxNofSteps( listSize );
int listIdx = 0;
for( i= diff3LineList.begin(); i!= diff3LineList.end(); ++i)
{
......@@ -2287,7 +2312,7 @@ bool fineDiff(
}
}
++listIdx;
pp.setCurrent(double(listIdx)/listSize);
pp.step();
}
return bTextsTotalEqual;
}
......
......@@ -47,7 +47,8 @@ struct LineData
const QChar* pFirstNonWhiteChar;
int size;
LineData(){ pLine=0; pFirstNonWhiteChar=0; size=0; /*occurances=0;*/ bContainsPureComment=false; }
LineData(){ pLine=0; pFirstNonWhiteChar=0; size=0; /*occurances=0;*/
bContainsPureComment=false; }
int width(int tabSize) const; // Calcs width considering tabs.
//int occurances;
bool whiteLine() const { return pFirstNonWhiteChar-pLine == size; }
......
......@@ -41,6 +41,8 @@
#include <cstdlib>
#include <assert.h>
#include <QFileDialog>
#include <QRunnable>
#include <QThreadPool>
class DiffTextWindowData
......@@ -102,7 +104,7 @@ public:
: m_d3LineIdx(d3LineIdx), m_textStart(textStart), m_textLength(textLength) {}
int m_d3LineIdx; int m_textStart; int m_textLength;
};
QVector<WrapLineCacheData> m_wrapLineCache;
QList< QVector<WrapLineCacheData> > m_wrapLineCacheList;
Options* m_pOptions;
QColor m_cThis;
......@@ -936,6 +938,15 @@ void DiffTextWindowData::writeLine(
// First calculate the "changed" information for each character.
int i=0;
QString lineString( pld->pLine, pld->size );
if ( !lineString.isEmpty() )
{
switch ( lineString[lineString.length()-1].unicode() )
{
case '\n' : lineString[lineString.length()-1] = 0x00B6; break; // "Pilcrow", "paragraph mark"
case '\r' : lineString[lineString.length()-1] = 0x00A4; break; // Currency sign ;0x2761 "curved stem paragraph sign ornament"
case '\0b' : lineString[lineString.length()-1] = 0x2756; break; // some other nice looking character
}
}
QVector<UINT8> charChanged( pld->size );
Merger merger( pLineDiff1, pLineDiff2 );
while( ! merger.isEndReached() && i<pld->size )
......@@ -1525,7 +1536,25 @@ void DiffTextWindow::convertSelectionToD3LCoords()
d->m_selection.end( lastD3LIdx, lastD3LPos );
}
void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth )
class RecalcWordWrapRunnable : public QRunnable
{
DiffTextWindow* m_pDTW;
int m_nofVisibleColumns;
int m_cacheIdx;
ProgressProxy* m_pProgressProxy;
public:
RecalcWordWrapRunnable( DiffTextWindow* p, int nofVisibleColumns, int cacheIdx, ProgressProxy* pPP )
: m_pDTW(p), m_nofVisibleColumns(nofVisibleColumns), m_cacheIdx(cacheIdx), m_pProgressProxy(pPP)
{
setAutoDelete(true);
}
void run()
{
m_pDTW->recalcWordWrapHelper(true,0,m_nofVisibleColumns,m_cacheIdx,m_pProgressProxy);
}
};
void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth, ProgressProxy* pPP )
{
if ( d->m_pDiff3LineVector==0 || ! d->m_bPaintingAllowed || !isVisible() )
{
......@@ -1536,16 +1565,40 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
d->m_bWordWrap = bWordWrap;
if ( !bWordWrap || wrapLineVectorSize==0 )
d->m_wrapLineCache.clear();
if ( bWordWrap )
{
ProgressProxy pp;
//ProgressProxy pp;
d->m_lineNumberWidth = d->m_pOptions->m_bShowLineNumbers ? (int)log10((double)qMax(d->m_size,1))+1 : 0;
d->m_diff3WrapLineVector.resize( wrapLineVectorSize );
}
if ( !bWordWrap || wrapLineVectorSize==0 )
d->m_wrapLineCacheList.clear();
if ( wrapLineVectorSize == 0 )
{
pPP->addNofSteps( d->m_pDiff3LineVector->size()/2000 );
for( int i=0,j=0; i<d->m_pDiff3LineVector->size(); i+=2000, ++j )
//int i=0;
{
d->m_wrapLineCacheList.append(QVector<DiffTextWindowData::WrapLineCacheData>());
QThreadPool::globalInstance()->start( new RecalcWordWrapRunnable(this,visibleTextWidth,j,pPP) );
}
//recalcWordWrap( bWordWrap, wrapLineVectorSize, visibleTextWidth, 0 );
}
else
{
recalcWordWrapHelper( bWordWrap, wrapLineVectorSize, visibleTextWidth, 0, pPP );
}
}
void DiffTextWindow::recalcWordWrapHelper( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth, int cacheListIdx, ProgressProxy* pPP )
{
if ( bWordWrap )
{
if ( pPP->wasCancelled() )
return;
if (visibleTextWidth<0)
visibleTextWidth = getVisibleTextAreaWidth();
else
......@@ -1554,41 +1607,64 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
int wrapLineIdx = 0;
int wrapLineCacheIdx = 0;
int size = d->m_pDiff3LineVector->size();
pp.setMaxNofSteps(size);
for( i=0; i<size; ++i )
//pp.setMaxNofSteps(size);
int firstD3LineIdx = wrapLineVectorSize > 0 ? 0 : cacheListIdx * 2000;
int endIdx = wrapLineVectorSize > 0 ? size : qMin(firstD3LineIdx+2000,size);
QVector<DiffTextWindowData::WrapLineCacheData>& wrapLineCache = d->m_wrapLineCacheList[cacheListIdx];
int cacheListIdx2 = 0;
QTextLayout textLayout( QString(), font(), this);
for( i=firstD3LineIdx; i<endIdx; ++i )
{
pp.setInformation( i18n("Word wrap"), double(i)/size, false );
if ( pp.wasCancelled() )
return;
//pp.setInformation( i18n("Word wrap"), double(i)/size, false );
int linesNeeded = 0;
if ( wrapLineVectorSize==0 )
{
QString s = d->getString( i );
QTextLayout textLayout( s, font(), this);
textLayout.clearLayout();
textLayout.setText( s );
d->prepareTextLayout( textLayout, true, visibleTextWidth );
linesNeeded = textLayout.lineCount();
for( int l=0; l<linesNeeded; ++l )
{
//Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
QTextLine line = textLayout.lineAt(l);
d->m_wrapLineCache.push_back( DiffTextWindowData::WrapLineCacheData(i,line.textStart(),line.textLength()) );
wrapLineCache.push_back( DiffTextWindowData::WrapLineCacheData(i,line.textStart(),line.textLength()) );
}
}
else if ( wrapLineVectorSize > 0 )
{
while( wrapLineCacheIdx<d->m_wrapLineCache.count() &&
d->m_wrapLineCache[wrapLineCacheIdx].m_d3LineIdx<i )
++wrapLineCacheIdx;
DiffTextWindowData::WrapLineCacheData* pWrapLineCache = d->m_wrapLineCacheList[cacheListIdx2].data();
int cacheIdx = 0;
int clc = d->m_wrapLineCacheList.count()-1 ;
int cllc = d->m_wrapLineCacheList.last().count() ;
int curCount = d->m_wrapLineCacheList[0].count()-1;
int l=0;
while( wrapLineCacheIdx<d->m_wrapLineCache.count() &&
d->m_wrapLineCache[wrapLineCacheIdx].m_d3LineIdx==i )
while( (cacheListIdx2 < clc
|| cacheListIdx2 == clc && cacheIdx < cllc)
&& pWrapLineCache->m_d3LineIdx<=i )
{
Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
pDiff3WrapLine->wrapLineOffset = d->m_wrapLineCache[wrapLineCacheIdx].m_textStart;
pDiff3WrapLine->wrapLineLength = d->m_wrapLineCache[wrapLineCacheIdx].m_textLength;
++l;
++wrapLineCacheIdx;
if ( pWrapLineCache->m_d3LineIdx==i )
{
Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
pDiff3WrapLine->wrapLineOffset = pWrapLineCache->m_textStart;
pDiff3WrapLine->wrapLineLength = pWrapLineCache->m_textLength;
++l;
}
if (cacheIdx < curCount )
{
++cacheIdx;
++pWrapLineCache;
}
else
{
++cacheListIdx2;
if (cacheListIdx2 >= d->m_wrapLineCacheList.count())
break;
pWrapLineCache = d->m_wrapLineCacheList[cacheListIdx2].data();
curCount = d->m_wrapLineCacheList[cacheListIdx2].count();
cacheIdx = 0;
}
}
linesNeeded = l;
}
......@@ -1615,6 +1691,7 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
}
}
}
pPP->step(false);
if ( wrapLineVectorSize>0 )
{
......
......@@ -76,7 +76,8 @@ public:
void getSelectionRange( int* firstLine, int* lastLine, e_CoordType coordType );
void setPaintingAllowed( bool bAllowPainting );
void recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int nofVisibleColumns );
void recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int nofVisibleColumns, ProgressProxy* );
void recalcWordWrapHelper( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth, int cacheListIdx, ProgressProxy* );
void print( MyPainter& painter, const QRect& r, int firstLine, int nofLinesPerPage );
Q_SIGNALS:
void resizeSignal( int nofVisibleColumns, int nofVisibleLines );
......
......@@ -806,6 +806,8 @@ bool DirectoryMergeWindow::Data::fastFileComparison(
t_FileSize fullSize = file1.size();
t_FileSize sizeLeft = fullSize;
pp.setMaxNofSteps( fullSize / buf1.size() );
while( sizeLeft>0 && ! pp.wasCancelled() )
{
int len = min2( sizeLeft, (t_FileSize)buf1.size() );
......@@ -827,7 +829,8 @@ bool DirectoryMergeWindow::Data::fastFileComparison(
return bEqual;
}
sizeLeft-=len;
pp.setCurrent(double(fullSize-sizeLeft)/fullSize, false );
//pp.setCurrent(double(fullSize-sizeLeft)/fullSize, false );
pp.step();
}
// If the program really arrives here, then the files are really equal.
......@@ -2647,6 +2650,8 @@ void DirectoryMergeWindow::Data::mergeContinue(bool bStart, bool bVerbose)
m_bError = false;
}
pp.setMaxNofSteps( nrOfItems );
bool bSuccess = true;
bool bSingleFileMerge = false;
bool bSim = m_bSimulatedMergeStarted;
......@@ -2755,7 +2760,7 @@ void DirectoryMergeWindow::Data::mergeContinue(bool bStart, bool bVerbose)
MergeFileInfos& mfi = *getMFI(miCurrent);
pp.setInformation( mfi.subPath(),
bSim ? double(nrOfCompletedSimItems)/nrOfItems : double(nrOfCompletedItems)/nrOfItems,
bSim ? nrOfCompletedSimItems : nrOfCompletedItems,
false // bRedrawUpdate
);
......
......@@ -692,6 +692,7 @@ static bool interruptableReadFile( QFile& f, void* pDestBuffer, unsigned long ma
ProgressProxy pp;
const unsigned long maxChunkSize = 100000;
unsigned long i=0;
pp.setMaxNofSteps( maxLength / maxChunkSize + 1 );
while( i<maxLength )
{
unsigned long nextLength = min2( maxLength-i, maxChunkSize );
......@@ -703,7 +704,8 @@ static bool interruptableReadFile( QFile& f, void* pDestBuffer, unsigned long ma
i+=reallyRead;
pp.setCurrent( double(i)/maxLength );
if ( pp.wasCancelled() ) return false;
if ( pp.wasCancelled() )
return false;
}
return true;
}
......@@ -740,6 +742,7 @@ bool FileAccess::writeFile( const void* pSrcBuffer, unsigned long length )
if ( f.open( QIODevice::WriteOnly ) )
{
const unsigned long maxChunkSize = 100000;
pp.setMaxNofSteps( length / maxChunkSize + 1 );
unsigned long i=0;
while( i<length )
{
......@@ -751,8 +754,9 @@ bool FileAccess::writeFile( const void* pSrcBuffer, unsigned long length )
}
i+=reallyWritten;
pp.setCurrent( double(i)/length );
if ( pp.wasCancelled() ) return false;
pp.step();
if ( pp.wasCancelled() )
return false;
}
f.close();
#ifndef _WIN32
......@@ -1774,12 +1778,12 @@ void FileAccessJobHandler::slotListDirProcessNewEntries( KIO::Job*, const KIO::U
void ProgressProxyExtender::slotListDirInfoMessage( KJob*, const QString& msg )
{
setInformation( msg, 0.0 );
setInformation( msg, 0 );
}
void ProgressProxyExtender::slotPercent( KJob*, unsigned long percent )
{
setCurrent( percent/100.0 );
setCurrent( percent );
}
......
......@@ -29,7 +29,8 @@ class QFileInfo;
class ProgressProxyExtender: public ProgressProxy
{
Q_OBJECT
public:
ProgressProxyExtender() { setMaxNofSteps(100); }
public Q_SLOTS:
void slotListDirInfoMessage( KJob*, const QString& msg );
void slotPercent( KJob*, unsigned long percent );
......
......@@ -29,6 +29,11 @@
#include <stdio.h>
#include <QString>
inline bool isEndOfLine( QChar c )
{
return c=='\n' || c=='\r' || c=='\x0b';
}
#define TAB_WIDTH 8
class GnuDiff
......
......@@ -64,7 +64,6 @@ static lin equivs_index;
/* Number of elements allocated in the array `equivs'. */
static lin equivs_alloc;
/* Check for binary files and compare them for exact identity. */
/* Return 1 if BUF contains a non text character.
......@@ -166,7 +165,7 @@ void GnuDiff::find_and_hash_each_line (struct file_data *current)
switch (ignore_white_space)
{
case IGNORE_ALL_SPACE:
while ( p<bufend && (c = *p) != '\n' )
while ( p<bufend && !isEndOfLine(c = *p) )
{
if (! (isWhite(c) || (bIgnoreNumbers && (c.isDigit() || c=='-' || c=='.' )) ))
h = HASH (h, c.toLower().unicode());
......@@ -175,7 +174,7 @@ void GnuDiff::find_and_hash_each_line (struct file_data *current)
break;
default:
while ( p<bufend && (c = *p) != '\n' )
while ( p<bufend && !isEndOfLine(c = *p) )
{
h = HASH (h, c.toLower().unicode());
++p;
......@@ -186,7 +185,7 @@ void GnuDiff::find_and_hash_each_line (struct file_data *current)
switch (ignore_white_space)
{
case IGNORE_ALL_SPACE:
while ( p<bufend && (c = *p) != '\n')
while ( p<bufend && !isEndOfLine(c = *p) )
{
if (! (isWhite(c)|| (bIgnoreNumbers && (c.isDigit() || c=='-' || c=='.' )) ))
h = HASH (h, c.unicode());
......@@ -195,7 +194,7 @@ void GnuDiff::find_and_hash_each_line (struct file_data *current)
break;
default:
while ( p<bufend && (c = *p) != '\n')
while ( p<bufend && !isEndOfLine(c = *p) )
{
h = HASH (h, c.unicode());
++p;
......@@ -299,7 +298,7 @@ void GnuDiff::find_and_hash_each_line (struct file_data *current)
line++;
while (p<bufend && *p++ != '\n')
while (p<bufend && !isEndOfLine(*p++) )
continue;
}
......@@ -356,7 +355,7 @@ void GnuDiff::find_identical_ends (struct file_data filevec[])
/* Now P0 and P1 point at the first nonmatching characters. */
/* Skip back to last line-beginning in the prefix. */
while (p0 != buffer0 && (p0[-1] != '\n' ))
while (p0 != buffer0 && ! isEndOfLine(p0[-1]) )
p0--, p1--;
/* Record the prefix. */
......@@ -393,7 +392,7 @@ void GnuDiff::find_identical_ends (struct file_data filevec[])
{
if (*p0 != *p1)
++p0;
while ( p0<pEnd0 && *p0++ != '\n')
while ( p0<pEnd0 && !isEndOfLine(*p0++) )
continue;
}
......@@ -459,7 +458,7 @@ void GnuDiff::find_identical_ends (struct file_data filevec[])
linbuf0 = (const QChar**) xrealloc (linbuf0, alloc_lines0 * sizeof(*linbuf0));
}
linbuf0[l] = p0;
while ( p0<pEnd0 && *p0++ != '\n' )
while ( p0<pEnd0 && !isEndOfLine(*p0++) )
continue;
}
}
......
......@@ -863,13 +863,13 @@ void OptionDialog::setupDiffPage( void ) {
QLabel* label = 0;
m_options.m_bPreserveCarriageReturn = false;
//OptionCheckBox* pPreserveCarriageReturn = new OptionCheckBox( i18n("Preserve carriage return"), false, "PreserveCarriageReturn", &m_bPreserveCarriageReturn, page, this );
//gbox->addWidget( pPreserveCarriageReturn, line, 0, 1, 2 );
//pPreserveCarriageReturn->setToolTip( i18n(
// "Show carriage return characters '\\r' if they exist.\n"
// "Helps to compare files that were modified under different operating systems.")
// );
//++line;
OptionCheckBox* pPreserveCarriageReturn = new OptionCheckBox( i18n("Preserve carriage return"), false, "PreserveCarriageReturn", &m_options.m_bPreserveCarriageReturn, page, this );
gbox->addWidget( pPreserveCarriageReturn, line, 0, 1, 2 );
pPreserveCarriageReturn->setToolTip( i18n(
"Show carriage return characters '\\r' if they exist.\n"
"Helps to compare files that were modified under different operating systems.")
);
++line;
QString treatAsWhiteSpace = " (" + i18n( "Treat as white space." ) + ")";
OptionCheckBox* pIgnoreNumbers = new OptionCheckBox( i18n( "Ignore numbers" ) + treatAsWhiteSpace, false, "IgnoreNumbers", &m_options.m_bIgnoreNumbers, page, this );
......
......@@ -1554,6 +1554,9 @@ void KDiff3App::slotRecalcWordWrap()
bool KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=0 only for printing, otherwise the really visible width is used
{
QElapsedTimer et;
et.start();
int tel1 = 0;
bool bPrinting = nofVisibleColumns>=0;
int firstD3LIdx = 0;
if( m_pDiffTextWindow1 )
......@@ -1581,31 +1584,41 @@ bool KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
}
ProgressProxy pp;
pp.setMaxNofSteps( (m_bTripleDiff ? 4 : 3 ) );
//pp.setMaxNofSteps( (m_bTripleDiff ? 4 : 3 ) );
pp.setInformation(i18n("Word wrap (Cancel disables word wrap)"),false);
// Let every window calc how many lines will be needed.
if ( m_pDiffTextWindow1 )
{
m_pDiffTextWindow1->recalcWordWrap(true,0,nofVisibleColumns);
m_pDiffTextWindow1->recalcWordWrap(true,0,nofVisibleColumns,&pp);
if ( pp.wasCancelled() )
return false;
pp.step();
//pp.step();
}
if ( m_pDiffTextWindow2 )
{
m_pDiffTextWindow2->recalcWordWrap(true,0,nofVisibleColumns);
m_pDiffTextWindow2->recalcWordWrap(true,0,nofVisibleColumns,&pp);
if ( pp.wasCancelled() )
return false;
pp.step();
//pp.step();
}
if ( m_pDiffTextWindow3 )
{
m_pDiffTextWindow3->recalcWordWrap(true,0,nofVisibleColumns);
m_pDiffTextWindow3->recalcWordWrap(true,0,nofVisibleColumns,&pp);
if ( pp.wasCancelled() )
return false;
pp.step();
//pp.step();
}
while( ! QThreadPool::globalInstance()->waitForDone(100) )
{
pp.recalc(); // implicit process events and redraw
}
if ( pp.wasCancelled() )
return false;
tel1 = et.elapsed();
et.restart();
sumOfLines=0;
for ( i=m_diff3LineList.begin(); i!=m_diff3LineList.end(); ++i )
{
......@@ -1617,35 +1630,37 @@ bool KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
// Finish the initialisation:
if ( m_pDiffTextWindow1 )
{
m_pDiffTextWindow1->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
m_pDiffTextWindow1->recalcWordWrap(true,sumOfLines,nofVisibleColumns, &pp);
if ( pp.wasCancelled() )
return false;
}
if ( m_pDiffTextWindow2 )
{
m_pDiffTextWindow2->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
m_pDiffTextWindow2->recalcWordWrap(true,sumOfLines,nofVisibleColumns, &pp);
if ( pp.wasCancelled() )
return false;
}
if ( m_pDiffTextWindow3 )
{
m_pDiffTextWindow3->recalcWordWrap(true,sumOfLines,nofVisibleColumns);
m_pDiffTextWindow3->recalcWordWrap(true,sumOfLines,nofVisibleColumns, &pp);
if ( pp.wasCancelled() )
return false;
}
pp.step();
int tel = et.elapsed();
m_neededLines = sumOfLines;
}
else
{
m_neededLines = m_diff3LineVector.size();
if ( m_pDiffTextWindow1 )
m_pDiffTextWindow1->recalcWordWrap(false,0,0);
m_pDiffTextWindow1->recalcWordWrap(false,0,0,0);
if ( m_pDiffTextWindow2 )
m_pDiffTextWindow2->recalcWordWrap(false,0,0);
m_pDiffTextWindow2->recalcWordWrap(false,0,0,0);
if ( m_pDiffTextWindow3 )
m_pDiffTextWindow3->recalcWordWrap(false,0,0);
m_pDiffTextWindow3->recalcWordWrap(false,0,0,0);
}
if (bPrinting)
return true;
......@@ -1677,6 +1692,7 @@ bool KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=
setHScrollBarRange();
m_pHScrollBar->setValue(0);
}
return true;
}
......
......@@ -15,6 +15,7 @@
#include <QPushButton>
#include <QLabel>
#include <QApplication>
#include <QThread>
#include <kio/job.h>
#include <klocalizedstring.h>
......@@ -24,6 +25,8 @@ ProgressDialog* g_pProgressDialog=0;
ProgressDialog::ProgressDialog( QWidget* pParent )
: QDialog( pParent )
{
m_pGuiThread = QThread::currentThread();
setObjectName("ProgressDialog");
m_bStayHidden = false;
setModal(true);
......@@ -54,6 +57,7 @@ ProgressDialog::ProgressDialog( QWidget* pParent )
connect(m_pAbortButton, &QPushButton::clicked, this, &ProgressDialog::slotAbort);
m_progressDelayTimer = 0;
m_delayedHideTimer = 0;
resize( 400, 100 );
m_t1.start();
m_t2.start();
......@@ -98,12 +102,12 @@ void ProgressDialog::pop( bool bRedrawUpdate )
}
}
void ProgressDialog::setInformation(const QString& info, double dCurrent, bool bRedrawUpdate )
void ProgressDialog::setInformation(const QString& info, int current, bool bRedrawUpdate )
{
if ( m_progressStack.empty() )
return;
ProgressLevelData& pld = m_progressStack.back();
pld.m_dCurrent = dCurrent;
pld.m_current = current;
int level = m_progressStack.size();
if ( level==1 )
{
......@@ -141,7 +145,15 @@ void ProgressDialog::setMaxNofSteps( int maxNofSteps )
return;
ProgressLevelData& pld = m_progressStack.back();
pld.m_maxNofSteps = maxNofSteps;
pld.m_dCurrent = 0;
pld.m_current = 0;
}
void ProgressDialog::addNofSteps( int nofSteps )
{
if ( m_progressStack.empty() )
return;
ProgressLevelData& pld = m_progressStack.back();
pld.m_maxNofSteps.fetchAndAddRelaxed( nofSteps );
}
void ProgressDialog::step( bool bRedrawUpdate )
......@@ -149,16 +161,16 @@ void ProgressDialog::step( bool bRedrawUpdate )
if ( m_progressStack.empty() )