Mercurial > hg > easyhg-kdiff3
changeset 6:a23681732506
Files have moved into the src directory.
author | joachim99 |
---|---|
date | Mon, 06 Oct 2003 18:32:37 +0000 |
parents | 0e88ed54da94 |
children | ff98a43bbfea |
files | kdiff3/kdiff3/Makefile.am kdiff3/kdiff3/diff.cpp kdiff3/kdiff3/diff.h kdiff3/kdiff3/difftextwindow.cpp kdiff3/kdiff3/down1arrow.xpm kdiff3/kdiff3/down2arrow.xpm kdiff3/kdiff3/downend.xpm kdiff3/kdiff3/filenew.xpm kdiff3/kdiff3/fileopen.xpm kdiff3/kdiff3/filesave.xpm kdiff3/kdiff3/hi16-app-kdiff3.png kdiff3/kdiff3/hi32-app-kdiff3.png kdiff3/kdiff3/iconA.xpm kdiff3/kdiff3/iconB.xpm kdiff3/kdiff3/iconC.xpm kdiff3/kdiff3/kdiff3.cpp kdiff3/kdiff3/kdiff3.desktop kdiff3/kdiff3/kdiff3.h kdiff3/kdiff3/kdiff3ui.rc kdiff3/kdiff3/left1arrow.xpm kdiff3/kdiff3/left2arrow.xpm kdiff3/kdiff3/leftend.xpm kdiff3/kdiff3/lo16-app-kdiff3.png kdiff3/kdiff3/lo32-app-kdiff3.png kdiff3/kdiff3/main.cpp kdiff3/kdiff3/merger.cpp kdiff3/kdiff3/merger.h kdiff3/kdiff3/mergeresultwindow.cpp kdiff3/kdiff3/optiondialog.cpp kdiff3/kdiff3/optiondialog.h kdiff3/kdiff3/pdiff.cpp kdiff3/kdiff3/right1arrow.xpm kdiff3/kdiff3/right2arrow.xpm kdiff3/kdiff3/rightend.xpm kdiff3/kdiff3/up1arrow.xpm kdiff3/kdiff3/up2arrow.xpm kdiff3/kdiff3/upend.xpm |
diffstat | 37 files changed, 0 insertions(+), 6973 deletions(-) [+] |
line wrap: on
line diff
--- a/kdiff3/kdiff3/Makefile.am Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -####### kdevelop will overwrite this part!!! (begin)########## -bin_PROGRAMS = kdiff3 - -## INCLUDES were found outside kdevelop specific part - -kdiff3_SOURCES = optiondialog.cpp merger.cpp pdiff.cpp mergeresultwindow.cpp difftextwindow.cpp diff.cpp kdiff3.cpp main.cpp -kdiff3_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) - - -EXTRA_DIST = main.cpp kdiff3.cpp kdiff3.h kdiff3ui.rc kdiff3.desktop lo32-app-kdiff3.png lo16-app-kdiff3.png diff.h diff.cpp difftextwindow.cpp mergeresultwindow.cpp pdiff.cpp merger.cpp merger.h optiondialog.cpp optiondialog.h hi32-app-kdiff3.png hi16-app-kdiff3.png - -install-data-local: - $(mkinstalldirs) $(kde_appsdir)/Applications/ - $(INSTALL_DATA) $(srcdir)/kdiff3.desktop $(kde_appsdir)/Applications/kdiff3.desktop - $(mkinstalldirs) $(kde_icondir)/locolor/32x32/apps/ - $(INSTALL_DATA) $(srcdir)/lo32-app-kdiff3.png $(kde_icondir)/locolor/32x32/apps/kdiff3.png - $(mkinstalldirs) $(kde_icondir)/locolor/16x16/apps/ - $(INSTALL_DATA) $(srcdir)/lo16-app-kdiff3.png $(kde_icondir)/locolor/16x16/apps/kdiff3.png - $(mkinstalldirs) $(kde_icondir)/hicolor/32x32/apps/ - $(INSTALL_DATA) $(srcdir)/hi32-app-kdiff3.png $(kde_icondir)/hicolor/32x32/apps/kdiff3.png - $(mkinstalldirs) $(kde_icondir)/hicolor/16x16/apps/ - $(INSTALL_DATA) $(srcdir)/hi16-app-kdiff3.png $(kde_icondir)/hicolor/16x16/apps/kdiff3.png - -uninstall-local: - -rm -f $(kde_appsdir)/Applications/kdiff3.desktop - -rm -f $(kde_icondir)/locolor/32x32/apps/kdiff3.png - -rm -f $(kde_icondir)/locolor/16x16/apps/kdiff3.png - -rm -f $(kde_icondir)/hicolor/32x32/apps/kdiff3.png - -rm -f $(kde_icondir)/hicolor/16x16/apps/kdiff3.png - -####### kdevelop will overwrite this part!!! (end)############ -# These paths are KDE specific. Use them: -# kde_appsdir Where your application's menu entry (.desktop) should go to. -# kde_icondir Where your icon should go to - better use KDE_ICON. -# kde_sounddir Where your sounds should go to. -# kde_htmldir Where your docs should go to. (contains lang subdirs) -# kde_datadir Where you install application data. (Use a subdir) -# kde_locale Where translation files should go to. (contains lang subdirs) -# kde_cgidir Where cgi-bin executables should go to. -# kde_confdir Where config files should go to (system-wide ones with default values). -# kde_mimedir Where mimetypes .desktop files should go to. -# kde_servicesdir Where services .desktop files should go to. -# kde_servicetypesdir Where servicetypes .desktop files should go to. -# kde_toolbardir Where general toolbar icons should go to (deprecated, use KDE_ICON). -# kde_wallpaperdir Where general wallpapers should go to. -# kde_templatesdir Where templates for the "New" menu (Konqueror/KDesktop) should go to. -# kde_bindir Where executables should go to. Use bin_PROGRAMS or bin_SCRIPTS. -# kde_libdir Where shared libraries should go to. Use lib_LTLIBRARIES. -# kde_moduledir Where modules (e.g. parts) should go to. Use kde_module_LTLIBRARIES. -# kde_styledir Where Qt/KDE widget styles should go to (new in KDE 3). -# kde_designerdir Where Qt Designer plugins should go to (new in KDE 3). - -# set the include path for X, qt and KDE -INCLUDES= $(all_includes) - -METASOURCES = AUTO - -# the library search path. -kdiff3_LDFLAGS = $(all_libraries) $(KDE_RPATH) - -rcdir = $(kde_datadir)/kdiff3 -rc_DATA = kdiff3ui.rc - -messages: rc.cpp - LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ - if test -n "$$LIST"; then \ - $(XGETTEXT) $$LIST -o $(podir)/kdiff3.pot; \ - fi -
--- a/kdiff3/kdiff3/diff.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,793 +0,0 @@ -/*************************************************************************** - diff.cpp - description - ------------------- - begin : Mon Mar 18 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:15 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include <stdio.h> -#include "diff.h" - -#include <kmessagebox.h> -#include <klocale.h> -using namespace std; - -int LineData::width() -{ - int w=0; - int j=0; - for( int i=0; i<size; ++i ) - { - if ( pLine[i]=='\t' ) - { - for(j %= g_tabSize; j<g_tabSize; ++j) - ++w; - j=0; - } - else - { - ++w; - ++j; - } - } - return w; -} - - -// The bStrict flag is true during the test where a nonmatching area ends. -// Then the equal()-function requires that the match has more than 2 nonwhite characters. -// This is to avoid matches on trivial lines (e.g. with white space only). -// This choice is good for C/C++. -bool equal( const LineData& l1, const LineData& l2, bool bStrict ) -{ - if ( l1.pLine==0 || l2.pLine==0) return false; - - // Ignore white space diff - const char* p1 = l1.pLine; - const char* p1End = p1 + l1.size; - - const char* p2 = l2.pLine; - const char* p2End = p2 + l2.size; - - if ( g_bIgnoreWhiteSpace ) - { - int nonWhite = 0; - for(;;) - { - while( (*p1==' ' || *p1=='\t') && p1!=p1End ) ++p1; - while( (*p2==' ' || *p2=='\t') && p2!=p2End ) ++p2; - - if ( p1 == p1End && p2 == p2End ) - return bStrict ? (nonWhite>2 || !g_bIgnoreTrivialMatches) : true; - else if ( p1 == p1End || p2 == p2End ) - return false; - - if( *p1 != *p2 ) - return false; - ++p1; - ++p2; - ++nonWhite; - } - } - - else - { - if ( l1.size==l2.size && memcmp(p1, p2, l1.size)==0) - return true; - else - return false; - } -} - - - -/** Prepare the linedata vector for every input line.*/ -int preprocess( const char* p, int size, vector<LineData>& v ) -{ - int lines = 1; - int i; - for( i=0; i<size; ++i ) - { - if (p[i]=='\n') - { - ++lines; - } - } - - v.resize( lines+5 ); - int lineIdx=0; - int lineLength=0; - for( i=0; i<=size; ++i ) - { - - // For WIN32 - if ( i==size || ( p[i]=='\r' && p[i+1]=='\n' ) || p[i]=='\n') // The last line does not end with a linefeed. - { - v[lineIdx].pLine = &p[ i-lineLength ]; - v[lineIdx].size = lineLength; - lineLength = 0; - ++lineIdx; - if ( i<size && p[i]=='\r') ++i; - } - else - { - ++lineLength; - } - } - assert( lineIdx == lines ); - - return lines; -} - - -const char* readFile( const char* filename, int& size ) -{ - size = 0; - if (filename==0 || filename[0]=='\0') return 0; - - FILE* f = fopen( filename, "rb" ); - if ( f==0 ) - { - cerr << "File open error for file: '"<< filename <<"': "; - perror(""); - return 0; - } - - fseek( f, 0, SEEK_END ); - - size = ftell(f); - - fseek( f, 0, SEEK_SET ); - - char* buf = new char[size+100]; - int bytesRead = fread( buf, 1, size, f ); - if( bytesRead != size ) - { - cerr << "File read error for file: '"<< filename <<"': "; - - - perror(""); - exit(-1); - } - - return buf; -} - - -// First step -void calcDiff3LineListUsingAB( - const DiffList* pDiffListAB, - Diff3LineList& d3ll - ) -{ - // First make d3ll for AB (from pDiffListAB) - - DiffList::const_iterator i=pDiffListAB->begin(); - int lineA=0; - int lineB=0; - Diff d(0,0,0); - - for(;;) - { - if ( d.nofEquals==0 && d.diff1==0 && d.diff2==0 ) - { - if ( i!=pDiffListAB->end() ) - { - d=*i; - ++i; - } - else - break; - } - - Diff3Line d3l; - if( d.nofEquals>0 ) - { - d3l.bAEqB = true; - d3l.lineA = lineA; - d3l.lineB = lineB; - --d.nofEquals; - ++lineA; - ++lineB; - } - else if ( d.diff1>0 && d.diff2>0 ) - { - d3l.lineA = lineA; - d3l.lineB = lineB; - --d.diff1; - --d.diff2; - ++lineA; - ++lineB; - } - else if ( d.diff1>0 ) - { - d3l.lineA = lineA; - --d.diff1; - ++lineA; - } - else if ( d.diff2>0 ) - { - d3l.lineB = lineB; - --d.diff2; - ++lineB; - } - - d3ll.push_back( d3l ); - } -} - - -// Second step -void calcDiff3LineListUsingAC( - const DiffList* pDiffListAC, - Diff3LineList& d3ll - ) -{ - //////////////// - // Now insert data from C using pDiffListAC - - DiffList::const_iterator i=pDiffListAC->begin(); - Diff3LineList::iterator i3 = d3ll.begin(); - int lineA=0; - int lineC=0; - Diff d(0,0,0); - - for(;;) - { - if ( d.nofEquals==0 && d.diff1==0 && d.diff2==0 ) - { - if ( i!=pDiffListAC->end() ) - { - d=*i; - ++i; - } - else - break; - } - - Diff3Line d3l; - if( d.nofEquals>0 ) - { - // Find the corresponding lineA - while( (*i3).lineA!=lineA ) - ++i3; - (*i3).lineC = lineC; - - - (*i3).bAEqC = true; - (*i3).bBEqC = (*i3).bAEqB; - - --d.nofEquals; - ++lineA; - ++lineC; - ++i3; - } - else if ( d.diff1>0 && d.diff2>0 ) - { - d3l.lineC = lineC; - d3ll.insert( i3, d3l ); - --d.diff1; - --d.diff2; - ++lineA; - ++lineC; - } - else if ( d.diff1>0 ) - { - --d.diff1; - ++lineA; - } - else if ( d.diff2>0 ) - { - d3l.lineC = lineC; - d3ll.insert( i3, d3l ); - --d.diff2; - ++lineC; - } - } -} - -// Third step -void calcDiff3LineListUsingBC( - const DiffList* pDiffListBC, - Diff3LineList& d3ll - ) -{ - //////////////// - // Now improve the position of data from C using pDiffListBC - // If a line from C equals a line from A then it is in the - // same Diff3Line already. - // If a line from C equals a line from B but not A, this - // information will be used here. - - DiffList::const_iterator i=pDiffListBC->begin(); - Diff3LineList::iterator i3b = d3ll.begin(); - Diff3LineList::iterator i3c = d3ll.begin(); - int lineB=0; - int lineC=0; - Diff d(0,0,0); - - for(;;) - { - if ( d.nofEquals==0 && d.diff1==0 && d.diff2==0 ) - { - if ( i!=pDiffListBC->end() ) - { - d=*i; - ++i; - } - else - break; - } - - Diff3Line d3l; - if( d.nofEquals>0 ) - { - // Find the corresponding lineB and lineC - while( i3b!=d3ll.end() && (*i3b).lineB!=lineB ) - ++i3b; - - while( i3c!=d3ll.end() && (*i3c).lineC!=lineC ) - ++i3c; - - assert(i3b!=d3ll.end()); - assert(i3c!=d3ll.end()); - - if ( i3b==i3c ) - { - assert( (*i3b).lineC == lineC ); - (*i3b).bBEqC = true; - } - else //if ( !(*i3b).bAEqB ) - { - // Is it possible to move this line up? - // Test if no other B's are used between i3c and i3b - - // First test which is before: i3c or i3b ? - Diff3LineList::iterator i3c1 = i3c; - Diff3LineList::iterator i3b1 = i3b; - while( i3c1!=i3b && i3b1!=i3c ) - { - assert(i3b1!=d3ll.end() || i3c1!=d3ll.end()); - if( i3c1!=d3ll.end() ) ++i3c1; - if( i3b1!=d3ll.end() ) ++i3b1; - } - - if( i3c1==i3b && !(*i3b).bAEqB ) // i3c before i3b - { - Diff3LineList::iterator i3 = i3c; - int nofDisturbingLines = 0; - while( i3 != i3b && i3!=d3ll.end() ) - { - if ( (*i3).lineB != -1 ) - ++nofDisturbingLines; - ++i3; - } - - if ( nofDisturbingLines>0 && nofDisturbingLines < d.nofEquals ) - { - // Move the disturbing lines up, out of sight. - i3 = i3c; - while( i3 != i3b ) - { - if ( (*i3).lineB != -1 ) - { - Diff3Line d3l; - d3l.lineB = (*i3).lineB; - (*i3).lineB = -1; - - - (*i3).bAEqB = false; - (*i3).bBEqC = false; - d3ll.insert( i3c, d3l ); - } - ++i3; - } - nofDisturbingLines=0; - } - - if ( nofDisturbingLines == 0 ) - { - // Yes, the line from B can be moved. - (*i3b).lineB = -1; // This might leave an empty line: removed later. - (*i3b).bAEqB = false; - (*i3b).bAEqC = false; - (*i3b).bBEqC = false; - //(*i3b).lineC = -1; - (*i3c).lineB = lineB; - (*i3c).bBEqC = true; - } - } - - else if( i3b1==i3c && !(*i3b).bAEqC) - { - Diff3LineList::iterator i3 = i3b; - int nofDisturbingLines = 0; - while( i3 != i3c && i3!=d3ll.end() ) - { - if ( (*i3).lineC != -1 ) - ++nofDisturbingLines; - ++i3; - } - - if ( nofDisturbingLines>0 && nofDisturbingLines < d.nofEquals ) - { - // Move the disturbing lines up, out of sight. - i3 = i3b; - while( i3 != i3c ) - { - if ( (*i3).lineC != -1 ) - { - Diff3Line d3l; - d3l.lineC = (*i3).lineC; - (*i3).lineC = -1; - (*i3).bAEqC = false; - (*i3).bBEqC = false; - d3ll.insert( i3b, d3l ); - } - ++i3; - - } - nofDisturbingLines=0; - } - - if ( nofDisturbingLines == 0 ) - { - // Yes, the line from C can be moved. - (*i3c).lineC = -1; // This might leave an empty line: removed later. - (*i3c).bAEqC = false; - (*i3c).bBEqC = false; - //(*i3c).lineB = -1; - (*i3b).lineC = lineC; - (*i3b).bBEqC = true; - } - } - } - - --d.nofEquals; - ++lineB; - ++lineC; - ++i3b; - ++i3c; - } - else if ( d.diff1>0 ) - { - Diff3LineList::iterator i3 = i3b; - while( (*i3).lineB!=lineB ) - ++i3; - if( i3 != i3b && (*i3).bAEqB==false ) - { - // Take this line and move it up as far as possible - d3l.lineB = lineB; - d3ll.insert( i3b, d3l ); - (*i3).lineB = -1; - } - else - { - i3b=i3; - } - --d.diff1; - ++lineB; - ++i3b; - - if( d.diff2>0 ) - { - --d.diff2; - ++lineC; - } - } - else if ( d.diff2>0 ) - { - --d.diff2; - ++lineC; - } - } -/* - Diff3LineList::iterator it = d3ll.begin(); - int li=0; - for( ; it!=d3ll.end(); ++it, ++li ) - { - printf( "%4d %4d %4d %4d A%c=B A%c=C B%c=C\n", - li, (*it).lineA, (*it).lineB, (*it).lineC, - (*it).bAEqB ? '=' : '!', (*it).bAEqC ? '=' : '!', (*it).bBEqC ? '=' : '!' ); - } - printf("\n");*/ -} - -// Fourth step -void calcDiff3LineListTrim( - Diff3LineList& d3ll, LineData* pldA, LineData* pldB, LineData* pldC - ) -{ - const Diff3Line d3l_empty; - d3ll.remove( d3l_empty ); - - Diff3LineList::iterator i3 = d3ll.begin(); - Diff3LineList::iterator i3A = d3ll.begin(); - Diff3LineList::iterator i3B = d3ll.begin(); - Diff3LineList::iterator i3C = d3ll.begin(); - - - int line=0; - int lineA=0; - int lineB=0; - int lineC=0; - - // The iterator i3 and the variable line look ahead. - // The iterators i3A, i3B, i3C and corresponding lineA, lineB and lineC stop at empty lines, if found. - // If possible, then the texts from the look ahead will be moved back to the empty places. - - for( ; i3!=d3ll.end(); ++i3, ++line ) - { - - if( line>lineA && (*i3).lineA != -1 && (*i3A).lineB!=-1 && (*i3A).bBEqC && - - equal( pldA[(*i3).lineA], pldB[(*i3A).lineB], false )) - { - // Empty space for A. A matches B and C in the empty line. Move it up. - (*i3A).lineA = (*i3).lineA; - (*i3A).bAEqB = true; - (*i3A).bAEqC = true; - (*i3).lineA = -1; - (*i3).bAEqB = false; - (*i3).bAEqC = false; - ++i3A; - ++lineA; - } - - if( line>lineB && (*i3).lineB != -1 && (*i3B).lineA!=-1 && (*i3B).bAEqC && - equal( pldB[(*i3).lineB], pldA[(*i3B).lineA], false )) - { - // Empty space for B. B matches A and C in the empty line. Move it up. - (*i3B).lineB = (*i3).lineB; - (*i3B).bAEqB = true; - (*i3B).bBEqC = true; - (*i3).lineB = -1; - (*i3).bAEqB = false; - (*i3).bBEqC = false; - ++i3B; - ++lineB; - } - - if( line>lineC && (*i3).lineC != -1 && (*i3C).lineA!=-1 && (*i3C).bAEqB && - equal( pldC[(*i3).lineC], pldA[(*i3C).lineA], false )) - { - // Empty space for C. C matches A and B in the empty line. Move it up. - (*i3C).lineC = (*i3).lineC; - (*i3C).bAEqC = true; - (*i3C).bBEqC = true; - (*i3).lineC = -1; - (*i3).bAEqC = false; - (*i3).bBEqC = false; - ++i3C; - ++lineC; - } - - if( line>lineA && (*i3).lineA != -1 && !(*i3).bAEqB && !(*i3).bAEqC ) - { - // Empty space for A. A doesn't match B or C. Move it up. - (*i3A).lineA = (*i3).lineA; - (*i3).lineA = -1; - ++i3A; - ++lineA; - } - - if( line>lineB && (*i3).lineB != -1 && !(*i3).bAEqB && !(*i3).bBEqC ) - { - // Empty space for B. B matches neither A nor C. Move B up. - (*i3B).lineB = (*i3).lineB; - (*i3).lineB = -1; - ++i3B; - ++lineB; - } - - if( line>lineC && (*i3).lineC != -1 && !(*i3).bAEqC && !(*i3).bBEqC ) - { - // Empty space for C. C matches neither A nor B. Move C up. - (*i3C).lineC = (*i3).lineC; - (*i3).lineC = -1; - ++i3C; - ++lineC; - } - - if( line>lineA && line>lineB && (*i3).lineA != -1 && (*i3).bAEqB && !(*i3).bAEqC ) - { - // Empty space for A and B. A matches B, but not C. Move A & B up. - Diff3LineList::iterator i = lineA > lineB ? i3A : i3B; - int l = lineA > lineB ? lineA : lineB; - (*i).lineA = (*i3).lineA; - (*i).lineB = (*i3).lineB; - (*i).bAEqB = true; - - (*i3).lineA = -1; - (*i3).lineB = -1; - (*i3).bAEqB = false; - i3A = i; - i3B = i; - ++i3A; - ++i3B; - lineA=l+1; - lineB=l+1; - } - else if( line>lineA && line>lineC && (*i3).lineA != -1 && (*i3).bAEqC && !(*i3).bAEqB ) - { - // Empty space for A and C. A matches C, but not B. Move A & C up. - Diff3LineList::iterator i = lineA > lineC ? i3A : i3C; - int l = lineA > lineC ? lineA : lineC; - (*i).lineA = (*i3).lineA; - (*i).lineC = (*i3).lineC; - (*i).bAEqC = true; - - (*i3).lineA = -1; - (*i3).lineC = -1; - (*i3).bAEqC = false; - i3A = i; - i3C = i; - ++i3A; - ++i3C; - lineA=l+1; - lineC=l+1; - } - else if( line>lineB && line>lineC && (*i3).lineB != -1 && (*i3).bBEqC && !(*i3).bAEqC ) - { - // Empty space for B and C. B matches C, but not A. Move B & C up. - Diff3LineList::iterator i = lineB > lineC ? i3B : i3C; - int l = lineB > lineC ? lineB : lineC; - (*i).lineB = (*i3).lineB; - (*i).lineC = (*i3).lineC; - (*i).bBEqC = true; - - (*i3).lineB = -1; - (*i3).lineC = -1; - (*i3).bBEqC = false; - i3B = i; - i3C = i; - ++i3B; - ++i3C; - lineB=l+1; - lineC=l+1; - } - - if ( (*i3).lineA != -1 ) - { - lineA = line+1; - i3A = i3; - ++i3A; - } - if ( (*i3).lineB != -1 ) - { - lineB = line+1; - i3B = i3; - ++i3B; - } - if ( (*i3).lineC != -1 ) - { - lineC = line+1; - i3C = i3; - ++i3C; - } - } - - d3ll.remove( d3l_empty ); - -/* - - Diff3LineList::iterator it = d3ll.begin(); - int li=0; - for( ; it!=d3ll.end(); ++it, ++li ) - { - printf( "%4d %4d %4d %4d A%c=B A%c=C B%c=C\n", - li, (*it).lineA, (*it).lineB, (*it).lineC, - (*it).bAEqB ? '=' : '!', (*it).bAEqC ? '=' : '!', (*it).bBEqC ? '=' : '!' ); - - } -*/ -} - - -// Just make sure that all input lines are in the output too, exactly once. -void debugLineCheck( Diff3LineList& d3ll, int size, int idx ) -{ - Diff3LineList::iterator it = d3ll.begin(); - - - int i=0; - - for ( it = d3ll.begin(); it!= d3ll.end(); ++it ) - { - int l; - if (idx==1) l=(*it).lineA; - else if (idx==2) l=(*it).lineB; - else if (idx==3) l=(*it).lineC; - else assert(false); - - if ( l!=-1 ) - { - if( l!=i ) - { - KMessageBox::error(0, i18n( - "Data loss error:\n" - "If it is reproducable please contact the author.\n" - ), "Severe internal Error" ); - assert(false); - cerr << "Severe Internal Error.\n"; - exit(-1); - } - ++i; - } - } - - if( size!=i ) - { - KMessageBox::error(0, i18n( - "Data loss error:\n" - "If it is reproducable please contact the author.\n" - ), "Severe internal Error" ); - assert(false); - cerr << "Severe Internal Error.\n"; - exit(-1); - } -} - - -void fineDiff( - Diff3LineList& diff3LineList, - int selector, - LineData* v1, - LineData* v2 - ) -{ - // Finetuning: Diff each line with deltas - Diff3LineList::iterator i; - int k1=0; - int k2=0; - for( i= diff3LineList.begin(); i!= diff3LineList.end(); ++i) - { - if (selector==1){ k1=i->lineA; k2=i->lineB; } - else if (selector==2){ k1=i->lineB; k2=i->lineC; } - else if (selector==3){ k1=i->lineC; k2=i->lineA; } - else assert(false); - - if( k1!=-1 && k2!=-1 ) - { - if ( v1[k1].size != v2[k2].size || memcmp( v1[k1].pLine, v2[k2].pLine, v1[k1].size)!=0 ) - { - DiffList* pDiffList = new DiffList; - calcDiff( v1[k1].pLine, v1[k1].size, v2[k2].pLine, v2[k2].size, *pDiffList, 2 ); - - // Optimize the diff list. - DiffList::iterator dli; - for( dli = pDiffList->begin(); dli!=pDiffList->end(); ++dli) - { - if( dli->nofEquals < 4 && (dli->diff1>0 || dli->diff2>0) ) - { - dli->diff1 += dli->nofEquals; - dli->diff2 += dli->nofEquals; - dli->nofEquals = 0; - } - } - - if (selector==1){ delete (*i).pFineAB; (*i).pFineAB = pDiffList; } - else if (selector==2){ delete (*i).pFineBC; (*i).pFineBC = pDiffList; } - else if (selector==3){ delete (*i).pFineCA; (*i).pFineCA = pDiffList; } - else assert(false); - } - } - } -} \ No newline at end of file
--- a/kdiff3/kdiff3/diff.h Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,731 +0,0 @@ -/*************************************************************************** - diff.h - description - ------------------- - begin : Mon Mar 18 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:17 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#ifndef DIFF_H -#define DIFF_H - -#include <qwidget.h> -#include <qpixmap.h> -#include <qtimer.h> -#include <qframe.h> -#include <list> -#include <vector> - -typedef unsigned char UINT8; -typedef unsigned short UINT16; -typedef unsigned int UINT32; - - -// Each range with matching elements is followed by a range with differences on either side. -// Then again range of matching elements should follow. -struct Diff -{ - int nofEquals; - - int diff1; - int diff2; - - Diff(int eq, int d1, int d2){nofEquals=eq; diff1=d1; diff2=d2; } -}; - -typedef std::list<Diff> DiffList; - -struct Diff3Line -{ - int lineA; - int lineB; - int lineC; - - bool bAEqC; - bool bBEqC; - bool bAEqB; - - DiffList* pFineAB; - DiffList* pFineBC; - DiffList* pFineCA; - - Diff3Line() - { - lineA=-1; lineB=-1; lineC=-1; - bAEqC=false; bAEqB=false; bBEqC=false; - pFineAB=0; pFineBC=0; pFineCA=0; - } - - ~Diff3Line() - { - if (pFineAB!=0) delete pFineAB; - if (pFineBC!=0) delete pFineBC; - if (pFineCA!=0) delete pFineCA; - pFineAB=0; pFineBC=0; pFineCA=0; - } - - bool operator==( const Diff3Line& d3l ) - { - return lineA == d3l.lineA && lineB == d3l.lineB && lineC == d3l.lineC - && bAEqB == d3l.bAEqB && bAEqC == d3l.bAEqC && bBEqC == d3l.bBEqC; - } -}; - -typedef std::list<Diff3Line> Diff3LineList; - -void calcDiff3LineListUsingAB( - const DiffList* pDiffListAB, - Diff3LineList& d3ll - ); - -void calcDiff3LineListUsingAC( - const DiffList* pDiffListBC, - Diff3LineList& d3ll - ); - -void calcDiff3LineListUsingBC( - const DiffList* pDiffListBC, - Diff3LineList& d3ll - ); - -struct LineData -{ - const char* pLine; - int size; - - LineData(){ pLine=0; size=0; } - int width(); // Calcs width considering tabs. -}; - -void calcDiff3LineListTrim( Diff3LineList& d3ll, LineData* pldA, LineData* pldB, LineData* pldC ); - -void debugLineCheck( Diff3LineList& d3ll, int size, int idx ); - -class QStatusBar; - - - - - - -class Selection -{ -public: - Selection(){ reset(); oldLastLine=-1; oldFirstLine=-1; } - int firstLine; - int firstPos; - int lastLine; - int lastPos; - int oldLastLine; - int oldFirstLine; - bool bSelectionContainsData; - void reset(){ - oldFirstLine=firstLine; - oldLastLine =lastLine; - firstLine=-1; - bSelectionContainsData = false; - } - void start( int l, int p ) { firstLine = l; firstPos = p; } - void end( int l, int p ) { - if ( oldLastLine == -1 ) - oldLastLine = lastLine; - lastLine = l; - lastPos = p; - } - bool within( int l, int p ); - bool lineWithin( int l ); - int firstPosInLine(int l); - int lastPosInLine(int l); - int beginLine(){ return min(firstLine,lastLine); } - int endLine(){ return max(firstLine,lastLine); } - int beginPos() { return firstLine==lastLine ? min(firstPos,lastPos) : - firstLine<lastLine ? firstPos : lastPos; } - int endPos() { return firstLine==lastLine ? max(firstPos,lastPos) : - firstLine<lastLine ? lastPos : firstPos; } -}; - -class OptionDialog; - -class DiffTextWindow : public QWidget -{ - Q_OBJECT -public: - DiffTextWindow( - QWidget* pParent, - QStatusBar* pStatusBar, - OptionDialog* pOptionDialog - ); - void init( - const char* pFilename, - LineData* pLineData, - int size, - const Diff3LineList* pDiff3LineList, - int winIdx, - bool bTriple - ); - virtual void mousePressEvent ( QMouseEvent * ); - virtual void mouseReleaseEvent ( QMouseEvent * ); - virtual void mouseMoveEvent ( QMouseEvent * ); - virtual void mouseDoubleClickEvent ( QMouseEvent * e ); - void convertToLinePos( int x, int y, int& line, int& pos ); - - virtual void paintEvent( QPaintEvent* ); - - //void setData( const char* pText); - - virtual void resizeEvent( QResizeEvent* ); - - QString getSelection(); - int getFirstLine() { return m_firstLine; } - - int getNofColumns(); - int getNofLines(); - -signals: - void resizeSignal( int nofVisibleColumns, int nofVisibleLines ); - void scroll( int deltaX, int deltaY ); - void newSelection(); - void selectionEnd(); - void setFastSelectorLine( int line ); - -public slots: - void setFirstLine( int line ); - void setFirstColumn( int col ); - void resetSelection(); - void setFastSelectorRange( int line1, int nofLines ); -private: - LineData* m_pLineData; - int m_size; - const char* m_pFilename; - - const Diff3LineList* m_pDiff3LineList; - - OptionDialog* m_pOptionDialog; - QColor m_cThis; - QColor m_cDiff1; - QColor m_cDiff2; - QColor m_cDiffBoth; - - int m_fastSelectorLine1; - int m_fastSelectorNofLines; - - bool m_bTriple; - int m_winIdx; - int m_firstLine; - int m_oldFirstLine; - int m_oldFirstColumn; - int m_firstColumn; - - int m_visibleColumns; - int m_visibleLines; - - void getLineInfo( - const Diff3Line& d, - int& lineIdx, - DiffList*& pFineDiff1, DiffList*& pFineDiff2, // return values - int& changed, int& changed ); - - QCString getString( int line ); - - void writeLine( - QPainter& p, const LineData* pld, - const DiffList* pLineDiff1, const DiffList* pLineDiff2, int line, - int whatChanged, int whatChanged2 ); - - QStatusBar* m_pStatusBar; - - Selection selection; - - int m_scrollDeltaX; - int m_scrollDeltaY; - virtual void timerEvent(QTimerEvent*); - bool m_bMyUpdate; - void myUpdate(int afterMilliSecs ); - - QRect m_invalidRect; -}; - - - -class Overview : public QWidget -{ - Q_OBJECT -public: - Overview( QWidget* pParent, Diff3LineList* pDiff3LineList, - OptionDialog* pOptions, bool bTripleDiff ); - void setRange( int firstLine, int pageHeight ); - -public slots: - void setFirstLine(int firstLine); -signals: - void setLine(int); -private: - const Diff3LineList* m_pDiff3LineList; - OptionDialog* m_pOptions; - bool m_bTripleDiff; - int m_firstLine; - int m_pageHeight; - QPixmap m_pixmap; - - virtual void paintEvent( QPaintEvent* e ); - virtual void mousePressEvent( QMouseEvent* e ); - virtual void mouseMoveEvent( QMouseEvent* e ); -}; - - -enum e_MergeDetails -{ - eDefault, - eNoChange, - eBChanged, - eCChanged, - eBCChanged, // conflict - eBCChangedAndEqual, // possible conflict - eBDeleted, - eCDeleted, - eBCDeleted, // possible conflict - - eBChanged_CDeleted, // conflict - eCChanged_BDeleted, // conflict - eBAdded, - eCAdded, - eBCAdded, // conflict - eBCAddedAndEqual // possible conflict -}; - -void mergeOneLine( const Diff3Line& d, e_MergeDetails& mergeDetails, bool& bConflict, bool& bLineRemoved, int& src, bool bTwoInputs ); - - -class MergeResultWindow : public QWidget -{ - Q_OBJECT -public: - - - MergeResultWindow( - QWidget* pParent, - const LineData* pLineDataA, - const LineData* pLineDataB, - const LineData* pLineDataC, - const Diff3LineList* pDiff3LineList, - QString fileName, - OptionDialog* pOptionDialog - ); - - bool saveDocument( const QString& fileName ); - void choose(int selector); - - int getNofColumns(); - int getNofLines(); - int getNofVisibleColumns(); - int getNofVisibleLines(); - virtual void resizeEvent( QResizeEvent* e ); - virtual void keyPressEvent( QKeyEvent* e ); - QString getSelection(); - void resetSelection(); -public slots: - void setFirstLine(int firstLine); - void setFirstColumn(int firstCol); - - void slotGoTop(); - void slotGoBottom(); - void slotGoPrevDelta(); - void slotGoNextDelta(); - void slotGoPrevConflict(); - - void slotGoNextConflict(); - void slotChooseA(); - void slotChooseB(); - void slotChooseC(); - - void slotSetFastSelectorLine(int); - - -signals: - void scroll( int deltaX, int deltaY ); - void modified(); - void savable( bool bSavable ); - void setFastSelectorRange( int line1, int nofLines ); - - void sourceMask( int srcMask, int enabledMask ); - void resizeSignal(); - void selectionEnd(); - void newSelection(); - -private: - void merge(); - - OptionDialog* m_pOptionDialog; - - const LineData* m_pldA; - const LineData* m_pldB; - const LineData* m_pldC; - - const Diff3LineList* m_pDiff3LineList; - -private: - - class MergeEditLine - { - public: - MergeEditLine(){ m_src=0; m_bLineRemoved=false; } - void setConflict() { m_src=0; m_bLineRemoved=false; m_str=QCString(); } - bool isConflict() { return m_src==0 && !m_bLineRemoved && m_str.isNull(); } - void setRemoved(int src=0) { m_src=src; m_bLineRemoved=true; m_str=QCString(); } - bool isRemoved() { return m_bLineRemoved; } - bool isEditableText() { return !isConflict() && !isRemoved(); } - void setString( const QCString& s ){ m_str=s; m_bLineRemoved=false; m_src=0; } - const char* getString( const MergeResultWindow*, int& size ); - bool isModified() { return ! m_str.isNull() || (m_bLineRemoved && m_src==0); } - void setSource( int src, Diff3LineList::const_iterator i, bool bLineRemoved ) - { - m_src=src; m_id3l=i; m_bLineRemoved =bLineRemoved; - } - int src() { return m_src; } - Diff3LineList::const_iterator id3l(){return m_id3l;} - // getString() is implemented as MergeResultWindow::getString() - private: - Diff3LineList::const_iterator m_id3l; - int m_src; // 1, 2 or 3 for A, B or C respectively, or 0 when line is from neither source. - QCString m_str; // String when modified by user or null-string when orig data is used. - bool m_bLineRemoved; - }; - typedef list<MergeEditLine> MergeEditLineList; - - friend class MergeEditLine; - - struct MergeLine - { - MergeLine() - { srcSelect=0; mergeDetails=eDefault; d3lLineIdx = -1; srcRangeLength=0; bConflict=false; bDelta=false;} - Diff3LineList::const_iterator id3l; - e_MergeDetails mergeDetails; - int d3lLineIdx; // Needed to show the correct window pos. - int srcRangeLength; // how many src-lines have this properties - bool bConflict; - bool bDelta; - int srcSelect; - MergeEditLineList mergeEditLineList; - }; - -private: - static bool sameKindCheck( const MergeLine& ml1, const MergeLine& ml2 ); - - - typedef list<MergeLine> MergeLineList; - MergeLineList m_mergeLineList; - - - MergeLineList::iterator m_currentMergeLineIt; - int m_currentPos; - - enum e_Direction { eUp, eDown }; - enum e_EndPoint { eDelta, eConflict, eLine, eEnd }; - void go( e_Direction eDir, e_EndPoint eEndPoint ); - void calcIteratorFromLineNr( - int line, - MergeLineList::iterator& mlIt, - MergeEditLineList::iterator& melIt - - ); - - virtual void paintEvent( QPaintEvent* e ); - - void myUpdate(int afterMilliSecs); - virtual void timerEvent(QTimerEvent*); - void writeLine( - QPainter& p, int line, const char* pStr, int size, - int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved - ); - void setFastSelector(MergeLineList::iterator i); - void convertToLinePos( int x, int y, int& line, int& pos ); - virtual void mousePressEvent ( QMouseEvent* e ); - virtual void mouseDoubleClickEvent ( QMouseEvent* e ); - virtual void mouseReleaseEvent ( QMouseEvent * ); - virtual void mouseMoveEvent ( QMouseEvent * ); - - QPixmap m_pixmap; - int m_firstLine; - int m_firstColumn; - int m_nofColumns; - int m_nofLines; - bool m_bMyUpdate; - bool m_bInsertMode; - QString m_fileName; - bool m_bModified; - void setModified(); - - int m_scrollDeltaX; - int m_scrollDeltaY; - int m_cursorXPos; - int m_cursorYPos; - int m_cursorOldXPos; - bool m_bCursorOn; // blinking on and off each second - QTimer m_cursorTimer; - - Selection m_selection; - - bool deleteSelection2( const char*& ps, int& stringLength, int& x, int& y, - MergeLineList::iterator& mlIt, MergeEditLineList::iterator& melIt ); -public slots: - void deleteSelection(); - void pasteClipboard(); -private slots: - void slotCursorUpdate(); -}; - -void fineDiff( - Diff3LineList& diff3LineList, - int selector, - LineData* v1, - LineData* v2 - ); - -const char* readFile( const char* filename, int& size ); - -int preprocess( const char* p, int size, std::vector<LineData>& v ); - -bool equal( const LineData& l1, const LineData& l2, bool bStrict ); - - - -inline bool equal( char c1, char c2, bool bStrict ) -{ - // If bStrict then white space doesn't match - if ( bStrict && ( c1==' ' || c1=='\t' ) ) - return false; - - return c1==c2; -} - - -template <class T> -void calcDiff( const T* p1, int size1, const T* p2, int size2, DiffList& diffList, int match=1 ) -{ - - diffList.clear(); - - const T* p1start = p1; - const T* p2start = p2; - const T* p1end=p1+size1; - const T* p2end=p2+size2; - for(;;) - { - int nofEquals = 0; - while( p1!=p1end && p2!=p2end && equal(*p1, *p2, false) ) - { - ++p1; - ++p2; - ++nofEquals; - } - - bool bBestValid=false; - int bestI1=0; - int bestI2=0; - int i1=0; - int i2=0; - for( i1=0; ; ++i1 ) - { - if ( &p1[i1]==p1end || ( bBestValid && i1>= bestI1+bestI2)) - { - break; - } - for(i2=0;;++i2) - { - if( &p2[i2]==p2end || ( bBestValid && i1+i2>=bestI1+bestI2) ) - { - break; - } - else if( equal( p2[i2], p1[i1], true ) && - ( match==1 || abs(i1-i2)<3 || ( &p2[i2+1]==p2end && &p1[i1+1]==p1end ) || - ( &p2[i2+1]!=p2end && &p1[i1+1]!=p1end && equal( p2[i2+1], p1[i1+1], false )) - ) - ) - { - if ( i1+i2 < bestI1+bestI2 || bBestValid==false ) - { - bestI1 = i1; - bestI2 = i2; - bBestValid = true; - break; - } - } - } - } - - // The match was found using the strict search. Go back if there are non-strict - // matches. - while( bestI1>=1 && bestI2>=1 && equal( p1[bestI1-1], p2[bestI2-1], false ) ) - { - --bestI1; - --bestI2; - } - - bool bEndReached = false; - if (bBestValid) - { - // continue somehow - Diff d(nofEquals, bestI1, bestI2); - diffList.push_back( d ); - - p1 += bestI1; - p2 += bestI2; - } - else - { - // Nothing else to match. - Diff d(nofEquals, p1end-p1, p2end-p2); - diffList.push_back( d ); - - bEndReached = true; //break; - } - - // Sometimes the algorithm that chooses the first match unfortunately chooses - // a match where later actually equal parts don't match anymore. - // A different match could be achieved, if we start at the end. - // Do it, if it would be a better match. - int nofUnmatched = 0; - const T* pu1 = p1-1; - const T* pu2 = p2-1; - while ( pu1>=p1start && pu2>=p2start && equal( *pu1, *pu2, false ) ) - { - ++nofUnmatched; - --pu1; - --pu2; - } - - - Diff d = diffList.back(); - if ( nofUnmatched > 0 ) - { - // We want to go backwards the nofUnmatched elements and redo - // the matching - d = diffList.back(); - Diff origBack = d; - diffList.pop_back(); - - while ( nofUnmatched > 0 ) - { - if ( d.diff1 > 0 && d.diff2 > 0 ) - { - --d.diff1; - --d.diff2; - --nofUnmatched; - } - else if ( d.nofEquals > 0 ) - { - --d.nofEquals; - --nofUnmatched; - } - - if ( d.nofEquals==0 && (d.diff1==0 || d.diff2==0) && nofUnmatched>0 ) - { - if ( diffList.empty() ) - break; - d.nofEquals += diffList.back().nofEquals; - d.diff1 += diffList.back().diff1; - d.diff2 += diffList.back().diff2; - diffList.pop_back(); - bEndReached = false; - } - } - - if ( bEndReached ) - diffList.push_back( origBack ); - else - { - p1 = pu1 + 1 + nofUnmatched; - p2 = pu2 + 1 + nofUnmatched; - diffList.push_back( d ); - } - } - if ( bEndReached ) - break; - } - -#ifndef NDEBUG - // Verify difflist - { - int l1=0; - int l2=0; - DiffList::iterator i; - for( i = diffList.begin(); i!=diffList.end(); ++i ) - { - l1+= i->nofEquals + i->diff1; - l2+= i->nofEquals + i->diff2; - } - - //if( l1!=p1-p1start || l2!=p2-p2start ) - if( l1!=size1 || l2!=size2 ) - assert( false ); - } -#endif -} - - -template <class T> -T min3( T d1, T d2, T d3 ) -{ - if ( d1 < d2 && d1 < d3 ) return d1; - if ( d2 < d3 ) return d2; - return d3; -} - -template <class T> -T max3( T d1, T d2, T d3 ) -{ - - if ( d1 > d2 && d1 > d3 ) return d1; - - if ( d2 > d3 ) return d2; - return d3; - -} - -template <class T> -T minMaxLimiter( T d, T minimum, T maximum ) -{ - assert(minimum<=maximum); - if ( d < minimum ) return minimum; - if ( d > maximum ) return maximum; - return d; -} - -/** Returns the number of equivalent spaces at position outPos. -*/ -inline int tabber( int outPos, int tabSize ) -{ - return tabSize - ( outPos % tabSize ); -} - -/** Returns a line number where the linerange [line, line+nofLines] can - be displayed best. If it fits into the currently visible range then - the returned value is the current firstLine. -*/ -int getBestFirstLine( int line, int nofLines, int firstLine, int visibleLines ); - -extern int g_tabSize; -extern bool g_bIgnoreWhiteSpace; -extern bool g_bIgnoreTrivialMatches; - -// Cursor conversions that consider g_tabSize. -int convertToPosInText( const char* p, int size, int posOnScreen ); -int convertToPosOnScreen( const char* p, int posInText ); -void calcTokenPos( const char* p, int size, int posOnScreen, int& pos1, int& pos2 ); -#endif \ No newline at end of file
--- a/kdiff3/kdiff3/difftextwindow.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,918 +0,0 @@ -/*************************************************************************** - difftextwindow.cpp - description - ------------------- - begin : Mon Apr 8 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:14 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include <iostream> -#include "diff.h" -#include "merger.h" -#include <qpainter.h> -#include <assert.h> -#include <qpixmap.h> -#include <qstatusbar.h> -#include <qapplication.h> -#include <optiondialog.h> - -#define leftInfoWidth 4 // Nr of information columns on left side - -using namespace std; - -DiffTextWindow::DiffTextWindow( - QWidget* pParent, - QStatusBar* pStatusBar, - OptionDialog* pOptionDialog - ) -: QWidget(pParent, 0, WRepaintNoErase) -{ - setFocusPolicy( QWidget::ClickFocus ); - - m_pOptionDialog = pOptionDialog; - init( 0, 0, 0, 0, 0, false ); - - setBackgroundMode( PaletteBase ); - setMinimumSize(QSize(20,20)); - - m_pStatusBar = pStatusBar; - - m_fastSelectorLine1 = 0; - m_fastSelectorNofLines = 0; -} - - -void DiffTextWindow::init( - const char* pFilename, - LineData* pLineData, - int size, - const Diff3LineList* pDiff3LineList, - int winIdx, - bool bTriple - ) -{ - m_pFilename = pFilename; - m_pLineData = pLineData; - m_size = size; - m_pDiff3LineList = pDiff3LineList; - m_winIdx = winIdx; - - m_firstLine = 0; - m_oldFirstLine = -1; - m_firstColumn = 0; - m_oldFirstColumn = -1; - m_bTriple = bTriple; - m_scrollDeltaX=0; - m_scrollDeltaY=0; - m_bMyUpdate = false; -} - -void DiffTextWindow::setFirstLine(int firstLine) -{ - m_firstLine = max(0,firstLine); - myUpdate(0); // Immediately -} - -void DiffTextWindow::setFirstColumn(int firstCol) -{ - m_firstColumn = max(0,firstCol); - myUpdate(0); // Immediately -} - -int DiffTextWindow::getNofColumns() -{ - int nofColumns = 0; - for( int i = 0; i< m_size; ++i ) - { - if ( m_pLineData[i].width() > nofColumns ) - nofColumns = m_pLineData[i].width(); - } - return nofColumns; -} - -int DiffTextWindow::getNofLines() -{ - return m_pDiff3LineList->size(); -} - -/** Returns a line number where the linerange [line, line+nofLines] can - be displayed best. If it fits into the currently visible range then - the returned value is the current firstLine. -*/ -int getBestFirstLine( int line, int nofLines, int firstLine, int visibleLines ) -{ - int newFirstLine = firstLine; - if ( line < firstLine || line + nofLines > firstLine + visibleLines ) - { - if ( nofLines > visibleLines || nofLines <= ( 2*visibleLines / 3 - 1) ) - newFirstLine = line - visibleLines/3; - else - newFirstLine = line - (visibleLines - nofLines); - } - - return newFirstLine; -} - - -void DiffTextWindow::setFastSelectorRange( int line1, int nofLines ) -{ - m_fastSelectorLine1 = line1; - m_fastSelectorNofLines = nofLines; - - int newFirstLine = getBestFirstLine( line1, nofLines, m_firstLine, m_visibleLines ); - if ( newFirstLine != m_firstLine ) - { - scroll( 0, newFirstLine - m_firstLine ); - } - - update(); -} - -static void showStatusLine(int line, int winIdx, const char* pFilename, const Diff3LineList* pd3ll, QStatusBar* sb) -{ - int l=0; - Diff3LineList::const_iterator i; - for ( i=pd3ll->begin();i!=pd3ll->end() && l!=line; ++i,++l ) - { - } - if(i!=pd3ll->end()) - { - if ( winIdx==1 ) l=(*i).lineA; - else if ( winIdx==2 ) l=(*i).lineB; - else if ( winIdx==3 ) l=(*i).lineC; - else assert(false); - - QString s; - if ( l!=-1 ) - s.sprintf("File %s: Line %d", pFilename, l+1 ); - else - s.sprintf("File %s: Line not available", pFilename ); - sb->message(s); - } -} - - -void DiffTextWindow::mousePressEvent ( QMouseEvent* e ) -{ - if ( e->button() == LeftButton ) - { - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - if ( pos < m_firstColumn ) - { - emit setFastSelectorLine( line ); - selection.firstLine = -1; // Disable current selection - } - else - { // Selection - resetSelection(); - selection.start( line, pos ); - selection.end( line, pos ); - - showStatusLine( line, m_winIdx, m_pFilename, m_pDiff3LineList, m_pStatusBar ); - } - } -} - -bool isCTokenChar( char c ) -{ - return (c=='_') || - ( c>='A' && c<='Z' ) || ( c>='a' && c<='z' ) || - (c>='0' && c<='9'); -} - -/// Calculate where a token starts and ends, given the x-position on screen. -void calcTokenPos( const char* p, int size, int posOnScreen, int& pos1, int& pos2 ) -{ - // Cursor conversions that consider g_tabSize - int pos = convertToPosInText( p, size, max( 0, posOnScreen ) ); - if ( pos>=size ) - { - pos1=size; - pos2=size; - return; - } - - pos1 = pos; - pos2 = pos+1; - - if( isCTokenChar( p[pos1] ) ) - { - while( pos1>=0 && isCTokenChar( p[pos1] ) ) - --pos1; - ++pos1; - - while( pos2<size && isCTokenChar( p[pos2] ) ) - ++pos2; - } -} - -void DiffTextWindow::mouseDoubleClickEvent( QMouseEvent* e ) -{ - if ( e->button() == LeftButton ) - { - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - - // Get the string data of the current line - QCString s = getString( line ); - - if ( ! s.isEmpty() ) - { - int pos1, pos2; - calcTokenPos( s, s.length(), pos, pos1, pos2 ); - - resetSelection(); - selection.start( line, convertToPosOnScreen( s, pos1 ) ); - selection.end( line, convertToPosOnScreen( s, pos2 ) ); - update(); - // emit selectionEnd() happens in the mouseReleaseEvent. - showStatusLine( line, m_winIdx, m_pFilename, m_pDiff3LineList, m_pStatusBar ); - } - } -} - -void DiffTextWindow::mouseReleaseEvent ( QMouseEvent * e ) -{ - if ( e->button() == LeftButton ) - { - killTimers(); - if (selection.firstLine != -1 ) - { - emit selectionEnd(); - } - } -} - -void DiffTextWindow::mouseMoveEvent ( QMouseEvent * e ) -{ - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - if (selection.firstLine != -1 ) - { - selection.end( line, pos ); - myUpdate(0); - - showStatusLine( line, m_winIdx, m_pFilename, m_pDiff3LineList, m_pStatusBar ); - - // Scroll because mouse moved out of the window - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width('W'); - int topLineYOffset = fontHeight + 3; - int deltaX=0; - int deltaY=0; - if ( e->x() < leftInfoWidth*fontWidth ) deltaX=-1; - if ( e->x() > width() ) deltaX=+1; - if ( e->y() < topLineYOffset ) deltaY=-1; - if ( e->y() > height() ) deltaY=+1; - m_scrollDeltaX = deltaX; - m_scrollDeltaY = deltaY; - if ( deltaX != 0 || deltaY!= 0) - { - emit scroll( deltaX, deltaY ); - } - } -} - - -void DiffTextWindow::myUpdate(int afterMilliSecs) -{ - killTimers(); - m_bMyUpdate = true; - startTimer( afterMilliSecs ); -} - -void DiffTextWindow::timerEvent(QTimerEvent*) -{ - killTimers(); - - if ( m_bMyUpdate ) - { - paintEvent( 0 ); - m_bMyUpdate = false; - } - - if ( m_scrollDeltaX != 0 || m_scrollDeltaY != 0 ) - { - selection.end( selection.lastLine + m_scrollDeltaY, selection.lastPos + m_scrollDeltaX ); - emit scroll( m_scrollDeltaX, m_scrollDeltaY ); - killTimers(); - startTimer(50); - } -} - -void DiffTextWindow::resetSelection() -{ - selection.reset(); - update(); -} - -void DiffTextWindow::convertToLinePos( int x, int y, int& line, int& pos ) -{ - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width('W'); - int xOffset = (leftInfoWidth-m_firstColumn)*fontWidth; - int topLineYOffset = fontHeight + 3; - - int yOffset = topLineYOffset - m_firstLine * fontHeight; - - line = ( y - yOffset ) / fontHeight; - pos = ( x - xOffset ) / fontWidth; -} - -int Selection::firstPosInLine(int l) -{ - assert( firstLine != -1 ); - - int l1 = firstLine; - int l2 = lastLine; - int p1 = firstPos; - int p2 = lastPos; - if ( l1>l2 ){ swap(l1,l2); swap(p1,p2); } - if ( l1==l2 && p1>p2 ){ swap(p1,p2); } - - if ( l==l1 ) - return p1; - return 0; -} - -int Selection::lastPosInLine(int l) -{ - assert( firstLine != -1 ); - - int l1 = firstLine; - int l2 = lastLine; - int p1 = firstPos; - int p2 = lastPos; - if ( l1>l2 ){ swap(l1,l2); swap(p1,p2); } - if ( l1==l2 && p1>p2 ){ swap(p1,p2); } - - if ( l==l2 ) - return p2; - return INT_MAX; -} - -bool Selection::within( int l, int p ) -{ - if ( firstLine == -1 ) return false; - int l1 = firstLine; - int l2 = lastLine; - int p1 = firstPos; - int p2 = lastPos; - if ( l1>l2 ){ swap(l1,l2); swap(p1,p2); } - if ( l1==l2 && p1>p2 ){ swap(p1,p2); } - if( l1 <= l && l <= l2 ) - { - if ( l1==l2 ) - return p>=p1 && p<p2; - if ( l==l1 ) - return p>=p1; - if ( l==l2 ) - return p<p2; - return true; - } - return false; -} - -bool Selection::lineWithin( int l ) -{ - if ( firstLine == -1 ) return false; - int l1 = firstLine; - int l2 = lastLine; - - if ( l1>l2 ){ swap(l1,l2); } - - return ( l1 <= l && l <= l2 ); -} - -void DiffTextWindow::writeLine( - QPainter& p, - const LineData* pld, - const DiffList* pLineDiff1, - const DiffList* pLineDiff2, - int line, - int whatChanged, - int whatChanged2 - ) -{ - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontAscent = fm.ascent(); - int fontDescent = fm.descent(); - int fontWidth = fm.width('W'); - int topLineYOffset = fontHeight + 3; - - int xOffset = (leftInfoWidth - m_firstColumn)*fontWidth; - int yOffset = (line-m_firstLine) * fontHeight + topLineYOffset; - - QRect lineRect( 0, yOffset, width(), fontHeight ); - if ( ! m_invalidRect.intersects( lineRect ) ) - return; - -// QRect winRect = rect(); //p.window(); - if ( yOffset+fontHeight<0 || height() + fontHeight < yOffset ) - return; - - int changed = whatChanged; - if ( pLineDiff1 != 0 ) changed |= 1; - if ( pLineDiff2 != 0 ) changed |= 2; - - QColor c = m_pOptionDialog->m_fgColor; - if ( changed == 2 ) { - c = m_cDiff2; - } else if ( changed == 1 ) { - c = m_cDiff1; - } else if ( changed == 3 ) { - c = m_cDiffBoth; - } - - - if (pld!=0) - { - // First calculate the "changed" information for each character. - int i=0; - vector<UINT8> charChanged( pld->size ); - if ( pLineDiff1!=0 || pLineDiff2 != 0 ) - { - Merger merger( pLineDiff1, pLineDiff2 ); - while( ! merger.isEndReached() && i<pld->size ) - { - if ( i < pld->size ) - { - charChanged[i] = merger.whatChanged(); - ++i; - } - merger.next(); - } - } - - QCString s=" "; - // Convert tabs - int outPos = 0; - for( i=0; i<pld->size; ++i ) - { - int spaces = 1; - - if ( pld->pLine[i]=='\t' ) - { - spaces = tabber( outPos, g_tabSize ); - s[0] = ' '; - } - else - { - s[0] = pld->pLine[i]; - } - - QColor c = m_pOptionDialog->m_fgColor; - int cchanged = charChanged[i] | whatChanged; - - if ( cchanged == 2 ) { - c = m_cDiff2; - } else if ( cchanged == 1 ) { - c = m_cDiff1; - } else if ( cchanged == 3 ) { - c = m_cDiffBoth; - } - - QRect outRect( xOffset + fontWidth*outPos, yOffset, fontWidth*spaces, fontHeight ); - if ( m_invalidRect.intersects( outRect ) ) - { - - if( !selection.within( line, outPos ) ) - { - if( c!=m_pOptionDialog->m_fgColor ) - { - QColor lightc = m_pOptionDialog->m_diffBgColor; - p.fillRect( xOffset + fontWidth*outPos, yOffset, - fontWidth*spaces, fontHeight, lightc ); - } - - p.setPen( c ); - if ( s[0]==' ' && c!=m_pOptionDialog->m_fgColor && charChanged[i]!=0 ) - { - p.fillRect( xOffset + fontWidth*outPos, yOffset+fontAscent, - fontWidth*(spaces)-1, fontDescent+1, c ); - } - else - { - p.drawText( xOffset + fontWidth*outPos, yOffset + fontAscent, s ); - } - } - else - { - p.fillRect( xOffset + fontWidth*outPos, yOffset, - fontWidth*(spaces), fontHeight, colorGroup().highlight() ); - p.setPen( colorGroup().highlightedText() ); - p.drawText( xOffset + fontWidth*outPos, yOffset + fontAscent, s ); - - selection.bSelectionContainsData = true; - } - } - - outPos += spaces; - } - - if( selection.lineWithin( line ) && selection.lineWithin( line+1 ) ) - { - p.fillRect( xOffset + fontWidth*outPos, yOffset, - width(), fontHeight, colorGroup().highlight() ); - } - - } - - p.fillRect( 0, yOffset, leftInfoWidth*fontWidth-1, fontHeight, m_pOptionDialog->m_bgColor ); - - xOffset = 2*fontWidth; - p.setPen( m_pOptionDialog->m_fgColor ); - if ( pld!=0 ) - p.drawLine( xOffset +1, yOffset, xOffset +1, yOffset+fontHeight-1 ); - if ( c!=m_pOptionDialog->m_fgColor && whatChanged2==0 && whatChanged==0 ) - { - p.fillRect( 0, yOffset, xOffset-1, fontHeight, QBrush(c,Dense5Pattern) ); - } - else - { - p.fillRect( 0, yOffset, xOffset-1, fontHeight, c==m_pOptionDialog->m_fgColor ? m_pOptionDialog->m_bgColor : c ); - } - - int fastSelectorLine2 = m_fastSelectorLine1+m_fastSelectorNofLines - 1; - if (line>=m_fastSelectorLine1 && line<= fastSelectorLine2 ) - { - p.drawLine( xOffset + fontWidth-1, yOffset, xOffset + fontWidth-1, yOffset+fontHeight-1 ); - if ( line == m_fastSelectorLine1 ) - { - p.drawLine( xOffset + fontWidth-1, yOffset, xOffset + fontWidth+2, yOffset ); - } - if ( line == fastSelectorLine2 ) - { - p.drawLine( xOffset + fontWidth-1, yOffset+fontHeight-1, xOffset + fontWidth+2, yOffset+fontHeight-1 ); - } - } -} - -void DiffTextWindow::paintEvent( QPaintEvent* e ) -{ - if (e!=0) - { - m_invalidRect |= e->rect(); - } - - if ( m_winIdx==1 ) - { - m_cThis = m_pOptionDialog->m_colorA; - m_cDiff1 = m_pOptionDialog->m_colorB; - m_cDiff2 = m_pOptionDialog->m_colorC; - } - if ( m_winIdx==2 ) - { - m_cThis = m_pOptionDialog->m_colorB; - m_cDiff1 = m_pOptionDialog->m_colorC; - m_cDiff2 = m_pOptionDialog->m_colorA; - } - if ( m_winIdx==3 ) - { - m_cThis = m_pOptionDialog->m_colorC; - m_cDiff1 = m_pOptionDialog->m_colorA; - m_cDiff2 = m_pOptionDialog->m_colorB; - } - m_cDiffBoth = m_pOptionDialog->m_colorForConflict; // Conflict color - - if (font() != m_pOptionDialog->m_font ) - { - setFont(m_pOptionDialog->m_font); - } - - bool bOldSelectionContainsData = selection.bSelectionContainsData; - selection.bSelectionContainsData = false; - - int fontHeight = fontMetrics().height(); - int fontAscent = fontMetrics().ascent(); -// int fontDescent = fontMetrics().descent(); - int fontWidth = fontMetrics().width('W'); - - int topLineYOffset = fontHeight + 3; - int xOffset = leftInfoWidth * fontWidth; - - int firstLineToDraw = 0; - int lastLineToDraw = (height() - topLineYOffset ) / fontHeight; - if ( abs(m_oldFirstLine - m_firstLine)>=lastLineToDraw ) - { - m_oldFirstLine = -1; - m_invalidRect |= QRect( 0, topLineYOffset, width(), height() ); - } - - if ( m_oldFirstLine != -1 && m_oldFirstLine != m_firstLine ) - { - int deltaY = fontHeight * ( m_oldFirstLine - m_firstLine ); - if ( deltaY > 0 ) - { // Move down - bitBlt( this, 0, deltaY + topLineYOffset /*dy*/, this, 0, topLineYOffset /*sy*/, width(), height()- (deltaY + topLineYOffset), CopyROP, true); - lastLineToDraw = firstLineToDraw + ( m_oldFirstLine - m_firstLine); - m_invalidRect |= QRect( 0, topLineYOffset, width(), deltaY ); - } - else - { // Move up - bitBlt( this, 0, topLineYOffset /*dy*/, this, 0, -deltaY+topLineYOffset /*sy*/, width(), height()-(-deltaY+topLineYOffset), CopyROP, true); - firstLineToDraw = lastLineToDraw + ( m_oldFirstLine - m_firstLine); - m_invalidRect |= QRect( 0, height()+deltaY, width(), -deltaY ); - } - } - - if ( m_oldFirstColumn != -1 && m_oldFirstColumn != m_firstColumn ) - { - int deltaX = fontWidth * ( m_oldFirstColumn - m_firstColumn ); - if ( deltaX > 0 ) - { // Move right, scroll left - bitBlt( this, deltaX+xOffset, topLineYOffset, this, xOffset, topLineYOffset, width(), height(), CopyROP, true); - m_invalidRect |= - QRect( xOffset, topLineYOffset, deltaX, height() - topLineYOffset ); - } - else - { // Move left, scroll right - bitBlt( this, xOffset, topLineYOffset, this, xOffset-deltaX, topLineYOffset, width()-(xOffset-deltaX), height()-topLineYOffset, CopyROP, true); - m_invalidRect |= - QRect( width() + deltaX, topLineYOffset, -deltaX, height() - topLineYOffset ); - } - } - - if ( selection.oldLastLine != -1 ) - { - int lastLine; - int firstLine; - if ( selection.oldFirstLine != -1 ) - { - firstLine = min3( selection.oldFirstLine, selection.lastLine, selection.oldLastLine ); - lastLine = max3( selection.oldFirstLine, selection.lastLine, selection.oldLastLine ); - } - else - { - firstLine = min( selection.lastLine, selection.oldLastLine ); - lastLine = max( selection.lastLine, selection.oldLastLine ); - } - int y1 = topLineYOffset + ( firstLine - m_firstLine ) * fontHeight; - int y2 = topLineYOffset + ( lastLine - m_firstLine +1 ) * fontHeight; - - if ( y1<height() && y2>topLineYOffset ) - { - m_invalidRect |= QRect( 0, y1, width(), y2-y1 ); - } - } - - if ( m_invalidRect.isEmpty() ) - return; - - QPainter painter(this); - //QPainter& p=painter; - QPixmap pixmap( m_invalidRect.size() ); - QPainter p( &pixmap ); - p.translate( -m_invalidRect.x(), -m_invalidRect.y() ); - - p.fillRect( m_invalidRect, m_pOptionDialog->m_bgColor ); - - firstLineToDraw += m_firstLine; - lastLineToDraw += m_firstLine; - - p.setFont( font() ); - - p.setPen( m_cThis ); - if( m_invalidRect.intersects( QRect(0,0,width(), topLineYOffset ) ) - || m_firstLine != m_oldFirstLine ) - { - Diff3LineList::const_iterator i; - int l=0; - for ( i=m_pDiff3LineList->begin();i!=m_pDiff3LineList->end() && l!=m_firstLine; ++i,++l ) - { - } - l=-1; - if(i!=m_pDiff3LineList->end()) - { - l=-1; - for ( ;i!=m_pDiff3LineList->end(); ++i ) - { - if ( m_winIdx==1 ) l=(*i).lineA; - else if ( m_winIdx==2 ) l=(*i).lineB; - else if ( m_winIdx==3 ) l=(*i).lineC; - else assert(false); - if (l!=-1) break; - } - } - - const char* winId = ( m_winIdx==1 ? (m_bTriple?"A (Base)":"A") : - ( m_winIdx==2 ? "B" : "C" ) ); - - QString s; - if ( l!=-1 ) - s.sprintf(" %s : %s : Topline %d", winId, m_pFilename, l+1 ); - else - s.sprintf(" %s : %s: End", winId, m_pFilename ); - - - if (hasFocus()) - { - painter.fillRect( 0, 0, width(), topLineYOffset, m_cThis ); - painter.setPen( m_pOptionDialog->m_bgColor ); - painter.drawText( 0, fontAscent+1, s ); - } - else - { - painter.fillRect( 0, 0, width(), topLineYOffset, m_pOptionDialog->m_bgColor ); - painter.setPen( m_cThis ); - painter.drawLine( 0, fontHeight + 2, width(), fontHeight + 2 ); - painter.drawText( 0, fontAscent+1, s ); - } - } - - int line=0; - - Diff3LineList::const_iterator it; - for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it ) - { - DiffList* pFineDiff1; - DiffList* pFineDiff2; - int changed=0; - int changed2=0; - int lineIdx; - - getLineInfo( *it, lineIdx, pFineDiff1, pFineDiff2, changed, changed2 ); - - writeLine( - p, // QPainter - lineIdx == -1 ? 0 : &m_pLineData[lineIdx], // Text in this line - pFineDiff1, - pFineDiff2, - line, // Line on the screen - changed, - changed2 - ); - - ++line; - } - // p.drawLine( m_invalidRect.x(), m_invalidRect.y(), m_invalidRect.right(), m_invalidRect.bottom() ); - p.end(); - - painter.setClipRect ( 0, topLineYOffset, width(), height()-topLineYOffset ); - - painter.drawPixmap( m_invalidRect.x(), m_invalidRect.y(), pixmap ); - - m_oldFirstLine = m_firstLine; - m_oldFirstColumn = m_firstColumn; - m_invalidRect = QRect(0,0,0,0); - selection.oldLastLine = -1; - if ( selection.oldFirstLine !=-1 ) - selection.oldFirstLine = -1; - if( !bOldSelectionContainsData && selection.bSelectionContainsData ) - emit newSelection(); - -} - -QCString DiffTextWindow::getString( int line ) -{ - int line1=0; - Diff3LineList::const_iterator it; - for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it ) - { - - if (line1==line) - { - DiffList* pFineDiff1; - DiffList* pFineDiff2; - int changed=0; - int changed2=0; - int lineIdx; - getLineInfo( *it, lineIdx, pFineDiff1, pFineDiff2, changed, changed2 ); - - if (lineIdx==-1) return QCString(); - else - { - LineData* ld = &m_pLineData[lineIdx]; - return QCString( ld->pLine, ld->size + 1 ); - } - } - ++line1; - } - return QCString(); -} - - -void DiffTextWindow::getLineInfo( - const Diff3Line& d, - int& lineIdx, - DiffList*& pFineDiff1, DiffList*& pFineDiff2, // return values - int& changed, int& changed2 - ) -{ - changed=0; - changed2=0; - if ( m_winIdx == 1 ) { - lineIdx=d.lineA; - pFineDiff1=d.pFineAB; - pFineDiff2=d.pFineCA; - changed |= ((d.lineB==-1)!=(lineIdx==-1) ? 1 : 0) + - ((d.lineC==-1)!=(lineIdx==-1) && m_bTriple ? 2 : 0); - changed2 |= ( d.bAEqB ? 0 : 1 ) + (d.bAEqC || !m_bTriple ? 0 : 2); - } - else if ( m_winIdx == 2 ) { - lineIdx=d.lineB; - pFineDiff1=d.pFineBC; - pFineDiff2=d.pFineAB; - changed |= ((d.lineC==-1)!=(lineIdx==-1) && m_bTriple ? 1 : 0) + - ((d.lineA==-1)!=(lineIdx==-1) ? 2 : 0); - changed2 |= ( d.bBEqC || !m_bTriple ? 0 : 1 ) + (d.bAEqB ? 0 : 2); - } - else if ( m_winIdx == 3 ) { - lineIdx=d.lineC; - pFineDiff1=d.pFineCA; - pFineDiff2=d.pFineBC; - changed |= ((d.lineA==-1)!=(lineIdx==-1) ? 1 : 0) + - ((d.lineB==-1)!=(lineIdx==-1) ? 2 : 0); - changed2 |= ( d.bAEqC ? 0 : 1 ) + (d.bBEqC ? 0 : 2); - } - else assert(false); -} - - - -void DiffTextWindow::resizeEvent( QResizeEvent* e ) -{ - QSize s = e->size(); - QFontMetrics fm = fontMetrics(); - m_visibleLines = s.height()/fm.height()-2; - m_visibleColumns = s.width()/fm.width('W')-leftInfoWidth; - emit resizeSignal( m_visibleColumns, m_visibleLines ); - QWidget::resizeEvent(e); -} - -QString DiffTextWindow::getSelection() -{ - QString selectionString; - - int line=0; - int lineIdx=0; - - Diff3LineList::const_iterator it; - for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it ) - { - const Diff3Line& d = *it; - if ( m_winIdx == 1 ) { lineIdx=d.lineA; } - else if ( m_winIdx == 2 ) { lineIdx=d.lineB; } - else if ( m_winIdx == 3 ) { lineIdx=d.lineC; } - else assert(false); - - if( lineIdx != -1 ) - { - const char* pLine = m_pLineData[lineIdx].pLine; - int size = m_pLineData[lineIdx].size; - - // Consider tabs - int outPos = 0; - for( int i=0; i<size; ++i ) - { - int spaces = 1; - if ( pLine[i]=='\t' ) - { - spaces = tabber( outPos, g_tabSize ); - } - - if( selection.within( line, outPos ) ) - { - selectionString += pLine[i]; - } - - outPos += spaces; - } - - if( selection.within( line, outPos ) ) - { - #ifdef WIN32 - selectionString += '\r'; - #endif - selectionString += '\n'; - } - } - - ++line; - } - - return selectionString; -}
--- a/kdiff3/kdiff3/down1arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *down1arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -"................", -"................", -"................", -".. ..", -"... ...", -".... ....", -"..... .....", -"...... ......", -"....... .......", -"................", -"................", -"................", -"................", -"................" -};
--- a/kdiff3/kdiff3/down2arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *down2arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -".. ..", -"... ...", -".... ....", -"..... .....", -"...... ......", -"....... .......", -".. ..", -"... ...", -".... ....", -"..... .....", -"...... ......", -"....... .......", -"................", -"................" -};
--- a/kdiff3/kdiff3/downend.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *downend[]={ -"16 16 2 1", -"# c #000000", -". c None", -"................", -"................", -"................", -"................", -"................", -"..############..", -"...##########...", -"....########....", -".....######.....", -"......####......", -".......##.......", -"..############..", -"................", -"................", -"................", -"................"};
--- a/kdiff3/kdiff3/filenew.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/* XPM */ -static const char * filenew[] = { -"10 14 5 1", -" c None", -". c #000000", -"+ c #FFFFFF", -"@ c #DCDCDC", -"# c #C0C0C0", -"....... ", -".++++@@. ", -".++++#+@. ", -".++++#++@.", -".++++#....", -".+++++###.", -".++++++++.", -".++++++++.", -".++++++++.", -".++++++++.", -".++++++++.", -".++++++++.", -".++++++++.", -".........."};
--- a/kdiff3/kdiff3/fileopen.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/* XPM */ -static const char *fileopen[] = { -" 16 13 5 1", -". c #040404", -"# c #808304", -"a c None", -"b c #f3f704", -"c c #f3f7f3", -"aaaaaaaaa...aaaa", -"aaaaaaaa.aaa.a.a", -"aaaaaaaaaaaaa..a", -"a...aaaaaaaa...a", -".bcb.......aaaaa", -".cbcbcbcbc.aaaaa", -".bcbcbcbcb.aaaaa", -".cbcb...........", -".bcb.#########.a", -".cb.#########.aa", -".b.#########.aaa", -"..#########.aaaa", -"...........aaaaa" -};
--- a/kdiff3/kdiff3/filesave.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *filesave[] = { -" 14 14 3 1", -". c #040404", -"# c #808304", -"a c #bfc2bf", -"..............", -".#.aaaaaaaa.a.", -".#.aaaaaaaa...", -".#.aaaaaaaa.#.", -".#.aaaaaaaa.#.", -".#.aaaaaaaa.#.", -".#.aaaaaaaa.#.", -".##........##.", -".############.", -".##.........#.", -".##......aa.#.", -".##......aa.#.", -".##......aa.#.", -"a............." -};
--- a/kdiff3/kdiff3/iconA.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *iconA[]={ -"16 16 2 1", -". c None", -"# c #000000", -"................", -"................", -"................", -"......####......", -".....######.....", -"....##....##....", -"....##....##....", -"....##....##....", -"....##....##....", -"....########....", -"....########....", -"....##....##....", -"....##....##....", -"................", -"................", -"................"};
--- a/kdiff3/kdiff3/iconB.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *iconB[]={ -"16 16 2 1", -". c None", -"# c #000000", -"................", -"................", -"................", -"....#######.....", -"....########....", -"....##....##....", -"....##....##....", -"....#######.....", -"....#######.....", -"....##....##....", -"....##....##....", -"....########....", -"....#######.....", -"................", -"................", -"................"};
--- a/kdiff3/kdiff3/iconC.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *iconC[]={ -"16 16 2 1", -". c None", -"# c #000000", -"................", -"................", -"................", -"......####......", -".....######.....", -"....###...#.....", -"....##..........", -"....##..........", -"....##..........", -"....##..........", -"....###...#.....", -".....######.....", -"......####......", -"................", -"................", -"................"};
--- a/kdiff3/kdiff3/kdiff3.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,368 +0,0 @@ -/*************************************************************************** - kdiff3.cpp - description - ------------------- - begin : Don Jul 11 12:31:29 CEST 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:16 joachim99 - * Initial revision - * * - ***************************************************************************/ - -// include files for QT -#include <qdir.h> -#include <qprinter.h> -#include <qpainter.h> - -// include files for KDE -#include <kiconloader.h> -#include <kmessagebox.h> -#include <kfiledialog.h> -#include <kmenubar.h> -#include <kstatusbar.h> -#include <klocale.h> -#include <kconfig.h> -#include <kstdaction.h> -#include <kcmdlineargs.h> - -// application specific includes -#include "kdiff3.h" -#include "optiondialog.h" - -#define ID_STATUS_MSG 1 - -KDiff3App::KDiff3App(QWidget* , const char* name):KMainWindow(0, name) -{ - config=kapp->config(); - - m_pBuf1 = 0; - m_pBuf2 = 0; - m_pBuf3 = 0; - - // Option handling - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - - m_outputFilename = args->getOption("output"); - - if ( m_outputFilename.isEmpty() && args->isSet("merge") ) - { - m_outputFilename = "unnamed.txt"; - m_bDefaultFilename = true; - } - else - m_bDefaultFilename = false; - - if ( args->count() > 0 ) m_filename1 = args->arg(0); - if ( args->count() > 1 ) m_filename2 = args->arg(1); - if ( args->count() > 2 ) m_filename3 = args->arg(2); - - args->clear(); // Free up some memory. - - -// setCaption(tr( APP_NAME " " VERSION)); - - /////////////////////////////////////////////////////////////////// - // call inits to invoke all other construction parts - initActions(); - initStatusBar(); - - // All default values must be set before calling readOptions(). - m_pOptionDialog = new OptionDialog( this ); - connect( m_pOptionDialog, SIGNAL(applyClicked()), this, SLOT(slotRefresh()) ); - - readOptions(); - - init( m_filename1, m_filename2, m_filename3 ); - - statusBar()->setSizeGripEnabled(false); - - - /////////////////////////////////////////////////////////////////// - // disable actions at startup - fileSave->setEnabled(false); - fileSaveAs->setEnabled(false); - - editCut->setEnabled(false); - editCopy->setEnabled(false); - editPaste->setEnabled(false); - - bool bFileOpenError = false; - if ( ! m_filename1.isEmpty() && m_pBuf1==0 || - ! m_filename2.isEmpty() && m_pBuf2==0 || - ! m_filename3.isEmpty() && m_pBuf3==0 ) - { - QString text( i18n("Opening of these files failed:") ); - text += "\n\n"; - if ( ! m_filename1.isEmpty() && m_pBuf1==0 ) - text += " - " + m_filename1 + "\n"; - if ( ! m_filename2.isEmpty() && m_pBuf2==0 ) - text += " - " + m_filename2 + "\n"; - if ( ! m_filename3.isEmpty() && m_pBuf3==0 ) - text += " - " + m_filename3 + "\n"; - - KMessageBox::sorry( this, text, i18n("File open error") ); - - bFileOpenError = true; - } - - if ( m_filename1.isEmpty() || m_filename2.isEmpty() || bFileOpenError ) - slotFileOpen(); - - slotClipboardChanged(); // For initialisation. -} - -KDiff3App::~KDiff3App() -{ - -} - -void KDiff3App::initActions() -{ - fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection()); - fileSave = KStdAction::save(this, SLOT(slotFileSave()), actionCollection()); - fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection()); - fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection()); - editCut = KStdAction::cut(this, SLOT(slotEditCut()), actionCollection()); - editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), actionCollection()); - editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), actionCollection()); - viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection()); - viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection()); - KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection() ); - - fileOpen->setStatusText(i18n("Opens documents for comparison ...")); - fileSave->setStatusText(i18n("Saves the merge result. All conflicts must be solved!")); - fileSaveAs->setStatusText(i18n("Saves the current document as...")); - fileQuit->setStatusText(i18n("Quits the application")); - editCut->setStatusText(i18n("Cuts the selected section and puts it to the clipboard")); - editCopy->setStatusText(i18n("Copies the selected section to the clipboard")); - editPaste->setStatusText(i18n("Pastes the clipboard contents to actual position")); - viewToolBar->setStatusText(i18n("Enables/disables the toolbar")); - viewStatusBar->setStatusText(i18n("Enables/disables the statusbar")); - -#include "downend.xpm" -#include "down1arrow.xpm" -#include "down2arrow.xpm" -#include "upend.xpm" -#include "up1arrow.xpm" -#include "up2arrow.xpm" -#include "iconA.xpm" -#include "iconB.xpm" -#include "iconC.xpm" - - goTop = new KAction(i18n("Go to Top"), QIconSet(QPixmap(upend)), 0, this, SLOT(slotGoTop()), actionCollection(), "go_top"); - goBottom = new KAction(i18n("Go to Bottom"), QIconSet(QPixmap(downend)), 0, this, SLOT(slotGoBottom()), actionCollection(), "go_bottom"); - goPrevDelta = new KAction(i18n("Go to PrevDelta"), QIconSet(QPixmap(up1arrow)), 0, this, SLOT(slotGoPrevDelta()), actionCollection(), "go_prev_delta"); - goNextDelta = new KAction(i18n("Go to NextDelta"), QIconSet(QPixmap(down1arrow)), 0, this, SLOT(slotGoNextDelta()), actionCollection(), "go_next_delta"); - goPrevConflict = new KAction(i18n("Go to Previous Conflict"), QIconSet(QPixmap(up2arrow)), 0, this, SLOT(slotGoPrevConflict()), actionCollection(), "go_prev_conflict"); - goNextConflict = new KAction(i18n("Go to Next Conflict"), QIconSet(QPixmap(down2arrow)), 0, this, SLOT(slotGoNextConflict()), actionCollection(), "go_next_conflict"); - chooseA = new KToggleAction(i18n("Select line(s) from A"), QIconSet(QPixmap(iconA)), 0, this, SLOT(slotChooseA()), actionCollection(), "choose_a"); - chooseB = new KToggleAction(i18n("Select line(s) from B"), QIconSet(QPixmap(iconB)), 0, this, SLOT(slotChooseB()), actionCollection(), "choose_b"); - chooseC = new KToggleAction(i18n("Select line(s) from C"), QIconSet(QPixmap(iconC)), 0, this, SLOT(slotChooseC()), actionCollection(), "choose_c"); - - // use the absolute path to your kdiff3ui.rc file for testing purpose in createGUI(); - createGUI(); - -} - - -void KDiff3App::initStatusBar() -{ - /////////////////////////////////////////////////////////////////// - // STATUSBAR - // TODO: add your own items you need for displaying current application status. - statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG); -} - -void KDiff3App::saveOptions() -{ - config->setGroup("General Options"); - config->writeEntry("Geometry", size()); - config->writeEntry("Show Toolbar", viewToolBar->isChecked()); - config->writeEntry("Show Statusbar",viewStatusBar->isChecked()); - config->writeEntry("ToolBarPos", (int) toolBar("mainToolBar")->barPos()); - - m_pOptionDialog->saveOptions( config ); -} - - -void KDiff3App::readOptions() -{ - config->setGroup("General Options"); - - // bar status settings - bool bViewToolbar = config->readBoolEntry("Show Toolbar", true); - viewToolBar->setChecked(bViewToolbar); - slotViewToolBar(); - - bool bViewStatusbar = config->readBoolEntry("Show Statusbar", true); - viewStatusBar->setChecked(bViewStatusbar); - slotViewStatusBar(); - - - // bar position settings - KToolBar::BarPosition toolBarPos; - toolBarPos=(KToolBar::BarPosition) config->readNumEntry("ToolBarPos", KToolBar::Top); - toolBar("mainToolBar")->setBarPos(toolBarPos); - - QSize size=config->readSizeEntry("Geometry"); - if(!size.isEmpty()) - { - resize(size); - } - - m_pOptionDialog->readOptions( config ); -} - - -bool KDiff3App::queryClose() -{ - if(m_bOutputModified) - { - int result = KMessageBox::warningYesNo(this, - i18n("The output file has been modified.\n" - "If you continue your changes will be lost."), - i18n("Warning"), i18n("Continue"), i18n("Cancel")); - if ( result==KMessageBox::No ) - return false; - else - return true; // Finished because user doesn't want to save. - } - - return true; -} - -bool KDiff3App::queryExit() -{ - saveOptions(); - return true; -} - -///////////////////////////////////////////////////////////////////// -// SLOT IMPLEMENTATION -///////////////////////////////////////////////////////////////////// - - -void KDiff3App::slotFileSave() -{ - if ( m_bDefaultFilename ) - { - slotFileSaveAs(); - } - else - { - slotStatusMsg(i18n("Saving file...")); - - bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename ); - if ( bSuccess ) - m_bOutputModified = false; - - slotStatusMsg(i18n("Ready.")); - } -} - -void KDiff3App::slotFileSaveAs() -{ - slotStatusMsg(i18n("Saving file with a new filename...")); - - QString s = KFileDialog::getSaveFileName( QDir::currentDirPath(), - i18n("*|All files"), this, i18n("Save as...") ); - if(!s.isEmpty()) - { - m_outputFilename = s; - bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename ); - if ( bSuccess ) - m_bOutputModified = false; - //setCaption(url.fileName(),doc->isModified()); - - m_bDefaultFilename = false; - } - - slotStatusMsg(i18n("Ready.")); -} - -void KDiff3App::slotFileClose() -{ - slotStatusMsg(i18n("Closing file...")); - - close(); - - slotStatusMsg(i18n("Ready.")); -} - - -void KDiff3App::slotFileQuit() -{ - slotStatusMsg(i18n("Exiting...")); - saveOptions(); - // close the first window, the list makes the next one the first again. - // This ensures that queryClose() is called on each window to ask for closing - KMainWindow* w; - if(memberList) - { - for(w=memberList->first(); w!=0; w=memberList->first()) - { - // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog, - // the window and the application stay open. - if(!w->close()) - break; - } - } -} - - - -void KDiff3App::slotViewToolBar() -{ - slotStatusMsg(i18n("Toggling toolbar...")); - /////////////////////////////////////////////////////////////////// - // turn Toolbar on or off - if(!viewToolBar->isChecked()) - { - toolBar("mainToolBar")->hide(); - } - else - { - toolBar("mainToolBar")->show(); - } - - slotStatusMsg(i18n("Ready.")); -} - -void KDiff3App::slotViewStatusBar() -{ - slotStatusMsg(i18n("Toggle the statusbar...")); - /////////////////////////////////////////////////////////////////// - //turn Statusbar on or off - if(!viewStatusBar->isChecked()) - { - statusBar()->hide(); - } - else - { - statusBar()->show(); - } - - slotStatusMsg(i18n("Ready.")); -} - - -void KDiff3App::slotStatusMsg(const QString &text) -{ - /////////////////////////////////////////////////////////////////// - // change status message permanently - statusBar()->clear(); - statusBar()->changeItem(text, ID_STATUS_MSG); -}
--- a/kdiff3/kdiff3/kdiff3.desktop Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -# KDE Config File -[Desktop Entry] -Encoding=UTF-8 -Type=Application -Exec=kdiff3 -caption "%c" %i %m -Icon=kdiff3.png -DocPath=kdiff3/index.html -Comment= -Comment[de]= -Terminal=0 -Name=KDiff3 -Name[de]=KDiff3
--- a/kdiff3/kdiff3/kdiff3.h Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,282 +0,0 @@ -/*************************************************************************** - kdiff3.h - description - ------------------- - begin : Don Jul 11 12:31:29 CEST 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:16 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#ifndef KDIFF3_H -#define KDIFF3_H - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -// include files for Qt -#include <qdialog.h> - -// include files for KDE -#include <kapp.h> -#include <kmainwindow.h> -#include <kaccel.h> -#include <kaction.h> -#include <kurl.h> - -#include "diff.h" - -// forward declaration of the KDiff3 classes -class OptionDialog; - -class QScrollBar; -class QComboBox; - -/** - * The base class for KDiff3 application windows. It sets up the main - * window and reads the config file as well as providing a menubar, toolbar - * and statusbar. An instance of KDiff3View creates your center view, which is connected - * to the window's Doc object. - * KDiff3App reimplements the methods that KMainWindow provides for main window handling and supports - * full session management as well as using KActions. - * @see KMainWindow - * @see KApplication - * @see KConfig - * - * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. - * @version KDevelop version 1.2 code generation - */ -class KDiff3App : public KMainWindow -{ - Q_OBJECT - - - public: - /** construtor of KDiff3App, calls all init functions to create the application. - */ - KDiff3App(QWidget* parent=0, const char* name=0); - ~KDiff3App(); - - - protected: - /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration - * file - */ - void saveOptions(); - /** read general Options again and initialize all variables like the recent file list - */ - void readOptions(); - /** initializes the KActions of the application */ - void initActions(); - /** sets up the statusbar for the main window by initialzing a statuslabel. - */ - void initStatusBar(); - - /** creates the centerwidget of the KMainWindow instance and sets it as the view - */ - void initView(); - /** queryClose is called by KMainWindow on each closeEvent of a window. Against the - * default implementation (only returns true), this calles saveModified() on the document object to ask if the document shall - * be saved if Modified; on cancel the closeEvent is rejected. - * @see KMainWindow#queryClose - * @see KMainWindow#closeEvent - */ - virtual bool queryClose(); - /** queryExit is called by KMainWindow when the last window of the application is going to be closed during the closeEvent(). - * Against the default implementation that just returns true, this calls saveOptions() to save the settings of the last window's - * properties. - * @see KMainWindow#queryExit - * @see KMainWindow#closeEvent - */ - virtual bool queryExit(); - - - public slots: - - /** open a file and load it into the document*/ - void slotFileOpen(); - /** save a document */ - void slotFileSave(); - /** save a document by a new filename*/ - void slotFileSaveAs(); - /** asks for saving if the file is modified, then closes the actual file and window*/ - void slotFileClose(); - - /** closes all open windows by calling close() on each memberList item until the list is empty, then quits the application. - * If queryClose() returns false because the user canceled the saveModified() dialog, the closing breaks. - */ - void slotFileQuit(); - /** put the marked text/object into the clipboard and remove - * it from the document - */ - void slotEditCut(); - /** put the marked text/object into the clipboard - */ - void slotEditCopy(); - /** paste the clipboard into the document - */ - void slotEditPaste(); - /** toggles the toolbar - */ - void slotViewToolBar(); - /** toggles the statusbar - */ - void slotViewStatusBar(); - /** changes the statusbar contents for the standard label permanently, used to indicate current actions. - * @param text the text that is displayed in the statusbar - */ - void slotStatusMsg(const QString &text); - - private: - /** the configuration object of the application */ - KConfig *config; - - // KAction pointers to enable/disable actions - KAction* fileOpen; - KAction* fileSave; - KAction* fileSaveAs; - KAction* fileQuit; - KAction* editCut; - KAction* editCopy; - KAction* editPaste; - KToggleAction* viewToolBar; - KToggleAction* viewStatusBar; - -//////////////////////////////////////////////////////////////////////// -// Special KDiff3 specific stuff starts here - - KAction *goTop; - KAction *goBottom; - KAction *goPrevConflict; - KAction *goNextConflict; - KAction *goPrevDelta; - KAction *goNextDelta; - KToggleAction *chooseA; - KToggleAction *chooseB; - KToggleAction *chooseC; - - QScrollBar* m_pHScrollBar; - QScrollBar* m_pDiffVScrollBar; - QScrollBar* m_pMergeVScrollBar; - - DiffTextWindow* m_pDiffTextWindow1; - DiffTextWindow* m_pDiffTextWindow2; - DiffTextWindow* m_pDiffTextWindow3; - - MergeResultWindow* m_pMergeResultWindow; - - Overview* m_pOverview; - - QWidget* m_pCornerWidget; - - - QString m_filename1; - const char* m_pBuf1; - int m_size1; - int m_v1size; // Nr of lines in m_pBuf1 and size of m_v1, m_dv12 and m_dv13 - std::vector<LineData> m_v1; - - QString m_filename2; - const char* m_pBuf2; - int m_size2; - int m_v2size; - std::vector<LineData> m_v2; - - QString m_filename3; - const char* m_pBuf3; - int m_size3; - int m_v3size; - std::vector<LineData> m_v3; - - QString m_outputFilename; - bool m_bDefaultFilename; - - DiffList m_diffList12; - DiffList m_diffList23; - DiffList m_diffList13; - - Diff3LineList m_diff3LineList; - - int m_neededLines; - int m_maxWidth; - int m_DTWHeight; - bool m_bOutputModified; - - OptionDialog* m_pOptionDialog; - - void init( const char* filename1, const char* filename2, const char* filename3 ); - - virtual bool eventFilter( QObject* o, QEvent* e ); - virtual void resizeEvent(QResizeEvent*); -// virtual void timerEvent(QTimerEvent*); -private slots: - void resizeDiffTextWindow(int newWidth, int newHeight); - void resizeMergeResultWindow(); - void scrollDiffTextWindow( int deltaX, int deltaY ); - void scrollMergeResultWindow( int deltaX, int deltaY ); - void setDiff3Line( int line ); - void sourceMask( int srcMask, int enabledMask ); - - void slotGoTop(); - void slotGoBottom(); - void slotGoPrevConflict(); - void slotGoNextConflict(); - void slotGoPrevDelta(); - void slotGoNextDelta(); - void slotChooseA(); - void slotChooseB(); - void slotChooseC(); - void slotConfigure(); - void slotRefresh(); - void slotSelectionEnd(); - void slotSelectionStart(); - void slotClipboardChanged(); - void slotOutputModified(); - void slotOutputSavable(bool); -}; - -class QCheckBox; - -class OpenDialog : public QDialog -{ - Q_OBJECT -public: - OpenDialog( - QWidget* pParent, const char* n1, const char* n2, const char* n3, - bool bMerge, const char* outputName, const char* slotConfigure, OptionDialog* pOptions ); - - QComboBox* m_lineA; - QComboBox* m_lineB; - QComboBox* m_lineC; - QComboBox* m_lineOutput; - QCheckBox* m_pMerge; - virtual void accept(); -private: - OptionDialog* m_pOptions; - -private slots: - void selectFileA(); - void selectFileB(); - void selectFileC(); - void selectOutputName(); - void internalSlot(int); -signals: - void internalSignal(bool); -}; -#endif // KDIFF3_H
--- a/kdiff3/kdiff3/kdiff3ui.rc Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -<!DOCTYPE kpartgui> -<kpartgui name="kdiff3" version="0.6"> -<MenuBar> - <Menu name="file"><text>&File</text> - <Action name="file_new_window"/> - </Menu> -</MenuBar> -<ToolBar name="mainToolBar"><text>Main Toolbar</text> - <Action name="go_top"/> - <Action name="go_bottom"/> - <Action name="go_prev_delta"/> - <Action name="go_next_delta"/> - <Action name="go_prev_conflict"/> - <Action name="go_next_conflict"/> - <Action name="choose_a"/> - <Action name="choose_b"/> - <Action name="choose_c"/> -</ToolBar> -</kpartgui>
--- a/kdiff3/kdiff3/left1arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *left1arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -".......... .....", -"......... .....", -"........ .....", -"....... .....", -"...... .....", -"..... .....", -"..... .....", -"...... .....", -"....... .....", -"........ .....", -"......... .....", -".......... .....", -"................", -"................" -};
--- a/kdiff3/kdiff3/left2arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *left2arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -"....... ..... ..", -"...... .... ..", -"..... ... ..", -".... .. ..", -"... . ..", -".. ..", -".. ..", -"... . ..", -".... .. ..", -"..... ... ..", -"...... .... ..", -"....... ..... ..", -"................", -"................" -};
--- a/kdiff3/kdiff3/leftend.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *leftend[]={ -"16 16 2 1", -"# c #000000", -". c None", -"................", -"................", -"....#.....#.....", -"....#....##.....", -"....#...###.....", -"....#..####.....", -"....#.#####.....", -"....#######.....", -"....#######.....", -"....#.#####.....", -"....#..####.....", -"....#...###.....", -"....#....##.....", -"....#.....#.....", -"................", -"................"};
--- a/kdiff3/kdiff3/main.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/*************************************************************************** - main.cpp - description - ------------------- - begin : Don Jul 11 12:31:29 CEST 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:16 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include <kcmdlineargs.h> -#include <kaboutdata.h> -#include <klocale.h> - -#include "kdiff3.h" - -static const char *description = - I18N_NOOP("Text Diff and Merge Tool"); - -static KCmdLineOptions options[] = -{ - { "m", 0, 0 }, - { "merge", I18N_NOOP("Automatically merge the input."), 0 }, - { "o", 0, 0 }, - { "output file", I18N_NOOP("Output file. Implies -m. E.g.: -o newfile.txt"), 0 }, - { "+[File1]", I18N_NOOP("file1 to open (base)"), 0 }, - { "+[File2]", I18N_NOOP("file2 to open"), 0 }, - { "+[File3]", I18N_NOOP("file3 to open"), 0 }, - { 0, 0, 0 } - // INSERT YOUR COMMANDLINE OPTIONS HERE -}; - -int main(int argc, char *argv[]) -{ - - KAboutData aboutData( "kdiff3", I18N_NOOP("KDiff3"), - VERSION, description, KAboutData::License_GPL, - "(c) 2002 Joachim Eibl", 0, 0, "joachim.eibl@gmx.de"); - aboutData.addAuthor("Joachim Eibl",0, "joachim.eibl@gmx.de"); - KCmdLineArgs::init( argc, argv, &aboutData ); - KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. - - KApplication app; - - if (app.isRestored()) - { - RESTORE(KDiff3App); - } - else - { - KDiff3App *kdiff3 = new KDiff3App(); - kdiff3->show(); - - /* With the following lines when the application starts a small window - flashes up and disappears so fast that one can't see what is happening. - But I think, I don't need these lines anyway: */ - - /* KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - - if (args->count()) - { - kdiff3->openDocumentFile(args->arg(0)); - } - else - { - kdiff3->openDocumentFile(); - } - args->clear();*/ - } - - return app.exec(); -}
--- a/kdiff3/kdiff3/merger.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/*************************************************************************** - merger.cpp - description - ------------------- - begin : Sun Mar 24 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:09 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include "merger.h" -#include <assert.h> -#include <iostream> -#include <iomanip> -using namespace std; - -Merger::Merger( const DiffList* pDiffListAB, const DiffList* pDiffListCA ) -: md1( pDiffListAB, 0 ), md2( pDiffListCA, 1 ) -{ -} - - -Merger::MergeData::MergeData( const DiffList* p, int i ) -: d(0,0,0) -{ - idx=i; - pDiffList = p; - if ( p!=0 ) - { - it=p->begin(); - update(); - } -} - -bool Merger::MergeData::eq() -{ - return pDiffList==0 || d.nofEquals > 0; -} - -bool Merger::MergeData::isEnd() -{ - return ( pDiffList==0 || ( it==pDiffList->end() && d.nofEquals==0 && - ( idx == 0 ? d.diff1==0 : d.diff2==0 ) - ) ); -} - -void Merger::MergeData::update() -{ - if ( d.nofEquals > 0 ) - --d.nofEquals; - else if ( idx==0 && d.diff1 > 0 ) - --d.diff1; - else if ( idx==1 && d.diff2 > 0 ) - --d.diff2; - - while( d.nofEquals == 0 && (idx==0 && d.diff1 == 0 || idx==1 && d.diff2 == 0) - && pDiffList!=0 && it != pDiffList->end() ) - { - d = *it; - ++it; - } -} - -void Merger::next() -{ - md1.update(); - md2.update(); -} - -int Merger::whatChanged() -{ - int changed = 0; - changed |= md1.eq() ? 0 : 1; - changed |= md2.eq() ? 0 : 2; - return changed; -} - -bool Merger::isEndReached() -{ - return md1.isEnd() && md2.isEnd(); -}
--- a/kdiff3/kdiff3/merger.h Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/*************************************************************************** - merger.h - description - ------------------- - begin : Sun Mar 24 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:17 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#ifndef MERGER_H -#define MERGER_H - -#include "diff.h" - - -class Merger -{ -public: - - Merger( const DiffList* pDiffList1, const DiffList* pDiffList2 ); - - /** Go one step. */ - void next(); - - /** Information about what changed. Can be used for coloring. - The return value is 0 if nothing changed here, - bit 1 is set if a difference from pDiffList1 was detected, - bit 2 is set if a difference from pDiffList2 was detected. - */ - int whatChanged(); - - /** End of both diff lists reached. */ - bool isEndReached(); -private: - - struct MergeData - { - DiffList::const_iterator it; - const DiffList* pDiffList; - Diff d; - int idx; - - MergeData( const DiffList* p, int i ); - bool eq(); - void update(); - bool isEnd(); - }; - - MergeData md1; - MergeData md2; -}; - -#endif \ No newline at end of file
--- a/kdiff3/kdiff3/mergeresultwindow.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1786 +0,0 @@ -/*************************************************************************** - mergeresultwindow.cpp - description - ------------------- - begin : Sun Apr 14 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:13 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include "diff.h" -#include <stdio.h> -#include <qpainter.h> -#include <qapplication.h> -#include <qclipboard.h> -#include <optiondialog.h> -#include <klocale.h> -#include <kmessagebox.h> - -#define leftInfoWidth 3 - -MergeResultWindow::MergeResultWindow( - QWidget* pParent, - const LineData* pLineDataA, - const LineData* pLineDataB, - const LineData* pLineDataC, - const Diff3LineList* pDiff3LineList, - QString fileName, - OptionDialog* pOptionDialog - ) -: QWidget( pParent, 0, WRepaintNoErase ) -{ - setFocusPolicy( QWidget::ClickFocus ); - - m_fileName = fileName; - m_pldA = pLineDataA; - m_pldB = pLineDataB; - m_pldC = pLineDataC; - - m_pDiff3LineList = pDiff3LineList; - - m_firstLine = 0; - m_firstColumn = 0; - m_nofColumns = 0; - m_nofLines = 0; - m_bMyUpdate = false; - m_bInsertMode = true; - m_scrollDeltaX = 0; - m_scrollDeltaY = 0; - m_bModified = false; - - m_pOptionDialog = pOptionDialog; - - m_cursorXPos=0; - m_cursorOldXPos=0; - m_cursorYPos=0; - m_bCursorOn = true; - connect( &m_cursorTimer, SIGNAL(timeout()), this, SLOT( slotCursorUpdate() ) ); - m_cursorTimer.start( 500 /*ms*/, true /*single shot*/ ); - m_selection.reset(); - - setMinimumSize( QSize(20,20) ); - - merge(); -} - - -const int A=1, B=2, C=3; - -// Calculate the merge information for the given Diff3Line. -// Results will be stored in mergeDetails, bConflict, bLineRemoved and src. -void mergeOneLine( - const Diff3Line& d, e_MergeDetails& mergeDetails, bool& bConflict, - bool& bLineRemoved, int& src, bool bTwoInputs - ) -{ - mergeDetails = eDefault; - bConflict = false; - bLineRemoved = false; - src = 0; - - if ( bTwoInputs ) // Only two input files - { - if ( d.lineA!=-1 && d.lineB!=-1 ) - { - if ( d.pFineAB == 0 ) - { - mergeDetails = eNoChange; src = A; - } - else - { - mergeDetails = eBChanged; bConflict = true; - } - } - else - { - if ( d.lineA!=-1 && d.lineB==-1 ) - { - mergeDetails = eBDeleted; bConflict = true; - } - else if ( d.lineA==-1 && d.lineB!=-1 ) - { - mergeDetails = eBDeleted; bConflict = true; - } - } - return; - } - - // Assume A is base. - if ( d.lineA!=-1 && d.lineB!=-1 && d.lineC!=-1 ) - { - if ( d.pFineAB == 0 && d.pFineBC == 0 && d.pFineCA == 0) - { - mergeDetails = eNoChange; src = A; - } - else if( d.pFineAB == 0 && d.pFineBC != 0 && d.pFineCA != 0 ) - { - mergeDetails = eCChanged; src = C; - } - else if( d.pFineAB != 0 && d.pFineBC != 0 && d.pFineCA == 0 ) - { - mergeDetails = eBChanged; src = B; - } - else if( d.pFineAB != 0 && d.pFineBC == 0 && d.pFineCA != 0 ) - { - mergeDetails = eBCChangedAndEqual; bConflict = true; - } - else if( d.pFineAB != 0 && d.pFineBC != 0 && d.pFineCA != 0 ) - { - mergeDetails = eBCChanged; bConflict = true; - } - else - assert(false); - } - else if ( d.lineA!=-1 && d.lineB!=-1 && d.lineC==-1 ) - { - if( d.pFineAB != 0 ) - { - mergeDetails = eBChanged_CDeleted; bConflict = true; - } - else - { - mergeDetails = eCDeleted; bLineRemoved = true; src = C; - } - } - else if ( d.lineA!=-1 && d.lineB==-1 && d.lineC!=-1 ) - { - if( d.pFineCA != 0 ) - { - mergeDetails = eCChanged_BDeleted; bConflict = true; - } - else - { - mergeDetails = eBDeleted; bLineRemoved = true; src = B; - } - } - else if ( d.lineA==-1 && d.lineB!=-1 && d.lineC!=-1 ) - { - if( d.pFineBC != 0 ) - { - mergeDetails = eBCAdded; bConflict = true; - } - else // B==C - { - mergeDetails = eBCAddedAndEqual; bConflict = true; - } - } - else if ( d.lineA==-1 && d.lineB==-1 && d.lineC!= -1 ) - { - mergeDetails = eCAdded; src = C; - } - else if ( d.lineA==-1 && d.lineB!=-1 && d.lineC== -1 ) - { - mergeDetails = eBAdded; src = B; - } - else if ( d.lineA!=-1 && d.lineB==-1 && d.lineC==-1 ) - { - mergeDetails = eBCDeleted; bConflict = true; - } - else - assert(false); -} - -bool MergeResultWindow::sameKindCheck( const MergeLine& ml1, const MergeLine& ml2 ) -{ - return ( - ml1.bConflict && ml2.bConflict || - !ml1.bConflict && !ml2.bConflict && ml1.bDelta && ml2.bDelta && ml1.srcSelect == ml2.srcSelect || - !ml1.bDelta && !ml2.bDelta - ); -} - -void MergeResultWindow::merge() -{ - m_mergeLineList.clear(); - int lineIdx = 0; - Diff3LineList::const_iterator it; - for( it=m_pDiff3LineList->begin(); it!=m_pDiff3LineList->end(); ++it, ++lineIdx ) - { - const Diff3Line& d = *it; - - MergeLine ml; - bool bLineRemoved; - mergeOneLine( d, ml.mergeDetails, ml.bConflict, bLineRemoved, ml.srcSelect, m_pldC==0 ); - - ml.d3lLineIdx = lineIdx; - ml.bDelta = ml.srcSelect != A; - ml.id3l = it; - ml.srcRangeLength = 1; - - MergeLine* back = m_mergeLineList.empty() ? 0 : &m_mergeLineList.back(); - - if( back!=0 && sameKindCheck( ml, *back ) ) - { - ++back->srcRangeLength; - } - else - { - m_mergeLineList.push_back( ml ); - } - - if ( ! ml.bConflict ) - { - MergeLine& newBack = m_mergeLineList.back(); - MergeEditLine mel; - mel.setSource( ml.srcSelect, ml.id3l, bLineRemoved ); - newBack.mergeEditLineList.push_back(mel); - } - else if ( back==0 || ! back->bConflict ) - { - MergeLine& newBack = m_mergeLineList.back(); - MergeEditLine mel; - mel.setConflict(); - newBack.mergeEditLineList.push_back(mel); - } - } - - MergeLineList::iterator mlIt; - for( mlIt=m_mergeLineList.begin(); mlIt!=m_mergeLineList.end(); ++mlIt ) - { - MergeLine& ml = *mlIt; - // Remove all lines that are empty, because no src lines are there. - int oldSrcLine = -1; - int oldSrc = -1; - MergeEditLineList::iterator melIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ) - { - MergeEditLine& mel = *melIt; - int melsrc = mel.src(); - - int srcLine = melsrc==1 ? mel.id3l()->lineA : - melsrc==2 ? mel.id3l()->lineB : - melsrc==3 ? mel.id3l()->lineC : -1; - - if ( srcLine == -1 && oldSrcLine==-1 && oldSrc == melsrc ) - melIt = ml.mergeEditLineList.erase( melIt ); - else - ++melIt; - - oldSrcLine = srcLine; - oldSrc = melsrc; - } - } - - m_currentMergeLineIt = m_mergeLineList.begin(); -} - -void MergeResultWindow::setFirstLine(int firstLine) -{ - m_firstLine = max(0,firstLine); - update(); -} - -void MergeResultWindow::setFirstColumn(int firstCol) -{ - m_firstColumn = max(0,firstCol); - update(); -} - -int MergeResultWindow::getNofColumns() -{ - return m_nofColumns; -} - -int MergeResultWindow::getNofLines() -{ - return m_nofLines; -} - -int MergeResultWindow::getNofVisibleColumns() -{ - QFontMetrics fm = fontMetrics(); - return width()/fm.width('W')-4; -} - -int MergeResultWindow::getNofVisibleLines() -{ - QFontMetrics fm = fontMetrics(); - return (height()-3)/fm.height()-2; -} - -void MergeResultWindow::resizeEvent( QResizeEvent* e ) -{ - QWidget::resizeEvent(e); - emit resizeSignal(); -} - -// Go to prev/next delta/conflict or first/last delta. -void MergeResultWindow::go( e_Direction eDir, e_EndPoint eEndPoint ) -{ - assert( eDir==eUp || eDir==eDown ); - MergeLineList::iterator i = m_currentMergeLineIt; - if( eEndPoint==eEnd ) - { - if (eDir==eUp) i = m_mergeLineList.begin(); // first mergeline - else i = --m_mergeLineList.end(); // last mergeline - -// while ( ! i->bDelta && i!=m_mergeLineList.end() ) -// { -// if ( eDir==eUp ) ++i; // search downwards -// else --i; // search upwards -// } - } - else if ( eEndPoint == eDelta && i!=m_mergeLineList.end()) - { - do - { - if ( eDir==eUp ) --i; - else ++i; - } - while ( i->bDelta == false && i!=m_mergeLineList.end() ); - } - else if ( eEndPoint == eConflict && i!=m_mergeLineList.end()) - { - do - { - if ( eDir==eUp ) --i; - else ++i; - } - while ( i->bConflict == false && i!=m_mergeLineList.end() ); - } - - setFastSelector( i ); -} - -void MergeResultWindow::slotGoTop() -{ - go( eUp, eEnd ); -} - -void MergeResultWindow::slotGoBottom() -{ - go( eDown, eEnd ); -} - -void MergeResultWindow::slotGoPrevDelta() -{ - go( eUp, eDelta ); -} - -void MergeResultWindow::slotGoNextDelta() -{ - go( eDown, eDelta ); -} - -void MergeResultWindow::slotGoPrevConflict() -{ - go( eUp, eConflict ); -} - -void MergeResultWindow::slotGoNextConflict() -{ - go( eDown, eConflict ); -} - -/** The line is given as a index in the Diff3LineList. - The function calculates the corresponding iterator. */ -void MergeResultWindow::slotSetFastSelectorLine( int line ) -{ - MergeLineList::iterator i; - for ( i = m_mergeLineList.begin(); i!=m_mergeLineList.end(); ++i ) - { - if ( line>=i->d3lLineIdx && line < i->d3lLineIdx + i->srcRangeLength ) - { - if ( i->bDelta ) - { - setFastSelector( i ); - } - break; - } - } -} - - -void MergeResultWindow::setFastSelector(MergeLineList::iterator i) -{ - if ( i==m_mergeLineList.end() ) - return; - m_currentMergeLineIt = i; - emit setFastSelectorRange( i->d3lLineIdx, i->srcRangeLength ); - - int line1 = 0; - - MergeLineList::iterator mlIt = m_mergeLineList.begin(); - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - if(mlIt==m_currentMergeLineIt) - break; - line1 += mlIt->mergeEditLineList.size(); - } - - int nofLines = m_currentMergeLineIt->mergeEditLineList.size(); - int newFirstLine = getBestFirstLine( line1, nofLines, m_firstLine, getNofVisibleLines() ); - if ( newFirstLine != m_firstLine ) - { - scroll( 0, newFirstLine - m_firstLine ); - } - - update(); -} - -void MergeResultWindow::choose( int selector ) -{ - setModified(); - - // First find range for which this change works. - MergeLine& ml = *m_currentMergeLineIt; - - MergeEditLineList::iterator melIt; - - // Now check if selector is active for this range already. - bool bActive = false; - - // Remove unneeded lines in the range. - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ) - { - MergeEditLine& mel = *melIt; - if ( mel.src()==selector ) - bActive = true; - - if ( mel.src()==selector || !mel.isEditableText() || mel.isModified() ) - melIt = ml.mergeEditLineList.erase( melIt ); - else - ++melIt; - } - - if ( !bActive ) // Selected source wasn't active. - { // Append the lines from selected source here at rangeEnd. - Diff3LineList::const_iterator d3llit=ml.id3l; - int j; - - for( j=0; j<ml.srcRangeLength; ++j ) - { - MergeEditLine mel; - mel.setSource( selector, d3llit, false ); - ml.mergeEditLineList.push_back(mel); - - ++d3llit; - } - } - - if ( ! ml.mergeEditLineList.empty() ) - { - // Remove all lines that are empty, because no src lines are there. - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ) - { - MergeEditLine& mel = *melIt; - - int srcLine = mel.src()==1 ? mel.id3l()->lineA : - mel.src()==2 ? mel.id3l()->lineB : - mel.src()==3 ? mel.id3l()->lineC : -1; - - if ( srcLine == -1 ) - melIt = ml.mergeEditLineList.erase( melIt ); - else - ++melIt; - } - } - - if ( ml.mergeEditLineList.empty() ) - { - // Insert a dummy line: - MergeEditLine mel; - - if ( bActive ) mel.setConflict(); // All src entries deleted => conflict - else mel.setRemoved(selector); // No lines in corresponding src found. - - ml.mergeEditLineList.push_back(mel); - } - - update(); -} - -void MergeResultWindow::slotChooseA() -{ - choose( A ); -} - -void MergeResultWindow::slotChooseB() -{ - choose( B ); -} - -void MergeResultWindow::slotChooseC() -{ - choose( C ); -} - -void MergeResultWindow::myUpdate(int afterMilliSecs) -{ - killTimers(); - m_bMyUpdate = true; - startTimer( afterMilliSecs ); -} - -void MergeResultWindow::timerEvent(QTimerEvent*) -{ - killTimers(); - - if ( m_bMyUpdate ) - { - update();//paintEvent( 0 ); - m_bMyUpdate = false; - } - - if ( m_scrollDeltaX != 0 || m_scrollDeltaY != 0 ) - { - m_selection.end( m_selection.lastLine + m_scrollDeltaY, m_selection.lastPos + m_scrollDeltaX ); - emit scroll( m_scrollDeltaX, m_scrollDeltaY ); - killTimers(); - startTimer(50); - } - -} - -const char* MergeResultWindow::MergeEditLine::getString( const MergeResultWindow* mrw, int& size ) -{ - size=-1; - if ( isRemoved() ) { size=0; return ""; } - - if ( ! isModified() ) - { - int src = m_src; - const Diff3Line& d3l = *m_id3l; - if ( src == 0 ) { size=0; return ""; } - const LineData* pld = 0; - assert( src == A || src == B || src == C ); - if ( src == A && d3l.lineA!=-1 ) pld = &mrw->m_pldA[ d3l.lineA ]; - else if ( src == B && d3l.lineB!=-1 ) pld = &mrw->m_pldB[ d3l.lineB ]; - else if ( src == C && d3l.lineC!=-1 ) pld = &mrw->m_pldC[ d3l.lineC ]; - - if ( pld == 0 ) - { - assert(false); - size = 0; - return ""; - } - - size = pld->size; - return pld->pLine; - } - else - { - size = m_str.length(); - return m_str; - } - return 0; -} - -/// Converts the cursor-posOnScreen into a text index, considering tabulators. -int convertToPosInText( const char* p, int size, int posOnScreen ) -{ - int localPosOnScreen = 0; - for ( int i=0; i<size; ++i ) - { - if ( localPosOnScreen>=posOnScreen ) - return i; - - // All letters except tabulator have width one. - int letterWidth = p[i]!='\t' ? 1 : tabber( localPosOnScreen, g_tabSize ); - - localPosOnScreen += letterWidth; - - if ( localPosOnScreen>posOnScreen ) - return i; - } - return size; -} - - -/// Converts the index into the text to a cursor-posOnScreen considering tabulators. -int convertToPosOnScreen( const char* p, int posInText ) -{ - int posOnScreen = 0; - for ( int i=0; i<posInText; ++i ) - { - // All letters except tabulator have width one. - int letterWidth = p[i]!='\t' ? 1 : tabber( posOnScreen, g_tabSize ); - - posOnScreen += letterWidth; - } - return posOnScreen; -} - -void MergeResultWindow::writeLine( - QPainter& p, int line, const char* pStr, int size, - int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved - ) -{ - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width("W"); - int fontAscent = fm.ascent(); - - int topLineYOffset = fontHeight + 3; - int xOffset = fontWidth * leftInfoWidth; - - int yOffset = ( line-m_firstLine ) * fontHeight; - if ( yOffset < 0 || yOffset > height() ) - return; - - yOffset += topLineYOffset; - - QString srcName = " "; - if ( bUserModified ) srcName = "m"; - else if ( srcSelect == A && mergeDetails != eNoChange ) srcName = "A"; - else if ( srcSelect == B ) srcName = "B"; - else if ( srcSelect == C ) srcName = "C"; - - - if( (srcSelect > 0 || bUserModified ) && !bLineRemoved ) - { - int outPos = 0; - QCString s; - for ( int i=0; i<size; ++i ) - { - int spaces = 1; - if ( pStr[i]=='\t' ) - { - spaces = tabber( outPos, g_tabSize ); - for( int j=0; j<spaces; ++j ) - s+=' '; - } - else - { - s+=pStr[i]; - } - outPos += spaces; - } - - if ( m_selection.lineWithin( line ) ) - { - int firstPosInLine = convertToPosOnScreen( pStr, convertToPosInText( pStr, size, m_selection.firstPosInLine(line) ) ); - int lastPosInLine = convertToPosOnScreen( pStr, convertToPosInText( pStr, size, m_selection.lastPosInLine(line) ) ); - int lengthInLine = max(0,lastPosInLine - firstPosInLine); - if (lengthInLine>0) m_selection.bSelectionContainsData = true; - - if ( lengthInLine < int(s.length()) ) - { // Draw a normal line first - p.setPen( m_pOptionDialog->m_fgColor ); - p.drawText( xOffset, yOffset+fontAscent, s.mid(m_firstColumn) ); - } - int firstPosInLine2 = max( firstPosInLine, m_firstColumn ); - int lengthInLine2 = max(0,lastPosInLine - firstPosInLine2); - - if( m_selection.lineWithin( line+1 ) ) - p.fillRect( xOffset + fontWidth*(firstPosInLine2-m_firstColumn), yOffset, - width(), fontHeight, colorGroup().highlight() ); - else - p.fillRect( xOffset + fontWidth*(firstPosInLine2-m_firstColumn), yOffset, - fontWidth*lengthInLine2, fontHeight, colorGroup().highlight() ); - - p.setPen( colorGroup().highlightedText() ); - p.drawText( xOffset + fontWidth*(firstPosInLine2-m_firstColumn), yOffset+fontAscent, - s.mid(firstPosInLine2,lengthInLine2) ); - } - else - { - p.setPen( m_pOptionDialog->m_fgColor ); - p.drawText( xOffset, yOffset+fontAscent, s.mid(m_firstColumn) ); - } - - p.setPen( m_pOptionDialog->m_fgColor ); - if ( m_cursorYPos==line ) - { - m_cursorXPos = minMaxLimiter( m_cursorXPos, 0, outPos ); - m_cursorXPos = convertToPosOnScreen( pStr, convertToPosInText( pStr, size, m_cursorXPos ) ); - } - - p.drawText( 1, yOffset+fontAscent, srcName ); - } - else if ( bLineRemoved ) - { - p.setPen( m_pOptionDialog->m_colorForConflict ); - p.drawText( xOffset, yOffset+fontAscent, "<No src line>" ); - p.drawText( 1, yOffset+fontAscent, srcName ); - if ( m_cursorYPos==line ) m_cursorXPos = 0; - } - else if ( srcSelect == 0 ) - { - p.setPen( m_pOptionDialog->m_colorForConflict ); - p.drawText( xOffset, yOffset+fontAscent, "<Merge Conflict>" ); - p.drawText( 1, yOffset+fontAscent, "?" ); - if ( m_cursorYPos==line ) m_cursorXPos = 0; - } - else assert(false); - - xOffset -= fontWidth; - p.setPen( m_pOptionDialog->m_fgColor ); - if ( rangeMark & 1 ) // begin mark - { - p.drawLine( xOffset, yOffset+1, xOffset, yOffset+fontHeight/2 ); - p.drawLine( xOffset, yOffset+1, xOffset-2, yOffset+1 ); - } - else - { - p.drawLine( xOffset, yOffset, xOffset, yOffset+fontHeight/2 ); - } - - if ( rangeMark & 2 ) // end mark - { - p.drawLine( xOffset, yOffset+fontHeight/2, xOffset, yOffset+fontHeight-1 ); - p.drawLine( xOffset, yOffset+fontHeight-1, xOffset-2, yOffset+fontHeight-1 ); - } - else - { - p.drawLine( xOffset, yOffset+fontHeight/2, xOffset, yOffset+fontHeight ); - } - - if ( rangeMark & 4 ) - { - p.setPen( blue ); - p.drawLine( xOffset+2, yOffset, xOffset+2, yOffset+fontHeight-1 ); - p.drawLine( xOffset+3, yOffset, xOffset+3, yOffset+fontHeight-1 ); - } -} - -void MergeResultWindow::paintEvent( QPaintEvent* e ) -{ - bool bOldSelectionContainsData = m_selection.bSelectionContainsData; - if (font() != m_pOptionDialog->m_font ) - { - setFont( m_pOptionDialog->m_font ); - } - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width("W"); - int fontAscent = fm.ascent(); - - if ( e!= 0 ) // e==0 for blinking cursor - { - m_selection.bSelectionContainsData = false; - if ( size() != m_pixmap.size() ) - m_pixmap.resize(size()); - - QPainter p(&m_pixmap); - p.setFont( font() ); - p.fillRect( rect(), m_pOptionDialog->m_bgColor ); - - //int visibleLines = height() / fontHeight; - - { // Draw the topline - QString s; - s.sprintf(" Output : %s ", (const char*)m_fileName ); - // s.sprintf(" Output : %s : Line %d",(const char*) m_fileName, m_firstLine+1 ); - if (m_bModified) - s += i18n("[Modified]"); - - int topLineYOffset = fontHeight + 3; - - if (hasFocus()) - { - p.fillRect( 0, 0, width(), topLineYOffset, m_pOptionDialog->m_diffBgColor ); - } - else - { - p.fillRect( 0, 0, width(), topLineYOffset, m_pOptionDialog->m_bgColor ); - } - p.setPen( m_pOptionDialog->m_fgColor ); - p.drawText( 0, fontAscent+1, s ); - p.drawLine( 0, fontHeight + 2, width(), fontHeight + 2 ); - } - - bool bAnyConflict = false; - int nofColumns = 0; - int line = 0; - MergeLineList::iterator mlIt = m_mergeLineList.begin(); - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - MergeEditLineList::iterator melIt, melIt1; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - MergeEditLine& mel = *melIt; - melIt1 = melIt; - ++melIt1; - - if( mel.isConflict() ) - bAnyConflict = true; - - int rangeMark = 0; - if ( melIt==ml.mergeEditLineList.begin() ) rangeMark |= 1; // Begin range mark - if ( melIt1==ml.mergeEditLineList.end() ) rangeMark |= 2; // End range mark - - if ( mlIt == m_currentMergeLineIt ) rangeMark |= 4; // Mark of the current line - - const char* s; - int size; - s = mel.getString( this, size ); - if (size>nofColumns) - nofColumns = size; - - writeLine( p, line, s, size, mel.src(), ml.mergeDetails, rangeMark, - mel.isModified(), mel.isRemoved() ); - ++line; - } - } - - emit savable( ! bAnyConflict ); - - if ( line != m_nofLines || nofColumns != m_nofColumns ) - { - m_nofLines = line; - m_nofColumns = nofColumns; - emit resizeSignal(); - } - - if( m_currentMergeLineIt == m_mergeLineList.end() ) - emit sourceMask( 0, 0 ); - else - { - int enabledMask = m_pldC==0 ? 3 : 7; - MergeLine& ml = *m_currentMergeLineIt; - - int srcMask = 0; - bool bModified = false; - MergeEditLineList::iterator melIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - MergeEditLine& mel = *melIt; - if ( mel.src()==1 ) srcMask |= 1; - if ( mel.src()==2 ) srcMask |= 2; - if ( mel.src()==3 ) srcMask |= 4; - if ( mel.isModified() || !mel.isEditableText() ) bModified = true; - } - - if ( ml.mergeDetails == eNoChange ) emit sourceMask( 0, bModified ? 1 : 0 ); - else emit sourceMask( srcMask, enabledMask ); - } - p.end(); - } - - QPainter painter(this); - if ( e!= 0 ) - { - painter.drawPixmap(0,0, m_pixmap); - } - - int topLineYOffset = fontHeight + 3; - int xOffset = fontWidth * leftInfoWidth; - int yOffset = ( m_cursorYPos - m_firstLine ) * fontHeight + topLineYOffset; - int xCursor = ( m_cursorXPos - m_firstColumn ) * fontWidth + xOffset; - - if ( e!= 0 ) - painter.drawPixmap(0,0, m_pixmap); - else - painter.drawPixmap(xCursor-2, yOffset, m_pixmap, - xCursor-2, yOffset, 5, fontAscent+2 ); - - if ( m_bCursorOn && hasFocus() ) - { - int topLineYOffset = fontHeight + 3; - int xOffset = fontWidth * leftInfoWidth; - - int yOffset = ( m_cursorYPos-m_firstLine ) * fontHeight + topLineYOffset; - - int xCursor = ( m_cursorXPos - m_firstColumn ) * fontWidth + xOffset; - painter.drawLine( xCursor, yOffset, xCursor, yOffset+fontAscent ); - painter.drawLine( xCursor-2, yOffset, xCursor+2, yOffset ); - painter.drawLine( xCursor-2, yOffset+fontAscent+1, xCursor+2, yOffset+fontAscent+1 ); - } - - if( !bOldSelectionContainsData && m_selection.bSelectionContainsData ) - emit newSelection(); -} - -void MergeResultWindow::convertToLinePos( int x, int y, int& line, int& pos ) -{ - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width('W'); - int xOffset = (leftInfoWidth-m_firstColumn)*fontWidth; - int topLineYOffset = fontHeight + 3; - - int yOffset = topLineYOffset - m_firstLine * fontHeight; - - line = min( ( y - yOffset ) / fontHeight, m_nofLines-1 ); - pos = ( x - xOffset ) / fontWidth; -} - -void MergeResultWindow::mousePressEvent ( QMouseEvent* e ) -{ - m_bCursorOn = true; - - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - - if ( e->button() == LeftButton ) - { - if ( pos < m_firstColumn ) // Fast range selection - { - m_cursorXPos = 0; - m_cursorOldXPos = 0; - m_cursorYPos = max(line,0); - int l = 0; - MergeLineList::iterator i = m_mergeLineList.begin(); - for(i = m_mergeLineList.begin();i!=m_mergeLineList.end(); ++i) - { - if (l==line) - break; - - l += i->mergeEditLineList.size(); - if (l>line) - break; - } - m_selection.reset(); // Disable current selection - - m_bCursorOn = true; - setFastSelector( i ); - } - else // Normal cursor placement - { - pos = max(pos,0); - line = max(line,0); - - if ( e->state() & ShiftButton ) - { - if (m_selection.firstLine==-1) - m_selection.start( line, pos ); - m_selection.end( line, pos ); - } - else - { - // Selection - m_selection.reset(); - m_selection.start( line, pos ); - m_selection.end( line, pos ); - } - m_cursorXPos = pos; - m_cursorOldXPos = pos; - m_cursorYPos = line; - - update(); - //showStatusLine( line, m_winIdx, m_pFilename, m_pDiff3LineList, m_pStatusBar ); - } - } - else if ( e->button() == MidButton ) // Paste clipboard - { - pos = max(pos,0); - line = max(line,0); - - m_selection.reset(); - m_cursorXPos = pos; - m_cursorOldXPos = pos; - m_cursorYPos = line; - - pasteClipboard(); - } -} - -void MergeResultWindow::mouseDoubleClickEvent( QMouseEvent* e ) -{ - if ( e->button() == LeftButton ) - { - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - m_cursorXPos = pos; - m_cursorOldXPos = pos; - m_cursorYPos = line; - - // Get the string data of the current line - - int size; - MergeLineList::iterator mlIt; - MergeEditLineList::iterator melIt; - calcIteratorFromLineNr( line, mlIt, melIt ); - const char* s = melIt->getString( this, size ); - - if ( s!=0 && size>0 ) - { - int pos1, pos2; - calcTokenPos( s, size, pos, pos1, pos2 ); - - resetSelection(); - m_selection.start( line, convertToPosOnScreen( s, pos1 ) ); - m_selection.end( line, convertToPosOnScreen( s, pos2 ) ); - - update(); - // emit selectionEnd() happens in the mouseReleaseEvent. - } - } -} - -void MergeResultWindow::mouseReleaseEvent ( QMouseEvent * e ) -{ - if ( e->button() == LeftButton ) - { - killTimers(); - - if (m_selection.firstLine != -1 ) - { - emit selectionEnd(); - } - } -} - -void MergeResultWindow::mouseMoveEvent ( QMouseEvent * e ) -{ - int line; - int pos; - convertToLinePos( e->x(), e->y(), line, pos ); - m_cursorXPos = pos; - m_cursorOldXPos = pos; - m_cursorYPos = line; - if (m_selection.firstLine != -1 ) - { - m_selection.end( line, pos ); - myUpdate(0); - - //showStatusLine( line, m_winIdx, m_pFilename, m_pDiff3LineList, m_pStatusBar ); - - // Scroll because mouse moved out of the window - const QFontMetrics& fm = fontMetrics(); - int fontHeight = fm.height(); - int fontWidth = fm.width('W'); - int topLineYOffset = fontHeight + 3; - int deltaX=0; - int deltaY=0; - if ( e->x() < leftInfoWidth*fontWidth ) deltaX=-1; - if ( e->x() > width() ) deltaX=+1; - if ( e->y() < topLineYOffset ) deltaY=-1; - if ( e->y() > height() ) deltaY=+1; - m_scrollDeltaX = deltaX; - m_scrollDeltaY = deltaY; - if ( deltaX != 0 || deltaY!= 0) - { - emit scroll( deltaX, deltaY ); - } - } -} - - -void MergeResultWindow::slotCursorUpdate() -{ - m_cursorTimer.stop(); - m_bCursorOn = !m_bCursorOn; - - if ( isVisible() ) - paintEvent(0); - - m_cursorTimer.start(500,true); -} - - -void MergeResultWindow::keyPressEvent( QKeyEvent* e ) -{ - int y = m_cursorYPos; - MergeLineList::iterator mlIt; - MergeEditLineList::iterator melIt; - calcIteratorFromLineNr( y, mlIt, melIt ); - int stringLength; - const char* ps = melIt->getString( this, stringLength ); - int x = convertToPosInText( ps, stringLength, m_cursorXPos ); - - bool bCtrl = ( e->state() & ControlButton ) != 0 ; -// bool bAlt = ( e->state() & AltButton ) != 0 ; - bool bShift = ( e->state() & ShiftButton ) != 0 ; - - - bool bYMoveKey = false; - // Special keys - switch ( e->key() ) - { - case Key_Escape: break; - //case Key_Tab: break; - case Key_Backtab: break; - case Key_Delete: - { - if ( deleteSelection2( ps, stringLength, x, y, mlIt, melIt )) break; - if( !melIt->isEditableText() ) break; - if (x>=stringLength) - { - if ( y<m_nofLines-1 ) - { - setModified(); - QCString s1( ps, stringLength+1 ); - MergeLineList::iterator mlIt1; - MergeEditLineList::iterator melIt1; - calcIteratorFromLineNr( y+1, mlIt1, melIt1 ); - if ( melIt1->isEditableText() ) - { - int stringLength1; - ps = melIt1->getString( this, stringLength1 ); - assert(ps!=0); - QCString s2( ps, stringLength1+1 ); - melIt->setString( s1 + s2 ); - - // Remove the line - if ( mlIt1->mergeEditLineList.size()>1 ) - mlIt1->mergeEditLineList.erase( melIt1 ); - else - melIt1->setRemoved(); - } - } - } - else - { - QCString s( ps, x+1 ); - s += QCString( ps+x+1, stringLength - x ); - melIt->setString( s ); - setModified(); - } - break; - } - case Key_Backspace: - { - if ( deleteSelection2( ps, stringLength, x, y, mlIt, melIt )) break; - if( !melIt->isEditableText() ) break; - if (x==0) - { - if ( y>0 ) - { - setModified(); - QCString s2( ps, stringLength+1 ); - MergeLineList::iterator mlIt1; - MergeEditLineList::iterator melIt1; - calcIteratorFromLineNr( y-1, mlIt1, melIt1 ); - if ( melIt1->isEditableText() ) - { - int stringLength1; - ps = melIt1->getString( this, stringLength1 ); - QCString s1( ps, stringLength1+1 ); - melIt1->setString( s1 + s2 ); - - // Remove the previous line - if ( mlIt->mergeEditLineList.size()>1 ) - mlIt->mergeEditLineList.erase( melIt ); - else - melIt->setRemoved(); - - --y; - x=stringLength1; - } - } - } - else - { - QCString s( ps, x ); - s += QCString( ps+x, stringLength - x + 1 ); - --x; - melIt->setString( s ); - setModified(); - } - break; - } - case Key_Return: - case Key_Enter: - { - if( !melIt->isEditableText() ) break; - deleteSelection2( ps, stringLength, x, y, mlIt, melIt ); - setModified(); - QCString indentation; - if ( m_pOptionDialog->m_bAutoIndentation ) - { // calc last indentation - MergeLineList::iterator mlIt1 = mlIt; - MergeEditLineList::iterator melIt1 = melIt; - for(;;) { - int size; - const char* s = melIt1->getString(this, size); - if ( s!=0 ) { - int i; - for( i=0; i<size; ++i ){ if(s[i]!=' ' && s[i]!='\t') break; } - if (i<size) { - indentation = QCString( s, i+1 ); - break; - } - } - --melIt1; - if ( melIt1 == mlIt1->mergeEditLineList.end() ) { - --mlIt1; - if ( mlIt1 == m_mergeLineList.end() ) break; - melIt1 = mlIt1->mergeEditLineList.end(); - --melIt1; - } - } - } - MergeEditLine mel; - mel.setString( indentation + QCString( ps+x, stringLength - x + 1 ) ); - - if ( x<stringLength ) // Cut off the old line. - { - // Since ps possibly points into melIt->str, first copy it into a temporary. - QCString temp = QCString( ps, x + 1 ); - melIt->setString( temp ); - } - - ++melIt; - mlIt->mergeEditLineList.insert( melIt, mel ); - x=indentation.length(); - ++y; - break; - } - case Key_Insert: m_bInsertMode = !m_bInsertMode; break; - case Key_Pause: break; - case Key_Print: break; - case Key_SysReq: break; - case Key_Home: x=0; if(bCtrl){y=0; } break; // cursor movement - case Key_End: x=INT_MAX; if(bCtrl){y=INT_MAX;} break; - - case Key_Left: - if ( !bCtrl ) - { - --x; - if(x<0 && y>0){--y; x=INT_MAX;} - } - else - { - while( x>0 && (ps[x-1]==' ' || ps[x-1]=='\t') ) --x; - while( x>0 && (ps[x-1]!=' ' && ps[x-1]!='\t') ) --x; - } - break; - - case Key_Right: - if ( !bCtrl ) - { - ++x; if(x>stringLength && y<m_nofLines-1){ ++y; x=0; } - } - else - { - while( x<stringLength && (ps[x]==' ' || ps[x]=='\t') ) ++x; - while( x<stringLength && (ps[x]!=' ' && ps[x]!='\t') ) ++x; - } - break; - - case Key_Up: --y; bYMoveKey=true; break; - case Key_Down: ++y; bYMoveKey=true; break; - case Key_PageUp: y-=getNofVisibleLines(); bYMoveKey=true; break; - case Key_PageDown: y+=getNofVisibleLines(); bYMoveKey=true; break; - default: - { - QString t = e->text(); - if( t.isEmpty() || bCtrl ) - { e->ignore(); return; } - else - { - if( bCtrl ) - { - e->ignore(); return; - } - else - { - if( !melIt->isEditableText() ) break; - deleteSelection2( ps, stringLength, x, y, mlIt, melIt ); - - setModified(); - // Characters to insert - QCString s( ps, stringLength+1 ); - if ( t[0]=='\t' && m_pOptionDialog->m_bReplaceTabs ) - { - int spaces = (m_cursorXPos / g_tabSize + 1)*g_tabSize - m_cursorXPos; - t.fill( ' ', spaces ); - } - if ( m_bInsertMode ) - s.insert( x, t ); - else - s.replace( x, t.length(), t ); - - melIt->setString( s ); - x += t.length(); - bShift = false; - } - } - } - } - - y = minMaxLimiter( y, 0, m_nofLines-1 ); - - calcIteratorFromLineNr( y, mlIt, melIt ); - ps = melIt->getString( this, stringLength ); - - x = minMaxLimiter( x, 0, stringLength ); - - int newFirstLine = m_firstLine; - int newFirstColumn = m_firstColumn; - - if ( y<m_firstLine ) - newFirstLine = y; - else if ( y > m_firstLine + getNofVisibleLines() ) - newFirstLine = y - getNofVisibleLines(); - - if (bYMoveKey) - x=convertToPosInText( ps, stringLength, m_cursorOldXPos ); - - int xOnScreen = convertToPosOnScreen( ps, x ); - if ( xOnScreen<m_firstColumn ) - newFirstColumn = xOnScreen; - else if ( xOnScreen > m_firstColumn + getNofVisibleColumns() ) - newFirstColumn = xOnScreen - getNofVisibleColumns(); - - if ( bShift ) - { - if (m_selection.firstLine==-1) - m_selection.start( m_cursorYPos, m_cursorXPos ); - - m_selection.end( y, xOnScreen ); - } - else - m_selection.reset(); - - m_cursorYPos = y; - m_cursorXPos = xOnScreen; - if ( ! bYMoveKey ) - m_cursorOldXPos = m_cursorXPos; - - m_bCursorOn = false; - - if ( newFirstLine!=m_firstLine || newFirstColumn!=m_firstColumn ) - { - m_bCursorOn = true; - scroll( newFirstColumn-m_firstColumn, newFirstLine-m_firstLine ); - return; - } - - m_bCursorOn = true; - update(); -} - -void MergeResultWindow::calcIteratorFromLineNr( - int line, - MergeResultWindow::MergeLineList::iterator& mlIt, - MergeResultWindow::MergeEditLineList::iterator& melIt - ) -{ - for( mlIt = m_mergeLineList.begin(); mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - --line; - if (line<0) return; - } - } - assert(false); -} - - -QString MergeResultWindow::getSelection() -{ - QString selectionString; - - int line = 0; - MergeLineList::iterator mlIt = m_mergeLineList.begin(); - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - MergeEditLineList::iterator melIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - MergeEditLine& mel = *melIt; - - if ( mel.isEditableText() && m_selection.lineWithin(line) ) - { - int size; - const char* pLine = mel.getString( this, size ); - - // Consider tabs - int outPos = 0; - for( int i=0; i<size; ++i ) - { - int spaces = 1; - if ( pLine[i]=='\t' ) - { - spaces = tabber( outPos, g_tabSize ); - } - - if( m_selection.within( line, outPos ) ) - { - selectionString += pLine[i]; - } - - outPos += spaces; - } - - if( m_selection.within( line, outPos ) ) - { - #ifdef WIN32 - selectionString += '\r'; - #endif - selectionString += '\n'; - } - } - - ++line; - } - } - - return selectionString; -} - -bool MergeResultWindow::deleteSelection2( const char*& ps, int& stringLength, int& x, int& y, - MergeLineList::iterator& mlIt, MergeEditLineList::iterator& melIt ) -{ - if (m_selection.firstLine!=-1 && m_selection.bSelectionContainsData ) - { - deleteSelection(); - y = m_cursorYPos; - calcIteratorFromLineNr( y, mlIt, melIt ); - ps = melIt->getString( this, stringLength ); - x = convertToPosInText( ps, stringLength, m_cursorXPos ); - return true; - } - return false; -} - -void MergeResultWindow::deleteSelection() -{ - if ( m_selection.firstLine==-1 || !m_selection.bSelectionContainsData ) - { - return; - } - setModified(); - - int line = 0; - MergeLineList::iterator mlItFirst; - MergeEditLineList::iterator melItFirst; - QCString firstLineString; - - int firstLine = -1; - int lastLine = -1; - - MergeLineList::iterator mlIt; - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - MergeEditLineList::iterator melIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - MergeEditLine& mel = *melIt; - - if ( mel.isEditableText() && m_selection.lineWithin(line) ) - { - if ( firstLine==-1 ) - firstLine = line; - lastLine = line; - } - - ++line; - } - } - - if ( firstLine == -1 ) - { - return; // Nothing to delete. - } - - line = 0; - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - MergeEditLineList::iterator melIt, melIt1; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ) - { - MergeEditLine& mel = *melIt; - melIt1 = melIt; - ++melIt1; - - if ( mel.isEditableText() && m_selection.lineWithin(line) ) - { - int size; - const char* pLine = mel.getString( this, size ); - - int firstPosInLine = m_selection.firstPosInLine(line); - int lastPosInLine = m_selection.lastPosInLine(line); - - if ( line==firstLine ) - { - mlItFirst = mlIt; - melItFirst = melIt; - int pos = convertToPosInText( pLine, size, firstPosInLine ); - firstLineString = QCString( pLine, pos+1 ); - } - - if ( line==lastLine ) - { - // This is the last line in the selection - int pos = convertToPosInText( pLine, size, lastPosInLine ); - firstLineString += QCString( pLine+pos, 1+max( 0,size-pos)); - melItFirst->setString( firstLineString ); - } - - if ( line!=firstLine ) - { - // Remove the line - if ( mlIt->mergeEditLineList.size()>1 ) - { mlIt->mergeEditLineList.erase( melIt ); --m_nofLines; } - else - { melIt->setRemoved(); } - } - } - - ++line; - melIt = melIt1; - } - } - - m_cursorYPos = m_selection.beginLine(); - m_cursorXPos = m_selection.beginPos(); - m_cursorOldXPos = m_cursorXPos; - - m_selection.reset(); -} - -void MergeResultWindow::pasteClipboard() -{ - if (m_selection.firstLine != -1 ) - deleteSelection(); - - setModified(); - - int y = m_cursorYPos; - MergeLineList::iterator mlIt; - MergeEditLineList::iterator melIt, melItAfter; - calcIteratorFromLineNr( y, mlIt, melIt ); - melItAfter = melIt; - ++melItAfter; - int stringLength; - const char* ps = melIt->getString( this, stringLength ); - int x = convertToPosInText( ps, stringLength, m_cursorXPos ); - - QString clipBoard = QApplication::clipboard()->text(); - - QCString currentLine = QCString( ps, x+1 ); - QCString endOfLine = QCString( ps+x, stringLength-x+1 ); - int i; - for( i=0; i<(int)clipBoard.length(); ++i ) - { - QChar uc = clipBoard[i]; - char c = uc; - if ( c == '\r' ) continue; - if ( c == '\n' ) - { - melIt->setString( currentLine ); - - melIt = mlIt->mergeEditLineList.insert( melItAfter, MergeEditLine() ); - currentLine = QCString(); - } - else - { - currentLine += c; - } - } - - currentLine += endOfLine; - melIt->setString( currentLine ); - - update(); -} - -void MergeResultWindow::resetSelection() -{ - m_selection.reset(); - update(); -} - -void MergeResultWindow::setModified() -{ - if (!m_bModified) - { - m_bModified = true; - emit modified(); - } -} - -/// Saves and returns true when successful. -bool MergeResultWindow::saveDocument( const QString& fileName ) -{ - m_fileName = fileName; - update(); - - FILE* file = fopen( m_fileName, "wb" ); - - if ( file == 0 ) - { - KMessageBox::error( this, i18n("Could not open file for saving."), i18n("File save error.") ); - return false; - } - - int line = 0; - MergeLineList::iterator mlIt = m_mergeLineList.begin(); - for(mlIt = m_mergeLineList.begin();mlIt!=m_mergeLineList.end(); ++mlIt) - { - MergeLine& ml = *mlIt; - MergeEditLineList::iterator melIt; - for( melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end(); ++melIt ) - { - MergeEditLine& mel = *melIt; - - if ( mel.isEditableText() ) - { - int size; - const char* pLine = mel.getString( this, size ); - - QCString s(pLine, size+1); - #ifdef WIN32 - s += '\r'; ++size; - #endif - s += '\n'; ++size; - - int written = fwrite( (const char*)s, 1, size, file ); - if ( written!=size ) - { - fclose(file); - KMessageBox::error( this, i18n("Error while writing."), i18n("File save error.") ); - return false; - } - } - - ++line; - } - } - - fclose( file ); - - m_bModified = false; - - return true; -} - - - -Overview::Overview( QWidget* pParent, Diff3LineList* pDiff3LineList, - OptionDialog* pOptions, bool bTripleDiff ) -: QWidget( pParent, 0, WRepaintNoErase ) -{ - m_pDiff3LineList = pDiff3LineList; - m_pOptions = pOptions; - m_bTripleDiff = bTripleDiff; - setFixedWidth(20); -} - -void Overview::setRange( int firstLine, int pageHeight ) -{ - m_firstLine = firstLine; - m_pageHeight = pageHeight; - update(); -} -void Overview::setFirstLine( int firstLine ) -{ - m_firstLine = firstLine; - update(); -} - -void Overview::mousePressEvent( QMouseEvent* e ) -{ - int h = height()-1; - int nofLines = m_pDiff3LineList->size(); - int h1 = h * m_pageHeight / nofLines+3; - if ( h>0 ) - emit setLine( ( e->y() - h1/2 )*nofLines/h ); -} - -void Overview::mouseMoveEvent( QMouseEvent* e ) -{ - mousePressEvent(e); -} - -void Overview::paintEvent( QPaintEvent* e ) -{ - int h = height()-1; - int w = width(); - int nofLines = m_pDiff3LineList->size(); - - if ( m_pixmap.size() != size() ) - { - m_pixmap.resize( size() ); - - QPainter p(&m_pixmap); - - p.fillRect( rect(), m_pOptions->m_bgColor ); - p.setPen(black); - p.drawLine( 0, 0, 0, h ); - - if (nofLines==0) return; - - int line = 0; - int oldY = 0; - int oldConflictY = -1; - Diff3LineList::const_iterator i; - for( i = m_pDiff3LineList->begin(); i!= m_pDiff3LineList->end(); ++i ) - { - const Diff3Line& d3l = *i; - int y = h * (line+1) / nofLines; - e_MergeDetails md; - bool bConflict; - bool bLineRemoved; - int src; - mergeOneLine( d3l, md, bConflict, bLineRemoved, src, !m_bTripleDiff ); - - QColor c; - if( bConflict ) c=m_pOptions->m_colorForConflict; - else - { - switch( md ) - { - case eDefault: - case eNoChange: - c = m_pOptions->m_bgColor; - break; - - case eBAdded: - case eBDeleted: - case eBChanged: - c = m_pOptions->m_colorB; - break; - - case eCAdded: - case eCDeleted: - case eCChanged: - c = m_pOptions->m_colorC; - break; - - case eBCChanged: // conflict - case eBCChangedAndEqual: // possible conflict - case eBCDeleted: // possible conflict - case eBChanged_CDeleted: // conflict - case eCChanged_BDeleted: // conflict - case eBCAdded: // conflict - case eBCAddedAndEqual: // possible conflict - c=m_pOptions->m_colorForConflict; - break; - default: assert(false); break; - } - } - - // Make sure that lines with conflict are not overwritten. - if ( c == m_pOptions->m_colorForConflict ) - { - p.fillRect(1, oldY, w, max(1,y-oldY), c ); - oldConflictY = oldY; - } - else if ( c!=m_pOptions->m_bgColor && oldY>oldConflictY ) - { - p.fillRect(1, oldY, w, max(1,y-oldY), c ); - } - - oldY = y; - - ++line; - } - } - - QPainter painter( this ); - painter.drawPixmap( 0,0, m_pixmap ); - - int y1 = h * m_firstLine / nofLines-1; - int h1 = h * m_pageHeight / nofLines+3; - painter.setPen(black); - painter.drawRect( 1, y1, w-1, h1 ); -} -
--- a/kdiff3/kdiff3/optiondialog.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,400 +0,0 @@ -/* - * kdiff3 - Text Diff And Merge Tool - * This file only: Copyright (C) 2002 Joachim Eibl, joachim.eibl@gmx.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:09 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include <qcheckbox.h> -#include <qcombobox.h> -#include <qfont.h> -#include <qframe.h> -#include <qlayout.h> -#include <qlabel.h> -#include <qlineedit.h> -#include <qvbox.h> -#include <qvalidator.h> -#include <qtooltip.h> - -#include <kapp.h> -#include <kcolorbtn.h> -#include <kfontdialog.h> // For KFontChooser -#include <kiconloader.h> -#include <klocale.h> -#include <kconfig.h> -#include <kmessagebox.h> - -#include "optiondialog.h" - - - -OptionDialog::OptionDialog( QWidget *parent, char *name ) - :KDialogBase( IconList, i18n("Configure"), Help|Default|Apply|Ok|Cancel, - Ok, parent, name, true /*modal*/, true ) -{ - setHelp( "kdiff3/index.html", QString::null ); - - setupFontPage(); - setupColorPage(); - setupEditPage(); - setupDiffPage(); - - // Initialize all values in the dialog - slotDefault(); - slotApply(); -} - -OptionDialog::~OptionDialog( void ) -{ -} - - -void OptionDialog::setupFontPage( void ) -{ - QVBox *page = addVBoxPage( i18n("Font"), i18n("Editor and diff output font" ), - BarIcon("fonts", KIcon::SizeMedium ) ); - m_fontChooser = new KFontChooser( page,"font",true/*onlyFixed*/,QStringList(),false,6 ); -} - - -void OptionDialog::setupColorPage( void ) -{ - QFrame *page = addPage( i18n("Color"), i18n("Colors in editor and diff output"), - BarIcon("colorize", KIcon::SizeMedium ) ); - QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); - - QGridLayout *gbox = new QGridLayout( 7, 2 ); - topLayout->addLayout(gbox); - - QLabel* label; - int line = 0; - - m_pFgColor = new KColorButton( page ); - label = new QLabel( m_pFgColor, i18n("Foreground color:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pFgColor, line, 1 ); - ++line; - - m_pBgColor = new KColorButton( page ); - label = new QLabel( m_pBgColor, i18n("Background color:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pBgColor, line, 1 ); - ++line; - - m_pDiffBgColor = new KColorButton( page ); - label = new QLabel( m_pDiffBgColor, i18n("Diff background color:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pDiffBgColor, line, 1 ); - ++line; - - m_pColorA = new KColorButton( page ); - label = new QLabel( m_pColorA, i18n("Color A:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pColorA, line, 1 ); - ++line; - - m_pColorB = new KColorButton( page ); - label = new QLabel( m_pColorB, i18n("Color B:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pColorB, line, 1 ); - ++line; - - m_pColorC = new KColorButton( page ); - label = new QLabel( m_pColorC, i18n("Color C:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pColorC, line, 1 ); - ++line; - - m_pColorForConflict = new KColorButton( page ); - label = new QLabel( m_pColorForConflict, i18n("Conflict Color:"), page ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pColorForConflict, line, 1 ); - ++line; - - topLayout->addStretch(10); -} - - -void OptionDialog::setupEditPage( void ) -{ - QFrame *page = addPage( i18n("Editor Settings"), i18n("Editor behaviour"), - BarIcon("edit", KIcon::SizeMedium ) ); - QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); - - QGridLayout *gbox = new QGridLayout( 4, 2 ); - topLayout->addLayout( gbox ); - QLabel* label; - int line=0; - - m_pReplaceTabs = new QCheckBox( i18n("Tab inserts spaces"), page ); - gbox->addMultiCellWidget( m_pReplaceTabs, line, line, 0, 1 ); - QToolTip::add( m_pReplaceTabs, i18n( - "On: Pressing tab generates the appropriate number of spaces.\n" - "Off: A Tab-character will be inserted.") - ); - ++line; - - m_pTabSize = new QLineEdit( page ); - label = new QLabel( m_pTabSize, i18n("Tab size:"), page ); - QIntValidator* v = new QIntValidator( m_pTabSize ); - v->setRange(0,100); - m_pTabSize->setValidator( v ); - gbox->addWidget( label, line, 0 ); - gbox->addWidget( m_pTabSize, line, 1 ); - ++line; - - m_pAutoIndentation = new QCheckBox( i18n("Auto Indentation"), page ); - gbox->addMultiCellWidget( m_pAutoIndentation, line, line, 0, 1 ); - QToolTip::add( m_pAutoIndentation, i18n( - "On: The indentation of the previous line is used for a new line.\n" - )); - ++line; - - m_pAutoCopySelection = new QCheckBox( i18n("Auto Copy Selection"), page ); - gbox->addMultiCellWidget( m_pAutoCopySelection, line, line, 0, 1 ); - QToolTip::add( m_pAutoCopySelection, i18n( - "On: Any selection is immediately written to the clipboard.\n" - "Off: You must explicitely copy e.g. via Ctrl-C." - )); - ++line; - - topLayout->addStretch(10); -} - - -void OptionDialog::setupDiffPage( void ) -{ - QFrame *page = addPage( i18n("Diff Settings"), i18n("Diff Settings"), - BarIcon("misc", KIcon::SizeMedium ) ); - QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); - - QGridLayout *gbox = new QGridLayout( 2, 2 ); - topLayout->addLayout( gbox ); - int line=0; - - m_pIgnoreWhiteSpace = new QCheckBox( i18n("Ignore white space"), page ); - gbox->addMultiCellWidget( m_pIgnoreWhiteSpace, line, line, 0, 1 ); - QToolTip::add( m_pIgnoreWhiteSpace, i18n( - "On: Text that differs only in white space will match and\n" - "be shown on the same line in the different output windows.\n" - "Off is useful when whitespace is very important.\n" - "On is good for C/C++ and similar languages." ) - ); - ++line; - - m_pIgnoreTrivialMatches = new QCheckBox( i18n("Ignore trivial matches"), page ); - gbox->addMultiCellWidget( m_pIgnoreTrivialMatches, line, line, 0, 1 ); - QToolTip::add( m_pIgnoreTrivialMatches, - "When a difference was found, the algorithm searches for matching lines\n" - "Short or trivial lines match even when the differences still continue.\n" - "Igoring trivial lines avoids this. Good for C/C++ and similar languages." - ); - ++line; - - topLayout->addStretch(10); -} - - -void OptionDialog::slotOk( void ) -{ - slotApply(); - - // My system returns variable width fonts even though I - // disabled this. Even QFont::fixedPitch() doesn't work. - QFontMetrics fm(m_font); - if ( fm.width('W')!=fm.width('i') ) - { - int result = KMessageBox::warningYesNo(this, i18n( - "You selected a variable width font.\n\n" - "Because this program doesn't handle variable width fonts\n" - "correctly, you might experience problems while editing.\n\n" - "Do you want to continue or do you want to select another font."), - i18n("Incompatible font."), - i18n("Continue at my own risk"), i18n("Select another font")); - if (result==KMessageBox::No) - return; - } - - accept(); -} - - -/** Copy the values from the widgets to the public variables.*/ -void OptionDialog::slotApply( void ) -{ - // FontConfigDlg - m_font = m_fontChooser->font(); - - // ColorConfigDlg - m_fgColor = m_pFgColor->color(); - m_bgColor = m_pBgColor->color(); - m_diffBgColor = m_pDiffBgColor->color(); - m_colorA = m_pColorA->color(); - m_colorB = m_pColorB->color(); - m_colorC = m_pColorC->color(); - m_colorForConflict = m_pColorForConflict->color(); - - // EditConfigDlg - m_bReplaceTabs = m_pReplaceTabs->isChecked(); - m_tabSize = m_pTabSize->text().toInt(); - m_bAutoIndentation = m_pAutoIndentation->isChecked(); - m_bAutoCopySelection = m_pAutoCopySelection->isChecked(); - - // DiffConfigDlg - m_bIgnoreWhiteSpace = m_pIgnoreWhiteSpace->isChecked(); - m_bIgnoreTrivialMatches = m_pIgnoreTrivialMatches->isChecked(); - - emit applyClicked(); -} - -/** Set the default values in the widgets only, while the - public variables remain unchanged. */ -void OptionDialog::slotDefault( void ) -{ - m_fontChooser->setFont( QFont("Courier", 10 ), true /*only fixed*/ ); - - // ColorConfigDlg - m_pFgColor->setColor( black ); - m_pBgColor->setColor( white ); - m_pDiffBgColor->setColor( lightGray ); - m_pColorA->setColor(qRgb( 0, 0, 200 )); // blue - m_pColorB->setColor(qRgb( 0, 150, 0 )); // green - m_pColorC->setColor(qRgb( 150, 0, 150 )); // magenta - m_pColorForConflict->setColor( red ); - - // EditConfigDlg - m_pReplaceTabs->setChecked( false ); - m_pTabSize->setText("8"); - m_pAutoIndentation->setChecked( true ); - m_pAutoCopySelection->setChecked( false ); - - // DiffConfigDlg - m_pIgnoreWhiteSpace->setChecked( true ); - m_pIgnoreTrivialMatches->setChecked( true ); -} - -/** Initialise the widgets using the values in the public varibles. */ -void OptionDialog::setState() -{ - m_fontChooser->setFont( m_font, true /*only fixed*/ ); - - // ColorConfigDlg - m_pFgColor->setColor( m_fgColor ); - m_pBgColor->setColor( m_bgColor ); - m_pDiffBgColor->setColor( m_diffBgColor ); - m_pColorA->setColor(m_colorA); - m_pColorB->setColor(m_colorB); - m_pColorC->setColor(m_colorC); - m_pColorForConflict->setColor( m_colorForConflict ); - - // EditConfigDlg - m_pReplaceTabs->setChecked( m_bReplaceTabs ); - QString s; - s.setNum(m_tabSize); - m_pTabSize->setText( s ); - m_pAutoIndentation->setChecked( m_bAutoIndentation ); - m_pAutoCopySelection->setChecked( m_bAutoCopySelection ); - - // DiffConfigDlg - m_pIgnoreWhiteSpace->setChecked( m_bIgnoreWhiteSpace ); - m_pIgnoreTrivialMatches->setChecked( m_bIgnoreTrivialMatches ); -} - -void OptionDialog::saveOptions( KConfig* config ) -{ - // No i18n()-Translations here! - - config->setGroup("KDiff3 Options"); - - // FontConfigDlg - config->writeEntry("Font", m_font ); - - // ColorConfigDlg - config->writeEntry("FgColor", m_fgColor ); - config->writeEntry("BgColor", m_bgColor ); - config->writeEntry("DiffBgColor", m_diffBgColor ); - config->writeEntry("ColorA", m_colorA ); - config->writeEntry("ColorB", m_colorB ); - config->writeEntry("ColorC", m_colorC ); - config->writeEntry("ColorForConflict", m_colorForConflict ); - - // EditConfigDlg - config->writeEntry("ReplaceTabs", m_colorForConflict ); - config->writeEntry("TabSize", m_tabSize ); - config->writeEntry("AutoIndentation", m_bAutoIndentation ); - config->writeEntry("AutoCopySelection", m_bAutoCopySelection ); - - // DiffConfigDlg - config->writeEntry("IgnoreWhiteSpace", m_bIgnoreWhiteSpace ); - config->writeEntry("IgnoreTrivialMatches", m_bIgnoreTrivialMatches ); - - // Recent files (selectable in the OpenDialog) - config->writeEntry( "RecentAFiles", m_recentAFiles, '|' ); - config->writeEntry( "RecentBFiles", m_recentBFiles, '|' ); - config->writeEntry( "RecentCFiles", m_recentCFiles, '|' ); - config->writeEntry( "RecentOutputFiles", m_recentOutputFiles, '|' ); -} - -void OptionDialog::readOptions( KConfig* config ) -{ - // No i18n()-Translations here! - - config->setGroup("KDiff3 Options"); - - // Use the current values as default settings. - - // FontConfigDlg - m_font = config->readFontEntry( "Font", &m_font); - - // ColorConfigDlg - m_fgColor = config->readColorEntry("FgColor", &m_fgColor ); - m_bgColor = config->readColorEntry("BgColor", &m_bgColor ); - m_diffBgColor = config->readColorEntry("DiffBgColor", &m_diffBgColor ); - m_colorA = config->readColorEntry("ColorA", &m_colorA ); - m_colorB = config->readColorEntry("ColorB", &m_colorB ); - m_colorC = config->readColorEntry("ColorC", &m_colorC ); - m_colorForConflict = config->readColorEntry("ColorForConflict", &m_colorForConflict ); - - // EditConfigDlg - m_bReplaceTabs = config->readBoolEntry("ReplaceTabs", m_bReplaceTabs ); - m_tabSize = config->readNumEntry("TabSize", m_tabSize ); - m_bAutoIndentation = config->readBoolEntry("AutoIndentation", m_bAutoIndentation ); - m_bAutoCopySelection = config->readBoolEntry("AutoCopySelection", m_bAutoCopySelection ); - - // DiffConfigDlg - m_bIgnoreWhiteSpace = config->readBoolEntry("IgnoreWhiteSpace", m_bIgnoreWhiteSpace ); - m_bIgnoreTrivialMatches = config->readBoolEntry("IgnoreTrivialMatches", m_bIgnoreTrivialMatches ); - - // Recent files (selectable in the OpenDialog) - config->readListEntry( "RecentAFiles", m_recentAFiles, '|' ); - config->readListEntry( "RecentBFiles", m_recentBFiles, '|' ); - config->readListEntry( "RecentCFiles", m_recentCFiles, '|' ); - config->readListEntry( "RecentOutputFiles", m_recentOutputFiles, '|' ); - - setState(); -} - -void OptionDialog::slotHelp( void ) -{ - KDialogBase::slotHelp(); -}
--- a/kdiff3/kdiff3/optiondialog.h Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* - * kdiff3 - Text Diff And Merge Tool - * This file only: Copyright (C) 2002 Joachim Eibl, joachim.eibl@gmx.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:17 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#ifndef OPTION_DIALOG_H -#define OPTION_DIALOG_H - -class QCheckBox; -class QLabel; -class QLineEdit; -class KColorButton; -class KFontChooser; -class KConfig; - -#include <kdialogbase.h> -#include <qstrlist.h> - - -class OptionDialog : public KDialogBase -{ - Q_OBJECT - -public: - - OptionDialog( QWidget *parent = 0, char *name = 0 ); - ~OptionDialog( void ); - - // These are the results of the option dialog. - QFont m_font; - - QColor m_fgColor; - QColor m_bgColor; - QColor m_diffBgColor; - QColor m_colorA; - QColor m_colorB; - QColor m_colorC; - QColor m_colorForConflict; - - bool m_bReplaceTabs; - bool m_bAutoIndentation; - int m_tabSize; - bool m_bAutoCopySelection; - - bool m_bIgnoreWhiteSpace; - bool m_bIgnoreTrivialMatches; - - QStrList m_recentAFiles; - QStrList m_recentBFiles; - QStrList m_recentCFiles; - QStrList m_recentOutputFiles; - - void saveOptions(KConfig* config); - void readOptions(KConfig* config); - - void setState(); // Must be called before calling exec(); - -protected slots: - virtual void slotDefault( void ); - virtual void slotOk( void ); - virtual void slotApply( void ); - virtual void slotHelp( void ); - -private: - // FontConfigDlg - KFontChooser *m_fontChooser; - - // ColorConfigDlg - KColorButton* m_pFgColor; - KColorButton* m_pBgColor; - KColorButton* m_pDiffBgColor; - KColorButton* m_pColorA; - KColorButton* m_pColorB; - KColorButton* m_pColorC; - KColorButton* m_pColorForConflict; - - - // EditConfigDlg - QCheckBox* m_pReplaceTabs; - QLineEdit* m_pTabSize; - QCheckBox* m_pAutoIndentation; - QCheckBox* m_pAutoCopySelection; - - // DiffConfigDlg - QCheckBox* m_pIgnoreWhiteSpace; - QCheckBox* m_pIgnoreTrivialMatches; - -private: - void setupFontPage( void ); - void setupColorPage( void ); - void setupEditPage( void ); - void setupDiffPage( void ); -}; - - -#endif - - - - - - -
--- a/kdiff3/kdiff3/pdiff.cpp Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,817 +0,0 @@ -/*************************************************************************** - kdiff.cpp - description - ------------------- - begin : Mon Mär 18 20:04:50 CET 2002 - copyright : (C) 2002 by Joachim Eibl - email : joachim.eibl@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -/*************************************************************************** - * $Log$ - * Revision 1.1 2002/08/18 16:24:10 joachim99 - * Initial revision - * * - ***************************************************************************/ - -#include <iostream> -#include <qaccel.h> - -#include <kfiledialog.h> -#include <klocale.h> -#include <kmessagebox.h> -#include <kfontdialog.h> -#include <kstatusbar.h> - -#include <qclipboard.h> -#include <qscrollbar.h> -#include <qlayout.h> -#include <qsplitter.h> -#include <qlabel.h> -#include <qpushbutton.h> -#include <qlineedit.h> -#include <qcheckbox.h> -#include <qcombobox.h> -#include <minmax.h> -#include <assert.h> - -#include "kdiff3.h" -#include "optiondialog.h" - -using namespace std; - -int g_tabSize = 8; -bool g_bIgnoreWhiteSpace = true; -bool g_bIgnoreTrivialMatches = true; - -void KDiff3App::init( const char* filename1, const char* filename2, const char* filename3 ) -{ - delete m_pBuf1; m_pBuf1 = 0; - delete m_pBuf2; m_pBuf2 = 0; - delete m_pBuf3; m_pBuf3 = 0; - - g_bIgnoreWhiteSpace = m_pOptionDialog->m_bIgnoreWhiteSpace; - g_bIgnoreTrivialMatches = m_pOptionDialog->m_bIgnoreTrivialMatches; - - m_diff3LineList.clear(); - - // First get all input data. - m_pBuf1 = readFile( filename1, m_size1 ); - m_v1size = preprocess( m_pBuf1, m_size1, m_v1 ); - - m_pBuf2 = readFile( filename2, m_size2 ); - m_v2size = preprocess( m_pBuf2, m_size2, m_v2 ); - - // Run the diff. - if ( filename3 == 0 || filename3[0]=='\0' ) - { - calcDiff( &m_v1[0], m_v1size, &m_v2[0], m_v2size, m_diffList12, 2 ); - - calcDiff3LineListUsingAB( &m_diffList12, m_diff3LineList ); - fineDiff( m_diff3LineList, 1, &m_v1[0], &m_v2[0] ); - } - - else - { - m_pBuf3 = readFile( filename3, m_size3 ); - - m_v3size = preprocess( m_pBuf3, m_size3, m_v3 ); - - calcDiff( &m_v1[0], m_v1size, &m_v2[0], m_v2size, m_diffList12, 2 ); - calcDiff( &m_v2[0], m_v2size, &m_v3[0], m_v3size, m_diffList23, 2 ); - calcDiff( &m_v1[0], m_v1size, &m_v3[0], m_v3size, m_diffList13, 2 ); - - calcDiff3LineListUsingAB( &m_diffList12, m_diff3LineList ); - calcDiff3LineListUsingAC( &m_diffList13, m_diff3LineList ); - calcDiff3LineListTrim( m_diff3LineList, &m_v1[0], &m_v2[0], &m_v3[0] ); - - calcDiff3LineListUsingBC( &m_diffList23, m_diff3LineList ); - calcDiff3LineListTrim( m_diff3LineList, &m_v1[0], &m_v2[0], &m_v3[0] ); - debugLineCheck( m_diff3LineList, m_v1size, 1 ); - debugLineCheck( m_diff3LineList, m_v2size, 2 ); - debugLineCheck( m_diff3LineList, m_v3size, 3 ); - - fineDiff( m_diff3LineList, 1, &m_v1[0], &m_v2[0] ); - fineDiff( m_diff3LineList, 2, &m_v2[0], &m_v3[0] ); - fineDiff( m_diff3LineList, 3, &m_v3[0], &m_v1[0] ); - } - - // Calc needed lines for display - m_neededLines = m_diff3LineList.size(); - - // Calc max width for display - m_maxWidth = 0; - int j; - for (j=0; j<m_v1size;++j ) - { - m_maxWidth = max( m_v1[j].size, m_maxWidth ); - } - for (j=0; j<m_v2size;++j ) - { - m_maxWidth = max( m_v2[j].size, m_maxWidth ); - } - - if(filename3!=0 && filename3[0]!='\0') - { - for (j=0; j<m_v3size;++j ) - { - m_maxWidth = max( m_v3[j].size, m_maxWidth ); - } - } - - initView(); -} - - -void KDiff3App::resizeDiffTextWindow(int newWidth, int newHeight) -{ - m_DTWHeight = newHeight; - m_pDiffVScrollBar->setRange(0, max(0, m_neededLines+1 - newHeight) ); - m_pDiffVScrollBar->setPageStep( newHeight ); - m_pOverview->setRange( m_pDiffVScrollBar->value(), m_pDiffVScrollBar->pageStep() ); - - // The second window has a somewhat inverse width - m_pHScrollBar->setRange(0, max(0, m_maxWidth - newWidth) ); - m_pHScrollBar->setPageStep( newWidth ); -} - -void KDiff3App::resizeMergeResultWindow() -{ - MergeResultWindow* p = m_pMergeResultWindow; - m_pMergeVScrollBar->setRange(0, max(0, p->getNofLines() - p->getNofVisibleLines()) ); - m_pMergeVScrollBar->setPageStep( p->getNofVisibleLines() ); - - // The second window has a somewhat inverse width -// m_pHScrollBar->setRange(0, max(0, m_maxWidth - newWidth) ); -// m_pHScrollBar->setPageStep( newWidth ); -} - -void KDiff3App::scrollDiffTextWindow( int deltaX, int deltaY ) -{ - if ( deltaY!= 0 ) - { - m_pDiffVScrollBar->setValue( m_pDiffVScrollBar->value() + deltaY ); - m_pOverview->setRange( m_pDiffVScrollBar->value(), m_pDiffVScrollBar->pageStep() ); - } - if ( deltaX!= 0) - m_pHScrollBar->setValue( m_pHScrollBar->value() + deltaX ); -} - -void KDiff3App::scrollMergeResultWindow( int deltaX, int deltaY ) -{ - if ( deltaY!= 0 ) - m_pMergeVScrollBar->setValue( m_pMergeVScrollBar->value() + deltaY ); - if ( deltaX!= 0) - m_pHScrollBar->setValue( m_pHScrollBar->value() + deltaX ); -} - -void KDiff3App::setDiff3Line( int line ) -{ - m_pDiffVScrollBar->setValue( line ); -} - -void KDiff3App::sourceMask( int srcMask, int enabledMask ) -{ - chooseA->setChecked( (srcMask & 1) != 0 ); - - chooseB->setChecked( (srcMask & 2) != 0 ); - chooseC->setChecked( (srcMask & 4) != 0 ); - chooseA->setEnabled( (enabledMask & 1) != 0 ); - chooseB->setEnabled( (enabledMask & 2) != 0 ); - chooseC->setEnabled( (enabledMask & 4) != 0 ); -} - - - -// Function uses setMinSize( sizeHint ) before adding the widget. -// void addWidget(QBoxLayout* layout, QWidget* widget); -template <class W, class L> -void addWidget( L* layout, W* widget) -{ - QSize s = widget->sizeHint(); - widget->setMinimumSize( QSize(max(s.width(),0),max(s.height(),0) ) ); - layout->addWidget( widget ); -} - -void KDiff3App::initView() -{ - // set the main widget here - QWidget* oldCentralWidget = centralWidget(); - if ( oldCentralWidget != 0 ) - { - delete oldCentralWidget; - } - QFrame* pMainWidget = new QFrame(this); - pMainWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken ); - pMainWidget->setLineWidth(1); - - bool bVisibleMergeResultWindow = ! m_outputFilename.isEmpty(); - bool bTripleDiff = ! m_filename3.isEmpty(); - - QVBoxLayout* pVLayout = new QVBoxLayout(pMainWidget); - QSplitter* pVSplitter = 0; - QSplitter* pDiffHSplitter = 0; - QHBoxLayout* pDiffHLayout = 0; - - QWidget* pDiffWindowFrame = 0; - - if ( ! bVisibleMergeResultWindow ) - { - pDiffWindowFrame = pMainWidget; - pDiffHLayout = new QHBoxLayout( pVLayout ); - } - else - { - pVSplitter = new QSplitter( pMainWidget ); - pVSplitter->setOrientation( Vertical ); - pVLayout->addWidget( pVSplitter ); - - pDiffWindowFrame = new QFrame( pVSplitter ); - pDiffHLayout = new QHBoxLayout( pDiffWindowFrame ); - } - - pDiffHSplitter = new QSplitter( pDiffWindowFrame ); // horizontal - pDiffHLayout->addWidget( pDiffHSplitter ); - - m_pOverview = new Overview( pDiffWindowFrame, &m_diff3LineList, m_pOptionDialog, bTripleDiff ); - pDiffHLayout->addWidget(m_pOverview); - connect( m_pOverview, SIGNAL(setLine(int)), this, SLOT(setDiff3Line(int)) ); - - m_pDiffVScrollBar = new QScrollBar( Vertical, pDiffWindowFrame ); - pDiffHLayout->addWidget( m_pDiffVScrollBar ); - - - m_pDiffTextWindow1 = new DiffTextWindow( pDiffHSplitter, statusBar(), m_pOptionDialog ); - m_pDiffTextWindow1->init( m_filename1, - &m_v1[0], m_v1size, &m_diff3LineList, 1, bTripleDiff ); - - - m_pDiffTextWindow2 = new DiffTextWindow( pDiffHSplitter, statusBar(), m_pOptionDialog ); - m_pDiffTextWindow2->init( m_filename2, - &m_v2[0], m_v2size, &m_diff3LineList, 2, bTripleDiff ); - - if ( bTripleDiff ) - { - m_pDiffTextWindow3 = new DiffTextWindow( pDiffHSplitter, statusBar(), m_pOptionDialog ); - m_pDiffTextWindow3->init( m_filename3, - &m_v3[0], m_v3size, &m_diff3LineList, 3, bTripleDiff ); - - } - else - { - m_pDiffTextWindow3=0; - } - - if ( bVisibleMergeResultWindow && pVSplitter !=0 ) - { - // Merge window - QFrame* pMergeWindowFrame = new QFrame( pVSplitter ); - QHBoxLayout* pMergeHLayout = new QHBoxLayout( pMergeWindowFrame ); - - m_pMergeResultWindow = new MergeResultWindow( pMergeWindowFrame, - &m_v1[0], &m_v2[0], - bTripleDiff ? &m_v3[0] : 0, - &m_diff3LineList, m_outputFilename, - m_pOptionDialog - ); - pMergeHLayout->addWidget( m_pMergeResultWindow ); - - m_pMergeVScrollBar = new QScrollBar( Vertical, pMergeWindowFrame ); - pMergeHLayout->addWidget( m_pMergeVScrollBar ); - - QValueList<int> sizes = pVSplitter->sizes(); - int total = sizes[0] + sizes[1]; - sizes[0]=total/2; sizes[1]=total/2; - pVSplitter->setSizes( sizes ); - } - else - { - m_pMergeResultWindow = new MergeResultWindow( pMainWidget, - &m_v1[0], &m_v2[0], - bTripleDiff ? &m_v3[0] : 0, - &m_diff3LineList, m_outputFilename, - m_pOptionDialog - ); - m_pMergeResultWindow->hide(); - m_pMergeVScrollBar = 0; - } - - QHBoxLayout* pHScrollBarLayout = new QHBoxLayout( pVLayout ); - m_pHScrollBar = new QScrollBar( Horizontal, pMainWidget ); - pHScrollBarLayout->addWidget( m_pHScrollBar ); - m_pCornerWidget = new QWidget( pMainWidget ); - pHScrollBarLayout->addWidget( m_pCornerWidget ); - - - setCentralWidget(pMainWidget); - - connect( m_pDiffVScrollBar, SIGNAL(valueChanged(int)), m_pOverview, SLOT(setFirstLine(int))); - - connect( m_pDiffVScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow1, SLOT(setFirstLine(int))); - connect( m_pHScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow1, SLOT(setFirstColumn(int))); - connect( m_pDiffTextWindow1, SIGNAL(newSelection()), this, SLOT(slotSelectionStart())); - connect( m_pDiffTextWindow1, SIGNAL(selectionEnd()), this, SLOT(slotSelectionEnd())); - connect( m_pDiffTextWindow1, SIGNAL(scroll(int,int)), this, SLOT(scrollDiffTextWindow(int,int))); - m_pDiffTextWindow1->installEventFilter( this ); - - connect( m_pDiffVScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow2, SLOT(setFirstLine(int))); - connect( m_pHScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow2, SLOT(setFirstColumn(int))); - connect( m_pDiffTextWindow2, SIGNAL(newSelection()), this, SLOT(slotSelectionStart())); - connect( m_pDiffTextWindow2, SIGNAL(selectionEnd()), this, SLOT(slotSelectionEnd())); - connect( m_pDiffTextWindow2, SIGNAL(scroll(int,int)), this, SLOT(scrollDiffTextWindow(int,int))); - m_pDiffTextWindow2->installEventFilter( this ); - - if ( m_pDiffTextWindow3 != 0 ) - { - connect( m_pDiffVScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow3, SLOT(setFirstLine(int))); - connect( m_pHScrollBar, SIGNAL(valueChanged(int)), m_pDiffTextWindow3, SLOT(setFirstColumn(int))); - connect( m_pDiffTextWindow3, SIGNAL(newSelection()), this, SLOT(slotSelectionStart())); - connect( m_pDiffTextWindow3, SIGNAL(selectionEnd()), this, SLOT(slotSelectionEnd())); - connect( m_pDiffTextWindow3, SIGNAL(scroll(int,int)), this, SLOT(scrollDiffTextWindow(int,int))); - m_pDiffTextWindow3->installEventFilter( this ); - } - - MergeResultWindow* p = m_pMergeResultWindow; - if ( bVisibleMergeResultWindow ) - { - connect( m_pMergeVScrollBar, SIGNAL(valueChanged(int)), p, SLOT(setFirstLine(int))); - - connect( m_pHScrollBar, SIGNAL(valueChanged(int)), p, SLOT(setFirstColumn(int))); - connect( p, SIGNAL(scroll(int,int)), this, SLOT(scrollMergeResultWindow(int,int))); - connect( p, SIGNAL(sourceMask(int,int)), this, SLOT(sourceMask(int,int))); - connect( p, SIGNAL( resizeSignal() ),this, SLOT(resizeMergeResultWindow())); - connect( p, SIGNAL( selectionEnd() ), this, SLOT( slotSelectionEnd() ) ); - connect( p, SIGNAL( newSelection() ), this, SLOT( slotSelectionStart() ) ); - connect( p, SIGNAL( modified() ), this, SLOT( slotOutputModified() ) ); - connect( p, SIGNAL( savable(bool)), this, SLOT(slotOutputSavable(bool))); - } - else - { - sourceMask(0,0); - } - - m_bOutputModified = false; - - - connect( p, SIGNAL(setFastSelectorRange(int,int)), m_pDiffTextWindow1, SLOT(setFastSelectorRange(int,int))); - connect( p, SIGNAL(setFastSelectorRange(int,int)), m_pDiffTextWindow2, SLOT(setFastSelectorRange(int,int))); - connect(m_pDiffTextWindow1, SIGNAL(setFastSelectorLine(int)), p, SLOT(slotSetFastSelectorLine(int))); - connect(m_pDiffTextWindow2, SIGNAL(setFastSelectorLine(int)), p, SLOT(slotSetFastSelectorLine(int))); - if ( m_pDiffTextWindow3 != 0 ) - { - connect(m_pDiffTextWindow3, SIGNAL(setFastSelectorLine(int)), p, SLOT(slotSetFastSelectorLine(int))); - connect( p, SIGNAL(setFastSelectorRange(int,int)), m_pDiffTextWindow3, SLOT(setFastSelectorRange(int,int))); - } - - - - connect( m_pDiffTextWindow1, SIGNAL( resizeSignal(int,int) ),this, SLOT(resizeDiffTextWindow(int,int))); - - m_pDiffTextWindow1->setFocus(); - show(); - pMainWidget->show(); - m_pCornerWidget->setFixedSize( m_pDiffVScrollBar->width(), m_pHScrollBar->height() ); - - // TODO: This won't work correctly if the widgets are not yet visible. - // The show() commands above don't help. - - m_pDiffVScrollBar->setRange(0, max(0, m_neededLines+1 - m_pDiffTextWindow1->getNofLines() ) ); - m_pDiffVScrollBar->setPageStep( m_pDiffTextWindow1->getNofLines() ); - m_pOverview->setRange( 0, m_pDiffTextWindow1->getNofLines() ); -} - -void KDiff3App::resizeEvent(QResizeEvent* e) -{ - KMainWindow::resizeEvent(e); - m_pCornerWidget->setFixedSize( m_pDiffVScrollBar->width(), m_pHScrollBar->height() ); -} - - -bool KDiff3App::eventFilter( QObject* o, QEvent* e ) -{ - if ( e->type() == QEvent::KeyPress ) { // key press - QKeyEvent *k = (QKeyEvent*)e; - - - - - int deltaX=0; - int deltaY=0; - int pageSize = m_DTWHeight; - switch( k->key() ) - { - case Key_Down: ++deltaY; break; - case Key_Up: --deltaY; break; - case Key_PageDown: deltaY+=pageSize; break; - case Key_PageUp: deltaY-=pageSize; break; - case Key_Left: --deltaX; break; - case Key_Right: ++deltaX; break; - case Key_Home: if ( k->state() & ControlButton ) m_pDiffVScrollBar->setValue( 0 ); - else m_pHScrollBar->setValue( 0 ); - break; - case Key_End: if ( k->state() & ControlButton ) m_pDiffVScrollBar->setValue( m_pDiffVScrollBar->maxValue() ); - else m_pHScrollBar->setValue( m_pHScrollBar->maxValue() ); - break; - default: break; - } - - scrollDiffTextWindow( deltaX, deltaY ); - - - - return TRUE; // eat event - } - return KMainWindow::eventFilter( o, e ); // standard event processing -} - - - -OpenDialog::OpenDialog( - QWidget* pParent, const char* n1, const char* n2, const char* n3, - bool bMerge, const char* outputName, const char* slotConfigure, OptionDialog* pOptions ) -: QDialog( pParent, "OpenDialog", true /*modal*/ ) -{ - m_pOptions = pOptions; - - QVBoxLayout* v = new QVBoxLayout( this, 5 ); - QGridLayout* h = new QGridLayout( v, 5, 3, 5 ); - - QLabel* label = new QLabel( "A (Base):", this ); - - m_lineA = new QComboBox( true, this ); - m_lineA->insertStrList( m_pOptions->m_recentAFiles ); - m_lineA->setEditText( n1 ); - QPushButton * button = new QPushButton( "Select...", this ); - connect( button, SIGNAL(clicked()), this, SLOT( selectFileA() ) ); - - h->addWidget( label, 0, 0 ); - h->addWidget( m_lineA, 0, 1 ); - h->addWidget( button, 0, 2 ); - - label = new QLabel( "B:", this ); - m_lineB = new QComboBox( true, this ); - m_lineB->insertStrList( m_pOptions->m_recentBFiles ); - m_lineB->setEditText( n2 ); - button = new QPushButton( "Select...", this ); - connect( button, SIGNAL(clicked()), this, SLOT( selectFileB() ) ); - - h->addWidget( label, 1, 0 ); - h->addWidget( m_lineB, 1, 1 ); - h->addWidget( button, 1, 2 ); - - label = new QLabel( "C (Optional):", this ); - m_lineC= new QComboBox( true, this ); - m_lineC->insertStrList( m_pOptions->m_recentCFiles ); - m_lineC->setEditText( n3 ); - button = new QPushButton( "Select...", this ); - connect( button, SIGNAL(clicked()), this, SLOT( selectFileC() ) ); - - h->addWidget( label, 2, 0 ); - h->addWidget( m_lineC, 2, 1 ); - h->addWidget( button, 2, 2 ); - - m_pMerge = new QCheckBox( "Merge", this ); - h->addWidget( m_pMerge, 3, 0 ); - - label = new QLabel( "Output (Optional):", this ); - m_lineOutput = new QComboBox( true, this ); - m_lineOutput->insertStrList( m_pOptions->m_recentOutputFiles ); - m_lineOutput->setEditText( outputName ); - button = new QPushButton( "Select...", this ); - connect( button, SIGNAL(clicked()), this, SLOT( selectOutputName() ) ); - connect( m_pMerge, SIGNAL(stateChanged(int)), this, SLOT(internalSlot(int)) ); - connect( this, SIGNAL(internalSignal(bool)), m_lineOutput, SLOT(setEnabled(bool)) ); - connect( this, SIGNAL(internalSignal(bool)), button, SLOT(setEnabled(bool)) ); - - m_pMerge->setChecked( bMerge ); - m_lineOutput->setEnabled( bMerge ); - - button->setEnabled( bMerge ); - - h->addWidget( label, 4, 0 ); - h->addWidget( m_lineOutput, 4, 1 ); - h->addWidget( button, 4, 2 ); - - h->addColSpacing( 1, 200 ); - - QHBoxLayout* l = new QHBoxLayout( v, 5 ); - button = new QPushButton( "Ok", this ); - connect( button, SIGNAL(clicked()), this, SLOT( accept() ) ); - l->addWidget( button ); - - button = new QPushButton( "Cancel", this ); - connect( button, SIGNAL(clicked()), this, SLOT( reject() ) ); - l->addWidget( button ); - - button = new QPushButton( "Configure", this ); - connect( button, SIGNAL(clicked()), pParent, slotConfigure ); - l->addWidget( button ); - - QSize sh = sizeHint(); - setFixedHeight( sh.height() ); -} - -void OpenDialog::selectFileA() -{ - QString fileName = KFileDialog::getOpenFileName(0,0,this); -// QString fileName = KFileDialog::getOpenURL(QString::null, -// i18n("*|All files"), this, i18n("Open File...")).fileName(); - m_lineA->setEditText( fileName ); -} -void OpenDialog::selectFileB() -{ - QString fileName = KFileDialog::getOpenFileName(0,0,this); - m_lineB->setEditText( fileName ); -} -void OpenDialog::selectFileC() -{ - - QString fileName = KFileDialog::getOpenFileName(0,0,this); - m_lineC->setEditText( fileName ); -} - -void OpenDialog::selectOutputName() -{ - QString fileName = KFileDialog::getOpenFileName(0,0,this); - m_lineOutput->setEditText( fileName ); -} - -void OpenDialog::internalSlot(int i) -{ - emit internalSignal(i!=0); -} - -void OpenDialog::accept() -{ - unsigned int maxNofRecentFiles = 6; - - QString s = m_lineA->currentText(); - QStrList* sl = &m_pOptions->m_recentAFiles; - if ( sl->find( s ) != -1 ) // A new item - { - s = sl->current(); - sl->remove(); - } - if ( !s.isEmpty() ) sl->prepend( s ); - while ( sl->count()>maxNofRecentFiles ) sl->removeLast(); - - s = m_lineB->currentText(); - sl = &m_pOptions->m_recentBFiles; - if ( sl->find( s ) != -1 ) // A new item - { - s = sl->current(); - sl->remove(); - } - if ( !s.isEmpty() ) sl->prepend( s ); - while ( sl->count()>maxNofRecentFiles ) sl->removeLast(); - - s = m_lineC->currentText(); - sl = &m_pOptions->m_recentCFiles; - if ( sl->find( s ) != -1 ) // A new item - { - s = sl->current(); - sl->remove(); - } - if ( !s.isEmpty() ) sl->prepend( s ); - while ( sl->count()>maxNofRecentFiles ) sl->removeLast(); - - s = m_lineOutput->currentText(); - sl = &m_pOptions->m_recentOutputFiles; - if ( sl->find( s ) != -1 ) // A new item - { - s = sl->current(); - sl->remove(); - } - if ( !s.isEmpty() ) sl->prepend( s ); - while ( sl->count()>maxNofRecentFiles ) sl->removeLast(); - - QDialog::accept(); -} - -void KDiff3App::slotFileOpen() -{ - if(m_bOutputModified) - { - int result = KMessageBox::warningContinueCancel(this, - i18n("The output file has been modified.\n" - "If you continue your changes will be lost."), - i18n("Warning"), i18n("Continue"), i18n("Cancel")); - if ( result==KMessageBox::Cancel ) - return; - - } - - - slotStatusMsg(i18n("Opening files...")); - - for(;;) - { - - OpenDialog d(this, m_filename1, m_filename2, m_filename3, - !m_outputFilename.isEmpty(), - m_bDefaultFilename ? "" : (const char*)m_outputFilename, - SLOT(slotConfigure()), m_pOptionDialog ); - int status = d.exec(); - if ( status == QDialog::Accepted ) - { - m_filename1 = d.m_lineA->currentText(); - m_filename2 = d.m_lineB->currentText(); - m_filename3 = d.m_lineC->currentText(); - - if ( d.m_pMerge->isChecked() ) - { - if ( d.m_lineOutput->currentText().isEmpty() ) - { - m_outputFilename = "unnamed.txt"; - m_bDefaultFilename = true; - } - else - { - m_outputFilename = d.m_lineOutput->currentText(); - m_bDefaultFilename = false; - } - } - else - m_outputFilename = QString(); - - init( m_filename1, m_filename2, m_filename3 ); - // setCaption(url.fileName(), false); - - if ( ! m_filename1.isEmpty() && m_pBuf1==0 || - ! m_filename2.isEmpty() && m_pBuf2==0 || - ! m_filename3.isEmpty() && m_pBuf3==0 ) - { - QString text( i18n("Opening of these files failed:") ); - text += "\n\n"; - if ( ! m_filename1.isEmpty() && m_pBuf1==0 ) - text += " - " + m_filename1 + "\n"; - if ( ! m_filename2.isEmpty() && m_pBuf2==0 ) - text += " - " + m_filename2 + "\n"; - if ( ! m_filename3.isEmpty() && m_pBuf3==0 ) - text += " - " + m_filename3 + "\n"; - - KMessageBox::sorry( this, text, i18n("File open error") ); - continue; - } - } - break; - } - - slotStatusMsg(i18n("Ready.")); -} - - -void KDiff3App::slotEditCut() -{ - slotStatusMsg(i18n("Cutting selection...")); - - QString s; - if ( m_pMergeResultWindow!=0 ) - { - s = m_pMergeResultWindow->getSelection(); - m_pMergeResultWindow->deleteSelection(); - - m_pMergeResultWindow->update(); - } - - if ( !s.isNull() ) - { - QApplication::clipboard()->setText( s ); - } - - slotStatusMsg(i18n("Ready.")); -} - -void KDiff3App::slotEditCopy() -{ - slotStatusMsg(i18n("Copying selection to clipboard...")); - - QString s = m_pDiffTextWindow1->getSelection(); - if ( s.isNull() ) - s = m_pDiffTextWindow2->getSelection(); - if ( s.isNull() && m_pDiffTextWindow3!=0 ) - s = m_pDiffTextWindow3->getSelection(); - if ( s.isNull() && m_pMergeResultWindow!=0 ) - s = m_pMergeResultWindow->getSelection(); - if ( !s.isNull() ) - { - QApplication::clipboard()->setText( s ); - } - - slotStatusMsg(i18n("Ready.")); -} - -void KDiff3App::slotEditPaste() -{ - slotStatusMsg(i18n("Inserting clipboard contents...")); - - if ( m_pMergeResultWindow!=0 ) - { - m_pMergeResultWindow->pasteClipboard(); - } - - slotStatusMsg(i18n("Ready.")); -} - - -void KDiff3App::slotGoTop() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoTop(); -} -void KDiff3App::slotGoBottom() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoBottom(); -} -void KDiff3App::slotGoPrevConflict() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoPrevConflict(); -} -void KDiff3App::slotGoNextConflict() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoNextConflict(); -} -void KDiff3App::slotGoPrevDelta() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoPrevDelta(); -} -void KDiff3App::slotGoNextDelta() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotGoNextDelta(); -} -void KDiff3App::slotChooseA() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotChooseA(); -} -void KDiff3App::slotChooseB() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotChooseB(); -} -void KDiff3App::slotChooseC() -{ - if (m_pMergeResultWindow) m_pMergeResultWindow->slotChooseC(); -} - -void KDiff3App::slotConfigure() -{ - m_pOptionDialog->setState(); - m_pOptionDialog->incInitialSize ( QSize(0,40) ); - m_pOptionDialog->exec(); - slotRefresh(); -} - -void KDiff3App::slotRefresh() -{ - g_tabSize = m_pOptionDialog->m_tabSize; - if (m_pDiffTextWindow1) m_pDiffTextWindow1->update(); - if (m_pDiffTextWindow2) m_pDiffTextWindow2->update(); - if (m_pDiffTextWindow3) m_pDiffTextWindow3->update(); - if (m_pMergeResultWindow) m_pMergeResultWindow->update(); -} - -void KDiff3App::slotSelectionStart() -{ - editCopy->setEnabled( false ); - editCut->setEnabled( false ); - - const QObject* s = sender(); - if (m_pDiffTextWindow1 && s!=m_pDiffTextWindow1) m_pDiffTextWindow1->resetSelection(); - if (m_pDiffTextWindow2 && s!=m_pDiffTextWindow2) m_pDiffTextWindow2->resetSelection(); - if (m_pDiffTextWindow3 && s!=m_pDiffTextWindow3) m_pDiffTextWindow3->resetSelection(); - if (m_pMergeResultWindow && s!=m_pMergeResultWindow) m_pMergeResultWindow->resetSelection(); -} - -void KDiff3App::slotSelectionEnd() -{ - const QObject* s = sender(); - editCopy->setEnabled(true); - editCut->setEnabled( s==m_pMergeResultWindow ); - if ( m_pOptionDialog->m_bAutoCopySelection ) - { - slotEditCopy(); - } -} - -void KDiff3App::slotClipboardChanged() -{ - QString s = QApplication::clipboard()->text(); - editPaste->setEnabled(!s.isEmpty()); -} - -void KDiff3App::slotOutputModified() -{ - m_bOutputModified=true; -} - -void KDiff3App::slotOutputSavable( bool bSavable ) -{ - fileSave->setEnabled( bSavable ); - fileSaveAs->setEnabled( bSavable ); -} \ No newline at end of file
--- a/kdiff3/kdiff3/right1arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *right1arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -"..... ..........", -"..... .........", -"..... ........", -"..... .......", -"..... ......", -"..... .....", -"..... .....", -"..... ......", -"..... .......", -"..... ........", -"..... .........", -"..... ..........", -"................", -"................" -};
--- a/kdiff3/kdiff3/right2arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *right2arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -".. ..... .......", -".. .... ......", -".. ... .....", -".. .. ....", -".. . ...", -".. ..", -".. ..", -".. . ...", -".. .. ....", -".. ... .....", -".. .... ......", -".. ..... .......", -"................", -"................" -};
--- a/kdiff3/kdiff3/rightend.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *rightend[]={ -"16 16 2 1", -"# c #000000", -". c None", -"................", -"................", -".....#.....#....", -".....##....#....", -".....###...#....", -".....####..#....", -".....#####.#....", -".....#######....", -".....#######....", -".....#####.#....", -".....####..#....", -".....###...#....", -".....##....#....", -".....#.....#....", -"................", -"................"};
--- a/kdiff3/kdiff3/up1arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *up1arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -"................", -"................", -"................", -"....... .......", -"...... ......", -"..... .....", -".... ....", -"... ...", -".. ..", -"................", -"................", -"................", -"................", -"................" -};
--- a/kdiff3/kdiff3/up2arrow.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* XPM */ -static const char *up2arrow[] = { -/* columns rows colors chars-per-pixel */ -"16 16 2 1", -" c #000000", -". c None", -/* pixels */ -"................", -"................", -"....... .......", -"...... ......", -"..... .....", -".... ....", -"... ...", -".. ..", -"....... .......", -"...... ......", -"..... .....", -".... ....", -"... ...", -".. ..", -"................", -"................" -};
--- a/kdiff3/kdiff3/upend.xpm Sun Aug 18 16:41:17 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* XPM */ -static const char *upend[]={ -"16 16 2 1", -"# c #000000", -". c None", -"................", -"................", -"................", -"................", -"..############..", -".......##.......", -"......####......", -".....######.....", -"....########....", -"...##########...", -"..############..", -"................", -"................", -"................", -"................", -"................"};