optiondialog.cpp 74.8 KB
Newer Older
Joachim Eibl's avatar
Joachim Eibl committed
1 2
/*
 *   kdiff3 - Text Diff And Merge Tool
Joachim Eibl's avatar
Joachim Eibl committed
3
 *   Copyright (C) 2002-2009  Joachim Eibl, joachim.eibl at gmx.de
Joachim Eibl's avatar
Joachim Eibl committed
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 *   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
Joachim Eibl's avatar
Joachim Eibl committed
17
 *   Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
Joachim Eibl's avatar
Joachim Eibl committed
18 19 20
 *
 */

Joachim Eibl's avatar
Joachim Eibl committed
21 22 23 24 25 26 27 28 29
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit> 
#include <QToolTip>
#include <QRadioButton>
#include <QGroupBox>
#include <QTextCodec>
Joachim Eibl's avatar
Joachim Eibl committed
30
#include <QDir>
Joachim Eibl's avatar
Joachim Eibl committed
31 32
#include <QSettings>
#include <QLocale>
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
33 34 35 36
#include <QGridLayout>
#include <QPixmap>
#include <QFrame>
#include <QVBoxLayout>
Joachim Eibl's avatar
Joachim Eibl committed
37 38

#include <kapplication.h>
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
39
#include <kcolorbutton.h>
Joachim Eibl's avatar
Joachim Eibl committed
40 41 42 43 44
#include <kfontdialog.h> // For KFontChooser
#include <kiconloader.h>
#include <klocale.h>
#include <kconfig.h>
#include <kmessagebox.h>
Joachim Eibl's avatar
Joachim Eibl committed
45
#include <kmainwindow.h> //For ktoolbar.h
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
46
#include <ktoolbar.h>
Joachim Eibl's avatar
Joachim Eibl committed
47

Joachim Eibl's avatar
Joachim Eibl committed
48
//#include <kkeydialog.h>
Joachim Eibl's avatar
Joachim Eibl committed
49
#include <map>
Joachim Eibl's avatar
Joachim Eibl committed
50 51 52

#include "optiondialog.h"
#include "diff.h"
Joachim Eibl's avatar
Joachim Eibl committed
53 54
#include "smalldialogs.h"

Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
55 56 57 58
#ifndef KREPLACEMENTS_H
#include <kglobalsettings.h>
#endif

Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
59 60
#define KDIFF3_CONFIG_GROUP "KDiff3 Options"

Joachim Eibl's avatar
Joachim Eibl committed
61 62 63 64 65
static QString s_historyEntryStartRegExpToolTip;
static QString s_historyEntryStartSortKeyOrderToolTip;
static QString s_autoMergeRegExpToolTip;
static QString s_historyStartRegExpToolTip;

Joachim Eibl's avatar
Joachim Eibl committed
66 67 68 69 70 71 72 73
void OptionDialog::addOptionItem(OptionItem* p)
{
   m_optionItemList.push_back(p);
}

class OptionItem
{
public:
Joachim Eibl's avatar
Joachim Eibl committed
74
   OptionItem( OptionDialog* pOptionDialog, const QString& saveName )
Joachim Eibl's avatar
Joachim Eibl committed
75 76 77 78
   {
      assert(pOptionDialog!=0);
      pOptionDialog->addOptionItem( this );
      m_saveName = saveName;
79
      m_bPreserved = false;
Joachim Eibl's avatar
Joachim Eibl committed
80 81 82 83 84
   }
   virtual ~OptionItem(){}
   virtual void setToDefault()=0;
   virtual void setToCurrent()=0;
   virtual void apply()=0;
Joachim Eibl's avatar
Joachim Eibl committed
85 86
   virtual void write(ValueMap*)=0;
   virtual void read(ValueMap*)=0;
87 88
   void doPreserve(){ if (!m_bPreserved){ m_bPreserved=true; preserve(); } }
   void doUnpreserve(){ if( m_bPreserved ){ unpreserve(); } }
Joachim Eibl's avatar
Joachim Eibl committed
89
   QString getSaveName(){return m_saveName;}
Joachim Eibl's avatar
Joachim Eibl committed
90
protected:
91 92 93
   virtual void preserve()=0;
   virtual void unpreserve()=0;
   bool m_bPreserved;
Joachim Eibl's avatar
Joachim Eibl committed
94 95 96
   QString m_saveName;
};

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
template <class T>
class OptionItemT : public OptionItem
{
public:
  OptionItemT( OptionDialog* pOptionDialog, const QString& saveName ) 
  : OptionItem(pOptionDialog,saveName ) 
  {}
  
protected:
   virtual void preserve(){ m_preservedVal = *m_pVar; }
   virtual void unpreserve(){ *m_pVar = m_preservedVal; }
   T* m_pVar;
   T m_preservedVal;
   T m_defaultVal;
};

class OptionCheckBox : public QCheckBox, public OptionItemT<bool>
Joachim Eibl's avatar
Joachim Eibl committed
114 115 116 117
{
public:
   OptionCheckBox( QString text, bool bDefaultVal, const QString& saveName, bool* pbVar,
                   QWidget* pParent, OptionDialog* pOD )
118
   : QCheckBox( text, pParent ), OptionItemT<bool>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
119
   {
120 121
      m_pVar = pbVar;
      m_defaultVal = bDefaultVal;
Joachim Eibl's avatar
Joachim Eibl committed
122
   }
123 124 125 126 127
   void setToDefault(){ setChecked( m_defaultVal );      }
   void setToCurrent(){ setChecked( *m_pVar );           }
   void apply()       { *m_pVar = isChecked();                              }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readBoolEntry( m_saveName, *m_pVar ); }
Joachim Eibl's avatar
Joachim Eibl committed
128 129 130 131
private:
   OptionCheckBox( const OptionCheckBox& ); // private copy constructor without implementation
};

132
class OptionRadioButton : public QRadioButton, public OptionItemT<bool>
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
133 134 135 136
{
public:
   OptionRadioButton( QString text, bool bDefaultVal, const QString& saveName, bool* pbVar,
                   QWidget* pParent, OptionDialog* pOD )
137
   : QRadioButton( text, pParent ), OptionItemT<bool>( pOD, saveName )
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
138
   {
139 140
      m_pVar = pbVar;
      m_defaultVal = bDefaultVal;
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
141
   }
142 143 144 145 146
   void setToDefault(){ setChecked( m_defaultVal );      }
   void setToCurrent(){ setChecked( *m_pVar );           }
   void apply()       { *m_pVar = isChecked();                              }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readBoolEntry( m_saveName, *m_pVar ); }
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
147 148 149 150
private:
   OptionRadioButton( const OptionRadioButton& ); // private copy constructor without implementation
};

Joachim Eibl's avatar
Joachim Eibl committed
151 152

template<class T>
153
class OptionT : public OptionItemT<T>
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
154 155
{
public:
Joachim Eibl's avatar
Joachim Eibl committed
156
   OptionT( const T& defaultVal, const QString& saveName, T* pVar, OptionDialog* pOD )
157
   : OptionItemT<T>( pOD, saveName )
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
158
   {
159 160
      this->m_pVar = pVar;
      *this->m_pVar = defaultVal;
Joachim Eibl's avatar
Joachim Eibl committed
161 162
   }
   OptionT( const QString& saveName, T* pVar, OptionDialog* pOD )
163
   : OptionItemT<T>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
164
   {
165
      this->m_pVar = pVar;
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
166 167 168 169
   }
   void setToDefault(){}
   void setToCurrent(){}
   void apply()       {}
170 171
   void write(ValueMap* vm){ writeEntry( vm, this->m_saveName, *this->m_pVar ); }
   void read (ValueMap* vm){ *this->m_pVar = vm->readEntry ( this->m_saveName, *this->m_pVar ); }
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
172
private:
Joachim Eibl's avatar
Joachim Eibl committed
173
   OptionT( const OptionT& ); // private copy constructor without implementation
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
174 175
};

Joachim Eibl's avatar
Joachim Eibl committed
176 177 178
template <class T> void writeEntry(ValueMap* vm, const QString& saveName, const T& v ) {   vm->writeEntry( saveName, v ); }
static void writeEntry(ValueMap* vm, const QString& saveName, const QStringList& v )   {   vm->writeEntry( saveName, v, '|' ); }

Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
179 180 181 182 183
//static void readEntry(ValueMap* vm, const QString& saveName, bool& v )       {   v = vm->readBoolEntry( saveName, v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, int&  v )       {   v = vm->readNumEntry( saveName, v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QSize& v )      {   v = vm->readSizeEntry( saveName, &v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QPoint& v )     {   v = vm->readPointEntry( saveName, &v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QStringList& v ){   v = vm->readListEntry( saveName, QStringList(), '|' ); }
Joachim Eibl's avatar
Joachim Eibl committed
184 185 186 187 188 189 190

typedef OptionT<bool> OptionToggleAction;
typedef OptionT<int>  OptionNum;
typedef OptionT<QPoint> OptionPoint;
typedef OptionT<QSize> OptionSize;
typedef OptionT<QStringList> OptionStringList;

191
class OptionFontChooser : public KFontChooser, public OptionItemT<QFont>
Joachim Eibl's avatar
Joachim Eibl committed
192 193
{
public:
194
   OptionFontChooser( const QFont& defaultVal, const QString& saveName, QFont* pVar, QWidget* pParent, OptionDialog* pOD ) :
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
195
       KFontChooser( pParent ),
196
       OptionItemT<QFont>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
197
   {
198 199 200
      m_pVar = pVar;
      *m_pVar = defaultVal;
      m_defaultVal = defaultVal;
Joachim Eibl's avatar
Joachim Eibl committed
201
   }
202 203
   void setToDefault(){ setFont( m_defaultVal, false ); }
   void setToCurrent(){ setFont( *m_pVar, false ); }
204 205 206
   void apply()       { *m_pVar = font();}
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readFontEntry( m_saveName, m_pVar ); }
Joachim Eibl's avatar
Joachim Eibl committed
207 208 209
private:
   OptionFontChooser( const OptionToggleAction& ); // private copy constructor without implementation
};
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
210

211
class OptionColorButton : public KColorButton, public OptionItemT<QColor>
Joachim Eibl's avatar
Joachim Eibl committed
212 213 214
{
public:
   OptionColorButton( QColor defaultVal, const QString& saveName, QColor* pVar, QWidget* pParent, OptionDialog* pOD )
215
   : KColorButton( pParent ), OptionItemT<QColor>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
216 217 218 219 220 221 222
   {
      m_pVar = pVar;
      m_defaultVal = defaultVal;
   }
   void setToDefault(){ setColor( m_defaultVal );      }
   void setToCurrent(){ setColor( *m_pVar );           }
   void apply()       { *m_pVar = color();                              }
Joachim Eibl's avatar
Joachim Eibl committed
223 224
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readColorEntry( m_saveName, m_pVar ); }
Joachim Eibl's avatar
Joachim Eibl committed
225 226 227 228
private:
   OptionColorButton( const OptionColorButton& ); // private copy constructor without implementation
};

229
class OptionLineEdit : public QComboBox, public OptionItemT<QString>
Joachim Eibl's avatar
Joachim Eibl committed
230 231 232 233
{
public:
   OptionLineEdit( const QString& defaultVal, const QString& saveName, QString* pVar,
                   QWidget* pParent, OptionDialog* pOD )
234
   : QComboBox( pParent ), OptionItemT<QString>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
235
   {
Joachim Eibl's avatar
Joachim Eibl committed
236 237
      setMinimumWidth(50);
      setEditable(true);
Joachim Eibl's avatar
Joachim Eibl committed
238 239
      m_pVar = pVar;
      m_defaultVal = defaultVal;
Joachim Eibl's avatar
Joachim Eibl committed
240
      m_list.push_back(defaultVal);
Joachim Eibl's avatar
Joachim Eibl committed
241
      insertText();
Joachim Eibl's avatar
Joachim Eibl committed
242
   }
Joachim Eibl's avatar
Joachim Eibl committed
243 244
   void setToDefault(){ setEditText( m_defaultVal );   }
   void setToCurrent(){ setEditText( *m_pVar );        }
Joachim Eibl's avatar
Joachim Eibl committed
245
   void apply()       { *m_pVar = currentText(); insertText();            }
Joachim Eibl's avatar
Joachim Eibl committed
246 247
   void write(ValueMap* config){ config->writeEntry( m_saveName, m_list, '|' );      }
   void read (ValueMap* config){ 
Joachim Eibl's avatar
Joachim Eibl committed
248
      m_list = config->readListEntry( m_saveName, QStringList(m_defaultVal), '|' ); 
Joachim Eibl's avatar
Joachim Eibl committed
249
      if ( !m_list.empty() ) *m_pVar = m_list.front();
Joachim Eibl's avatar
Joachim Eibl committed
250
      clear();
Joachim Eibl's avatar
Joachim Eibl committed
251
      insertItems(0,m_list);
Joachim Eibl's avatar
Joachim Eibl committed
252 253
   }
private:
Joachim Eibl's avatar
Joachim Eibl committed
254
   void insertText()
Joachim Eibl's avatar
Joachim Eibl committed
255
   {  // Check if the text exists. If yes remove it and push it in as first element
Joachim Eibl's avatar
Joachim Eibl committed
256
      QString current = currentText();
Joachim Eibl's avatar
Joachim Eibl committed
257
      m_list.removeAll( current );
Joachim Eibl's avatar
Joachim Eibl committed
258 259
      m_list.push_front( current );
      clear();
Joachim Eibl's avatar
Joachim Eibl committed
260
      if ( m_list.size()>10 ) 
Joachim Eibl's avatar
Joachim Eibl committed
261
         m_list.erase( m_list.begin()+10, m_list.end() );
Joachim Eibl's avatar
Joachim Eibl committed
262
      insertItems(0,m_list);
Joachim Eibl's avatar
Joachim Eibl committed
263
   }
Joachim Eibl's avatar
Joachim Eibl committed
264
   OptionLineEdit( const OptionLineEdit& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
265
   QStringList m_list;
Joachim Eibl's avatar
Joachim Eibl committed
266 267 268 269 270
};

#if defined QT_NO_VALIDATOR
#error No validator
#endif
271
class OptionIntEdit : public QLineEdit, public OptionItemT<int>
Joachim Eibl's avatar
Joachim Eibl committed
272 273 274 275
{
public:
   OptionIntEdit( int defaultVal, const QString& saveName, int* pVar, int rangeMin, int rangeMax,
                   QWidget* pParent, OptionDialog* pOD )
276
   : QLineEdit( pParent ), OptionItemT<int>( pOD, saveName )
Joachim Eibl's avatar
Joachim Eibl committed
277 278 279
   {
      m_pVar = pVar;
      m_defaultVal = defaultVal;
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
280
      QIntValidator* v = new QIntValidator(this);
Joachim Eibl's avatar
Joachim Eibl committed
281 282 283 284 285 286 287 288
      v->setRange( rangeMin, rangeMax );
      setValidator( v );
   }
   void setToDefault(){ QString s;  s.setNum(m_defaultVal); setText( s );  }
   void setToCurrent(){ QString s;  s.setNum(*m_pVar);      setText( s );  }
   void apply()       { const QIntValidator* v=static_cast<const QIntValidator*>(validator());
                        *m_pVar = minMaxLimiter( text().toInt(), v->bottom(), v->top());
                        setText( QString::number(*m_pVar) );  }
Joachim Eibl's avatar
Joachim Eibl committed
289 290
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readNumEntry( m_saveName, *m_pVar ); }
Joachim Eibl's avatar
Joachim Eibl committed
291 292 293 294
private:
   OptionIntEdit( const OptionIntEdit& ); // private copy constructor without implementation
};

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
295 296 297
class OptionComboBox : public QComboBox, public OptionItem
{
public:
Joachim Eibl's avatar
Joachim Eibl committed
298
   OptionComboBox( int defaultVal, const QString& saveName, int* pVarNum,
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
299 300 301
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
Joachim Eibl's avatar
Joachim Eibl committed
302
      setMinimumWidth(50);
Joachim Eibl's avatar
Joachim Eibl committed
303 304
      m_pVarNum = pVarNum;
      m_pVarStr = 0;
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
305 306 307
      m_defaultVal = defaultVal;
      setEditable(false);
   }
Joachim Eibl's avatar
Joachim Eibl committed
308 309 310 311 312 313 314 315 316 317 318
   OptionComboBox( int defaultVal, const QString& saveName, QString* pVarStr,
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
      m_pVarNum = 0;
      m_pVarStr = pVarStr;
      m_defaultVal = defaultVal;
      setEditable(false);
   }
   void setToDefault()
   { 
Joachim Eibl's avatar
Joachim Eibl committed
319
      setCurrentIndex( m_defaultVal ); 
Joachim Eibl's avatar
Joachim Eibl committed
320 321 322 323
      if (m_pVarStr!=0){ *m_pVarStr=currentText(); } 
   }
   void setToCurrent()
   { 
Joachim Eibl's avatar
Joachim Eibl committed
324
      if (m_pVarNum!=0) setCurrentIndex( *m_pVarNum );
Joachim Eibl's avatar
Joachim Eibl committed
325 326
      else              setText( *m_pVarStr );
   }
Joachim Eibl's avatar
Joachim Eibl committed
327
   void apply()
Joachim Eibl's avatar
Joachim Eibl committed
328
   { 
Joachim Eibl's avatar
Joachim Eibl committed
329
      if (m_pVarNum!=0){ *m_pVarNum = currentIndex(); }
Joachim Eibl's avatar
Joachim Eibl committed
330 331
      else             { *m_pVarStr = currentText(); }
   }
Joachim Eibl's avatar
Joachim Eibl committed
332
   void write(ValueMap* config)
Joachim Eibl's avatar
Joachim Eibl committed
333 334 335 336
   { 
      if (m_pVarStr!=0) config->writeEntry(m_saveName, *m_pVarStr );
      else              config->writeEntry(m_saveName, *m_pVarNum );   
   }
Joachim Eibl's avatar
Joachim Eibl committed
337
   void read (ValueMap* config)
Joachim Eibl's avatar
Joachim Eibl committed
338 339 340 341
   {
      if (m_pVarStr!=0)  setText( config->readEntry( m_saveName, currentText() ) );
      else               *m_pVarNum = config->readNumEntry( m_saveName, *m_pVarNum ); 
   }
342 343 344 345 346 347 348 349 350 351
   void preserve()
   {
      if (m_pVarStr!=0)  { m_preservedStrVal = *m_pVarStr; }
      else               { m_preservedNumVal = *m_pVarNum; }
   }
   void unpreserve()
   {
      if (m_pVarStr!=0)  { *m_pVarStr = m_preservedStrVal; }
      else               { *m_pVarNum = m_preservedNumVal; }
   }
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
352 353
private:
   OptionComboBox( const OptionIntEdit& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
354
   int* m_pVarNum;
355
   int m_preservedNumVal;
Joachim Eibl's avatar
Joachim Eibl committed
356
   QString* m_pVarStr;
357
   QString m_preservedStrVal;
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
358
   int m_defaultVal;
Joachim Eibl's avatar
Joachim Eibl committed
359 360 361 362 363 364
   
   void setText(const QString& s)
   {
      // Find the string in the combobox-list, don't change the value if nothing fits.
      for( int i=0; i<count(); ++i )
      {
Joachim Eibl's avatar
Joachim Eibl committed
365
         if ( itemText(i)==s )
Joachim Eibl's avatar
Joachim Eibl committed
366 367 368
         {
            if (m_pVarNum!=0) *m_pVarNum = i;
            if (m_pVarStr!=0) *m_pVarStr = s;
Joachim Eibl's avatar
Joachim Eibl committed
369
            setCurrentIndex(i);
Joachim Eibl's avatar
Joachim Eibl committed
370 371 372 373
            return;
         }
      }
   }
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
374
};
Joachim Eibl's avatar
Joachim Eibl committed
375

Joachim Eibl's avatar
Joachim Eibl committed
376 377
class OptionEncodingComboBox : public QComboBox, public OptionItem
{
378
   QVector<QTextCodec*> m_codecVec;
Joachim Eibl's avatar
Joachim Eibl committed
379 380 381 382 383 384 385 386 387 388 389 390 391
   QTextCodec** m_ppVarCodec;
public:
   OptionEncodingComboBox( const QString& saveName, QTextCodec** ppVarCodec,
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
      m_ppVarCodec = ppVarCodec;
      insertCodec( i18n("Unicode, 8 bit"),  QTextCodec::codecForName("UTF-8") );
      insertCodec( i18n("Unicode"), QTextCodec::codecForName("iso-10646-UCS-2") );
      insertCodec( i18n("Latin1"), QTextCodec::codecForName("iso 8859-1") );

      // First sort codec names:
      std::map<QString, QTextCodec*> names;
Joachim Eibl's avatar
Joachim Eibl committed
392 393
      QList<int> mibs = QTextCodec::availableMibs();
      foreach(int i, mibs)
Joachim Eibl's avatar
Joachim Eibl committed
394
      {
Joachim Eibl's avatar
Joachim Eibl committed
395
         QTextCodec* c = QTextCodec::codecForMib(i);
Joachim Eibl's avatar
Joachim Eibl committed
396 397
         if ( c!=0 )
            names[QString(c->name()).toUpper()]=c;
Joachim Eibl's avatar
Joachim Eibl committed
398 399 400 401 402 403 404 405
      }

      std::map<QString, QTextCodec*>::iterator it;
      for(it=names.begin();it!=names.end();++it)
      {
         insertCodec( "", it->second );
      }

Joachim Eibl's avatar
Joachim Eibl committed
406
      this->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
407 408 409 410 411 412 413
         "Change this if non-ASCII characters are not displayed correctly."
         ));
   }
   void insertCodec( const QString& visibleCodecName, QTextCodec* c )
   {
      if (c!=0)
      {
414
         for( int i=0; i<m_codecVec.size(); ++i )
Joachim Eibl's avatar
Joachim Eibl committed
415 416 417 418
         {
            if ( c==m_codecVec[i] )
               return;  // don't insert any codec twice
         }
Joachim Eibl's avatar
Joachim Eibl committed
419
         addItem( visibleCodecName.isEmpty() ? QString(c->name()) : visibleCodecName+" ("+c->name()+")", (int)m_codecVec.size() );
Joachim Eibl's avatar
Joachim Eibl committed
420 421 422 423
         m_codecVec.push_back( c );
      }
   }
   void setToDefault()
Joachim Eibl's avatar
Joachim Eibl committed
424 425 426 427
   {
      QString defaultName = QTextCodec::codecForLocale()->name();
      for(int i=0;i<count();++i)
      {
Joachim Eibl's avatar
Joachim Eibl committed
428
         if (defaultName==itemText(i) &&
Joachim Eibl's avatar
Joachim Eibl committed
429 430
             m_codecVec[i]==QTextCodec::codecForLocale())
         {
Joachim Eibl's avatar
Joachim Eibl committed
431
            setCurrentIndex(i);
Joachim Eibl's avatar
Joachim Eibl committed
432 433 434 435 436
            if (m_ppVarCodec!=0){ *m_ppVarCodec=m_codecVec[i]; }
            return;
         }
      }

Joachim Eibl's avatar
Joachim Eibl committed
437
      setCurrentIndex( 0 );
Joachim Eibl's avatar
Joachim Eibl committed
438
      if (m_ppVarCodec!=0){ *m_ppVarCodec=m_codecVec[0]; }
Joachim Eibl's avatar
Joachim Eibl committed
439 440 441 442 443
   }
   void setToCurrent()
   {
      if (m_ppVarCodec!=0)
      {
444
         for( int i=0; i<m_codecVec.size(); ++i)
Joachim Eibl's avatar
Joachim Eibl committed
445 446 447
         {
            if ( *m_ppVarCodec==m_codecVec[i] )
            {
Joachim Eibl's avatar
Joachim Eibl committed
448
               setCurrentIndex( i );
Joachim Eibl's avatar
Joachim Eibl committed
449 450 451 452 453 454 455
               break;
            }
         }
      }
   }
   void apply()
   {
Joachim Eibl's avatar
Joachim Eibl committed
456
      if (m_ppVarCodec!=0){ *m_ppVarCodec = m_codecVec[ currentIndex() ]; }
Joachim Eibl's avatar
Joachim Eibl committed
457
   }
Joachim Eibl's avatar
Joachim Eibl committed
458
   void write(ValueMap* config)
Joachim Eibl's avatar
Joachim Eibl committed
459
   {
Joachim Eibl's avatar
Joachim Eibl committed
460
      if (m_ppVarCodec!=0) config->writeEntry(m_saveName, QString((*m_ppVarCodec)->name()) );
Joachim Eibl's avatar
Joachim Eibl committed
461
   }
Joachim Eibl's avatar
Joachim Eibl committed
462
   void read (ValueMap* config)
Joachim Eibl's avatar
Joachim Eibl committed
463
   {
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
464
      QString codecName = config->readEntry( m_saveName, QString(m_codecVec[ currentIndex() ]->name()) );
465
      for( int i=0; i<m_codecVec.size(); ++i)
Joachim Eibl's avatar
Joachim Eibl committed
466 467 468
      {
         if ( codecName == m_codecVec[i]->name() )
         {
Joachim Eibl's avatar
Joachim Eibl committed
469
            setCurrentIndex( i );
Joachim Eibl's avatar
Joachim Eibl committed
470 471 472 473 474
            if (m_ppVarCodec!=0) *m_ppVarCodec = m_codecVec[i];
            break;
         }
      }
   }
475 476 477 478
protected:
   void preserve()   { m_preservedVal = currentIndex(); }
   void unpreserve() { setCurrentIndex( m_preservedVal ); }
   int m_preservedVal;
Joachim Eibl's avatar
Joachim Eibl committed
479 480 481
};


Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
482 483 484 485
OptionDialog::OptionDialog( bool bShowDirMergeSettings, QWidget *parent, char *name ) : 
//    KPageDialog( IconList, i18n("Configure"), Help|Default|Apply|Ok|Cancel,
//                 Ok, parent, name, true /*modal*/, true )
    KPageDialog( parent )
Joachim Eibl's avatar
Joachim Eibl committed
486
{
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
487 488 489 490 491 492 493
   setFaceType( List );
   setWindowTitle( i18n("Configure") );
   setButtons( Help|Default|Apply|Ok|Cancel );
   setDefaultButton( Ok );
   setObjectName( name );
   setModal( true  );
   showButtonSeparator( true );
Joachim Eibl's avatar
Joachim Eibl committed
494
   setHelp( "kdiff3/index.html", QString::null );
Joachim Eibl's avatar
Joachim Eibl committed
495

Joachim Eibl's avatar
Joachim Eibl committed
496 497 498 499
   setupFontPage();
   setupColorPage();
   setupEditPage();
   setupDiffPage();
Joachim Eibl's avatar
Joachim Eibl committed
500
   setupMergePage();
Joachim Eibl's avatar
Joachim Eibl committed
501 502 503
   setupOtherOptions();
   if (bShowDirMergeSettings)
      setupDirectoryMergePage();
Joachim Eibl's avatar
Joachim Eibl committed
504

Joachim Eibl's avatar
Joachim Eibl committed
505
   setupRegionalPage();
Joachim Eibl's avatar
Joachim Eibl committed
506
   setupIntegrationPage();
Joachim Eibl's avatar
Joachim Eibl committed
507 508 509 510 511 512

   //setupKeysPage();

   // Initialize all values in the dialog
   resetToDefaults();
   slotApply();
513 514
   connect(this, &OptionDialog::applyClicked, this, &OptionDialog::slotApply);
   connect(this, &OptionDialog::okClicked, this, &OptionDialog::slotOk);
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
515
   //helpClicked() is connected in KDiff3App::KDiff3App
516
   connect(this, &OptionDialog::defaultClicked, this, &OptionDialog::slotDefault);
Joachim Eibl's avatar
Joachim Eibl committed
517 518 519 520 521 522
}

OptionDialog::~OptionDialog( void )
{
}

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
523 524
void OptionDialog::setupOtherOptions()
{
525 526 527 528 529 530
   new OptionToggleAction( false, "AutoAdvance", &m_options.m_bAutoAdvance, this );
   new OptionToggleAction( true,  "ShowWhiteSpaceCharacters", &m_options.m_bShowWhiteSpaceCharacters, this );
   new OptionToggleAction( true,  "ShowWhiteSpace", &m_options.m_bShowWhiteSpace, this );
   new OptionToggleAction( false, "ShowLineNumbers", &m_options.m_bShowLineNumbers, this );
   new OptionToggleAction( true,  "HorizDiffWindowSplitting", &m_options.m_bHorizDiffWindowSplitting, this );
   new OptionToggleAction( false, "WordWrap", &m_options.m_bWordWrap, this );
Joachim Eibl's avatar
Joachim Eibl committed
531

532
   new OptionToggleAction( true,  "ShowIdenticalFiles", &m_options.m_bDmShowIdenticalFiles, this );
Joachim Eibl's avatar
Joachim Eibl committed
533

534 535
   new OptionToggleAction( true,  "Show Toolbar", &m_options.m_bShowToolBar, this );
   new OptionToggleAction( true,  "Show Statusbar", &m_options.m_bShowStatusBar, this );
Joachim Eibl's avatar
Joachim Eibl committed
536

Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
537 538
/*
   TODO manage toolbar positioning
Joachim Eibl's avatar
Joachim Eibl committed
539
   new OptionNum( (int)KToolBar::Top, "ToolBarPos", &m_toolBarPos, this );
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
540
*/
541 542 543
   new OptionSize( QSize(600,400),"Geometry", &m_options.m_geometry, this );
   new OptionPoint( QPoint(0,22), "Position", &m_options.m_position, this );
   new OptionToggleAction( false, "WindowStateMaximised", &m_options.m_bMaximised, this );
Joachim Eibl's avatar
Joachim Eibl committed
544

545 546 547 548 549
   new OptionStringList( "RecentAFiles", &m_options.m_recentAFiles, this );
   new OptionStringList( "RecentBFiles", &m_options.m_recentBFiles, this );
   new OptionStringList( "RecentCFiles", &m_options.m_recentCFiles, this );
   new OptionStringList( "RecentOutputFiles", &m_options.m_recentOutputFiles, this );
   new OptionStringList( "RecentEncodings", &m_options.m_recentEncodings, this );
550

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
551
}
Joachim Eibl's avatar
Joachim Eibl committed
552 553 554

void OptionDialog::setupFontPage( void )
{
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
555 556 557 558 559
   QFrame* page = new QFrame();
   KPageWidgetItem *pageItem = new KPageWidgetItem( page, i18n("Font") );
   pageItem->setHeader( i18n("Editor & Diff Output Font" ) );
   pageItem->setIcon( KIcon( "preferences-desktop-font" ) );
   addPage( pageItem );
Joachim Eibl's avatar
Joachim Eibl committed
560

Joachim Eibl's avatar
Joachim Eibl committed
561 562 563
   QVBoxLayout *topLayout = new QVBoxLayout( page );
   topLayout->setMargin( 5 );
   topLayout->setSpacing( spacingHint() );
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
564

Joachim Eibl's avatar
Joachim Eibl committed
565 566 567 568 569 570 571 572 573
   QFont defaultFont =
#ifdef _WIN32
      QFont("Courier New", 10 );
#elif defined( KREPLACEMENTS_H )
      QFont("Courier", 10 );
#else
      KGlobalSettings::fixedFont();
#endif

574
   OptionFontChooser* pFontChooser = new OptionFontChooser( defaultFont, "Font", &m_options.m_font, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
575
   topLayout->addWidget( pFontChooser );
Joachim Eibl's avatar
Joachim Eibl committed
576

Joachim Eibl's avatar
Joachim Eibl committed
577
   QGridLayout *gbox = new QGridLayout();
Joachim Eibl's avatar
Joachim Eibl committed
578 579 580
   topLayout->addLayout( gbox );
   int line=0;

581
   OptionCheckBox* pItalicDeltas = new OptionCheckBox( i18n("Italic font for deltas"), false, "ItalicForDeltas", &m_options.m_bItalicForDeltas, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
582 583
   gbox->addWidget( pItalicDeltas, line, 0, 1, 2 );
   pItalicDeltas->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
584 585 586 587 588 589 590 591
      "Selects the italic version of the font for differences.\n"
      "If the font doesn't support italic characters, then this does nothing.")
      );
}


void OptionDialog::setupColorPage( void )
{
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
592 593 594 595 596 597
   QFrame* page = new QFrame();
   KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n("Color") );
   pageItem->setHeader( i18n("Colors Settings") );
   pageItem->setIcon( KIcon("preferences-desktop-color") );
   addPage( pageItem );

Joachim Eibl's avatar
Joachim Eibl committed
598 599 600
   QVBoxLayout *topLayout = new QVBoxLayout( page );
   topLayout->setMargin( 5 );
   topLayout->setSpacing( spacingHint() );
Joachim Eibl's avatar
Joachim Eibl committed
601

Joachim Eibl's avatar
Joachim Eibl committed
602 603 604

  QGridLayout *gbox = new QGridLayout();
  gbox->setColumnStretch(1,5);
Joachim Eibl's avatar
Joachim Eibl committed
605 606 607 608 609
  topLayout->addLayout(gbox);

  QLabel* label;
  int line = 0;

Joachim Eibl's avatar
Joachim Eibl committed
610
  int depth = QPixmap::defaultDepth();
Joachim Eibl's avatar
Joachim Eibl committed
611 612
  bool bLowColor = depth<=8;

Joachim Eibl's avatar
Joachim Eibl committed
613 614 615 616 617 618 619
  label = new QLabel( i18n("Editor and Diff Views:"), page );
  gbox->addWidget( label, line, 0 );
  QFont f( label->font() );
  f.setBold(true);
  label->setFont(f);
  ++line;

620
  OptionColorButton* pFgColor = new OptionColorButton( Qt::black,"FgColor", &m_options.m_fgColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
621 622
  label = new QLabel( i18n("Foreground color:"), page );
  label->setBuddy(pFgColor);
Joachim Eibl's avatar
Joachim Eibl committed
623 624 625 626
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pFgColor, line, 1 );
  ++line;

627
  OptionColorButton* pBgColor = new OptionColorButton( Qt::white, "BgColor", &m_options.m_bgColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
628 629
  label = new QLabel( i18n("Background color:"), page );
  label->setBuddy(pBgColor);
Joachim Eibl's avatar
Joachim Eibl committed
630 631 632 633 634
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pBgColor, line, 1 );

  ++line;

Joachim Eibl's avatar
Joachim Eibl committed
635
  OptionColorButton* pDiffBgColor = new OptionColorButton( 
636
     bLowColor ? QColor(Qt::lightGray) : qRgb(224,224,224), "DiffBgColor", &m_options.m_diffBgColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
637 638
  label = new QLabel( i18n("Diff background color:"), page );
  label->setBuddy(pDiffBgColor);
Joachim Eibl's avatar
Joachim Eibl committed
639 640 641 642 643
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pDiffBgColor, line, 1 );
  ++line;

  OptionColorButton* pColorA = new OptionColorButton(
644
     bLowColor ? qRgb(0,0,255) : qRgb(0,0,200)/*blue*/, "ColorA", &m_options.m_colorA, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
645 646
  label = new QLabel( i18n("Color A:"), page );
  label->setBuddy(pColorA);
Joachim Eibl's avatar
Joachim Eibl committed
647 648 649 650 651
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColorA, line, 1 );
  ++line;

  OptionColorButton* pColorB = new OptionColorButton(
652
     bLowColor ? qRgb(0,128,0) : qRgb(0,150,0)/*green*/, "ColorB", &m_options.m_colorB, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
653 654
  label = new QLabel( i18n("Color B:"), page );
  label->setBuddy(pColorB);
Joachim Eibl's avatar
Joachim Eibl committed
655 656 657 658 659
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColorB, line, 1 );
  ++line;

  OptionColorButton* pColorC = new OptionColorButton(
660
     bLowColor ? qRgb(128,0,128) : qRgb(150,0,150)/*magenta*/, "ColorC", &m_options.m_colorC, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
661 662
  label = new QLabel( i18n("Color C:"), page );
  label->setBuddy(pColorC);
Joachim Eibl's avatar
Joachim Eibl committed
663 664 665 666
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColorC, line, 1 );
  ++line;

667
  OptionColorButton* pColorForConflict = new OptionColorButton( Qt::red, "ColorForConflict", &m_options.m_colorForConflict, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
668 669
  label = new QLabel( i18n("Conflict color:"), page );
  label->setBuddy(pColorForConflict);
Joachim Eibl's avatar
Joachim Eibl committed
670 671 672 673 674
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColorForConflict, line, 1 );
  ++line;

  OptionColorButton* pColor = new OptionColorButton( 
675
     bLowColor ? qRgb(192,192,192) : qRgb(220,220,100), "CurrentRangeBgColor", &m_options.m_currentRangeBgColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
676 677
  label = new QLabel( i18n("Current range background color:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
678 679 680 681 682
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
  ++line;

  pColor = new OptionColorButton( 
683
     bLowColor ? qRgb(255,255,0) : qRgb(255,255,150), "CurrentRangeDiffBgColor", &m_options.m_currentRangeDiffBgColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
684 685
  label = new QLabel( i18n("Current range diff background color:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
686 687 688 689
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
  ++line;

690
  pColor = new OptionColorButton( qRgb(0xff,0xd0,0x80), "ManualAlignmentRangeColor", &m_options.m_manualHelpRangeColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
691 692
  label = new QLabel( i18n("Color for manually aligned difference ranges:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
693 694 695 696 697 698 699 700 701
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
  ++line;

  label = new QLabel( i18n("Directory Comparison View:"), page );
  gbox->addWidget( label, line, 0 );
  label->setFont(f);
  ++line;

702
  pColor = new OptionColorButton( qRgb(0,0xd0,0), "NewestFileColor", &m_options.m_newestFileColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
703 704
  label = new QLabel( i18n("Newest file color:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
705 706 707
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
  QString dirColorTip = i18n( "Changing this color will only be effective when starting the next directory comparison.");
Joachim Eibl's avatar
Joachim Eibl committed
708
  label->setToolTip( dirColorTip );
Joachim Eibl's avatar
Joachim Eibl committed
709 710
  ++line;

711
  pColor = new OptionColorButton( qRgb(0xf0,0,0), "OldestFileColor", &m_options.m_oldestFileColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
712 713
  label = new QLabel( i18n("Oldest file color:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
714 715
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
Joachim Eibl's avatar
Joachim Eibl committed
716
  label->setToolTip( dirColorTip );
Joachim Eibl's avatar
Joachim Eibl committed
717 718
  ++line;

719
  pColor = new OptionColorButton( qRgb(0xc0,0xc0,0), "MidAgeFileColor", &m_options.m_midAgeFileColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
720 721
  label = new QLabel( i18n("Middle age file color:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
722 723
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
Joachim Eibl's avatar
Joachim Eibl committed
724
  label->setToolTip( dirColorTip );
Joachim Eibl's avatar
Joachim Eibl committed
725 726
  ++line;

727
  pColor = new OptionColorButton( qRgb(0,0,0), "MissingFileColor", &m_options.m_missingFileColor, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
728 729
  label = new QLabel( i18n("Color for missing files:"), page );
  label->setBuddy(pColor);
Joachim Eibl's avatar
Joachim Eibl committed
730 731
  gbox->addWidget( label, line, 0 );
  gbox->addWidget( pColor, line, 1 );
Joachim Eibl's avatar
Joachim Eibl committed
732
  label->setToolTip( dirColorTip );
Joachim Eibl's avatar
Joachim Eibl committed
733 734
  ++line;

Joachim Eibl's avatar
Joachim Eibl committed
735 736 737 738 739 740
  topLayout->addStretch(10);
}


void OptionDialog::setupEditPage( void )
{
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
741 742 743 744 745 746
   QFrame* page = new QFrame();
   KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n("Editor") );
   pageItem->setHeader( i18n("Editor Behavior") );
   pageItem->setIcon( KIcon( "accessories-text-editor") );
   addPage( pageItem );

Joachim Eibl's avatar
Joachim Eibl committed
747 748 749 750 751 752
   QVBoxLayout *topLayout = new QVBoxLayout( page );
   topLayout->setMargin( 5 );
   topLayout->setSpacing( spacingHint() );

   QGridLayout *gbox = new QGridLayout();
   gbox->setColumnStretch(1,5);
Joachim Eibl's avatar
Joachim Eibl committed
753 754 755 756
   topLayout->addLayout( gbox );
   QLabel* label;
   int line=0;

757
   OptionCheckBox* pReplaceTabs = new OptionCheckBox( i18n("Tab inserts spaces"), false, "ReplaceTabs", &m_options.m_bReplaceTabs, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
758 759
   gbox->addWidget( pReplaceTabs, line, 0, 1, 2 );
   pReplaceTabs->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
760
      "On: Pressing tab generates the appropriate number of spaces.\n"
Joachim Eibl's avatar
Joachim Eibl committed
761
      "Off: A tab character will be inserted.")
Joachim Eibl's avatar
Joachim Eibl committed
762 763 764
      );
   ++line;

765
   OptionIntEdit* pTabSize = new OptionIntEdit( 8, "TabSize", &m_options.m_tabSize, 1, 100, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
766 767
   label = new QLabel( i18n("Tab size:"), page );
   label->setBuddy( pTabSize );
Joachim Eibl's avatar
Joachim Eibl committed
768 769 770 771
   gbox->addWidget( label, line, 0 );
   gbox->addWidget( pTabSize, line, 1 );
   ++line;

772
   OptionCheckBox* pAutoIndentation = new OptionCheckBox( i18n("Auto indentation"), true, "AutoIndentation", &m_options.m_bAutoIndentation, page, this  );
Joachim Eibl's avatar
Joachim Eibl committed
773 774
   gbox->addWidget( pAutoIndentation, line, 0, 1, 2 );
   pAutoIndentation->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
775 776 777 778
      "On: The indentation of the previous line is used for a new line.\n"
      ));
   ++line;

779
   OptionCheckBox* pAutoCopySelection = new OptionCheckBox( i18n("Auto copy selection"), false, "AutoCopySelection", &m_options.m_bAutoCopySelection, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
780 781
   gbox->addWidget( pAutoCopySelection, line, 0, 1, 2 );
   pAutoCopySelection->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
782 783 784 785
      "On: Any selection is immediately written to the clipboard.\n"
      "Off: You must explicitely copy e.g. via Ctrl-C."
      ));
   ++line;
Joachim Eibl's avatar
Joachim Eibl committed
786
   
Joachim Eibl's avatar
Joachim Eibl committed
787
   label = new QLabel( i18n("Line end style:"), page );
Joachim Eibl's avatar
Joachim Eibl committed
788
   gbox->addWidget( label, line, 0 );
Joachim Eibl's avatar
Joachim Eibl committed
789

790
   OptionComboBox* pLineEndStyle = new OptionComboBox( eLineEndStyleAutoDetect, "LineEndStyle", &m_options.m_lineEndStyle, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
791
   gbox->addWidget( pLineEndStyle, line, 1 );
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
792 793 794 795
   pLineEndStyle->insertItem( eLineEndStyleUnix, "Unix" );
   pLineEndStyle->insertItem( eLineEndStyleDos, "Dos/Windows" );
   pLineEndStyle->insertItem( eLineEndStyleAutoDetect, "Autodetect" );

Joachim Eibl's avatar
Joachim Eibl committed
796
   label->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
797 798
      "Sets the line endings for when an edited file is saved.\n"
      "DOS/Windows: CR+LF; UNIX: LF; with CR=0D, LF=0A")
Joachim Eibl's avatar
Joachim Eibl committed
799 800 801
      );
   ++line;
      
Joachim Eibl's avatar
Joachim Eibl committed
802 803 804 805 806 807
   topLayout->addStretch(10);
}


void OptionDialog::setupDiffPage( void )
{
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
808 809 810 811 812 813 814
   QFrame* page = new QFrame();
   KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n("Diff") );
   pageItem->setHeader( i18n("Diff Settings") );
   pageItem->setIcon( KIcon( "preferences-other" ) );
   addPage( pageItem );


Joachim Eibl's avatar
Joachim Eibl committed
815 816 817
   QVBoxLayout *topLayout = new QVBoxLayout( page );
   topLayout->setMargin( 5 );
   topLayout->setSpacing( spacingHint() );
Joachim Eibl's avatar
Joachim Eibl committed
818

Joachim Eibl's avatar
Joachim Eibl committed
819 820
   QGridLayout *gbox = new QGridLayout();
   gbox->setColumnStretch(1,5);
Joachim Eibl's avatar
Joachim Eibl committed
821 822 823
   topLayout->addLayout( gbox );
   int line=0;

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
824
   QLabel* label=0;
Joachim Eibl's avatar
Joachim Eibl committed
825

826
   m_options.m_bPreserveCarriageReturn = false;
Joachim Eibl's avatar
Joachim Eibl committed
827 828 829 830 831 832 833 834
   //OptionCheckBox* pPreserveCarriageReturn = new OptionCheckBox( i18n("Preserve carriage return"), false, "PreserveCarriageReturn", &m_bPreserveCarriageReturn, page, this );
   //gbox->addWidget( pPreserveCarriageReturn, line, 0, 1, 2 );
   //pPreserveCarriageReturn->setToolTip( i18n(
   //   "Show carriage return characters '\\r' if they exist.\n"
   //   "Helps to compare files that were modified under different operating systems.")
   //   );
   //++line;
   QString treatAsWhiteSpace = " ("+i18n("Treat as white space.")+")";
Joachim Eibl's avatar
Joachim Eibl committed
835

836
   OptionCheckBox* pIgnoreNumbers = new OptionCheckBox( i18n("Ignore numbers")+treatAsWhiteSpace, false, "IgnoreNumbers", &m_options.m_bIgnoreNumbers, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
837 838
   gbox->addWidget( pIgnoreNumbers, line, 0, 1, 2 );
   pIgnoreNumbers->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
839
      "Ignore number characters during line matching phase. (Similar to Ignore white space.)\n"
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
840
      "Might help to compare files with numeric data.")
Joachim Eibl's avatar
Joachim Eibl committed
841 842 843
      );
   ++line;

844
   OptionCheckBox* pIgnoreComments = new OptionCheckBox( i18n("Ignore C/C++ comments")+treatAsWhiteSpace, false, "IgnoreComments", &m_options.m_bIgnoreComments, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
845 846
   gbox->addWidget( pIgnoreComments, line, 0, 1, 2 );
   pIgnoreComments->setToolTip( i18n( "Treat C/C++ comments like white space.")
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
847 848 849
      );
   ++line;

850
   OptionCheckBox* pIgnoreCase = new OptionCheckBox( i18n("Ignore case")+treatAsWhiteSpace, false, "IgnoreCase", &m_options.m_bIgnoreCase, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
851 852
   gbox->addWidget( pIgnoreCase, line, 0, 1, 2 );
   pIgnoreCase->setToolTip( i18n(
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
853
      "Treat case differences like white space changes. ('a'<=>'A')")
Joachim Eibl's avatar
Joachim Eibl committed
854 855 856
      );
   ++line;

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
857
   label = new QLabel( i18n("Preprocessor command:"), page );
Joachim Eibl's avatar
Joachim Eibl committed
858
   gbox->addWidget( label, line, 0 );
859
   OptionLineEdit* pLE = new OptionLineEdit( "", "PreProcessorCmd", &m_options.m_PreProcessorCmd, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
860
   gbox->addWidget( pLE, line, 1 );
Joachim Eibl's avatar
Joachim Eibl committed
861
   label->setToolTip( i18n("User defined pre-processing. (See the docs for details.)") );
Joachim Eibl's avatar
Joachim Eibl committed
862 863
   ++line;

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
864
   label = new QLabel( i18n("Line-matching preprocessor command:"), page );
Joachim Eibl's avatar
Joachim Eibl committed
865
   gbox->addWidget( label, line, 0 );
866
   pLE = new OptionLineEdit( "", "LineMatchingPreProcessorCmd", &m_options.m_LineMatchingPreProcessorCmd, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
867
   gbox->addWidget( pLE, line, 1 );
Joachim Eibl's avatar
Joachim Eibl committed
868
   label->setToolTip( i18n("This pre-processor is only used during line matching.\n(See the docs for details.)") );
Joachim Eibl's avatar
Joachim Eibl committed
869 870
   ++line;

871
   OptionCheckBox* pTryHard = new OptionCheckBox( i18n("Try hard (slower)"), true, "TryHard", &m_options.m_bTryHard, page, this );
Joachim Eibl's avatar
Joachim Eibl committed
872 873
   gbox->addWidget( pTryHard, line, 0, 1, 2 );
   pTryHard->setToolTip( i18n(
Joachim Eibl's avatar
Joachim Eibl committed
874
      "Enables the --minimal option for the external diff.\n"
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
875
      "The analysis of big files will be much slower.")
Joachim Eibl's avatar
Joachim Eibl committed
876 877 878
      );
   ++line;

879
   OptionCheckBox* pDiff3AlignBC = new OptionCheckBox( i18n("Align B and C for 3 input files"), false, "Diff3AlignBC", &m_options.m_bDiff3AlignBC, page, this );
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
880 881 882 <