Skip to content
Snippets Groups Projects
ConfigDialog.cpp 68.2 KiB
Newer Older
Roman Tolchenov's avatar
Roman Tolchenov committed
/***************************************************************************
    File                 : ConfigDialog.cpp
    Project              : QtiPlot
    --------------------------------------------------------------------
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
    Description          : Preferences dialog

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *  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., 51 Franklin Street, Fifth Floor,                    *
 *   Boston, MA  02110-1301  USA                                           *
 *                                                                         *
 ***************************************************************************/
#include "ConfigDialog.h"
#include "ApplicationWindow.h"
#include "MultiLayer.h"
#include "Graph.h"
#include "Matrix.h"
#include "ColorButton.h"
#include "ColorBox.h"
#include "pixmaps.h"
#include "DoubleSpinBox.h"

#include <QLocale>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>
#include <QGroupBox>
#include <QFont>
#include <QFontDialog>
#include <QTabWidget>
#include <QStackedWidget>
#include <QWidget>
#include <QComboBox>
#include <QSpinBox>
#include <QRadioButton>
#include <QStyleFactory>
#include <QRegExp>
#include <QMessageBox>
#include <QTranslator>
#include <QApplication>
#include <QDir>
#include <QPixmap>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QListWidget>
#include <QFontMetrics>
#include <QFileDialog>
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IBackgroundFunction.h"
Roman Tolchenov's avatar
Roman Tolchenov committed

static const char* choose_folder_xpm[]={
    "16 16 11 1",
    "# c #000000",
    "g c #c0c0c0",
    "e c #303030",
    "a c #ffa858",
    "b c #808080",
    "d c #a0a0a4",
    "f c #585858",
    "c c #ffdca8",
    "h c #dcdcdc",
    "i c #ffffff",
    ". c None",
    "....###.........",
    "....#ab##.......",
    "....#acab####...",
    "###.#acccccca#..",
    "#ddefaaaccccca#.",
    "#bdddbaaaacccab#",
    ".eddddbbaaaacab#",
    ".#bddggdbbaaaab#",
    "..edgdggggbbaab#",
    "..#bgggghghdaab#",
    "...ebhggghicfab#",
    "....#edhhiiidab#",
    "......#egiiicfb#",
    "........#egiibb#",
    "..........#egib#",
    "............#ee#"};

ConfigDialog::ConfigDialog( QWidget* parent, Qt::WFlags fl )
    : QDialog( parent, fl )
{
	// get current values from app window
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();
	plot3DTitleFont = app->plot3DTitleFont;
	plot3DNumbersFont = app->plot3DNumbersFont;
	plot3DAxesFont = app->plot3DAxesFont;
	textFont = app->tableTextFont;
	headerFont = app->tableHeaderFont;
	appFont = app->appFont;
	axesFont = app->plotAxesFont;
	numbersFont = app->plotNumbersFont;
	legendFont = app->plotLegendFont;
	titleFont = app->plotTitleFont;

	// create the GUI
	generalDialog = new QStackedWidget();
	itemsList = new QListWidget();
	itemsList->setSpacing(10);
	itemsList->setAlternatingRowColors( true );

	initAppPage();
Roman Tolchenov's avatar
Roman Tolchenov committed
	initTablesPage();
	initPlotsPage();
	initPlots3DPage();
	initFittingPage();

	generalDialog->addWidget(appTabWidget);
Roman Tolchenov's avatar
Roman Tolchenov committed
	generalDialog->addWidget(tables);
	generalDialog->addWidget(plotsTabWidget);
	generalDialog->addWidget(plots3D);
	generalDialog->addWidget(fitPage);

	QVBoxLayout * rightLayout = new QVBoxLayout();
	lblPageHeader = new QLabel();
	QFont fnt = this->font();
	fnt.setPointSize(fnt.pointSize() + 3);
	fnt.setBold(true);
	lblPageHeader->setFont(fnt);
	lblPageHeader->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);

	QPalette pal = lblPageHeader->palette();
	pal.setColor( QPalette::Window, app->panelsColor );
	lblPageHeader->setPalette(pal);
	lblPageHeader->setAutoFillBackground( true );

	rightLayout->setSpacing(10);
	rightLayout->addWidget( lblPageHeader );
	rightLayout->addWidget( generalDialog );

	QHBoxLayout * topLayout = new QHBoxLayout();
	topLayout->setSpacing(5);
	topLayout->setMargin(5);
	topLayout->addWidget( itemsList );
	topLayout->addLayout( rightLayout );

	QHBoxLayout * bottomButtons = new QHBoxLayout();
	bottomButtons->addStretch();
	buttonApply = new QPushButton();
	buttonApply->setAutoDefault( true );
	bottomButtons->addWidget( buttonApply );

	buttonOk = new QPushButton();
	buttonOk->setAutoDefault( true );
	buttonOk->setDefault( true );
	bottomButtons->addWidget( buttonOk );

	buttonCancel = new QPushButton();
	buttonCancel->setAutoDefault( true );
	bottomButtons->addWidget( buttonCancel );

	QVBoxLayout * mainLayout = new QVBoxLayout( this );
	mainLayout->addLayout(topLayout);
	mainLayout->addLayout(bottomButtons);

	languageChange();

	// signals and slots connections
	connect( itemsList, SIGNAL(currentRowChanged(int)), this, SLOT(setCurrentPage(int)));
	connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
	connect( buttonApply, SIGNAL( clicked() ), this, SLOT( apply() ) );
	connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
	connect( buttonTextFont, SIGNAL( clicked() ), this, SLOT( pickTextFont() ) );
	connect( buttonHeaderFont, SIGNAL( clicked() ), this, SLOT( pickHeaderFont() ) );

	setCurrentPage(0);
}

void ConfigDialog::setCurrentPage(int index)
{
	generalDialog->setCurrentIndex(index);
	if(itemsList->currentItem())
		lblPageHeader->setText(itemsList->currentItem()->text());
}

void ConfigDialog::initTablesPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();
	tables = new QWidget();

	QHBoxLayout * topLayout = new QHBoxLayout();
	topLayout->setSpacing(5);

	lblSeparator = new QLabel();
	topLayout->addWidget( lblSeparator );
	boxSeparator = new QComboBox();
	boxSeparator->setEditable( true );
	topLayout->addWidget( boxSeparator );

	QString help = tr("The column separator can be customized. \nThe following special codes can be used:\n\\t for a TAB character \n\\s for a SPACE");
	help += "\n"+tr("The separator must not contain the following characters: \n0-9eE.+-");

	boxSeparator->setWhatsThis(help);
	boxSeparator->setToolTip(help);
	lblSeparator->setWhatsThis(help);
	lblSeparator->setToolTip(help);

	groupBoxTableCol = new QGroupBox();
	QGridLayout * colorsLayout = new QGridLayout(groupBoxTableCol);

	lblTableBackground = new QLabel();
	colorsLayout->addWidget( lblTableBackground, 0, 0 );
	buttonBackground= new ColorButton();
	buttonBackground->setColor(app->tableBkgdColor);
	colorsLayout->addWidget( buttonBackground, 0, 1 );

	lblTextColor = new QLabel();
	colorsLayout->addWidget( lblTextColor, 1, 0 );
	buttonText = new ColorButton();
	buttonText->setColor(app->tableTextColor);
	colorsLayout->addWidget( buttonText, 1, 1 );

	lblHeaderColor = new QLabel();
	colorsLayout->addWidget( lblHeaderColor, 2, 0 );
	buttonHeader= new ColorButton();
	buttonHeader->setColor(app->tableHeaderColor);
	colorsLayout->addWidget( buttonHeader, 2, 1 );

	groupBoxTableFonts = new QGroupBox();
	QHBoxLayout * bottomLayout = new QHBoxLayout( groupBoxTableFonts );

	buttonTextFont= new QPushButton();
	bottomLayout->addWidget( buttonTextFont );
	buttonHeaderFont= new QPushButton();
	bottomLayout->addWidget( buttonHeaderFont );

	boxTableComments = new QCheckBox();
	boxTableComments->setChecked(app->d_show_table_comments);

	boxUpdateTableValues = new QCheckBox();
	boxUpdateTableValues->setChecked(app->autoUpdateTableValues());
	
	QVBoxLayout * tablesPageLayout = new QVBoxLayout( tables );
	tablesPageLayout->addLayout(topLayout,1);
	tablesPageLayout->addWidget(groupBoxTableCol);
	tablesPageLayout->addWidget(groupBoxTableFonts);
    tablesPageLayout->addWidget(boxTableComments);
	tablesPageLayout->addWidget(boxUpdateTableValues);
	tablesPageLayout->addStretch();
}

void ConfigDialog::initPlotsPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();

	plotsTabWidget = new QTabWidget();

Roman Tolchenov's avatar
Roman Tolchenov committed

Roman Tolchenov's avatar
Roman Tolchenov committed

	initCurvesPage();

	plotsTabWidget->addTab( curves, QString() );

	plotTicks = new QWidget();
	QVBoxLayout * plotTicksLayout = new QVBoxLayout( plotTicks );

	QGroupBox * ticksGroupBox = new QGroupBox();
	QGridLayout * ticksLayout = new QGridLayout( ticksGroupBox );
	plotTicksLayout->addWidget( ticksGroupBox );

	lblMajTicks = new QLabel();
	ticksLayout->addWidget( lblMajTicks, 0, 0 );
	boxMajTicks = new QComboBox();
	ticksLayout->addWidget( boxMajTicks, 0, 1 );

	lblMajTicksLength = new QLabel();
	ticksLayout->addWidget( lblMajTicksLength, 0, 2 );
	boxMajTicksLength = new QSpinBox();
	boxMajTicksLength->setRange(0, 100);
	boxMajTicksLength->setValue(app->majTicksLength);
	ticksLayout->addWidget( boxMajTicksLength, 0, 3 );

	lblMinTicks = new QLabel();
	ticksLayout->addWidget( lblMinTicks, 1, 0 );
	boxMinTicks = new QComboBox();
	ticksLayout->addWidget( boxMinTicks, 1, 1 );

	lblMinTicksLength = new QLabel();
	ticksLayout->addWidget( lblMinTicksLength, 1, 2 );
	boxMinTicksLength = new QSpinBox();
	boxMinTicksLength->setRange(0, 100);
	boxMinTicksLength->setValue(app->minTicksLength);
	ticksLayout->addWidget( boxMinTicksLength, 1, 3 );

	ticksLayout->setRowStretch( 4, 1 );

	plotsTabWidget->addTab( plotTicks, QString() );

	plotFonts = new QWidget();
	QVBoxLayout * plotFontsLayout = new QVBoxLayout( plotFonts );

	QGroupBox * groupBox2DFonts = new QGroupBox();
	plotFontsLayout->addWidget( groupBox2DFonts );
	QVBoxLayout * fontsLayout = new QVBoxLayout( groupBox2DFonts );
	buttonTitleFont= new QPushButton();
	fontsLayout->addWidget( buttonTitleFont );
	buttonLegendFont= new QPushButton();
	fontsLayout->addWidget( buttonLegendFont );
	buttonAxesFont= new QPushButton();
	fontsLayout->addWidget( buttonAxesFont );
	buttonNumbersFont= new QPushButton();
	fontsLayout->addWidget( buttonNumbersFont );
	fontsLayout->addStretch();

	plotsTabWidget->addTab( plotFonts, QString() );

	plotPrint = new QWidget();
	QVBoxLayout *printLayout = new QVBoxLayout( plotPrint );

	boxScaleLayersOnPrint = new QCheckBox();
	boxScaleLayersOnPrint->setChecked(app->d_scale_plots_on_print);
	printLayout->addWidget( boxScaleLayersOnPrint );

	boxPrintCropmarks = new QCheckBox();
	boxPrintCropmarks->setChecked(app->d_print_cropmarks);
	printLayout->addWidget( boxPrintCropmarks );
	printLayout->addStretch();
	plotsTabWidget->addTab(plotPrint, QString());

	connect( boxResize, SIGNAL( clicked() ), this, SLOT( enableScaleFonts() ) );
	connect( boxFrame, SIGNAL( toggled(bool) ), this, SLOT( showFrameWidth(bool) ) );
	connect( buttonAxesFont, SIGNAL( clicked() ), this, SLOT( pickAxesFont() ) );
	connect( buttonNumbersFont, SIGNAL( clicked() ), this, SLOT( pickNumbersFont() ) );
	connect( buttonLegendFont, SIGNAL( clicked() ), this, SLOT( pickLegendFont() ) );
	connect( buttonTitleFont, SIGNAL( clicked() ), this, SLOT( pickTitleFont() ) );
}

void ConfigDialog::enableScaleFonts()
{
	if(boxResize->isChecked())
		boxScaleFonts->setEnabled(false);
	else
		boxScaleFonts->setEnabled(true);
}

void ConfigDialog::showFrameWidth(bool ok)
{
	if (!ok)
	{
		boxFrameWidth->hide();
		labelFrameWidth->hide();
	}
	else
	{
		boxFrameWidth->show();
		labelFrameWidth->show();
	}
}

void ConfigDialog::initPlots3DPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();
	plots3D = new QWidget();

	QGroupBox * topBox = new QGroupBox();
	QGridLayout * topLayout = new QGridLayout( topBox );
	topLayout->setSpacing(5);

	lblResolution = new QLabel();
	topLayout->addWidget( lblResolution, 0, 0 );
	boxResolution = new QSpinBox();
	boxResolution->setRange(1, 100);
	boxResolution->setValue(app->plot3DResolution);
	topLayout->addWidget( boxResolution, 0, 1 );

	boxShowLegend = new QCheckBox();
	boxShowLegend->setChecked(app->showPlot3DLegend);
	topLayout->addWidget( boxShowLegend, 1, 0 );

	boxShowProjection = new QCheckBox();
	boxShowProjection->setChecked(app->showPlot3DProjection);
	topLayout->addWidget( boxShowProjection, 1, 1 );

	boxSmoothMesh = new QCheckBox();
	boxSmoothMesh->setChecked(app->smooth3DMesh);
	topLayout->addWidget( boxSmoothMesh, 2, 0 );

	boxOrthogonal = new QCheckBox();
	boxOrthogonal->setChecked(app->orthogonal3DPlots);
	topLayout->addWidget( boxOrthogonal, 2, 1 );

	boxAutoscale3DPlots = new QCheckBox();
	boxAutoscale3DPlots->setChecked(app->autoscale3DPlots);
	topLayout->addWidget( boxAutoscale3DPlots, 3, 0 );

	groupBox3DCol = new QGroupBox();
	QGridLayout * middleLayout = new QGridLayout( groupBox3DCol );

	QStringList plot3DColors = app->plot3DColors;

	btnFromColor = new ColorButton();
	btnFromColor->setColor(QColor(plot3DColors[4]));
	middleLayout->addWidget( btnFromColor, 0, 0 );
	btnLabels = new ColorButton();
	btnLabels->setColor(QColor(plot3DColors[1]));
	middleLayout->addWidget( btnLabels, 0, 1 );
	btnMesh = new ColorButton();
	btnMesh->setColor(QColor(plot3DColors[2]));
	middleLayout->addWidget( btnMesh, 0, 2 );
	btnGrid = new ColorButton();
	btnGrid->setColor(QColor(plot3DColors[3]));
	middleLayout->addWidget( btnGrid, 0, 3 );
	btnToColor = new ColorButton();
	btnToColor->setColor(QColor(plot3DColors[0]));
	middleLayout->addWidget( btnToColor, 1, 0 );
	btnNumbers = new ColorButton();
	btnNumbers->setColor(QColor(plot3DColors[5]));
	middleLayout->addWidget( btnNumbers, 1, 1 );
	btnAxes = new ColorButton();
	btnAxes->setColor(QColor(plot3DColors[6]));
	middleLayout->addWidget( btnAxes, 1, 2 );
	btnBackground3D = new ColorButton();
	btnBackground3D->setColor(QColor(plot3DColors[7]));
	middleLayout->addWidget( btnBackground3D, 1, 3 );

	groupBox3DFonts = new QGroupBox();
	QHBoxLayout * bottomLayout = new QHBoxLayout( groupBox3DFonts );
	btnTitleFnt = new QPushButton();
	bottomLayout->addWidget( btnTitleFnt );
	btnLabelsFnt = new QPushButton();
	bottomLayout->addWidget( btnLabelsFnt );
	btnNumFnt = new QPushButton();
	bottomLayout->addWidget( btnNumFnt );

	QVBoxLayout * plots3DPageLayout = new QVBoxLayout( plots3D );
	plots3DPageLayout->addWidget(topBox);
	plots3DPageLayout->addWidget(groupBox3DCol);
	plots3DPageLayout->addWidget(groupBox3DFonts);
	plots3DPageLayout->addStretch();

	connect( btnNumFnt, SIGNAL( clicked() ), this, SLOT(pick3DNumbersFont() ) );
	connect( btnTitleFnt, SIGNAL( clicked() ), this, SLOT(pick3DTitleFont() ) );
	connect( btnLabelsFnt, SIGNAL( clicked() ), this, SLOT(pick3DAxesFont() ) );
}

void ConfigDialog::initAppPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();

	appTabWidget = new QTabWidget(generalDialog);
	appTabWidget->setUsesScrollButtons(false);

	application = new QWidget();
	QVBoxLayout * applicationLayout = new QVBoxLayout( application );
	QGroupBox * groupBoxApp = new QGroupBox();
	applicationLayout->addWidget(groupBoxApp);
	QGridLayout * topBoxLayout = new QGridLayout( groupBoxApp );

	lblLanguage = new QLabel();
	topBoxLayout->addWidget( lblLanguage, 0, 0 );
	boxLanguage = new QComboBox();
	insertLanguagesList();
	topBoxLayout->addWidget( boxLanguage, 0, 1 );

	lblStyle = new QLabel();
	topBoxLayout->addWidget( lblStyle, 1, 0 );
	boxStyle = new QComboBox();
	topBoxLayout->addWidget( boxStyle, 1, 1 );
	QStringList styles = QStyleFactory::keys();
	styles.sort();
	boxStyle->addItems(styles);
	boxStyle->setCurrentIndex(boxStyle->findText(app->appStyle,Qt::MatchWildcard));

	lblFonts = new QLabel();
	topBoxLayout->addWidget( lblFonts, 2, 0 );
	fontsBtn= new QPushButton();
	topBoxLayout->addWidget( fontsBtn, 2, 1 );

	lblScriptingLanguage = new QLabel();
	topBoxLayout->addWidget( lblScriptingLanguage, 3, 0 );
	boxScriptingLanguage = new QComboBox();
	QStringList llist = ScriptingLangManager::languages();
	boxScriptingLanguage->insertStringList(llist);
	boxScriptingLanguage->setCurrentItem(llist.findIndex(app->defaultScriptingLang));
	topBoxLayout->addWidget( boxScriptingLanguage, 3, 1 );

    lblUndoStackSize = new QLabel();
	topBoxLayout->addWidget( lblUndoStackSize, 4, 0 );
    undoStackSizeBox = new QSpinBox();
    undoStackSizeBox->setValue(app->matrixUndoStackSize());
    topBoxLayout->addWidget( undoStackSizeBox, 4, 1 );

	lblEndOfLine = new QLabel();
	topBoxLayout->addWidget(lblEndOfLine, 5, 0 );
	boxEndLine = new QComboBox();
	boxEndLine->addItem(tr("LF (Unix)"));
	boxEndLine->addItem(tr("CRLF (Windows)"));
	boxEndLine->addItem(tr("CR (Mac)"));
	boxEndLine->setCurrentIndex((int)app->d_eol);
	topBoxLayout->addWidget(boxEndLine, 5, 1);

	lblInitWindow = new QLabel();
	topBoxLayout->addWidget( lblInitWindow, 6, 0 );
	boxInitWindow = new QComboBox();
	topBoxLayout->addWidget( boxInitWindow, 6, 1 );

    boxSave= new QCheckBox();
	boxSave->setChecked(app->autoSave);
	topBoxLayout->addWidget( boxSave, 7, 0 );

	boxMinutes = new QSpinBox();
	boxMinutes->setRange(1, 100);
	boxMinutes->setValue(app->autoSaveTime);
	boxMinutes->setEnabled(app->autoSave);
	topBoxLayout->addWidget( boxMinutes, 7, 1 );

    boxBackupProject = new QCheckBox();
	boxBackupProject->setChecked(app->d_backup_files);
	topBoxLayout->addWidget( boxBackupProject, 8, 0, 1, 2 );

	boxSearchUpdates = new QCheckBox();
	boxSearchUpdates->setChecked(app->autoSearchUpdates);
	topBoxLayout->addWidget( boxSearchUpdates, 9, 0, 1, 2 );

	topBoxLayout->setRowStretch(10, 1);

	appTabWidget->addTab(application, QString());

	initConfirmationsPage();

	appTabWidget->addTab( confirm, QString() );

	appColors = new QWidget();
	QVBoxLayout * appColorsLayout = new QVBoxLayout( appColors );
	QGroupBox * groupBoxAppCol = new QGroupBox();
	appColorsLayout->addWidget( groupBoxAppCol );
	QGridLayout * colorsBoxLayout = new QGridLayout( groupBoxAppCol );

	lblWorkspace = new QLabel();
	colorsBoxLayout->addWidget( lblWorkspace, 0, 0 );
	btnWorkspace = new ColorButton();
	btnWorkspace->setColor(app->workspaceColor);
	colorsBoxLayout->addWidget( btnWorkspace, 0, 1 );

	lblPanels = new QLabel();
	colorsBoxLayout->addWidget( lblPanels, 1, 0 );
	btnPanels = new ColorButton();
	colorsBoxLayout->addWidget( btnPanels, 1, 1 );
	btnPanels->setColor(app->panelsColor);

	lblPanelsText = new QLabel();
	colorsBoxLayout->addWidget( lblPanelsText, 2, 0 );
	btnPanelsText = new ColorButton();
	colorsBoxLayout->addWidget( btnPanelsText, 2, 1 );
	btnPanelsText->setColor(app->panelsTextColor);

	colorsBoxLayout->setRowStretch( 3, 1 );

	appTabWidget->addTab( appColors, QString() );

	numericFormatPage = new QWidget();
	QVBoxLayout *numLayout = new QVBoxLayout( numericFormatPage );
	QGroupBox *numericFormatBox = new QGroupBox();
	numLayout->addWidget( numericFormatBox );
	QGridLayout *numericFormatLayout = new QGridLayout( numericFormatBox );

	lblAppPrecision = new QLabel();
	numericFormatLayout->addWidget(lblAppPrecision, 0, 0);
	boxAppPrecision = new QSpinBox();
	boxAppPrecision->setRange(0, 14);
	boxAppPrecision->setValue(app->d_decimal_digits);
	numericFormatLayout->addWidget(boxAppPrecision, 0, 1);

    lblDecimalSeparator = new QLabel();
    numericFormatLayout->addWidget(lblDecimalSeparator, 1, 0 );
	boxDecimalSeparator = new QComboBox();
	boxDecimalSeparator->addItem(tr("System Locale Setting"));
	boxDecimalSeparator->addItem("1,000.0");
	boxDecimalSeparator->addItem("1.000,0");
	boxDecimalSeparator->addItem("1 000,0");

	numericFormatLayout->addWidget(boxDecimalSeparator, 1, 1);

    boxThousandsSeparator = new QCheckBox();
    boxThousandsSeparator->setChecked(app->locale().numberOptions() & QLocale::OmitGroupSeparator);
    numericFormatLayout->addWidget(boxThousandsSeparator, 2, 0);

    boxUpdateSeparators = new QCheckBox();
    boxUpdateSeparators->setChecked(true);
    numericFormatLayout->addWidget(boxUpdateSeparators, 3, 0);
	numericFormatLayout->setRowStretch(4, 1);

	appTabWidget->addTab( numericFormatPage, QString() );

	initFileLocationsPage();

	connect( boxLanguage, SIGNAL( activated(int) ), this, SLOT( switchToLanguage(int) ) );
	connect( fontsBtn, SIGNAL( clicked() ), this, SLOT( pickApplicationFont() ) );
	connect( boxSave, SIGNAL( toggled(bool) ), boxMinutes, SLOT( setEnabled(bool) ) );
}

/**
 * Configure a Mantid page on the config dialog
 */
void ConfigDialog::initMantidPage()
{
  mtdTabWidget = new QTabWidget(generalDialog);
  mtdTabWidget->setUsesScrollButtons(false);

  instrumentPage = new QWidget();
  QVBoxLayout *instrTabLayout = new QVBoxLayout(instrumentPage);
  QGroupBox *frame = new QGroupBox();
  instrTabLayout->addWidget(frame);
  QGridLayout *grid = new QGridLayout(frame);
  mtdTabWidget->addTab(instrumentPage, QString());
  
  facility = new QComboBox();
  grid->addWidget(new QLabel("Facility"), 0, 0);
  grid->addWidget(facility, 0, 1);

  knownInstruments = new QLineEdit();
  connect(knownInstruments, SIGNAL(textChanged(const QString&)), this, SLOT(updateDefInstrList()));
  grid->addWidget(new QLabel("Instrument Prefixes"), 1, 0);
  grid->addWidget(knownInstruments, 1, 1);

  grid->addWidget(new QLabel("Default Prefix"), 2, 0);
  grid->addWidget(instrPrefix, 2, 1);
  grid->setRowStretch(3,1);

  // Populate boxes
  Mantid::Kernel::ConfigServiceImpl & mantid_config = Mantid::Kernel::ConfigService::Instance();
  QString property = QString::fromStdString(mantid_config.getString("supported.facilities"));
  
  QStringList prop_list = property.split(";", QString::SkipEmptyParts);
  facility->addItems(prop_list);

  // Set default property
  property = QString::fromStdString(mantid_config.getString("default.facility"));
  int index = facility->findText(property);
  if( index < 0 )
  {
    index = 0;
  }
  property = QString::fromStdString(mantid_config.getString("instrument.prefixes." + property.toStdString()));
  knownInstruments->setText(property);
    
  property = QString::fromStdString(mantid_config.getString("default.instrument"));
  index = instrPrefix->findText(property);
  if( index < 0 )
  {
    index = 0;
  }
  instrPrefix->setCurrentIndex(index);    
  
  directoriesPage = new QWidget();
  QVBoxLayout *dirTabLayout = new QVBoxLayout(directoriesPage);
  QGridLayout *grid = new QGridLayout(frame);
  mtdTabWidget->addTab(directoriesPage, "Directories");

  /// datasearch.directories

  QLabel* label = new QLabel(tr("Data search"));
	grid->addWidget(label, 0, 0);

  std::string str = Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories");
	leDataSearchDirs = new QLineEdit();
  leDataSearchDirs->setText(QString::fromStdString(str));
	grid->addWidget(leDataSearchDirs, 0, 1);

	QPushButton *button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 0, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addDataSearchDirs()) );

  /// defaultsave.directory
  label = new QLabel(tr("Default save"));
	grid->addWidget(label, 1, 0);

  str = Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory");
	leDefaultSaveDir = new QLineEdit();
  leDefaultSaveDir->setText(QString::fromStdString(str));
	grid->addWidget(leDefaultSaveDir, 1, 1);

	button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 1, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addDefaultSaveDir()) );

  /// pythonscripts.directories

  label = new QLabel(tr("Python scripts"));
	grid->addWidget(label, 2, 0);

  str = Mantid::Kernel::ConfigService::Instance().getString("pythonscripts.directories");
	lePythonScriptsDirs = new QLineEdit();
  lePythonScriptsDirs->setText(QString::fromStdString(str));
	grid->addWidget(lePythonScriptsDirs, 2, 1);

	button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 2, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addPythonScriptsDirs()) );

  /// pythonscripts.directories

  label = new QLabel(tr("Python algorithms"));
	grid->addWidget(label, 3, 0);

  str = Mantid::Kernel::ConfigService::Instance().getString("pythonalgorithms.directories");
	lePythonAlgorithmsDirs = new QLineEdit();
  lePythonAlgorithmsDirs->setText(QString::fromStdString(str));
	grid->addWidget(lePythonAlgorithmsDirs, 3, 1);

	button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 3, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addPythonAlgorithmsDirs()) );

  /// instrumentDefinition.directory
  label = new QLabel(tr("Instrument definitions"));
	grid->addWidget(label, 4, 0);

  str = Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory");
	leInstrumentDir = new QLineEdit();
  leInstrumentDir->setText(QString::fromStdString(str));
	grid->addWidget(leInstrumentDir, 4, 1);

	button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 4, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addInstrumentDir()) );

  /// parameterDefinition.directory
  label = new QLabel(tr("Parameter definitions"));
	grid->addWidget(label, 5, 0);

  str = Mantid::Kernel::ConfigService::Instance().getString("parameterDefinition.directory");
	leParameterDir = new QLineEdit();
  leParameterDir->setText(QString::fromStdString(str));
	grid->addWidget(leParameterDir, 5, 1);
	button = new QPushButton();
	button->setIcon(QIcon(QPixmap(choose_folder_xpm)));
	grid->addWidget(button, 5, 2);

  connect( button, SIGNAL(clicked()), this, SLOT(addParameterDir()) );
  grid->setRowStretch(6,1);
void ConfigDialog::initCurveFittingTab()
{
  curveFittingPage = new QWidget();
  QVBoxLayout *curveTabLayout = new QVBoxLayout(curveFittingPage);
  QGroupBox *frame = new QGroupBox();
  curveTabLayout->addWidget(frame);
  QGridLayout *grid = new QGridLayout(frame);
  mtdTabWidget->addTab(curveFittingPage, "Curve Fitting");

  // Background functions list
  grid->addWidget(new QLabel(tr("Auto background")),0,0);
  backgroundFunctions = new QComboBox();
  grid->addWidget(backgroundFunctions, 0, 1);

  QLabel *label = new QLabel(tr("Background arguments"));
  QString tip = tr("A space-separated list of name=value arguments, \n"
		   "i.e. a=1 b=2");
  label->setToolTip(tip);
  grid->addWidget(label,1,0);

  grid->addWidget(new QLabel(tr("Default peak shape")),2,0);
  defaultPeakShape = new QComboBox();
  grid->addWidget(defaultPeakShape, 2,1);

  grid->addWidget(new QLabel(tr("FindPeaks FWHM")),3,0);
  findPeaksFWHM = new QSpinBox();
  grid->addWidget(findPeaksFWHM, 3,1);

  grid->addWidget(new QLabel(tr("FindPeaks Tolerance")),4,0);
  findPeaksTolerance = new QSpinBox();
  grid->addWidget(findPeaksTolerance, 4,1);

  grid->setRowStretch(5,1);
  label = new QLabel("<span style=\"font-weight:600;\">Note: Changes will not take effect until MantidPlot has been restarted.</span>");
  curveTabLayout->addWidget(label);

  // Find list of background functions
  // Add none option
  backgroundFunctions->addItem("None");
  Mantid::API::FunctionFactoryImpl & function_creator = Mantid::API::FunctionFactory::Instance();
  std::vector<std::string> allfunctions = function_creator.getKeys();
  size_t nfuncs = allfunctions.size(); 
  for( size_t i = 0; i < nfuncs; ++i )
  {
    std::string name = allfunctions[i];
    Mantid::API::IFunction* function = function_creator.createUnwrapped(name);
    if( dynamic_cast<Mantid::API::IBackgroundFunction*>(function) )
    {
      backgroundFunctions->addItem(QString::fromStdString(name));
    }
    if( dynamic_cast<Mantid::API::IPeakFunction*>(function) )
    {
      defaultPeakShape->addItem(QString::fromStdString(name));
    }
  }
  
  // Set the correct default property
  QString setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("CurveFitting.AutoBackground"));
  QStringList value = setting.split(' ');
  int index(-1);
  if( value.isEmpty() )
  {
    index = 0;
  }
  else
  {
    index = backgroundFunctions->findText(value[0], Qt::MatchFixedString);// Case insensitive
    if( value.size() > 1 )
    {
      value.removeFirst();
      QString args = value.join(" ");
      functionArguments->setText(args);
    }
  }
  if( index < 0 )
  {
    backgroundFunctions->setCurrentIndex(0);
  }
  else
  {
    backgroundFunctions->setCurrentIndex(index);
  }

  setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("CurveFitting.DefaultPeak"));
  if (setting.isEmpty()) setting = "Gaussian";
  index = defaultPeakShape->findText(setting);
  if (index >= 0)
  {
    defaultPeakShape->setCurrentIndex(index);
  }

  setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("CurveFitting.FindPeaksFWHM"));
  if (!setting.isEmpty())
  {
    findPeaksFWHM->setValue(setting.toInt());
  }
  else
  {
    findPeaksFWHM->setValue(7);
  }

  setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("CurveFitting.FindPeaksTolerance"));
  if (!setting.isEmpty())
  {
    findPeaksTolerance->setValue(setting.toInt());
  }
  else
  {
    findPeaksTolerance->setValue(4);
  }

  
void ConfigDialog::initOptionsPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();

  plotOptions = new QWidget();

	QVBoxLayout * optionsTabLayout = new QVBoxLayout( plotOptions );
	optionsTabLayout->setSpacing(5);

	QGroupBox * groupBoxOptions = new QGroupBox();
	optionsTabLayout->addWidget( groupBoxOptions );

	QGridLayout * optionsLayout = new QGridLayout( groupBoxOptions );

	boxAutoscaling = new QCheckBox();
	boxAutoscaling->setChecked(app->autoscale2DPlots);
	optionsLayout->addWidget( boxAutoscaling, 0, 0 );

	boxScaleFonts = new QCheckBox();
	boxScaleFonts->setChecked(app->autoScaleFonts);
	optionsLayout->addWidget( boxScaleFonts, 0, 1 );

	boxTitle = new QCheckBox();
	boxTitle->setChecked(app->titleOn);
	optionsLayout->addWidget( boxTitle, 1, 0 );

	boxAntialiasing = new QCheckBox();
	boxAntialiasing->setChecked(app->antialiasing2DPlots);
	optionsLayout->addWidget( boxAntialiasing, 1, 1 );

	boxFrame = new QCheckBox();
	boxFrame->setChecked(app->canvasFrameWidth > 0);
	optionsLayout->addWidget( boxFrame, 2, 0 );

	labelFrameWidth = new QLabel();
	optionsLayout->addWidget( labelFrameWidth, 3, 0 );
	boxFrameWidth= new QSpinBox();
	optionsLayout->addWidget( boxFrameWidth, 3, 1 );
	boxFrameWidth->setRange(1, 100);
	boxFrameWidth->setValue(app->canvasFrameWidth);
	if (!app->canvasFrameWidth)
	{
		labelFrameWidth->hide();
		boxFrameWidth->hide();
	}

	lblMargin = new QLabel();
	optionsLayout->addWidget( lblMargin, 4, 0 );
	boxMargin= new QSpinBox();
	boxMargin->setRange(0, 1000);
	boxMargin->setSingleStep(5);
	boxMargin->setValue(app->defaultPlotMargin);
	optionsLayout->addWidget( boxMargin, 4, 1 );

	optionsLayout->setRowStretch( 7, 1 );

	boxResize = new QCheckBox();
	boxResize->setChecked(!app->autoResizeLayers);
	if(boxResize->isChecked())
		boxScaleFonts->setEnabled(false);

	optionsTabLayout->addWidget( boxResize );

  boxLabelsEditing = new QCheckBox();
  boxLabelsEditing->setChecked(!app->d_in_place_editing);
  optionsTabLayout->addWidget(boxLabelsEditing);

  plotsTabWidget->addTab( plotOptions, QString() );
}

void ConfigDialog::initAxesPage()
{
	ApplicationWindow *app = (ApplicationWindow *)parentWidget();

  plotAxes = new QWidget();

  plotsTabWidget->addTab( plotAxes, QString() );

	QGroupBox * axesGroupBox = new QGroupBox();
	QGridLayout * axisBoxLayout = new QGridLayout( axesGroupBox );

  lblXLogLin = new QLabel();
	axisBoxLayout->addWidget( lblXLogLin, 0, 0 );

  cbXLog = new QComboBox();
  cbXLog->addItem(tr("linear"));
  cbXLog->addItem("log");
  if ( app->xaxisScale == "log" )
  {
    cbXLog->setCurrentIndex(1);
  }
  else
  {
    cbXLog->setCurrentIndex(0);
  }
	axisBoxLayout->addWidget(cbXLog, 0, 1);

  lblYLogLin = new QLabel();
	axisBoxLayout->addWidget( lblYLogLin, 1, 0 );