comparison kdiff3/src-QT4/mergeresultwindow.cpp @ 80:fcd146072e0c

0.9.93
author joachim99
date Tue, 06 Jan 2009 17:51:29 +0000
parents 1184fc843210
children fa1a49fc1ec1
comparison
equal deleted inserted replaced
79:881e47f5076b 80:fcd146072e0c
34 #include <QTextCodec> 34 #include <QTextCodec>
35 #include <QComboBox> 35 #include <QComboBox>
36 #include <QHBoxLayout> 36 #include <QHBoxLayout>
37 #include <QLabel> 37 #include <QLabel>
38 #include <QUrl> 38 #include <QUrl>
39 //Added by qt3to4:
40 #include <QTimerEvent>
41 #include <QResizeEvent>
42 #include <QWheelEvent>
43 #include <QPixmap>
44 #include <QFocusEvent>
45 #include <QEvent>
46 #include <QInputEvent>
47 #include <QDropEvent>
48 #include <QPaintEvent>
49 #include <QTextStream>
39 50
40 #include <klocale.h> 51 #include <klocale.h>
41 #include <kmessagebox.h> 52 #include <kmessagebox.h>
42 #include <iostream> 53 #include <iostream>
43 54
136 updateSourceMask(); 147 updateSourceMask();
137 148
138 int wsc; 149 int wsc;
139 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc); 150 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc);
140 if (m_pStatusBar) 151 if (m_pStatusBar)
141 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)") 152 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)"
142 .arg(nofUnsolved).arg(wsc) ); 153 ,nofUnsolved,wsc) );
143 } 154 }
144 155
145 void MergeResultWindow::reset() 156 void MergeResultWindow::reset()
146 { 157 {
147 m_pDiff3LineList = 0; 158 m_pDiff3LineList = 0;
287 if(m_bModified) 298 if(m_bModified)
288 { 299 {
289 int result = KMessageBox::warningYesNo(this, 300 int result = KMessageBox::warningYesNo(this,
290 i18n("The output has been modified.\n" 301 i18n("The output has been modified.\n"
291 "If you continue your changes will be lost."), 302 "If you continue your changes will be lost."),
292 i18n("Warning"), i18n("C&ontinue"), i18n("&Cancel")); 303 i18n("Warning"),
304 KStandardGuiItem::cont(),
305 KStandardGuiItem::cancel());
293 if ( result==KMessageBox::No ) 306 if ( result==KMessageBox::No )
294 return; 307 return;
295 } 308 }
296 309
297 m_mergeLineList.clear(); 310 m_mergeLineList.clear();
799 return nrOfUnsolvedConflicts; 812 return nrOfUnsolvedConflicts;
800 } 813 }
801 814
802 void MergeResultWindow::showNrOfConflicts() 815 void MergeResultWindow::showNrOfConflicts()
803 { 816 {
817 if (!m_pOptionDialog->m_bShowInfoDialogs)
818 return;
804 int nrOfConflicts = 0; 819 int nrOfConflicts = 0;
805 MergeLineList::iterator i; 820 MergeLineList::iterator i;
806 for ( i = m_mergeLineList.begin(); i!=m_mergeLineList.end(); ++i ) 821 for ( i = m_mergeLineList.begin(); i!=m_mergeLineList.end(); ++i )
807 { 822 {
808 if ( i->bConflict || i->bDelta ) 823 if ( i->bConflict || i->bDelta )
812 if ( m_pTotalDiffStatus->bBinaryAEqB && m_pTotalDiffStatus->bBinaryAEqC ) 827 if ( m_pTotalDiffStatus->bBinaryAEqB && m_pTotalDiffStatus->bBinaryAEqC )
813 totalInfo += i18n("All input files are binary equal."); 828 totalInfo += i18n("All input files are binary equal.");
814 else if ( m_pTotalDiffStatus->bTextAEqB && m_pTotalDiffStatus->bTextAEqC ) 829 else if ( m_pTotalDiffStatus->bTextAEqB && m_pTotalDiffStatus->bTextAEqC )
815 totalInfo += i18n("All input files contain the same text."); 830 totalInfo += i18n("All input files contain the same text.");
816 else { 831 else {
817 if ( m_pTotalDiffStatus->bBinaryAEqB ) totalInfo += i18n("Files %1 and %2 are binary equal.\n").arg("A").arg("B"); 832 if ( m_pTotalDiffStatus->bBinaryAEqB ) totalInfo += i18n("Files %1 and %2 are binary equal.\n",QString("A"),QString("B"));
818 else if ( m_pTotalDiffStatus->bTextAEqB ) totalInfo += i18n("Files %1 and %2 have equal text.\n").arg("A").arg("B"); 833 else if ( m_pTotalDiffStatus->bTextAEqB ) totalInfo += i18n("Files %1 and %2 have equal text.\n",QString("A"),QString("B"));
819 if ( m_pTotalDiffStatus->bBinaryAEqC ) totalInfo += i18n("Files %1 and %2 are binary equal.\n").arg("A").arg("C"); 834 if ( m_pTotalDiffStatus->bBinaryAEqC ) totalInfo += i18n("Files %1 and %2 are binary equal.\n",QString("A"),QString("C"));
820 else if ( m_pTotalDiffStatus->bTextAEqC ) totalInfo += i18n("Files %1 and %2 have equal text.\n").arg("A").arg("C"); 835 else if ( m_pTotalDiffStatus->bTextAEqC ) totalInfo += i18n("Files %1 and %2 have equal text.\n",QString("A"),QString("C"));
821 if ( m_pTotalDiffStatus->bBinaryBEqC ) totalInfo += i18n("Files %1 and %2 are binary equal.\n").arg("B").arg("C"); 836 if ( m_pTotalDiffStatus->bBinaryBEqC ) totalInfo += i18n("Files %1 and %2 are binary equal.\n",QString("B"),QString("C"));
822 else if ( m_pTotalDiffStatus->bTextBEqC ) totalInfo += i18n("Files %1 and %2 have equal text.\n").arg("B").arg("C"); 837 else if ( m_pTotalDiffStatus->bTextBEqC ) totalInfo += i18n("Files %1 and %2 have equal text.\n",QString("B"),QString("C"));
823 } 838 }
824 839
825 int nrOfUnsolvedConflicts = getNrOfUnsolvedConflicts(); 840 int nrOfUnsolvedConflicts = getNrOfUnsolvedConflicts();
826 841
827 KMessageBox::information( this, 842 KMessageBox::information( this,
950 update(); 965 update();
951 updateSourceMask(); 966 updateSourceMask();
952 emit updateAvailabilities(); 967 emit updateAvailabilities();
953 int wsc; 968 int wsc;
954 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc); 969 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc);
955 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)") 970 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)"
956 .arg(nofUnsolved).arg(wsc) ); 971 ,nofUnsolved,wsc) );
957 } 972 }
958 973
959 // bConflictsOnly: automatically choose for conflicts only (true) or for everywhere (false) 974 // bConflictsOnly: automatically choose for conflicts only (true) or for everywhere (false)
960 void MergeResultWindow::chooseGlobal(int selector, bool bConflictsOnly, bool bWhiteSpaceOnly ) 975 void MergeResultWindow::chooseGlobal(int selector, bool bConflictsOnly, bool bWhiteSpaceOnly )
961 { 976 {
964 merge( false, selector, bConflictsOnly, bWhiteSpaceOnly ); 979 merge( false, selector, bConflictsOnly, bWhiteSpaceOnly );
965 setModified( true ); 980 setModified( true );
966 update(); 981 update();
967 int wsc; 982 int wsc;
968 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc); 983 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc);
969 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)") 984 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)"
970 .arg(nofUnsolved).arg(wsc) ); 985 ,nofUnsolved,wsc) );
971 } 986 }
972 987
973 void MergeResultWindow::slotAutoSolve() 988 void MergeResultWindow::slotAutoSolve()
974 { 989 {
975 resetSelection(); 990 resetSelection();
976 merge( true, -1 ); 991 merge( true, -1 );
977 setModified( true ); 992 setModified( true );
978 update(); 993 update();
979 int wsc; 994 int wsc;
980 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc); 995 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc);
981 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)") 996 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)"
982 .arg(nofUnsolved).arg(wsc) ); 997 ,nofUnsolved,wsc) );
983 } 998 }
984 999
985 void MergeResultWindow::slotUnsolve() 1000 void MergeResultWindow::slotUnsolve()
986 { 1001 {
987 resetSelection(); 1002 resetSelection();
988 merge( false, -1 ); 1003 merge( false, -1 );
989 setModified( true ); 1004 setModified( true );
990 update(); 1005 update();
991 int wsc; 1006 int wsc;
992 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc); 1007 int nofUnsolved = getNrOfUnsolvedConflicts(&wsc);
993 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)") 1008 m_pStatusBar->showMessage( i18n("Number of remaining unsolved conflicts: %1 (of which %2 are whitespace)"
994 .arg(nofUnsolved).arg(wsc) ); 1009 ,nofUnsolved,wsc) );
995 } 1010 }
996 1011
997 static QString calcHistoryLead(const QString& s ) 1012 static QString calcHistoryLead(const QString& s )
998 { 1013 {
999 // Return the start of the line until the first white char after the first non white char. 1014 // Return the start of the line until the first white char after the first non white char.
1138 const LineData* pld = id3l->getLineData(src); 1153 const LineData* pld = id3l->getLineData(src);
1139 QString s( pld->pLine, pld->size ); 1154 QString s( pld->pLine, pld->size );
1140 historyLead = calcHistoryLead(s); 1155 historyLead = calcHistoryLead(s);
1141 } 1156 }
1142 QRegExp historyStart( m_pOptionDialog->m_historyStartRegExp ); 1157 QRegExp historyStart( m_pOptionDialog->m_historyStartRegExp );
1158 if ( id3l == iHistoryEnd )
1159 return;
1143 ++id3l; // Skip line with "$Log ... $" 1160 ++id3l; // Skip line with "$Log ... $"
1144 QRegExp newHistoryEntry( m_pOptionDialog->m_historyEntryStartRegExp ); 1161 QRegExp newHistoryEntry( m_pOptionDialog->m_historyEntryStartRegExp );
1145 QStringList parenthesesGroups; 1162 QStringList parenthesesGroups;
1146 findParenthesesGroups( m_pOptionDialog->m_historyEntryStartRegExp, parenthesesGroups ); 1163 findParenthesesGroups( m_pOptionDialog->m_historyEntryStartRegExp, parenthesesGroups );
1147 QString key; 1164 QString key;
1747 if ( !m_bPaintingAllowed ) 1764 if ( !m_bPaintingAllowed )
1748 { 1765 {
1749 m_currentMergeLineIt = m_mergeLineList.end(); 1766 m_currentMergeLineIt = m_mergeLineList.end();
1750 reset(); 1767 reset();
1751 } 1768 }
1752 } 1769 update();
1753 1770 }
1754 void MergeResultWindow::paintEvent( QPaintEvent* ) 1771
1755 { 1772 void MergeResultWindow::paintEvent( QPaintEvent* )
1756 if (m_pDiff3LineList==0 || !m_bPaintingAllowed) return; 1773 {
1774 if (m_pDiff3LineList==0 || !m_bPaintingAllowed)
1775 return;
1757 1776
1758 bool bOldSelectionContainsData = m_selection.bSelectionContainsData; 1777 bool bOldSelectionContainsData = m_selection.bSelectionContainsData;
1759 const QFontMetrics& fm = fontMetrics(); 1778 const QFontMetrics& fm = fontMetrics();
1760 int fontHeight = fm.height(); 1779 int fontHeight = fm.height();
1761 int fontWidth = fm.width("W"); 1780 int fontWidth = fm.width("W");
1835 1854
1836 if ( !m_bCursorUpdate ) 1855 if ( !m_bCursorUpdate )
1837 painter.drawPixmap(0,0, m_pixmap); 1856 painter.drawPixmap(0,0, m_pixmap);
1838 else 1857 else
1839 { 1858 {
1840 if (!m_pOptionDialog->m_bRightToLeftLanguage) 1859 painter.drawPixmap(0,0, m_pixmap ); // Draw everything. (Internally cursor rect is clipped anyway.)
1841 painter.drawPixmap(xCursor-2, yOffset, m_pixmap, 1860 //if (!m_pOptionDialog->m_bRightToLeftLanguage)
1842 xCursor-2, yOffset, 5, fontAscent+2 ); 1861 // painter.drawPixmap(xCursor-2, yOffset, m_pixmap,
1843 else 1862 // xCursor-2, yOffset, 5, fontAscent+2 );
1844 painter.drawPixmap(width()-1-4-(xCursor-2), yOffset, m_pixmap, 1863 //else
1845 width()-1-4-(xCursor-2), yOffset, 5, fontAscent+2 ); 1864 // painter.drawPixmap(width()-1-4-(xCursor-2), yOffset, m_pixmap,
1865 // width()-1-4-(xCursor-2), yOffset, 5, fontAscent+2 );
1846 m_bCursorUpdate = false; 1866 m_bCursorUpdate = false;
1847 } 1867 }
1848 painter.end(); 1868 painter.end();
1849 1869
1850 if ( m_bCursorOn && hasFocus() && m_cursorYPos>=m_firstLine ) 1870 if ( m_bCursorOn && hasFocus() && m_cursorYPos>=m_firstLine )
2675 emit modifiedChanged(m_bModified); 2695 emit modifiedChanged(m_bModified);
2676 } 2696 }
2677 } 2697 }
2678 2698
2679 /// Saves and returns true when successful. 2699 /// Saves and returns true when successful.
2680 bool MergeResultWindow::saveDocument( const QString& fileName, QTextCodec* pEncoding ) 2700 bool MergeResultWindow::saveDocument( const QString& fileName, QTextCodec* pEncoding, e_LineEndStyle eLineEndStyle )
2681 { 2701 {
2682 // Are still conflicts somewhere? 2702 // Are still conflicts somewhere?
2683 if ( getNrOfUnsolvedConflicts()>0 ) 2703 if ( getNrOfUnsolvedConflicts()>0 )
2684 { 2704 {
2685 KMessageBox::error( this, 2705 KMessageBox::error( this,
2687 "File not saved.\n"), 2707 "File not saved.\n"),
2688 i18n("Conflicts Left")); 2708 i18n("Conflicts Left"));
2689 return false; 2709 return false;
2690 } 2710 }
2691 2711
2712 if ( eLineEndStyle==eLineEndStyleConflict || eLineEndStyle==eLineEndStyleUndefined )
2713 {
2714 KMessageBox::error( this,
2715 i18n("There is a line end style conflict. Please choose the line end style manually.\n"
2716 "File not saved.\n"),
2717 i18n("Conflicts Left"));
2718 return false;
2719 }
2720
2692 update(); 2721 update();
2693 2722
2694 FileAccess file( fileName, true /*bWantToWrite*/ ); 2723 FileAccess file( fileName, true /*bWantToWrite*/ );
2695 if ( m_pOptionDialog->m_bDmCreateBakFiles && file.exists() ) 2724 if ( m_pOptionDialog->m_bDmCreateBakFiles && file.exists() )
2696 { 2725 {
2721 { 2750 {
2722 QString str = mel.getString( this ); 2751 QString str = mel.getString( this );
2723 2752
2724 if (line>0) // Prepend line feed, but not for first line 2753 if (line>0) // Prepend line feed, but not for first line
2725 { 2754 {
2726 if ( m_pOptionDialog->m_lineEndStyle == eLineEndDos ) 2755 if ( eLineEndStyle == eLineEndStyleDos )
2727 { str.prepend("\r\n"); } 2756 { str.prepend("\r\n"); }
2728 else 2757 else
2729 { str.prepend("\n"); } 2758 { str.prepend("\n"); }
2730 } 2759 }
2731 2760
3089 3118
3090 m_pEncodingLabel = new QLabel(i18n("Encoding for saving")+":"); 3119 m_pEncodingLabel = new QLabel(i18n("Encoding for saving")+":");
3091 pHLayout->addWidget( m_pEncodingLabel ); 3120 pHLayout->addWidget( m_pEncodingLabel );
3092 3121
3093 m_pEncodingSelector = new QComboBox(); 3122 m_pEncodingSelector = new QComboBox();
3123 m_pEncodingSelector->setSizeAdjustPolicy( QComboBox::AdjustToContents );
3094 pHLayout->addWidget( m_pEncodingSelector, 2 ); 3124 pHLayout->addWidget( m_pEncodingSelector, 2 );
3095 setEncodings(0,0,0); 3125 setEncodings(0,0,0);
3126
3127 m_pLineEndStyleLabel = new QLabel( i18n("Line end style:") );
3128 pHLayout->addWidget( m_pLineEndStyleLabel );
3129 m_pLineEndStyleSelector = new QComboBox();
3130 m_pLineEndStyleSelector->setSizeAdjustPolicy( QComboBox::AdjustToContents );
3131 pHLayout->addWidget( m_pLineEndStyleSelector );
3132 setLineEndStyles(eLineEndStyleUndefined,eLineEndStyleUndefined,eLineEndStyleUndefined);
3096 } 3133 }
3097 3134
3098 void WindowTitleWidget::setFileName( const QString& fileName ) 3135 void WindowTitleWidget::setFileName( const QString& fileName )
3099 { 3136 {
3100 m_pFileNameLineEdit->setText( QDir::toNativeSeparators(fileName) ); 3137 m_pFileNameLineEdit->setText( QDir::toNativeSeparators(fileName) );
3101 } 3138 }
3102 3139
3103 QString WindowTitleWidget::getFileName() 3140 QString WindowTitleWidget::getFileName()
3104 { 3141 {
3105 return m_pFileNameLineEdit->text(); 3142 return m_pFileNameLineEdit->text();
3143 }
3144
3145 static QString getLineEndStyleName( e_LineEndStyle eLineEndStyle )
3146 {
3147 if ( eLineEndStyle == eLineEndStyleDos )
3148 return "DOS";
3149 else if ( eLineEndStyle == eLineEndStyleUnix )
3150 return "Unix";
3151 return QString();
3152 }
3153
3154 void WindowTitleWidget::setLineEndStyles( e_LineEndStyle eLineEndStyleA, e_LineEndStyle eLineEndStyleB, e_LineEndStyle eLineEndStyleC)
3155 {
3156 m_pLineEndStyleSelector->clear();
3157 QString dosUsers;
3158 if ( eLineEndStyleA == eLineEndStyleDos )
3159 dosUsers += "A";
3160 if ( eLineEndStyleB == eLineEndStyleDos )
3161 dosUsers += (dosUsers.isEmpty() ? "" : ", ") + QString("B");
3162 if ( eLineEndStyleC == eLineEndStyleDos )
3163 dosUsers += (dosUsers.isEmpty() ? "" : ", ") + QString("C");
3164 QString unxUsers;
3165 if ( eLineEndStyleA == eLineEndStyleUnix )
3166 unxUsers += "A";
3167 if ( eLineEndStyleB == eLineEndStyleUnix )
3168 unxUsers += (unxUsers.isEmpty() ? "" : ", ") + QString("B");
3169 if ( eLineEndStyleC == eLineEndStyleUnix )
3170 unxUsers += (unxUsers.isEmpty() ? "" : ", ") + QString("C");
3171
3172 m_pLineEndStyleSelector->addItem( i18n("Unix") + (unxUsers.isEmpty() ? "" : " (" + unxUsers + ")" ) );
3173 m_pLineEndStyleSelector->addItem( i18n("DOS") + (dosUsers.isEmpty() ? "" : " (" + dosUsers + ")" ) );
3174
3175 e_LineEndStyle autoChoice = (e_LineEndStyle)m_pOptionDialog->m_lineEndStyle;
3176
3177 if ( m_pOptionDialog->m_lineEndStyle == eLineEndStyleAutoDetect )
3178 {
3179 if ( eLineEndStyleA != eLineEndStyleUndefined && eLineEndStyleB != eLineEndStyleUndefined && eLineEndStyleC != eLineEndStyleUndefined )
3180 {
3181 if ( eLineEndStyleA == eLineEndStyleB )
3182 autoChoice = eLineEndStyleC;
3183 else if ( eLineEndStyleA == eLineEndStyleC )
3184 autoChoice = eLineEndStyleB;
3185 else
3186 autoChoice = eLineEndStyleConflict; //conflict (not likely while only two values exist)
3187 }
3188 else
3189 {
3190 e_LineEndStyle c1, c2;
3191 if ( eLineEndStyleA == eLineEndStyleUndefined ) { c1 = eLineEndStyleB; c2 = eLineEndStyleC; }
3192 else if( eLineEndStyleB == eLineEndStyleUndefined ) { c1 = eLineEndStyleA; c2 = eLineEndStyleC; }
3193 else /*if( eLineEndStyleC == eLineEndStyleUndefined )*/ { c1 = eLineEndStyleA; c2 = eLineEndStyleB; }
3194 if ( c1 == c2 && c1!=eLineEndStyleUndefined )
3195 autoChoice = c1;
3196 else
3197 autoChoice = eLineEndStyleConflict;
3198 }
3199 }
3200
3201 if ( autoChoice == eLineEndStyleUnix )
3202 m_pLineEndStyleSelector->setCurrentIndex(0);
3203 else if ( autoChoice == eLineEndStyleDos )
3204 m_pLineEndStyleSelector->setCurrentIndex(1);
3205 else if ( autoChoice == eLineEndStyleConflict )
3206 {
3207 m_pLineEndStyleSelector->addItem( i18n("Conflict") );
3208 m_pLineEndStyleSelector->setCurrentIndex(2);
3209 }
3210 }
3211
3212 e_LineEndStyle WindowTitleWidget::getLineEndStyle( )
3213 {
3214
3215 int current = m_pLineEndStyleSelector->currentIndex();
3216 if (current == 0)
3217 return eLineEndStyleUnix;
3218 else if (current == 1)
3219 return eLineEndStyleDos;
3220 else
3221 return eLineEndStyleConflict;
3106 } 3222 }
3107 3223
3108 void WindowTitleWidget::setEncodings( QTextCodec* pCodecForA, QTextCodec* pCodecForB, QTextCodec* pCodecForC ) 3224 void WindowTitleWidget::setEncodings( QTextCodec* pCodecForA, QTextCodec* pCodecForB, QTextCodec* pCodecForC )
3109 { 3225 {
3110 m_pEncodingSelector->clear(); 3226 m_pEncodingSelector->clear();
3162 3278
3163 //void WindowTitleWidget::slotBrowseButtonClicked() 3279 //void WindowTitleWidget::slotBrowseButtonClicked()
3164 //{ 3280 //{
3165 // QString current = m_pFileNameLineEdit->text(); 3281 // QString current = m_pFileNameLineEdit->text();
3166 // 3282 //
3167 // KURL newURL = KFileDialog::getSaveURL( current, 0, this, i18n("Select file (not saving yet)")); 3283 // KUrl newURL = KFileDialog::getSaveUrl( current, 0, this, i18n("Select file (not saving yet)"));
3168 // if ( !newURL.isEmpty() ) 3284 // if ( !newURL.isEmpty() )
3169 // { 3285 // {
3170 // m_pFileNameLineEdit->setText( newURL.url() ); 3286 // m_pFileNameLineEdit->setText( newURL.url() );
3171 // } 3287 // }
3172 //} 3288 //}