comparison kdiff3/src/mergeresultwindow.cpp @ 58:8af4bb9d9a5a

Version 0.9.83
author joachim99
date Sun, 07 Mar 2004 09:59:09 +0000
parents 32d5cbf9db71
children efe33e938730
comparison
equal deleted inserted replaced
57:023fbd76c1e3 58:8af4bb9d9a5a
1 /*************************************************************************** 1 /***************************************************************************
2 mergeresultwindow.cpp - description 2 mergeresultwindow.cpp - description
3 ------------------- 3 -------------------
4 begin : Sun Apr 14 2002 4 begin : Sun Apr 14 2002
5 copyright : (C) 2002 by Joachim Eibl 5 copyright : (C) 2002-2004 by Joachim Eibl
6 email : joachim.eibl@gmx.de 6 email : joachim.eibl@gmx.de
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9 /*************************************************************************** 9 /***************************************************************************
10 * * 10 * *
25 #include <qcursor.h> 25 #include <qcursor.h>
26 #include <qpopupmenu.h> 26 #include <qpopupmenu.h>
27 #include <optiondialog.h> 27 #include <optiondialog.h>
28 #include <klocale.h> 28 #include <klocale.h>
29 #include <kmessagebox.h> 29 #include <kmessagebox.h>
30 #include <iostream>
30 31
31 int g_bAutoSolve = true; 32 int g_bAutoSolve = true;
32 33
33 #undef leftInfoWidth 34 #undef leftInfoWidth
34 #define leftInfoWidth 3 35 #define leftInfoWidth 3
43 44
44 m_firstLine = 0; 45 m_firstLine = 0;
45 m_firstColumn = 0; 46 m_firstColumn = 0;
46 m_nofColumns = 0; 47 m_nofColumns = 0;
47 m_nofLines = 0; 48 m_nofLines = 0;
49 m_totalSize = 0;
48 m_bMyUpdate = false; 50 m_bMyUpdate = false;
49 m_bInsertMode = true; 51 m_bInsertMode = true;
50 m_scrollDeltaX = 0; 52 m_scrollDeltaX = 0;
51 m_scrollDeltaY = 0; 53 m_scrollDeltaY = 0;
52 m_bModified = false; 54 m_bModified = false;
56 m_pldB = 0; 58 m_pldB = 0;
57 m_pldC = 0; 59 m_pldC = 0;
58 60
59 m_pDiff3LineList = 0; 61 m_pDiff3LineList = 0;
60 m_pTotalDiffStatus = 0; 62 m_pTotalDiffStatus = 0;
61 63
62 m_pOptionDialog = pOptionDialog; 64 m_pOptionDialog = pOptionDialog;
65 m_bPaintingAllowed = false;
63 66
64 m_cursorXPos=0; 67 m_cursorXPos=0;
65 m_cursorOldXPos=0; 68 m_cursorOldXPos=0;
66 m_cursorYPos=0; 69 m_cursorYPos=0;
67 m_bCursorOn = true; 70 m_bCursorOn = true;
253 if ( result==KMessageBox::No ) 256 if ( result==KMessageBox::No )
254 return; 257 return;
255 } 258 }
256 259
257 m_mergeLineList.clear(); 260 m_mergeLineList.clear();
261 m_totalSize = 0;
258 int lineIdx = 0; 262 int lineIdx = 0;
259 Diff3LineList::const_iterator it; 263 Diff3LineList::const_iterator it;
260 for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it, ++lineIdx ) 264 for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it, ++lineIdx )
261 { 265 {
262 const Diff3Line& d = *it; 266 const Diff3Line& d = *it;
300 { 304 {
301 back->srcSelect = m_pOptionDialog->m_whiteSpace3FileMergeDefault; 305 back->srcSelect = m_pOptionDialog->m_whiteSpace3FileMergeDefault;
302 back->bConflict = false; 306 back->bConflict = false;
303 } 307 }
304 } 308 }
309 ml.mergeEditLineList.setTotalSizePtr(&m_totalSize);
305 m_mergeLineList.push_back( ml ); 310 m_mergeLineList.push_back( ml );
306 } 311 }
307 312
308 if ( ! ml.bConflict ) 313 if ( ! ml.bConflict )
309 { 314 {
391 int srcLine = melsrc==1 ? mel.id3l()->lineA : 396 int srcLine = melsrc==1 ? mel.id3l()->lineA :
392 melsrc==2 ? mel.id3l()->lineB : 397 melsrc==2 ? mel.id3l()->lineB :
393 melsrc==3 ? mel.id3l()->lineC : -1; 398 melsrc==3 ? mel.id3l()->lineC : -1;
394 399
395 if ( srcLine == -1 && oldSrcLine==-1 && oldSrc == melsrc ) 400 if ( srcLine == -1 && oldSrcLine==-1 && oldSrc == melsrc )
396
397 melIt = ml.mergeEditLineList.erase( melIt ); 401 melIt = ml.mergeEditLineList.erase( melIt );
398 else 402 else
399 ++melIt; 403 ++melIt;
400 404
401 oldSrcLine = srcLine; 405 oldSrcLine = srcLine;
432 return m_nofColumns; 436 return m_nofColumns;
433 } 437 }
434 438
435 int MergeResultWindow::getNofLines() 439 int MergeResultWindow::getNofLines()
436 { 440 {
437 return m_nofLines; 441 return m_totalSize;
438 } 442 }
439 443
440 int MergeResultWindow::getNofVisibleColumns() 444 int MergeResultWindow::getNofVisibleColumns()
441 { 445 {
442 QFontMetrics fm = fontMetrics(); 446 QFontMetrics fm = fontMetrics();
789 if ( bActive ) mel.setConflict(); // All src entries deleted => conflict 793 if ( bActive ) mel.setConflict(); // All src entries deleted => conflict
790 else mel.setRemoved(selector); // No lines in corresponding src found. 794 else mel.setRemoved(selector); // No lines in corresponding src found.
791 795
792 ml.mergeEditLineList.push_back(mel); 796 ml.mergeEditLineList.push_back(mel);
793 } 797 }
798
799 if ( m_cursorYPos >= m_totalSize )
800 {
801 m_cursorYPos = m_totalSize-1;
802 m_cursorXPos = 0;
803 }
794 804
795 update(); 805 update();
796 emit updateAvailabilities(); 806 emit updateAvailabilities();
797 } 807 }
798 808
1054 p.drawLine( xOffset+2, yOffset, xOffset+2, yOffset+fontHeight-1 ); 1064 p.drawLine( xOffset+2, yOffset, xOffset+2, yOffset+fontHeight-1 );
1055 p.drawLine( xOffset+3, yOffset, xOffset+3, yOffset+fontHeight-1 );*/ 1065 p.drawLine( xOffset+3, yOffset, xOffset+3, yOffset+fontHeight-1 );*/
1056 } 1066 }
1057 } 1067 }
1058 1068
1069 void MergeResultWindow::setPaintingAllowed(bool bPaintingAllowed)
1070 {
1071 m_bPaintingAllowed = bPaintingAllowed;
1072 }
1073
1059 void MergeResultWindow::paintEvent( QPaintEvent* e ) 1074 void MergeResultWindow::paintEvent( QPaintEvent* e )
1060 { 1075 {
1061 if (m_pDiff3LineList==0) return; 1076 if (m_pDiff3LineList==0 || !m_bPaintingAllowed) return;
1062 1077
1063 bool bOldSelectionContainsData = m_selection.bSelectionContainsData; 1078 bool bOldSelectionContainsData = m_selection.bSelectionContainsData;
1064 const QFontMetrics& fm = fontMetrics(); 1079 const QFontMetrics& fm = fontMetrics();
1065 int fontHeight = fm.height(); 1080 int fontHeight = fm.height();
1066 int fontWidth = fm.width("W"); 1081 int fontWidth = fm.width("W");
1077 p.fillRect( rect(), m_pOptionDialog->m_bgColor ); 1092 p.fillRect( rect(), m_pOptionDialog->m_bgColor );
1078 1093
1079 //int visibleLines = height() / fontHeight; 1094 //int visibleLines = height() / fontHeight;
1080 1095
1081 { // Draw the topline 1096 { // Draw the topline
1082 QString s; 1097 QString s = " " +i18n("Output") + " : " + m_fileName + " ";
1083 s.sprintf(" Output : %s ", m_fileName.ascii() );
1084 // s.sprintf(" Output : %s : Line %d",(const char*) m_fileName, m_firstLine+1 );
1085 if (m_bModified) 1098 if (m_bModified)
1086 s += i18n("[Modified]"); 1099 s += i18n("[Modified]");
1087 1100
1088 int topLineYOffset = fontHeight + 3; 1101 int topLineYOffset = fontHeight + 3;
1089 1102
1143 } 1156 }
1144 1157
1145 if ( line != m_nofLines || nofColumns != m_nofColumns ) 1158 if ( line != m_nofLines || nofColumns != m_nofColumns )
1146 { 1159 {
1147 m_nofLines = line; 1160 m_nofLines = line;
1161 assert( m_nofLines == m_totalSize );
1148 1162
1149 m_nofColumns = nofColumns; 1163 m_nofColumns = nofColumns;
1150 emit resizeSignal(); 1164 emit resizeSignal();
1151 } 1165 }
1152 1166
1221 int xOffset = (leftInfoWidth-m_firstColumn)*fontWidth; 1235 int xOffset = (leftInfoWidth-m_firstColumn)*fontWidth;
1222 int topLineYOffset = fontHeight + 3; 1236 int topLineYOffset = fontHeight + 3;
1223 1237
1224 int yOffset = topLineYOffset - m_firstLine * fontHeight; 1238 int yOffset = topLineYOffset - m_firstLine * fontHeight;
1225 1239
1226 line = min2( ( y - yOffset ) / fontHeight, m_nofLines-1 ); 1240 line = min2( ( y - yOffset ) / fontHeight, m_totalSize-1 );
1227 pos = ( x - xOffset ) / fontWidth; 1241 pos = ( x - xOffset ) / fontWidth;
1228 } 1242 }
1229 1243
1230 void MergeResultWindow::mousePressEvent ( QMouseEvent* e ) 1244 void MergeResultWindow::mousePressEvent ( QMouseEvent* e )
1231 { 1245 {
1436 { 1450 {
1437 if ( deleteSelection2( ps, stringLength, x, y, mlIt, melIt )) break; 1451 if ( deleteSelection2( ps, stringLength, x, y, mlIt, melIt )) break;
1438 if( !melIt->isEditableText() ) break; 1452 if( !melIt->isEditableText() ) break;
1439 if (x>=stringLength) 1453 if (x>=stringLength)
1440 { 1454 {
1441 if ( y<m_nofLines-1 ) 1455 if ( y<m_totalSize-1 )
1442 { 1456 {
1443 setModified(); 1457 setModified();
1444 QCString s1( ps, stringLength+1 ); 1458 QCString s1( ps, stringLength+1 );
1445 MergeLineList::iterator mlIt1; 1459 MergeLineList::iterator mlIt1;
1446 MergeEditLineList::iterator melIt1; 1460 MergeEditLineList::iterator melIt1;
1579 break; 1593 break;
1580 1594
1581 case Key_Right: 1595 case Key_Right:
1582 if ( !bCtrl ) 1596 if ( !bCtrl )
1583 { 1597 {
1584 ++x; if(x>stringLength && y<m_nofLines-1){ ++y; x=0; } 1598 ++x; if(x>stringLength && y<m_totalSize-1){ ++y; x=0; }
1585 } 1599 }
1586 1600
1587 else 1601 else
1588 { 1602 {
1589 while( x<stringLength && (ps[x]==' ' || ps[x]=='\t') ) ++x; 1603 while( x<stringLength && (ps[x]==' ' || ps[x]=='\t') ) ++x;
1618 { 1632 {
1619 int spaces = (m_cursorXPos / g_tabSize + 1)*g_tabSize - m_cursorXPos; 1633 int spaces = (m_cursorXPos / g_tabSize + 1)*g_tabSize - m_cursorXPos;
1620 t.fill( ' ', spaces ); 1634 t.fill( ' ', spaces );
1621 } 1635 }
1622 if ( m_bInsertMode ) 1636 if ( m_bInsertMode )
1623 s.insert( x, t.ascii() ); 1637 s.insert( x, encodeString(t, m_pOptionDialog) );
1624 else 1638 else
1625 s.replace( x, t.length(), t.ascii() ); 1639 s.replace( x, t.length(), encodeString(t, m_pOptionDialog) );
1626 1640
1627 melIt->setString( s ); 1641 melIt->setString( s );
1628 x += t.length(); 1642 x += t.length();
1629 bShift = false; 1643 bShift = false;
1630 } 1644 }
1631 } 1645 }
1632 } 1646 }
1633 } 1647 }
1634 1648
1635 y = minMaxLimiter( y, 0, m_nofLines-1 ); 1649 y = minMaxLimiter( y, 0, m_totalSize-1 );
1636 1650
1637 calcIteratorFromLineNr( y, mlIt, melIt ); 1651 calcIteratorFromLineNr( y, mlIt, melIt );
1638 ps = melIt->getString( this, stringLength ); 1652 ps = melIt->getString( this, stringLength );
1639 1653
1640 x = minMaxLimiter( x, 0, stringLength ); 1654 x = minMaxLimiter( x, 0, stringLength );
1742 spaces = tabber( outPos, g_tabSize ); 1756 spaces = tabber( outPos, g_tabSize );
1743 } 1757 }
1744 1758
1745 if( m_selection.within( line, outPos ) ) 1759 if( m_selection.within( line, outPos ) )
1746 { 1760 {
1747 selectionString += pLine[i]; 1761 char buf[2];
1762 buf[0] = pLine[i];
1763 buf[1] = '\0';
1764 selectionString += decodeString( buf, m_pOptionDialog );
1748 } 1765 }
1749 1766
1750 outPos += spaces; 1767 outPos += spaces;
1751 } 1768 }
1752 } 1769 }
1753 else if ( mel.isConflict() ) 1770 else if ( mel.isConflict() )
1754 { 1771 {
1755 selectionString += "<Merge Conflict>"; 1772 selectionString += i18n("<Merge Conflict>");
1756 } 1773 }
1757 1774
1758 if( m_selection.within( line, outPos ) ) 1775 if( m_selection.within( line, outPos ) )
1759 { 1776 {
1760 #ifdef _WIN32 1777 #ifdef _WIN32
1864 1881
1865 if ( line!=firstLine ) 1882 if ( line!=firstLine )
1866 { 1883 {
1867 // Remove the line 1884 // Remove the line
1868 if ( mlIt->mergeEditLineList.size()>1 ) 1885 if ( mlIt->mergeEditLineList.size()>1 )
1869 { mlIt->mergeEditLineList.erase( melIt ); --m_nofLines; } 1886 mlIt->mergeEditLineList.erase( melIt );
1870 else 1887 else
1871 { melIt->setRemoved(); } 1888 melIt->setRemoved();
1872 } 1889 }
1873 } 1890 }
1874 1891
1875 ++line; 1892 ++line;
1876 melIt = melIt1; 1893 melIt = melIt1;
1899 ++melItAfter; 1916 ++melItAfter;
1900 int stringLength; 1917 int stringLength;
1901 const char* ps = melIt->getString( this, stringLength ); 1918 const char* ps = melIt->getString( this, stringLength );
1902 int x = convertToPosInText( ps, stringLength, m_cursorXPos ); 1919 int x = convertToPosInText( ps, stringLength, m_cursorXPos );
1903 1920
1904 QString clipBoard = QApplication::clipboard()->text(); 1921 QCString clipBoard = encodeString( QApplication::clipboard()->text(), m_pOptionDialog );
1905 1922
1906 QCString currentLine = QCString( ps, x+1 ); 1923 QCString currentLine = QCString( ps, x+1 );
1907 QCString endOfLine = QCString( ps+x, stringLength-x+1 ); 1924 QCString endOfLine = QCString( ps+x, stringLength-x+1 );
1908 int i; 1925 int i;
1909 for( i=0; i<(int)clipBoard.length(); ++i ) 1926 for( i=0; i<(int)clipBoard.length(); ++i )
1910 { 1927 {
1911 QChar uc = clipBoard[i]; 1928 char c = clipBoard[i];
1912 char c = uc;
1913 if ( c == '\r' ) continue; 1929 if ( c == '\r' ) continue;
1914 if ( c == '\n' ) 1930 if ( c == '\n' )
1915 { 1931 {
1916 melIt->setString( currentLine ); 1932 melIt->setString( currentLine );
1917 1933
2013 2029
2014 QCString s(pLine, size+1); 2030 QCString s(pLine, size+1);
2015 2031
2016 if (line>0) // Prepend line feed, but not for first line 2032 if (line>0) // Prepend line feed, but not for first line
2017 { 2033 {
2018 #ifdef _WIN32 2034 if ( m_pOptionDialog->m_lineEndStyle == eLineEndDos )
2019 s.prepend("\r\n"); size+=2; 2035 { s.prepend("\r\n"); size+=2; }
2020 #else 2036 else
2021 s.prepend("\n"); size+=1; 2037 { s.prepend("\n"); size+=1; }
2022 #endif
2023 } 2038 }
2024 2039
2025 if (i==0) neededBufferSize += size; 2040 if (i==0) neededBufferSize += size;
2026 else 2041 else
2027 { 2042 {
2090 m_selection.reset(); 2105 m_selection.reset();
2091 m_selection.start( firstLine, convertToPosOnScreen( getString(firstLine), startPos ) ); 2106 m_selection.start( firstLine, convertToPosOnScreen( getString(firstLine), startPos ) );
2092 m_selection.end( lastLine, convertToPosOnScreen( getString(lastLine), endPos ) ); 2107 m_selection.end( lastLine, convertToPosOnScreen( getString(lastLine), endPos ) );
2093 update(); 2108 update();
2094 } 2109 }
2095
2096 2110
2097 Overview::Overview( QWidget* pParent, OptionDialog* pOptions ) 2111 Overview::Overview( QWidget* pParent, OptionDialog* pOptions )
2098 : QWidget( pParent, 0, WRepaintNoErase ) 2112 : QWidget( pParent, 0, WRepaintNoErase )
2099 { 2113 {
2100 m_pDiff3LineList = 0; 2114 m_pDiff3LineList = 0;