Commit 6f7e6c07 authored by Joachim Eibl's avatar Joachim Eibl

- Fixed editing for right to left texts.

- Performance improvements by avoiding repeated calculations.
Signed-off-by: default avatarjoachim99 <joachim.eibl@gmx.de>
parent 2c04e149
......@@ -66,6 +66,7 @@ public:
m_oldFirstLine = 0;
m_horizScrollOffset = 0;
m_lineNumberWidth = 0;
m_maxTextWidth = -1;
m_pStatusBar = 0;
m_scrollDeltaX = 0;
m_scrollDeltaY = 0;
......@@ -109,6 +110,7 @@ public:
int m_oldFirstLine;
int m_horizScrollOffset;
int m_lineNumberWidth;
int m_maxTextWidth;
void getLineInfo(
const Diff3Line& d,
......@@ -209,6 +211,7 @@ void DiffTextWindow::init(
d->m_fastSelectorLine1 = 0;
d->m_fastSelectorNofLines = 0;
d->m_lineNumberWidth = 0;
d->m_maxTextWidth = -1;
d->m_selection.reset();
d->m_selection.oldFirstLine = -1; // reset is not enough here.
d->m_selection.oldLastLine = -1;
......@@ -312,19 +315,19 @@ int DiffTextWindow::getMaxTextWidth()
{
return getVisibleTextAreaWidth();
}
else
else if ( d->m_maxTextWidth < 0 )
{
int w = 0;
d->m_maxTextWidth = 0;
QFontMetrics fm( fontMetrics() );
for( int i = 0; i< d->m_size; ++i )
{
QTextLayout textLayout( d->getString(i), font(), this );
d->prepareTextLayout( textLayout, true );
if ( textLayout.maximumWidth() > w )
w = textLayout.maximumWidth();
if ( textLayout.maximumWidth() > d->m_maxTextWidth )
d->m_maxTextWidth = textLayout.maximumWidth();
}
return w;
}
return d->m_maxTextWidth;
}
int DiffTextWindow::getNofLines()
......
......@@ -142,6 +142,7 @@ KDiff3App::KDiff3App(QWidget* pParent, const char* /*name*/, KDiff3Part* pKDiff3
m_pDiffVScrollBar = 0;
m_pMergeVScrollBar = 0;
viewToolBar = 0;
m_bRecalcWordWrapPosted = false;
// Needed before any file operations via FileAccess happen.
if (!g_pProgressDialog)
......
......@@ -322,6 +322,7 @@ class KDiff3App : public QSplitter
bool m_bAutoFlag;
bool m_bAutoMode;
void recalcWordWrap(int nofVisibleColumns=-1);
bool m_bRecalcWordWrapPosted;
void setHScrollBarRange();
int m_iCumulativeWheelDelta;
......@@ -330,6 +331,7 @@ public slots:
void resizeDiffTextWindow(int newWidth, int newHeight);
void resizeMergeResultWindow();
void slotRecalcWordWrap();
void postRecalcWordWrap();
void showPopupMenu( const QPoint& point );
......
......@@ -96,6 +96,7 @@ MergeResultWindow::MergeResultWindow(
m_cursorYPos=0;
m_bCursorOn = true;
m_bCursorUpdate = false;
m_maxTextWidth = -1;
connect( &m_cursorTimer, SIGNAL(timeout()), this, SLOT( slotCursorUpdate() ) );
m_cursorTimer.setSingleShot(true);
m_cursorTimer.start( 500 /*ms*/ );
......@@ -137,6 +138,8 @@ void MergeResultWindow::init(
m_cursorOldXPixelPos=0;
m_cursorYPos=0;
m_maxTextWidth = -1;
merge( g_bAutoSolve, -1 );
g_bAutoSolve = true;
update();
......@@ -495,6 +498,8 @@ void MergeResultWindow::merge(bool bAutoSolve, int defaultSelector, bool bConfli
m_cursorXPos=0;
m_cursorOldXPixelPos=0;
m_cursorYPos=0;
m_maxTextWidth = -1;
//m_firstLine = 0; // Must not set line/column without scrolling there
//m_horizScrollOffset = 0;
......@@ -521,19 +526,32 @@ void MergeResultWindow::setHorizScrollOffset(int horizScrollOffset)
int MergeResultWindow::getMaxTextWidth()
{
int w=0;
for(int i=0; i<getNofLines(); ++i)
if ( m_maxTextWidth < 0 )
{
QTextLayout textLayout( getString(i), font(), this );
textLayout.beginLayout();
textLayout.createLine();
textLayout.endLayout();
if ( w < textLayout.maximumWidth() )
m_maxTextWidth=0;
MergeLineList::iterator mlIt = m_mergeLineList.begin();
for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt)
{
w = textLayout.maximumWidth();
MergeLine& ml = *mlIt;
MergeEditLineList::iterator melIt;
for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt )
{
MergeEditLine& mel = *melIt;
QString s = mel.getString( this );
QTextLayout textLayout( s, font(), this );
textLayout.beginLayout();
textLayout.createLine();
textLayout.endLayout();
if ( m_maxTextWidth < textLayout.maximumWidth() )
{
m_maxTextWidth = textLayout.maximumWidth();
}
}
}
}
return w;
return m_maxTextWidth;
}
int MergeResultWindow::getNofLines()
......@@ -982,6 +1000,7 @@ void MergeResultWindow::choose( int selector )
m_cursorXPos = 0;
}
m_maxTextWidth = -1;
update();
updateSourceMask();
emit updateAvailabilities();
......@@ -2213,6 +2232,9 @@ void MergeResultWindow::keyPressEvent( QKeyEvent* e )
QString str = melIt->getString( this );
int x = convertToPosInText( str, m_cursorXPos, m_pOptions->m_tabSize );
QTextLayout textLayoutOrig( str, font(), this );
getTextLayoutForLine( y, str, textLayoutOrig );
bool bCtrl = ( e->QInputEvent::modifiers() & Qt::ControlModifier ) != 0 ;
bool bShift = ( e->QInputEvent::modifiers() & Qt::ShiftModifier ) != 0 ;
#ifdef _WIN32
......@@ -2361,26 +2383,48 @@ void MergeResultWindow::keyPressEvent( QKeyEvent* e )
{
if ( !bCtrl )
{
--x;
if(x<0 && y>0){--y; x=INT_MAX;}
int newX = textLayoutOrig.previousCursorPosition(x);
if( newX == x && y>0 ){--y; x=INT_MAX;}
else { x = newX; }
}
else
{
while( x>0 && (str[x-1]==' ' || str[x-1]=='\t') ) --x;
while( x>0 && (str[x-1]!=' ' && str[x-1]!='\t') ) --x;
while( x>0 && (str[x-1]==' ' || str[x-1]=='\t') )
{
int newX = textLayoutOrig.previousCursorPosition(x);
if ( newX==x ) break;
x = newX;
}
while( x>0 && (str[x-1]!=' ' && str[x-1]!='\t') )
{
int newX = textLayoutOrig.previousCursorPosition(x);
if ( newX==x ) break;
x = newX;
}
}
}
else
{
if ( !bCtrl )
{
++x; if(x>(int)str.length() && y<m_totalSize-1){ ++y; x=0; }
int newX = textLayoutOrig.nextCursorPosition(x);
if( newX == x && y<m_totalSize-1){ ++y; x=0; }
else { x = newX; }
}
else
{
while( x<(int)str.length() && (str[x]==' ' || str[x]=='\t') ) ++x;
while( x<(int)str.length() && (str[x]!=' ' && str[x]!='\t') ) ++x;
while( x<(int)str.length() && (str[x]==' ' || str[x]=='\t') )
{
int newX = textLayoutOrig.nextCursorPosition(x);
if ( newX==x ) break;
x = newX;
}
while( x<(int)str.length() && (str[x]!=' ' && str[x]!='\t') )
{
int newX = textLayoutOrig.nextCursorPosition(x);
if ( newX==x ) break;
x = newX;
}
}
}
break;
......@@ -2441,6 +2485,7 @@ void MergeResultWindow::keyPressEvent( QKeyEvent* e )
else if ( y > m_firstLine + getNofVisibleLines() )
newFirstLine = y - getNofVisibleLines();
QTextLayout textLayout( str, font(), this );
getTextLayoutForLine( m_cursorYPos, str, textLayout );
......@@ -2456,7 +2501,7 @@ void MergeResultWindow::keyPressEvent( QKeyEvent* e )
else if ( m_cursorXPixelPos > m_horizScrollOffset + width() - getTextXOffset() - fontMetrics().width('0') )
newHorizScrollOffset = m_cursorXPixelPos - (width() - getTextXOffset() - fontMetrics().width('0') );
int newCursorX = textLayout.lineAt(0).xToCursor( m_cursorXPixelPos );
int newCursorX = x;
if ( bShift )
{
if (m_selection.firstLine==-1)
......@@ -2753,6 +2798,8 @@ void MergeResultWindow::resetSelection()
void MergeResultWindow::setModified(bool bModified)
{
if ( bModified )
m_maxTextWidth = -1;
if (bModified != m_bModified)
{
m_bModified = bModified;
......
......@@ -394,6 +394,7 @@ private:
int m_horizScrollOffset;
int m_nofLines;
int m_totalSize; //Same as m_nofLines, but calculated differently
int m_maxTextWidth;
bool m_bMyUpdate;
bool m_bInsertMode;
bool m_bModified;
......
......@@ -526,7 +526,7 @@ void KDiff3App::resizeDiffTextWindow(int /*newWidth*/, int newHeight)
{
m_DTWHeight = newHeight;
recalcWordWrap();
postRecalcWordWrap();
m_pDiffVScrollBar->setRange(0, max2(0, m_neededLines+1 - newHeight) );
m_pDiffVScrollBar->setPageStep( newHeight );
......@@ -760,8 +760,8 @@ void KDiff3App::initView()
connect( m_pDiffTextWindow1, SIGNAL( resizeSignal(int,int) ),this, SLOT(resizeDiffTextWindow(int,int)));
// The following two connects cause the wordwrap to be recalced thrice, just to make sure. Better than forgetting one.
connect( m_pDiffTextWindow2, SIGNAL( resizeSignal(int,int) ),this, SLOT(slotRecalcWordWrap()));
connect( m_pDiffTextWindow3, SIGNAL( resizeSignal(int,int) ),this, SLOT(slotRecalcWordWrap()));
connect( m_pDiffTextWindow2, SIGNAL( resizeSignal(int,int) ),this, SLOT(postRecalcWordWrap()));
connect( m_pDiffTextWindow3, SIGNAL( resizeSignal(int,int) ),this, SLOT(postRecalcWordWrap()));
m_pDiffTextWindow1->setFocus();
m_pMainWidget->setMinimumSize(50,50);
......@@ -791,7 +791,7 @@ void KDiff3App::slotAfterFirstPaint()
/*int newWidth = m_pDiffTextWindow1->getNofVisibleColumns();*/
m_DTWHeight = newHeight;
recalcWordWrap();
postRecalcWordWrap();
m_pDiffVScrollBar->setRange(0, max2(0, m_neededLines+1 - newHeight) );
m_pDiffVScrollBar->setPageStep( newHeight );
......@@ -1540,9 +1540,19 @@ void KDiff3App::slotWordWrapToggled()
recalcWordWrap();
}
void KDiff3App::postRecalcWordWrap()
{
if ( ! m_bRecalcWordWrapPosted )
{
QTimer::singleShot( 1, this, SLOT(slotRecalcWordWrap()) );
m_bRecalcWordWrapPosted = true;
}
}
void KDiff3App::slotRecalcWordWrap()
{
recalcWordWrap();
m_bRecalcWordWrapPosted = false;
}
void KDiff3App::recalcWordWrap(int nofVisibleColumns) // nofVisibleColumns is >=0 only for printing, otherwise the really visible width is used
......
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